# Length of string
le() { echo -n "${*}" | wc -c; }
# quick calculations
calc() { python3 -c "from math import *; print(${*})"; }
alias calci='python3 -qic "from math import *;"'
# Quick number base conversions
bin2dec() { python3 -c "print(0b${*})"; }
bin2hex() { python3 -c "print(hex(0b${*})[2:])"; }
dec2bin() { python3 -c "print(bin(${*})[2:])"; }
dec2hex() { python3 -c "print(hex(${*})[2:])"; }
hex2bin() { python3 -c "print(bin(0x${*})[2:])"; }
hex2dec() { python3 -c "print(0x${*})"; }
# one-letter aliases for super frequent commands
alias e='exit'
alias c='clear'
alias a='ip -brief address show'
# vim aliases
alias vi='nvim'
alias vim='nvim'
# Power command shortcuts
alias reboot='sudo reboot'
alias shutdown='sudo shutdown -h now'
# Ignore robots.txt when mirroring websites
alias wget='wget -e robots=off'
# pacman
alias pc='pacman'
alias autoremove='sudo pacman -Rns $(pacman -Qtdq)' # remove unused deps
alias autopurge='paccache -ruk0' # purge cache
# lsblk with some defaults
alias blk='lsblk -o NAME,FSTYPE,FSVER,SIZE,FSUSE%,TYPE,LABEL,MOUNTPOINTS'
# Feh with some defaults
alias feh='feh -g 540x540+960-540 -S filename --scale-down --zoom max'
# exit if text fits within one screen
alias less='less -F'
# blank/unblank TTY
alias b='setterm -blank=force'
alias p='setterm -blank=poke'
# Sort newline-delimited list from stdin
alias sort-list='sort | uniq -c | sort -nr | cut -b 9-'
alias sort-list-count='sort | uniq -c | sort -nr' # show count
# uppercase/lowercase quick text transformation
alias l2u='tr "[:lower:]" "[:upper:]"'
alias u2l='tr "[:upper:]" "[:lower:]"'
# Type out clipboard content
alias at='sleep 3; xdotool type "$(xclip -o -rmlastnl -sel clip)"'
# copy text/image to X11 clipboard
alias cs='xclip -selection clipboard'
alias csi='xclip -sel clip -t image/png' # images
# yt-dlp shortcuts
alias yt-video='yt-dlp -f bestvideo+bestaudio --embed-chapters --embed-metadata --embed-subs --sub-langs all'
alias yt-video-thumb='yt-video --embed-thumbnail'
alias yt-music='yt-dlp --no-video -x -f bestaudio --embed-chapters --embed-metadata --embed-thumbnail --convert-thumb png'
alias yt-music-thumb='yt-music --ppa "ThumbnailsConvertor+ffmpeg_o:-c:v png -vf crop=\"'\''if(gt(ih,iw),iw,ih)'\'':'\''if(gt(iw,ih),ih,iw)'\''\""'
# shortcut to restart Plasma because FDOfags can't write competent software
alias plasma='killall -9 plasmashell; plasmashell --replace &'