# included from ~/.bashrc or ~/.zshrc
################################################################################
# Here some of my current aliases, reviewed by blackmoor
# Have fun !
################################################################################
# feel free to take all or any part and modify as you want
# no real code here, just quick declaration, do what you want with it

################################################################################
# Programmation aliases
alias py3=ipython3
alias py2=ipython2
alias py=py3

################################################################################
# HTML documentation aliases
alias w3m-py2='w3m /usr/share/doc/python/html/index.html'
alias w3m-py3='w3m /usr/share/doc/python3/html/index.html'
alias w3m-py=w3m-py3
alias w3m-make='w3m /usr/share/doc/make-doc/make.html/index.html'
alias w3m-mutt='w3m /usr/share/doc/mutt/html/index.html'
alias w3m-i3='w3m /usr/share/doc/i3-wm/userguide.html'

################################################################################
# Debug aliases
alias diff='colordiff'
alias strace='strace -y -yy'

################################################################################
# Admin aliases
alias rm='rm -I --preserve-root'
#alias rm='rm --verbose' # when removing big directories, it's horrible
alias chown='chown --preserve-root'
alias chmod='chmod --preserve-root'
alias chgrp='chgrp --preserve-root'
mount() { /bin/mount "$@" | column -t; }
alias fumount='fusermount -u'
alias dmesg='sudo dmesg'
alias df='df -h'
alias du='du -ch'
alias top='htop'
alias ping='ping -c 5'
alias ping4='ping4 -c 5'
alias ping6='ping6 -c 5'
alias ping-fast='ping -c 100 -s.2'
alias sudo='sudo ' # allows to expand aliases before getting to sudo
alias alias-edit='e ~/.config/shell/aliases && alias-reload'
alias alias-reload='. ~/.config/shell/aliases'
alias i3-edit='e ~/.config/i3/config && i3-msg reload'

################################################################################
# Packages Manager aliases
apt() {
    if test "$1" = "search" -o "$1" = "show"; then
        /usr/bin/apt "$@"
    else
        /usr/bin/sudo /usr/bin/apt "$@"
    fi
}
alias apt-get='sudo apt-get'
dpkg-s-which() { dpkg -S $(which "$1"); }
alias p-upgrade='sudo apt-get update && sudo apt-get upgrade'
alias p-update='sudo apt-get update'
alias p-install='sudo apt-get install'
alias p-purge='sudo apt-get purge'
alias p-autopurge='sudo apt-get autoremove --purge'
alias p-show='apt-cache show'
alias p-search='apt-cache search'
# when I want to see manually installed packages to check if I forget nothing
# in my package list (I do it only in interactive shell):
alias apt-manually="comm -23 <(apt-mark showmanual | sort -u) <(gzip -dc /var/log/installer/initial-status.gz | sed -n 's/^Package: //p' | sort -u)"
alias p-manually='apt-manually'
alias update='sudo apt update'
alias upgrade='sudo apt upgrade'
alias dist-upgrade='sudo apt dist-upgrade'
alias upup="update && dist-upgrade"

################################################################################
# Vocabulary search spell aliases
grep-dict() { cd /usr/share/dict; grep -ri "$@"; }
grep-dictfr() { cd /usr/share/dict; grep -i "$@" french; }
grep-dicten() { cd /usr/share/dict; grep -i "$@" american-english; }

################################################################################
# Current usage
rg() { if [[ -z "$RANGER_LEVEL" ]]; then \ranger "$@"; else exit; fi; }
alias ranger='rg'
function ranger-cd()
{
    ranger --choosedir=/tmp/chosen
    if [ -f /tmp/chosen -a "$(cat /tmp/chosen)" != "$(pwd | tr -d "\n")" ];
    then
        cd "$(cat /tmp/chosen)"
    fi
    rm -f /tmp/chosen
}
alias wget='wget -c'
alias wget+c='wget --no-continue'
# history
alias historytopten="history|awk '{a[\$4]++ } END{for(i in a){print a[i] \" \" i}}'|sort -rn|head"
function mkdircd() { mkdir -p "$@" && eval cd "\"\$$#\""; }

################################################################################
# cd aliases (no I'm not crasy, I've just some very deep folder)
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ......="cd ../../../../.."
alias ..1="cd .."
alias ..2="cd ../.."
alias ..3="cd ../../.."
alias ..4="cd ../../../.."
alias ..5="cd ../../../../.."
alias ..6="cd ../../../../../.."
alias ..7="cd ../../../../../../.."
alias ..8="cd ../../../../../../../.."
alias ..9="cd ../../../../../../../../.."

################################################################################
# path and datetime
alias path='echo -e ${PATH//:/\\n}'
alias now='date +"%T"'
alias nowtime=now
alias nowdate='date +"%d-%m-%Y"'
alias datef="date +%F"

################################################################################
# editing/opening files
# ge = graphic edit, te = new term edit
alias ge="gvim"
alias e="vim"
alias o="xdg-open"
# td: quick clean test/temp dir, then inside remove it with rm -r $PWD
alias td='cd "$(mktemp -d -p ~/temp/)"'

################################################################################
# term/shell edit
alias t="term"
alias te="term vim"
alias termtitle="printf '\033]0;%s\007'"
alias xtermtitle="termtitle"
alias setxtermtitle="termtitle"
titleprefix() { TITLEPREFIX="$* "; }

################################################################################
# vcsh (special git repositories)
alias conf='vcsh conf'
alias git-status-conf='vcsh run conf git status'
alias git-status-gtk='vcsh run gtk git status'

################################################################################
# pim
alias m="mutt"
alias mu="mutt -y -Z || mutt -y"
# for sending mails from command-line I require to have a profile set
alias m-profile-vg="mutt -e 'set from=vg@devys.org'"

################################################################################
# power management
alias halt="sudo halt"
alias poweroff="sudo poweroff"
alias reboot="sudo reboot"
alias pm-suspend="sudo pm-suspend"
alias pm-hibernate="sudo pm-hibernate"
alias pm-hybrid="sudo pm-suspend"

################################################################################
# browser aliases
alias b="fx"
b_translate_enfr() { fx "http://www.wordreference.com/enfr/$1"; }
b_translate_fren() { fx "http://www.wordreference.com/fren/$1"; }
alias b-translate="b_translate_enfr"
alias b-translate-enfr="b_translate_enfr"
alias b-translate-fren="b_translate_fren"
b_define_en() { fx "http://en.wiktionary.org/wiki/$1"; }
b_define_fr() { fx "http://fr.wiktionary.org/wiki/$1"; }
alias b-define-en="b_define_en"
alias b-define-fr="b_define_fr"
alias b-define="b-define-en"
b_wiki_fr() { fx "http://en.wikipedia.org/wiki/$1"; }
b_wiki_en() { fx "http://fr.wikipedia.org/wiki/$1"; }
alias b-wiki-en="b_wiki_en"
alias b-wiki-fr="b_wiki_fr"
alias b-wiki="b-wiki-en"

# vim: set ft=sh et sts=4 sw=4 ts=4 :