# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

export ZSH="/root/.oh-my-zsh"
PATH=/snap/bin:/usr/sbin:/sbin:/usr/local/sbin:$PATH
export LC_ALL="en_US.UTF-8"
ZSH_THEME="aussiegeek"
plugins=(
  zsh-syntax-highlighting
  zsh-autosuggestions
)
source $ZSH/oh-my-zsh.sh
alias sync="rsync -avz -e 'ssh -p1079'"
alias udemydl="youtube-dl -u malin@cenusa.me -o '%(playlist)s/%(chapter_number)s - %(chapter)s/%(playlist_index)s. %(title)s.%(ext)s'"
alias clmac="find ./ -name '._*' -o -name '.DS_Store' -o -name '.apdisk' -o -name '.lyndisk' | sed 's/.*/\"&\"/' | xargs rm -rfv"
alias cpwp="cp -a /root/wordpress/* ."
alias fixow="chown -R nobody:nogroup ./"
alias wpht="cat /root/.htaccess >> ./.htaccess"
alias fixwp="cpwp && wpht && fixow"
alias goup="apt update && apt upgrade -y && apt autoremove && apt dist-upgrade -y"
alias flt="mkdir $1{files,tmp,log}"
alias wssl="wget --no-check-certificate"
alias wrip="wget -r -nc -np"
alias move="rsync -avz --remove-source-files --progress"
alias wbulk="wget --content-disposition -c -N --tries=0 --read-timeout=20 -q --show-progress"
alias mp3rip="youtube-dlc --restrict-filenames --extract-audio --audio-format mp3"
alias cleancrap="find ./ -type f -regex '.*\.exe\|.*\.diz\|.*\.nfo\|.*\.txt\|.*\.url\|.*\.nzb\|.*\.torrent' -exec rm -rfv {} \;"
alias license="/usr/local/cpanel/cpkeyclt"

editz() {
pdnsutil edit-zone $1
        }

createz() {
        pdnsutil create-zone $1
        }

push() {
        for i in {1..10}
                do
                        pdnsutil increase-serial $1
                        pdns_control notify $1
        done
}

sslcert() {
        certbot certonly --webroot -w /home/www/$1/files -d $1 -d www.$1 -d cdn.$1
}

wban() {
  fail2ban-client set wordpress banip $1
}

flickr() {
  ruby flickr-photo-downloader.rb $1 -d /flickr/$2
}

weather() {
  curl "wttr.in/${1:-vilafranca de bonany}?m"
}

resolve() {
        dig +short $1 $2
}

ns12() {
        echo -n 'NS1: '; dig +short $1 @ns1.palmasolutions.net
        echo -n 'NS2: '; dig +short $1 @ns2.palmasolutions.net
}

ttfb() {
        curl -s -w 'Testing Website Response Time for :%{url_effective}\n\nLookup Time:\t\t%{time_namelookup} seconds\nConnect Time:\t\t%{time_connect} seconds\nAppCon Time:\t\t%{time_appconnect} seconds\nRedirect Time:\t\t%{time_redirect} seconds\nPre-transfer Time:\t%{time_pretransfer} seconds\nStart-transfer Time:\t%{time_starttransfer} seconds\n\nTotal Time:\t\t%{time_total}\n' -o /dev/null https://$1
}

lcheck() {
        latency=`ttfb $1 | grep Total | cut -f3-`
        if (( $(bc -l <<< "$latency >= 1") ));
                then
                echo -n $1; echo -n ' > lag > '; echo $latency
                else
                echo -n $1; echo -n ' > no lag > '; echo $latency
        fi
}

pwg() {
    printf "%s" "$(tr -cd '[:graph:]' < /dev/urandom | tr -d '\-#&\+,\.\/\:\`\"'\' | head -c"${1:-32}")";
};

getpings() {
        for i in $(cat /root/sites);
                do lcheck $i;
        done
}

alias dfd='df -h | grep -e "/dev/sd" -e "Filesystem" --color=never'

login() {
        ssh root@$i -p 1079
}

wlfw() {
        ufw allow from $1 to any port $2 proto $3 comment "$4"
}

inst() {
        apt install $1 -y
}

ripw() {
        wget -r -np -nc --tries=0 --reject iso,exe,html,htm,nfo,nzb,torrent --read-timeout=20 --no-check-certificate -q --show-progress $1
}

# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
