dotfiles

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

aliases.zsh (6275B)


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