mcd() { [ $# = 1 ] && mkdir -p -- "$1" && cd -- "$1" } compdef _directories mcd gclone() { git clone --recursive "$1" && cd "$(basename "$1" | sed -e 's/\.git$//')" } wcc() { wc -c "$@" | numfmt --to=si } wcl() { wc -l "$@" | numfmt --grouping } ppgrep() { pgrep "$@" | xargs --no-run-if-empty ps fp } setgov() { GOVS=($(cpufreq-info -g)) if [ -z "$1" ] ; then cat </dev/null 2>&1 else xdg-open "$@" >/dev/null 2>&1 fi } retry() { for i in $(seq 5) ; do "$@" && break || sleep 5 done } datediff() { d1=$(date --date "$1" +%s) d2=$(date --date "$2" +%s) echo $(( (d1 - d2) / 86300 )) days } st() { ssh -t "$@" tmux -u new-session -A -s main } compdef st=ssh calc() { echo "scale=3;$@" | bc -l } alias calc="noglob calc" # Take from @garybernhardt activate_virtualenv() { local found_location="" local default_name=venv for name in $default_name env ; do for up in . ../.. ../../.. ; do if [ -f "$up/$name/bin/activate" ] ; then found_location="$up/$name/bin/activate" break fi done [ -n "$found_location" ] && break done if [ -z "$found_location" ] ; then # create read -r "answer?Virtualenv not found, create? " if [[ "$answer" =~ ^[Yy]$ ]] ; then if command -v virtualenv>/dev/null ; then virtualenv $default_name else python3 -m venv $default_name fi activate_virtualenv fi else . "$found_location" fi } edit-which() { command=$(which "$@") [ -x "$command" ] && $EDITOR "$command" } compdef edit-which=which which-package() { whence -p "$1" | xargs --no-run-if-empty apt-file search --fixed-string } compdef which-package=which ipinfo() { curl ipinfo.io/json } docker-images-clean() { docker images --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}\t{{.Size}}" | fzf --multi --header-lines=1 | awk '{print $1}' | xargs -r docker rmi -f } transfer() { curl --progress-bar --upload-file "$1" https://transfer.sh/$(basename "$1") | tee /dev/null; echo } web-bookmarks() { local bookmarks_path="$HOME/.config/chromium/Default/Bookmarks" local jq_script='def ancestors: while(. | length >= 2; del(.[-1,-2])); . as $in | paths(.url?) as $key | $in | getpath($key) | {name,url, path: [$key[0:-2] | ancestors as $a | $in | getpath($a) | .name?] | reverse | join("/") } | .path + "/" + .name + "\t" + .url' jq -r $jq_script < "$bookmarks_path" | sed -E $'s/(.*)\t(.*)/\\1\t\x1b[36m\\2\x1b[m/g' | fzf --ansi --multi | cut -d$'\t' -f2 | xargs xdg-open >/dev/null 2>&1 } vpn-up() { name="$1" nmcli connection up "$name" >/dev/null } vpn-down() { name="$1" if nmcli connection show "$name" | grep 'GENERAL.STATE' >/dev/null ; then nmcli connection down "$name" >/dev/null fi } vpn-toggle() { name="$1" if nmcli connection show "$name" | grep 'GENERAL.STATE' >/dev/null ; then vpn-down "$name" else for vpn in "WG Home" "wgDe" "riga.bobov.name" "bobov.name" ; do if [ "$name" != "$vpn" ] ; then vpn-down "$vpn" fi done vpn-up "$1" fi } # vim: ft=zsh :