dotfiles

My dotfiles, nothing really interesting to see ...
git clone https://git.onna.be/dotfiles.git
Log | Files | Refs | README

aliases.zsh (8377B)


      1 alias open="xdg-open"
      2 alias ls='ls -F'
      3 alias lst='ls -latr'
      4 alias cp='cp -v'
      5 alias tm='tmux attach'
      6 alias info='info --vi-keys' # GNU info act like man command
      7 alias figletfonts='ls -1 `figlet -I2` | grep "\.flf$" | cut -f 1 -d "." | sort -u'
      8 alias gpg='gpg2'
      9 alias lsalias='printf "%s\n" "${(k)aliases[@]}" | sort'
     10 alias lsbuiltins='printf "%s\n" "${(k)builtins[@]}" | sort'
     11 alias lscommands='printf "%s\n" "${(k)commands[@]}" | sort'
     12 alias lsfunctions='printf "%s\n" "${(k)functions[@]}" | sort'
     13 command -v ncdu > /dev/null && alias pdu='ncdu --color dark -rr'
     14 command -v nvim > /dev/null && alias vim='nvim'
     15 command -v neomutt > /dev/null && alias mutt='neomutt'
     16 if command -v task > /dev/null ; then
     17     alias cal='task calendar'
     18     alias t='task'
     19 fi
     20 
     21 CLIP_COMMAND="xclip -f -selection clipboard"
     22 
     23 MYOS=$(uname)
     24 if [[ "$MYOS" == "Linux" ]]; then
     25     alias ls='ls -F --color'
     26     alias cal='cal -3'
     27     alias tree='tree -C'
     28 fi
     29 
     30 if [[ "$MYOS" == "Darwin" ]]; then
     31     alias cal='cal -3'
     32     alias tree='tree -C'
     33     alias htpasswd-openssl="openssl passwd -apr1"
     34     CLIP_COMMAND="pbcopy"
     35 fi
     36 
     37 if command -v docker > /dev/null ; then
     38     alias d='docker'
     39     alias dps='docker ps -a'
     40     alias dim='docker images'
     41     alias dex='docker exec -ti'
     42     alias drun='docker run --rm'
     43     alias dpull='docker pull'
     44     alias dpush='docker push'
     45     alias dclean='docker system prune -af'
     46     alias ddf='docker system df'
     47 fi
     48 
     49 if command -v kubectl > /dev/null ; then
     50     alias k='kubectl'
     51     alias kg='kubectl get'
     52     alias kgdep='kubectl get deployment'
     53     alias kgsvc='kubectl get service'
     54     alias kging='kubectl get ingress'
     55     alias kgcm='kubectl get configmap'
     56     alias kgsec='kubectl get secret'
     57     alias kd='kubectl describe'
     58     alias ka='kubectl apply -f'
     59     alias krm='kubectl delete'
     60     alias kex='kubectl exec -i -t'
     61     alias kedep='kubectl edit deployment'
     62     alias kecm='kubectl edit configmap'
     63     alias ktopn='kubectl top node'
     64 fi
     65 
     66 if command -v gcloud > /dev/null ; then
     67     alias gcil='gcloud compute instances list'
     68     alias gcssh='gcloud compute ssh'
     69     alias gcscp='gcloud compute scp'
     70     alias Sprod='gcloud config configurations activate prod'
     71     alias Sstg='gcloud config configurations activate default'
     72 fi
     73 
     74 g() {
     75     if (( $# == 0 )); then
     76         git st
     77     else
     78         git "$@"
     79     fi
     80 }
     81 
     82 # most used config files fast access
     83 cfg-nvim() { $EDITOR $HOME/.config/nvim/init.vim }
     84 cfg-ranger() { $EDITOR $HOME/.config/ranger/rc.conf }
     85 cfg-ranger-rifle() { $EDITOR $HOME/.config/ranger/rifle.conf }
     86 cfg-ranger-commands() { $EDITOR ~/.config/ranger/commands.py }
     87 cfg-zsh() { $EDITOR $HOME/.zshrc }
     88 cfg-zsh-alias() { $EDITOR $HOME/.zsh/aliases.zsh }
     89 cfg-mutt() { $EDITOR $HOME/.muttrc }
     90 cfg-tmux() { $EDITOR $HOME/.tmux.conf }
     91 cfg-ssh() { $EDITOR $HOME/.ssh/config }
     92 cfg-ssh-authorized-keys() { $EDITOR $HOME/.ssh/authorized_keys }
     93 cfg-ssh-known-hosts() { $EDITOR $HOME/.ssh/known_hosts }
     94 
     95 # directory definitions
     96 s=$HOME/src
     97 sp=$HOME/src/github.com/WelcomingGroup
     98 so=$HOME/src/git.onna.be
     99 sg=$HOME/src/galadriel
    100 Sp=$HOME/Sync/powerspace
    101 S=$HOME/Sync
    102 M=$HOME/Mobile
    103 d=$HOME/Documents
    104 D=$HOME/Downloads
    105 f=/mnt/fotos
    106 m=/mnt/media
    107 M=/mnt/mirror
    108 h=/mnt/home
    109 
    110 # transmission stuff
    111 alias trls='transmission-remote pippin.h.e1e0.net --authenv -l'
    112 function trrm () {
    113     transmission-remote pippin.h.e1e0.net --authenv -t $1 --remove-and-delete
    114 }
    115 function trclean() {
    116     for i in $(transmission-remote pippin.h.e1e0.net --authenv -l | awk '$2=="100%" {print $1}')
    117     do
    118         transmission-remote pippin.h.e1e0.net --authenv -t $i --remove-and-delete
    119     done
    120 }
    121 
    122 ## useful base conversion functions
    123 function h2d(){ printf "%'d\n" 0x$@; }
    124 function b2d(){ printf "%'d\n" 0b$@; }
    125 function o2d(){ printf "%'d\n" "[8]$@"; }
    126 # the other permutations are a python script in ~/bin
    127 
    128 # temperatura calculators
    129 function c2f() {
    130     F=$(printf "scale=2\n$1 *  1.80 + 32\n" | bc)
    131     printf "C: $1\nF: $F\n"
    132 }
    133 
    134 function f2c() {
    135     C=$(printf "scale=2\n($1 -32)/1.80\n" | bc)
    136     printf "F: $1\nC: $C\n"
    137 }
    138 
    139 # for everything else, use units(1)
    140 
    141 # What is my External IP
    142 function myip() { printf "External IP: %s\n" $(curl -s -4 http://ifconfig.co/) ;}
    143 
    144 # Utils
    145 
    146 # Retry a function
    147 # @param $1 number Retry Times
    148 # @param $2 number Retry Wait
    149 # @param $@ mixed Function and arguments
    150 function retry() {
    151     times=$1; shift;
    152     wait=$1; shift;
    153     until "$@"; do
    154         (( --times <= 0 )) && return 1
    155         sleep $wait
    156     done
    157 }
    158 # quick and dirty file backup
    159 function bak() {
    160     \cp -v ${1}{,.bak}
    161 }
    162 # replace all spaces by underscore
    163 function mvsp() {
    164     autoload -U zmv
    165     zmv '* *' '$f:gs/ /_'
    166 }
    167 # Grep the history with 'h'
    168 function h () {
    169     if command -v rg > /dev/null 2>&1
    170     then
    171         mycommand=rg
    172     else
    173         mycommand=grep
    174     fi
    175 
    176     history 0 | $mycommand $1
    177 }
    178 # Curl alias to calculate response time.
    179 function curl_time() {
    180     curl -o /dev/null -Ls -w " \
    181    time_namelookup:  %{time_namelookup}\n \
    182       time_connect:  %{time_connect}\n \
    183    time_appconnect:  %{time_appconnect}\n \
    184   time_pretransfer:  %{time_pretransfer}\n \
    185      time_redirect:  %{time_redirect}\n \
    186 time_starttransfer:  %{time_starttransfer}\n \
    187                    ----------\n \
    188         time_total:  %{time_total}\n" "$1"
    189 }
    190 # weather forecast on the terminal
    191 function wf () {
    192     CITY=$1
    193     if [[ -z "$CITY" ]]; then
    194         CITY="MatarĂ³"
    195     fi
    196     curl wttr.in/${CITY}
    197 }
    198 # transfer.sh upload helper
    199 function transfer() {
    200     if [ $# -eq 0 ]; then
    201         echo -e "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"
    202         return 1
    203     fi 
    204     tmpfile=$( mktemp -t transferXXX )
    205     if tty -s; then
    206         basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g')
    207         curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" >> $tmpfile
    208     else
    209         curl --progress-bar --upload-file "-" "https://transfer.sh/$1" >> $tmpfile
    210     fi
    211     # send output to stderr AND to clipboard
    212     cat $tmpfile >&2 | $CLIP_COMMAND
    213     echo " "
    214     rm -f $tmpfile
    215 }
    216 # function to copy main ssh keys to clipboard when needed
    217 function pubkey () {
    218     ssh-add -L |grep 'cardno:000608115828' |\
    219         ${=CLIP_COMMAND}
    220     echo "=> Public key copied to clipboard."
    221 }
    222 # poor man's pastebin service (and secure !)
    223 function pb() {
    224     filename="$1"
    225     dest=""
    226     if [[ -z "$filename" ]]; then
    227         dest=$(tr -cd '[:alnum:]' < /dev/urandom |dd bs=1 count=8 2>/dev/null)
    228         ssh r2.e1e0.net "cat > /var/www/pastes/$dest"
    229     else
    230         dest=$(basename "$filename")
    231         scp -q "$filename" "r2.e1e0.net:/var/www/pastes/$dest"
    232     fi
    233     echo -n "https://onna.be/paste/$dest" |\
    234         ${=CLIP_COMMAND}
    235     echo ''
    236 }
    237 
    238 # Neat trick from https://github.com/lf94/peek-for-tmux/blob/master/README.md
    239 function peek() {
    240     tmux split-window -p 33 less $@ || exit;
    241 }
    242 
    243 # ports stuff
    244 function port-search() {
    245     local pt="/usr/ports"
    246 
    247     [[ -z ${1} ]] && echo "Need a keyword to search for" && return
    248     [[ ! -d ${pt} ]] && echo "Cannot find ports tree" && return
    249 
    250     cd ${pt} && make search name=${1}
    251 }
    252 alias port-sql='sqlite3 /usr/local/share/sqlports'
    253 alias port-pldc='make port-lib-depends-check'
    254 alias port-ldc='make lib-depends-check'
    255 alias port-pdiff='diff -up pkg/PLIST.orig pkg/PLIST'
    256 alias port-src='cd `make show=WRKSRC`'
    257 alias port-fast='MAKE_JOBS=4 make'
    258 alias port-cleanup='make clean=all && env FLAVOR=python3 make clean=all'
    259 alias py3='env FLAVOR=python3'
    260 
    261 function port-diff()
    262 {
    263     cvs diff > /usr/ports/mystuff/${PWD##*/}.diff
    264     if command -v colordiff > /dev/null ; then
    265         colordiff < /usr/ports/mystuff/${PWD##*/}.diff | less
    266     else
    267         less /usr/ports/mystuff/${PWD##*/}.diff
    268     fi
    269 }
    270 function port-lessdiff() {
    271     if command -v colordiff > /dev/null ; then
    272         colordiff < /usr/ports/mystuff/${PWD##*/}.diff | less
    273     else
    274         less /usr/ports/mystuff/${PWD##*/}.diff
    275     fi
    276 }
    277 function port-pygrep() { rg $@ --type make --glob '!*mystuff*' --glob '!lost+found' /usr/ports/*/py-* }
    278 function port-lib() { nm -g "$1" | cut -c10- | grep -e^T > /tmp/"$(pwd |xargs basename)" }
    279 function port-find() { grep -i $@ /usr/local/share/sqlports.list }
    280 function port-grep() { rg $@ --type make --glob '!*mystuff*' --glob '!lost+found' /usr/ports }
    281 function port-up() { cd /usr/ports && cvs -q up -Pd -A && cd - }
    282 function port-lessmake() { less "/usr/ports/$1/Makefile" }