dotfiles

*nix config files
git clone git://git.pyratebeard.net/dotfiles.git
Log | Files | Refs | README

aliases.zsh (13371B)


      1 #                 ██
      2 #                ░██
      3 #  ██████  ██████░██
      4 # ░░░░██  ██░░░░ ░██████
      5 #    ██  ░░█████ ░██░░░██
      6 #   ██    ░░░░░██░██  ░██
      7 #  ██████ ██████ ░██  ░██
      8 # ░░░░░░ ░░░░░░  ░░   ░░
      9 # s h e l l  a l i a s e s
     10 #
     11 #  author ▓▒ pyratebeard
     12 #    code ▓▒ https://git.pyratebeard.net/dotfiles/file/zsh/.zsh/aliases.zsh.html
     13 # colours
     14 red="\e[31m"
     15 green="\e[32m"
     16 reset="\e[0m"
     17 
     18 # ▓▓▒░ root
     19 # check for doas so aliases can be used on different systems
     20 # add whitespace for hack to make aliases woth with {sudo,doas}
     21 command -v doas >/dev/null && \
     22     alias sudo='doas ' || \
     23     alias sudo='sudo '
     24 
     25 # ▓▓▒░ unix
     26 # openbsd's ls(1) doesn't provide the `--color` option.
     27 # i have grown to like this and spent a long time
     28 # trying to find a work around, but none exists tiko.
     29 # so i succumbed to installing coreutils and doing this
     30 command -v gls >/dev/null && \
     31     alias ls="gls -hF --color=auto" || \
     32     alias ls="ls -hF --color=auto"
     33 
     34 # i also need dircolors(1) from coreutils for zsh autocompletion
     35 command -v gdircolors >/dev/null && alias dircolors="gdircolors"
     36 
     37 # i make use of some funky shit in my log makefiles
     38 # which isn't possible using the openbsd make(1)
     39 command -v gmake >/dev/null && alias make='gmake'
     40 
     41 
     42 # ▓▓▒░ sys
     43                                                                         alias \
     44     ll="ls -lahF --color=auto"                                                \
     45     lsl="ls -lhF --color=auto"                                                \
     46     llrt="ls -lahFrt --color=auto"                                            \
     47                                                                               \
     48     cp="cp -r"                                                                \
     49     rmrf="rm -rf"                                                             \
     50     scp="scp -r"                                                              \
     51                                                                               \
     52     up="cd ../"                                                               \
     53     mkdir="mkdir -p"                                                          \
     54                                                                               \
     55     xsel="xsel -b"                                                            \
     56     fuck='sudo $(fc -ln -1)'                                                  \
     57     dd="dd status=progress"                                                   \
     58                                                                               \
     59     term="urxvtc -hold -e "                                                   \
     60                                                                               \
     61     reboot="sudo reboot"                                                      \
     62     systemctl="sudo systemctl"
     63 
     64 
     65 # ▓▓▒░ info
     66                                                                         alias \
     67     psef="ps -ef"                                                             \
     68     jobs="jobs -l"                                                            \
     69     \?is="whereis"                                                            \
     70     history="history -i"                                                      \
     71     disks='echo "┌──┄";echo "├┄ m o u n t . p o i n t s"; echo "└──┄┄────┄┄"; lsblk -a; echo ""; echo "┌──┄";echo "├┄ d i s k . u s a g e"; echo "└──┄┄────┄┄"; sudo df -h -x tmpfs -x devtmpfs;' \
     72     ag="ag --color --color-line-number '0;35' --color-match '46;30' --color-path '4;36'" \
     73     tree='tree -CAFa -I "CVS|*.*.package|.svn|.git|.hg|node_modules|bower_components" --dirsfirst'
     74 
     75 
     76 # ▓▓▒░ almighty text editor
     77                                                                         alias \
     78     v="nvim"                                                                   \
     79     vi="nvim"                                                                  \
     80     emacs="nvim"
     81 
     82 
     83 # ▓▓▒░ git
     84                                                                         alias \
     85     g="git"                                                                   \
     86     ga="git add"                                                              \
     87     gb="git branch"                                                           \
     88     gc="git commit -S -m"                                                     \
     89     gs="git status -sb"                                                       \
     90     gd="git diff"                                                             \
     91     gf="git fetch && git log --pretty=format:'%C(always,yellow)%h%Creset %s %Cred%d' ..@{u}" \
     92     gm="git merge"                                                            \
     93     gr="git rebase"                                                           \
     94     gp="git push"                                                             \
     95     gu="git unstage"                                                          \
     96     gg="git log --graph"                                                      \
     97     gco="git checkout"                                                        \
     98     gsm="git status -sbuno"                                                   \
     99     gpr="git request-pull"                                                    \
    100     ggg="git graphgpg"
    101 
    102     gcl() {
    103         git clone "${@}"
    104         test -n "${2}" && _dir=${2} || _dir=${1##*/}
    105         cd ${_dir%.git}
    106     }
    107 
    108 
    109 # ▓▓▒░ pacman
    110                                                                         alias \
    111     pac="sudo pacman"                                                         \
    112     pacman="sudo pacman"                                                      \
    113     update="sudo paccache -r ; pacman -S --noconfirm archlinux-keyring ; pacman -Syu"
    114 
    115 
    116 # ▓▓▒░ net
    117                                                                         alias \
    118     ss="sudo ss"                                                              \
    119     netctl="sudo netctl"                                                      \
    120     openvpn="sudo openvpn"                                                    \
    121     # need ot find a better way to do this
    122     #iip="ip a s $(ip r | grep default | grep -oP '(?<=dev )[^ ]*')"           \
    123     failover="sudo ip link set enp5s0 down"                                   \
    124     failback="sudo ip link set enp5s0 up"
    125 
    126 
    127 # ▓▓▒░ devops
    128                                                                         alias \
    129     ap="ansible-playbook"                                                     \
    130                                                                               \
    131     lxc-ls="lxc-ls -f"                                                        \
    132     lxls="lxc-ls -f"                                                          \
    133     lxst="lxc-start"                                                          \
    134     lxsp="lxc-stop"                                                           \
    135     lxat="lxc-attach"                                                         \
    136                                                                               \
    137     docker="sudo docker"                                                      \
    138     docker-compose="sudo docker-compose"                                      \
    139     dtail="docker logs -tf --tail='50'"                                       \
    140     dps="docker ps"                                                           \
    141     dpsa="docker ps -a"                                                       \
    142     dstart="docker start"                                                     \
    143     dstop="docker stop"                                                       \
    144     drm="docker rm"                                                           \
    145     drmi="docker rmi"                                                         \
    146     dcomp="docker-compose -f ./docker-compose.yml"                            \
    147                                                                               \
    148     tf="terraform"                                                            \
    149     tfi="terraform init"                                                      \
    150     tfa="terraform apply --auto-approve"                                      \
    151     tfp="terraform plan"                                                      \
    152     tfd="terraform destroy"                                                   \
    153                                                                               \
    154     kc="KUBECONFIG=./kubeconfig.yml kubectl"
    155 
    156 
    157 # ▓▓▒░ recording
    158 
    159                                                                         alias \
    160     record="ffmpeg -f x11grab -s 1366x768 -an -r 16 -loglevel quiet -i :0.0 -b:v 5M -y"
    161 
    162     # record the primary screen
    163     screencast() {
    164         test $1 && NAME=$1 || NAME="screencast"
    165         RESOLUTION=$(xrandr | grep "*" | awk '{print $1}' | head -n1)
    166         echo "recording to ${HOME}/lib/videos/recordings/screencasts/$(date +%Y%m%d)-${NAME}.webm"
    167         ffmpeg -f x11grab -s ${RESOLUTION} -an -r 16 -loglevel quiet -i :0.0 -b:v 5M -y ${HOME}/lib/videos/recordings/screencasts/$(date +%Y%m%d)-${NAME}.webm
    168     }
    169 
    170     # take picture with webcam
    171     webcapture() {
    172         NUM=$(ls -l $HOME/tmp/*webcapture*|wc -l)
    173         NUM=$(( NUM + 1 ))
    174         ffmpeg -f video4linux2 -s 640x480 -i /dev/video0 -ss 0:0:2 -frames 1 $HOME/tmp/$(date +%Y%m%d)-webcapture-${NUM}.png
    175     }
    176 
    177 
    178 # ▓▓▒░ suffix
    179                                                                      alias -s \
    180     md=nvim                                                                    \
    181     {png,jpg,jpeg}=sxiv                                                       \
    182     pdf=zathura                                                               \
    183     mp4=mpv
    184 
    185 
    186 # ▓▓▒░ misc
    187                                                                         alias \
    188     mixer="alsamixer"                                                         \
    189     news="newsboat"                                                           \
    190     gifview="gifview -a"                                                      \
    191                                                                               \
    192     headsetbatt="bluetooth_battery 34:DF:2A:5F:04:2C"                         \
    193     headset="echo 'connect 34:DF:2A:5F:04:2C' | bluetoothctl"                 \
    194     bton="echo 'power on' | bluetoothctl"                                     \
    195     btoff="echo 'power off' | bluetoothctl"                                   \
    196                                                                               \
    197     nodisturb="dunstctl set-paused true"                                      \
    198     disturb="dunstctl set-paused false"                                       \
    199                                                                               \
    200     sacc="PAGER=less sacc"                                                    \
    201     gopher="PAGER=less sacc g.nixers.net/1/~pyratebeard/startpage.gph"        \
    202     buku="buku --np"                                                          \
    203     tin="NNTPSERVER=eu.newsdemon.com ~/.local/src/warez/tin/tin-latest/src/tin -r -A"\
    204     drawterm="drawterm -h 9p.sdf.org -a 9p.sdf.org -u pyratebeard"            \
    205                                                                               \
    206     kb="keybase"                                                              \
    207     irc="mosh irclient -- ksh -c 'dtach -A /tmp/irc irssi'"                   \
    208     feh="feh -g 640x480"                                                      \
    209     rum.sh="nc rum.sh 9999"                                                   \
    210     moebius="cd $HOME/.local/src/warez/moebius ; /usr/bin/npm start"                 \
    211     cointop="$HOME/.local/src/go/bin/cointop --hide-statusbar"
    212 
    213 # ▓▓▒░ fun(ctions)
    214 
    215     email() {
    216       echo $3 | mutt -s $2 $1
    217     }
    218 
    219     # connect to tmux on ssh
    220     # host autocomplete - $HOME/.zsh/completion/_ssux
    221     ssux() {
    222         test $# -gt 0 && SYSTEM="$@" || SYSTEM=$(tmux list-windows | awk '/*/{print $2}' | tr -d '*')
    223         TERM=screen ssh -t "${SYSTEM}" 'tmux attach || tmux new' || ssh "${SYSTEM}"
    224     }
    225 
    226     # sets terminal title
    227     # useful for unhide (~/.interrobangrc:39)
    228     title() {
    229         printf "\033]2;${1}\007"
    230     }
    231 
    232     # read markdown files like manpages
    233     md() {
    234         pandoc -s -f markdown -t man "$*" | man -l -
    235     }
    236 
    237     # read webpage as manpage
    238     webman() {
    239         curl -L "$@" | pandoc -s -f html -t man | man -l -
    240     }
    241 
    242     # read anything as manpage
    243     nam() {
    244         pandoc -s -t man "$*" | man -l -
    245     }
    246 
    247     mkcd() {
    248         mkdir -p "$1" && cd "$1"
    249     }
    250 
    251     :q!() {
    252         [[ -v SSH_TTY ]] && echo dumpshock || {
    253             ping -q -c1 pigley >/dev/null 2>&1 && {
    254                 echo -e "${red}lab still online${reset}"
    255                 vared -p 'shutdown? [Y/n]: ' -c sdwn
    256                 case ${sdwn} in
    257                     y|Y) lab down ;;
    258                     n) ;;
    259                     *) lab down ;;
    260                 esac
    261             } || echo -e "${green}lab offline${reset}"
    262             rm -f /tmp/tmux.lock
    263             sudo halt -p
    264         }
    265     }