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

181 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
# **** aliases ****
2018-05-13 16:13:14 +02:00
alias zz='source $HOME/.zshrc'
2019-11-17 18:22:45 +01:00
alias {update_zsh,zu}='echo "LAST_EPOCH=0" > $ZSH_CACHE_DIR/.zsh-custom-update > $ZSH_CACHE_DIR/.zsh-update; source $HOME/.zshrc'
2018-05-13 16:13:14 +02:00
alias vz='vim $HOME/.zshrc && source $HOME/.zshrc'
2019-11-17 18:10:47 +01:00
alias vp='vim $ZSH_CUSTOM/plugins/zsh-david/zsh-david.plugin.zsh && source $HOME/.zshrc; echo "if you made changes please push to master with vu"'
2020-11-16 23:31:15 +01:00
alias vd='vim $HOME/.zprezto-contrib/zsh-david/zsh-david.plugin.zsh'
2019-11-17 17:52:52 +01:00
alias vu='cd $ZSH_CUSTOM/plugins/zsh-david; git commit -am "plugin update" && git push origin master; cd -'
2018-05-11 13:06:49 +02:00
alias vi='vim'
alias v='vim'
2018-05-13 16:13:14 +02:00
alias vv='vim $HOME/.vimrc'
2020-01-25 00:15:01 +01:00
alias vh="sudo vim /etc/hosts; echo hosts updated"
2020-01-25 00:19:07 +01:00
alias s="ssh"
alias m="mosh"
2018-05-11 13:06:49 +02:00
alias serve="python2 -m SimpleHTTPServer"
alias push="git push origin master"
alias pull="git pull origin master"
alias commit="git commit -a"
2019-06-26 19:31:48 +02:00
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"
2018-05-11 13:06:49 +02:00
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 c="clear"
#alias cleardnscache="sudo killall -HUP mDNSResponder; sudo killall mDNSResponderHelper; sudo dscacheutil -flushcache; say DNS cache has been cleared"
alias cleardnscache="sudo killall -HUP mDNSResponder; sudo dscacheutil -flushcache; say DNS cache has been cleared"
2018-05-11 13:06:49 +02:00
#alias ls='ls --color=auto' #does not work on macos
2018-05-11 13:06:49 +02:00
alias pacrepo='sudo reflector -l 20 -f 10 --save /etc/pacman.d/mirrorlist'
alias pacman='sudo pacman'
alias journalctl='sudo journalctl'
alias pacu='sudo pacman -Syu --noconfirm'
alias auru='yaourt -Syua --noconfirm'
alias systemctl='sudo systemctl'
alias se='ls /usr/bin | grep'
2018-05-13 16:13:14 +02:00
# **** variables ****
2018-05-11 13:06:49 +02:00
export EDITOR=vim
if [[ $LANG = '' ]]; then
2018-05-13 16:13:14 +02:00
export LANG=en_US.UTF-8
2018-05-11 13:06:49 +02:00
fi
2018-05-13 16:13:14 +02:00
# **** function definitions ****
2019-11-17 18:53:27 +01:00
## 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}"
}
# setup user accounts on linux systems
# update them if existing
# ? delete them
# add authorized_keys
2019-11-17 18:53:27 +01:00
setup_user() {
if [ $1 ]; then
log info "setting up account for $1"
#TODO: do the groups exist beforehand?
useradd -m -d /home/$1 -G "sudo sshusers docker" $1
if [ $? -ne 0 ]; then
log error "error while creating user ($1)"
fi
2019-11-17 18:53:27 +01:00
else
log error "no username given"
return 1
fi
}
2018-05-13 16:13:14 +02:00
## RDP client
rdp() {
2018-05-13 16:13:14 +02:00
if [ -z $1 ]; then
echo -e "server: \c"
read server
else
server=$1
fi
echo -e "username [davidadm]: \c"
read username
if [ -z $username ]; then
username="davidadm"
fi
echo -e "domain [aec.at]: \c"
read domain
if [ -z $domain ]; then
domain="aec.at"
fi
which rdesktop >/dev/null
if [ $? -eq 0 ]; then
#rdesktop -u $username -p - -d $domain -g 1366x768 $server -k de
rdesktop -K -u $username -p - -d $domain -g workarea $server -k de
else
which xfreerdp >/dev/null
2018-05-11 13:06:49 +02:00
if [ $? -eq 0 ]; then
2018-05-13 16:13:14 +02:00
#xfreerdp +clipboard /v:$server /u:$username /d:$domain /size:1920x1080
xfreerdp /v:$server /u:$username /d:$domain /size:1366x768 -wallpaper:on
2018-05-11 13:06:49 +02:00
else
2018-05-13 16:13:14 +02:00
echo "error: no rdp client found"
return 1
2018-05-11 13:06:49 +02:00
fi
2018-05-13 16:13:14 +02:00
fi
2018-05-11 13:06:49 +02:00
}
## OS upgrade for various systems
update() {
2018-05-13 16:13:14 +02:00
systems="ubuntu arch solus raspbian antergos"
issue="$(cat /etc/issue)"
for item in $systems; do
echo $issue | grep -i $item >> /dev/null
if [ $? -eq 0 ]; then
system=$item
2018-05-13 16:13:14 +02:00
fi
done
case $system in
ubuntu|debian|raspbian)
echo "Updating Ubuntu/Debian.."
sudo apt update && sudo apt dist-upgrade -y && sudo apt autoremove -y && sudo apt autoclean -y
2018-05-13 16:13:14 +02:00
;;
arch|antergos)
echo "Updating Arch Linux.."
sudo pacman -Syu
;;
solus)
echo "Updating Solus OS.."
sudo eopkg update-repo && sudo eopkg upgrade
;;
?)
echo "error: unknown system."
return 1
;;
esac
2018-05-13 16:13:14 +02:00
if [ $? -ne 0 ]; then
echo "error: something went wrong."
return 1
fi
2018-05-11 13:06:49 +02:00
}
2018-05-13 16:13:14 +02:00
## Thinkpad Trackpoint input fix (for for thinkpad x131e/chromebook)
#fixtrackpoint() {
2019-11-17 18:02:13 +01:00
# xinput set-prop "TPPS/2 IBM TrackPoint" "Evdev Wheel Emulation" 1
# xinput set-prop "TPPS/2 IBM TrackPoint" "Evdev Wheel Emulation Button" 2
# xinput set-prop "TPPS/2 IBM TrackPoint" "Evdev Wheel Emulation Timeout" 200
# xinput set-prop "TPPS/2 IBM TrackPoint" "Evdev Wheel Emulation Axes" 6 7 4 5
# xinput set-prop "TPPS/2 IBM TrackPoint" "Device Accel Constant Deceleration" 0.75
#}