1
1
Fork 0
zsh-david/zsh-david.plugin.zsh

183 lines
4.8 KiB
Bash
Raw Normal View History

2018-05-11 13:06:49 +02:00
# My personal ZSH plugin with custom aliases and functions.
2019-11-18 10:14:01 +01:00
# It might not be very useful to you.
2018-05-11 13:06:49 +02:00
2018-05-13 16:13:14 +02:00
# **** zsh options ****
2018-05-11 13:06:49 +02:00
set -o shwordsplit
2023-06-26 22:24:44 +02:00
setopt HIST_IGNORE_SPACE
2018-05-11 13:06:49 +02:00
2023-09-19 19:43:25 +02:00
# **** am i macos? ****
#if [ "$(uname)" == "Darwin" ]; then
#else
#fi
# **** variables ****
2023-09-19 19:43:25 +02:00
if $(command -v helix > /dev/null); then
export EDITOR=helix
elif $(command -v hx > /dev/null); then
export EDITOR=hx
else
export EDITOR=vim
fi
export VISUAL=$EDITOR
if [[ $LANG = '' ]]; then
export LANG=en_US.UTF-8
fi
# **** aliases ****
alias c="clear"
alias s="ssh"
2021-10-14 20:49:48 +02:00
alias m="mosh --family=prefer-inet6"
alias g="git"
2018-05-13 16:13:14 +02:00
alias zz='source $HOME/.zshrc'
2023-09-19 19:43:25 +02:00
alias vz='$EDITOR $HOME/.zshrc && source $HOME/.zshrc'
alias vp='$EDITOR $ZPREZTODIR/contrib/david/zsh-david.plugin.zsh && source $ZPREZTODIR/contrib/*/*.zsh'
2023-09-19 19:45:32 +02:00
alias {v,vi,vim,e}='$EDITOR'
2023-09-19 19:43:25 +02:00
alias vv='$EDITOR $HOME/.vimrc'
alias vh="sudo $EDITOR /etc/hosts; echo hosts updated"
alias vs="$EDITOR ~/.ssh/config"
2018-05-11 13:06:49 +02:00
alias serve="python2 -m SimpleHTTPServer"
alias push="git push origin main"
alias pull="git pull origin main"
2018-05-11 13:06:49 +02:00
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"
2023-04-05 22:22:17 +02:00
alias vc="code -n ."
2018-05-11 13:06:49 +02:00
alias {systemctl,sc}='sudo systemctl'
2021-10-14 20:49:48 +02:00
alias {journalctl,jc}='sudo journalctl'
2018-05-11 13:06:49 +02:00
alias {myip,myip4}="curl http://4.ifconfig.pro"
alias myip6="curl http://6.ifconfig.pro"
2023-06-26 22:28:14 +02:00
alias wg='sudo wg'
alias {p,pacman}='sudo pacman'
alias {pu,pacu}='sudo pacman -Syu --noconfirm'
alias {pi,paci}='sudo pacman -S --noconfirm'
2021-08-25 20:36:27 +02:00
alias {a,apt}="sudo apt"
2023-06-26 22:28:14 +02:00
alias {ai,apti}="sudo apt install"
alias {au,aptu}="sudo apt update"
2021-10-14 20:49:48 +02:00
alias {u,ufw}="sudo ufw"
2018-05-11 13:06:49 +02:00
alias dc="docker compose"
2023-04-05 22:22:17 +02:00
alias d="docker"
alias {vanity,vanity-address}="docker run --rm -it socialnerds/wg-vanity-address:latest --in 5"
2023-06-26 22:24:44 +02:00
# Multipass
alias mp="multipass"
alias {phobos,pho}="multipass shell phobos"
2018-05-13 16:13:14 +02:00
# **** function definitions ****
## output handling
2019-11-17 18:53:27 +01:00
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
2018-05-13 16:13:14 +02:00
if [ $? -eq 0 ]; then
log success "All packages up-to-date."
else
log error "Something went wrong while running brew."
2018-05-13 16:13:14 +02:00
fi
else
#if not Darwin then its probably Linux
systems="ubuntu arch raspbian antergos elementary manjaro"
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|manjaro)
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."
2018-05-13 16:13:14 +02:00
return 1
fi
2018-05-13 16:13:14 +02:00
fi
2018-05-11 13:06:49 +02:00
}
## 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
}
2019-11-17 18:02:13 +01:00