# My personal ZSH plugin with custom aliases and functions. # It might not be very useful to you. # **** zsh options **** set -o shwordsplit # **** variables **** export EDITOR=vim export VISUAL=vim if [[ $LANG = '' ]]; then export LANG=en_US.UTF-8 fi # **** aliases **** alias c="clear" alias s="ssh" alias m="mosh --family=prefer-inet6" alias g="git" alias zz='source $HOME/.zshrc' alias vz='vim $HOME/.zshrc && source $HOME/.zshrc' alias vp='vim $ZPREZTODIR/contrib/david/zsh-david.plugin.zsh && source $ZPREZTODIR/contrib/*/*.zsh' alias vi='vim' alias v='vim' alias vv='vim $HOME/.vimrc' alias vh="sudo vim /etc/hosts; echo hosts updated" alias vs="vim ~/.ssh/config" alias serve="python2 -m SimpleHTTPServer" alias push="git push origin main" alias pull="git pull origin main" alias commit="git commit -a" #alias aec="sshuttle -vvr 90.146.8.233 192.168.6.0/24 90.146.8.0/26 10.9.0.0/26 10.12.0.0/16 10.2.0.0/26 192.168.3.0/24 10.12.4.0/22 192.168.42.0/24" #alias home="sshuttle -vvr stargazer.socialnerds.org:2222 10.1.0.0/16" #alias dmz="sshuttle -vvr 90.146.8.9 90.146.8.0/26" alias cleardnscache="sudo killall -HUP mDNSResponder; sudo dscacheutil -flushcache; say DNS cache has been cleared" alias vc="code -n ." #alias ls='ls --color=auto' #does not work on macos alias wg='sudo wg' alias pacman='sudo pacman' alias pacu='sudo pacman -Syu --noconfirm' alias {systemctl,sc}='sudo systemctl' alias {journalctl,jc}='sudo journalctl' alias {myip,myip4}="curl http://4.ifconfig.pro" alias myip6="curl http://6.ifconfig.pro" alias {a,apt}="sudo apt" alias {u,ufw}="sudo ufw" alias dc="docker compose" alias d="docker" alias {vanity,vanity-address}="docker run --rm -it socialnerds/wg-vanity-address:latest --in 5" # **** function definitions **** ## output handling log() { case $1 in "error") level="\033[31m✗\033[0m" ;; "warn") level="\033[33m!\033[0m" ;; "debug") level="\033[2md\033[0m" ;; "success") level="\033[32m✓\033[0m" ;; "info") level="i" ;; *) level="\033[31mLoglevel unknown. Programming error? ($1)\033[0m" ;; esac sleep 0.5; echo -e "[$level] ${@:2}" } ## Update systems packages update() { bold=$(tput bold) normal=$(tput sgr0) if [ "$(uname)" = "Darwin" ]; then log info "macOS detected. Using ${bold}brew${normal} to update packages." brew update && brew upgrade if [ $? -eq 0 ]; then log success "All packages up-to-date." else log error "Something went wrong while running brew." fi else #if not Darwin then its probably Linux systems="ubuntu arch raspbian antergos elementary" issue="$(cat /etc/issue)" for item in $systems; do echo $issue | grep -i $item >> /dev/null if [ $? -eq 0 ]; then system=$item fi done case $system in ubuntu|debian|raspbian|elementary) log info "Debian based system detected. Using ${bold}apt${normal} to update packages." sudo apt update && sudo apt dist-upgrade -y && sudo apt autoremove -y && sudo apt autoclean -y if [ $? -eq 0 ]; then log success "All packages up-to-date." else log error "Something went wrong while running ${bold}apt${normal}." fi ;; arch|antergos) log info "Arch Linux detected. Using ${bold}pacman${normal} to update packages." sudo pacman -Syu --noconfirm if [ $? -eq 0 ]; then log success "All packages up-to-date." else log error "Something went wrong while running ${bold}pacman${normal}." fi ;; ?) log error "Unknown system. Aborting." return 1 ;; esac if [ $? -ne 0 ]; then echo "error: something went wrong." return 1 fi fi } ## update authorized_keys update-keys() { local SSH_PATH="$HOME/.ssh" local SSH_KEYS="$SSH_PATH/authorized_keys" local KEYS_URL="https://public.socialnerds.org/ssh/$USER.pub" if [ ! -d $SSH_PATH ]; then mkdir -p $SSH_PATH log warn "Created new config folder [$SSH_PATH]" fi chmod 700 $SSH_PATH log info "Downloading updated authorized_keys file. [$SSH_KEYS]" curl -s -u "$USER" -o "$SSH_KEYS" "$KEYS_URL" if [ $? -eq 0 ]; then chmod 600 $SSH_KEYS log success "Successfully updated authorized_keys file. [$SSH_KEYS]" else log error "Something went wrong while updating authorized_keys file. [$SSH_KEYS]" fi }