function is_command() { command -v $1 > /dev/null } # {{{ Global aliases alias -g G='|grep -i' alias -g H='|head' alias -g T='|tail' alias -g L='|less' alias -g LA='2>&1|less' alias -g X='|xclip' alias -g XC='|xclip -selection clipboard' alias -g UP='|&\up' alias -g S='|sort' alias -g SN='|sort -n' alias -g NO='>/dev/null' alias -g NE='2>/dev/null' alias -g NUL='&>/dev/null' alias -g X='| xargs' alias -g X1='| xargs -n 1' alias -g XL='| tr "\n" "\0" | xargs -0' alias -g A1="| awk '{print \$1}'" alias -g A2="| awk '{print \$2}'" alias -g A3="| awk '{print \$3}'" alias -g A4="| awk '{print \$4}'" alias -g A5="| awk '{print \$5}'" alias -g A6="| awk '{print \$6}'" alias -g A7="| awk '{print \$7}'" alias -g A8="| awk '{print \$8}'" alias -g A9="| awk '{print \$9}'" # }}} # Suffix aliases {{{ alias -s html=open alias -s pdf=open is_command wine && alias -s exe=wine alias -s jar="java -jar" alias -s git="gclone" is_command gdebi && alias -s deb="sudo gdebi" || alias -s deb="sudo dpkg -i" is_command aria2c && alias -s torrent="aria2c" # }}} # Common tools {{{ # Fix aliases alias sudo='sudo ' alias sudo-path='sudo env "PATH=$PATH" ' alias watch='watch ' # Remove grml alias for ag unalias ag alias -- -="cd -" alias df='df -h' alias free='free -tm' alias whois='whois -H' alias grep='grep --color=auto' alias zgrep='zgrep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' alias fn='find . -name' alias ip='ip -color -brief' alias dmesg='dmesg --human' alias nf="numfmt --from=auto --to=iec" alias tree="tree --dirsfirst" alias dig='dig +nocmd +multiline +noall +answer' alias lsof='lsof -w' is_command bat && alias cat='bat' alias crontab='crontab -i' alias rm='rm --interactive=once' alias rmcdir='cd ..; rm -rfi "$OLDPWD" || cd "$OLDPWD"' is_command trash-put && alias rm='trash-put' alias mv='mv --interactive' alias cp='cp --interactive --recursive --reflink=auto' alias ln='ln --interactive --verbose' alias mkdir='mkdir -pv' if is_command colordiff; then alias diff='colordiff -u' else alias diff='diff -u' fi alias fd='fdfind' alias dd='dd status=progress' alias ls='ls --color=auto -h -F --group-directories-first' alias l='ls -l' alias d='dirs -v | head -10' alias da='\du -sch' if is_command gdu; then alias du='gdu --no-delete --no-cross' alias ncdu='gdu' elif is_command ncdu; then alias du='ncdu -rr -x --exclude .git' alias ncdu='ncdu -q' else alias du='du -h' fi alias bc='bc -lq' alias c=' clear' check_com g || alias g='git' check_com lg && is_command lazygit || alias lg='lazygit' check_com s || alias s='ssh' alias v='vim' alias vp='vim -c "setlocal buftype=nofile bufhidden=hide noswapfile buflisted" -' alias sv='sudo -e' alias t='tmux new-session -A -s main' if is_command tmuxp; then alias mux='tmuxp load -y' elif is_command tmuxinator; then alias mux='tmuxinator' fi alias scratch='vim -c Scratch +startinsert' alias scratchmd='scratch -c "set ft=markdown"' alias rscp='rsync -rlptDvzhP' is_command pigz && alias gzip='pigz' is_command pigz && alias zcat='pigz -cd' is_command unpigz && alias gunzip='unpigz' if is_command viman ; then alias man='LANG=C viman' compdef _man viman else alias man='LANG=C man' fi alias sc=systemctl alias scu="systemctl --user" alias jc="journalctl --lines=30 --follow --unit" alias jcu="journalctl --user --lines=30 --follow --unit" alias pwgen="pwgen --capitalize --numerals --secure" alias pw="pwgen 40 1" alias lsblk="lsblk -o NAME,SIZE,UUID,FSTYPE,MOUNTPOINT,LABEL,MODEL" alias gpgencrypt='gpg --encrypt-files' alias gpgdecrypt='gpg --decrypt-files' # }}} # Network and web {{{ if is_command prettyping; then alias ping='prettyping --nolegend' fi alias localip="hostname -I | gawk '{print \$1}'" alias tcp-listen="netstat --tcp --listen --numeric --program 2>/dev/null || netstat -an | grep LISTEN" alias portcheck='nc -z -v -w 5' is_command netstat && alias ports='netstat -tulanp' is_command ss && alias ports='ss -tulanp' is_command lynx && alias urls="lynx -nonumbers -listonly -dump" alias ipv6_disable='sudo sysctl net.ipv6.conf.all.disable_ipv6=1' alias ipv6_enable='sudo sysctl net.ipv6.conf.all.disable_ipv6=0' alias aria2c-rpc="aria2c --enable-rpc" if [ -f "$HOME/.config/chromium/Default/Cookies" ] ; then alias aria2c-cookies="aria2c --load-cookies='$HOME/.config/chromium/Default/Cookies'" fi if is_command python3; then alias httpserver='python3 -m http.server' else alias httpserver='python -m SimpleHTTPServer' fi alias yd='yt-dlp' alias yd-date='yd --download-archive=download-archive.log --playlist-reverse --ignore-errors --output="[%(playlist_autonumber)04d] %(upload_date)s - %(title)s-%(id)s.%(ext)s"' alias yd-audio='yd --format bestaudio --embed-thumbnail --extract-audio --audio-format mp3' alias yd-cb='xsel -bo | xargs yt-dlp' alias yd-url='yd --flat-playlist --get-url' is_command buku && alias b='buku --suggest' # }}} # Building tools and development {{{ alias k='kubectl' alias make='make -j$(nproc)' alias nicer='nice -n 15 ionice -c 2 -n 7 ' alias gco="git branch --sort=-committerdate | fzf --tiebreak=index | xargs git checkout" alias gst="git status" alias ghome='cd "$(git rev-parse --show-toplevel)"' test -f ~/bin/pandoc-filter-includes.py && alias pdoc='pandoc --standalone --filter ~/bin/pandoc-filter-includes.py' is_command pgcli && alias pgcli="pgcli --pgclirc ~/.config/pgcli/config --pgclirc ~/.config/pgcli/local.config" alias pipr="pip3 install -r" alias pipup="pip3 list --outdated | awk 'NR>2{print \$1}' | xargs --interactive pip3 install --no-cache-dir --upgrade" function mvn-or-mvnw() { if [ -x ./mvnw ]; then echo "executing mvnw instead of mvn" ./mvnw "$@" else command mvn "$@" fi } alias mvn="mvn-or-mvnw" compdef _mvn mvn-or-mvnw compdef _mvn mvnd # Docker and docker-compose alias dbash='docker exec -it `docker ps -ql` bash' alias dps='docker ps --format "table {{.ID}}\t{{.Image}}\t{{.Status}}\t{{.Names}}\t{{.Ports}}"' alias drun='docker run -it --rm' alias dlog='docker logs --tail 100 --follow' alias dc='docker-compose' alias dc-down='dc down --volumes --rmi local --remove-orphans' alias dc-logs='dc logs --tail 100 --follow' function dc-stats() { dc $@ ps -q | xargs --no-run-if-empty docker stats } function docker-save() { docker save "$1" | gzip > $(slugify "$1").tar.gz } alias docker-top='docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock moncho/dry' alias docker-dive='docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock wagoodman/dive' # }}} # Package manager {{{ if [ -r /etc/debian_version ] ; then if is_command aptitude; then alias upa='sudo aptitude -u' alias apurge='sudo aptitude purge --purge-unused' else alias up='sudo apt update; sudo apt upgrade' alias apurge='sudo apt purge' fi elif [ -r /etc/arch-release ] ; then alias ati='sudo pacman -S' alias acs='sudo pacman -Ss' alias up='sudo pacman -Syu' alias apurge='sudo pacman -Rs' elif [ -r /etc/redhat-release ] ; then alias ati='sudo dnf install' alias acs='dnf search' alias up='sudo dnf upgrade' alias apurge='sudo dnf remove' fi # }}} # Calendar & tasks {{{ alias cal='ncal -Mb' alias ta='task add' alias task-no-spell='TW_IGNORE_SPELL=1 task' if is_command remind; then alias remind="noglob remind -@ -m -b1" alias rem="noglob rem -@ -m -b1" alias rem1="rem -cu+1" alias rem2="rem -cu+2" alias tt="rem; task" alias tkremind="tkremind -m -b1" for day in {1..9} ; do alias $day="rem '*$day'" done remind-schedule() { remind -@ "${@:-*7}" | grep -vEe '^(No reminders\.|)$' } rem-schedule() { rem -@ "${@:-*7}" | grep -vEe '^(No reminders\.|)$' } fi # }}} # Other and unsorted {{{ if is_command unoconv; then alias 2pdf='unoconv --format pdf' elif is_command libreoffice; then alias 2pdf='libreoffice --headless --convert-to pdf' fi alias pdoc-pdf='pandoc -V fontenc=T2A -V geometry:margin=1in -V mainfont="Linux Libertine O"' alias ocrmypdf='ocrmypdf --clean --deskew --rotate-pages' alias ocrmypdf-rus='ocrmypdf --language rus' alias ocrmypdf-eng='ocrmypdf --language eng' alias ocrmypdf-rus-eng='ocrmypdf --language rus+eng' alias ocrmypdf-swe-eng='ocrmypdf --language swe+eng' alias display_off='xset dpms force off' alias cclip='xclip -selection clipboard' alias remove-colors='sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g"' alias boot-log="sed 's/\^\[/\o33/g;s/\[1G\[/\[27G\[/' /var/log/boot | less -r" # TLP alias tlp-stat='sudo tlp-stat' alias tlp-fullcharge='sudo tlp fullcharge BAT0; sudo tlp fullcharge BAT1' alias tlp-setcharge='sudo tlp setcharge BAT0; sudo tlp setcharge BAT1' # ZFS alias zfs='sudo zfs' alias zpool='sudo zpool' # Exim #alias exim-queue-list='sudo exim -bp' #alias exim-queue-header='sudo exim -Mvh' #alias exim-queue-body='sudo exim -Mvb' #alias exim-queue-rm='sudo exim -Mrm' # }}} # Cleanup {{{ unfunction is_command # }}} # vim: et ft=zsh fdm=marker :