# Mullvad VPN checker. function mullvad() { echo "" python3 <(cat < ' given. last=$3 case $1 in ("") printf '%s\n\n' 'ERROR: No search string specified. Aborting.' printf '%s\n%s\n\n' ${usage} ${help} && return 1 ;; (-h) printf '%s\n\n' ${usage} print 'OPTIONS:' printf $format_l '-h' 'show help text' print '\f' print 'SEARCH RANGE:' printf $format_l "'0'" 'the whole history,' printf $format_l '-' 'offset to the current history number; (default: -100)' printf $format_s '<[-]first> []' 'just searching within a give range' printf '\n%s\n' 'EXAMPLES:' printf ${format_l/(\\t)/} 'whatwhen grml' '# Range is set to -100 by default.' printf $format_l 'whatwhen zsh -250' printf $format_l 'whatwhen foo 1 99' ;; (\?) printf '%s\n%s\n\n' ${usage} ${help} && return 1 ;; (*) # -l list results on stout rather than invoking $EDITOR. # -i Print dates as in YYYY-MM-DD. # -m Search for a - quoted - pattern within the history. fc -li -m "*${first_char}${remain}*" $first $last ;; esac } # Lifted from the extract plugin for oh-my-zsh. # Extract archive into current directory. function extract() { setopt localoptions noautopushd if (( $# == 0 )); then cat >&2 <<'EOF' Usage: extract [-option] [file ...] Options: -r, --remove Remove archive after unpacking. EOF fi local remove_archive=1 if [[ "$1" == "-r" ]] || [[ "$1" == "--remove" ]]; then remove_archive=0 shift fi local pwd="$PWD" while (( $# > 0 )); do if [[ ! -f "$1" ]]; then echo "extract: '$1' is not a valid file" >&2 shift continue fi local success=0 local extract_dir="${1:t:r}" local file="$1" full_path="${1:A}" case "${file:l}" in (*.tar.gz|*.tgz) (( $+commands[pigz] )) && { pigz -dc "$file" | tar xv } || tar zxvf "$file" ;; (*.tar.bz2|*.tbz|*.tbz2) tar xvjf "$file" ;; (*.tar.xz|*.txz) tar --xz --help &> /dev/null \ && tar --xz -xvf "$file" \ || xzcat "$file" | tar xvf - ;; (*.tar.zma|*.tlz) tar --lzma --help &> /dev/null \ && tar --lzma -xvf "$file" \ || lzcat "$file" | tar xvf - ;; (*.tar.zst|*.tzst) tar --zstd --help &> /dev/null \ && tar --zstd -xvf "$file" \ || zstdcat "$file" | tar xvf - ;; (*.tar) tar xvf "$file" ;; (*.tar.lz) (( $+commands[lzip] )) && tar xvf "$file" ;; (*.tar.lz4) lz4 -c -d "$file" | tar xvf - ;; (*.tar.lrz) (( $+commands[lrzuntar] )) && lrzuntar "$file" ;; (*.gz) (( $+commands[pigz] )) && pigz -dk "$file" || gunzip -k "$file" ;; (*.bz2) bunzip2 "$file" ;; (*.xz) unxz "$file" ;; (*.lrz) (( $+commands[lrunzip] )) && lrunzip "$file" ;; (*.lz4) lz4 -d "$file" ;; (*.lzma) unlzma "$file" ;; (*.z) uncompress "$file" ;; (*.zip|*.war|*.jar|*.ear|*.sublime-package|*.ipa|*.ipsw|*.xpi|*.apk|*.aar|*.whl) unzip "$file" -d "$extract_dir" ;; (*.rar) unrar x -ad "$file" ;; (*.rpm) command mkdir -p "$extract_dir" && builtin cd -q "$extract_dir" \ && rpm2cpio "$full_path" | cpio --quiet -id ;; (*.7z) 7za x "$file" ;; (*.deb) command mkdir -p "$extract_dir/control" "$extract_dir/data" builtin cd -q "$extract_dir"; ar vx "$full_path" > /dev/null builtin cd -q control; extract ../control.tar.* builtin cd -q ../data; extract ../data.tar.* builtin cd -q ..; command rm *.tar.* debian-binary ;; (*.zst) unzstd "$file" ;; (*.cab) cabextract -d "$extract_dir" "$file" ;; (*.cpio) cpio -idmvF "$file" ;; (*) echo "extract: '$file' cannot be extracted" >&2 success=1 ;; esac (( success = success > 0 ? success : $? )) (( success == 0 && remove_archive == 0 )) && rm "$full_path" shift # Go back to original working directory in case we ran cd previously builtin cd -q "$pwd" done } alias x=extract # Create a tarball from given directory. function create-archive() { local archive_name archive_name="$1.tar.gz" archive_name=${archive_name/\//} tar cvfz "$archive_name" "$1" echo "Created archive $archive_name" } compdef _directories create-archive # Create a /overview/ of all available function()'s; the description for # each funtion() *must* be the first line above the string `function'! # Otherwise it wont work. # Display all function()'s with their descriptions. function funlist() { grep -B 1 "^function" $HOME/.zshrc.d/functions.zsh | \ grep -v "^\-\-$" | \ awk '{ if(/^#/) { gsub(/^#[:space:]*/, ""); ht=$0 }; getline; gsub(/ ?\(\)/, ":"); printf("-> %-20s %s\n", $2, ht); }' | \ sort -u -k 3 } # Show directory stack and ask for a dir to switch to. function dstack() { emulate -L zsh autoload -U colors local color=$fg_bold[blue] integer i=0 dirs -p | while read dir do local num="${$(printf "%-4d " $i)/ /.}" printf " %s $color%s$reset_color\n" $num $dir (( i++ )) done integer dir=-1 read -r 'dir?Jump to directory: ' || return (( dir == -1 )) && return if (( dir < 0 || dir >= i )) then echo d: no such directory stack entry: $dir return 1 fi cd ~$dir } # zremovecomp() remove *.zwc files. function zremovecomp() { local i for i in ${HOME}/*.zwc(N); do printf "Removing $i\n" command rm -f $i done } # grep(1)'ing $HISTFILE. function histgrep () { fc -fl -m "*(#i)$1*" 1 | grep -i --color $1 } # A nicer output of cal(1) # Colorize the output of cal(1). function calendar() { if [[ ! -f /usr/bin/cal ]] ; then echo "Please install cal before trying to use it!" return fi if [[ "$#" = "0" ]] ; then /usr/bin/cal | egrep -C 40 --color "\<$(date +%e| tr -d ' ')\>" else /usr/bin/cal $@ | egrep -C 40 --color "\<($(date +%B)|$(date +%e | tr -d ' '))\>" fi } # Invoke this every time you change .zshrc to recompile it. function src() { autoload -U zrecompile [ -f ~/.zshrc ] && zrecompile -p ~/.zshrc [ -f ~/.zcompdump ] && zrecompile -p ~/.zcompdump [ -f ~/.zcompdump ] && zrecompile -p ~/.zcompdump [ -f ~/.zshrc.zwc.old ] && command rm -f ~/.zshrc.zwc.old [ -f ~/.zcompdump.zwc.old ] && command rm -f ~/.zcompdump.zwc.old source ~/.zshrc } # Do an ls after cd. function cd() { builtin cd "$@" && ls; } # Create new directory and enter it. function mkd() { mkdir -p "$@" && cd "$_"; } # Display pids of commands. function pids() { pgrep -a "$@"; } # zshall manpage. function manzsh() { /usr/bin/man zshall | most +/"$1" ; } # Restart zsh. function restart() { exec $SHELL $SHELL_ARGS "$@"; } # cd to ~, clear screen, and restart zsh. function rsrc() { cd && clear && restart; } # Parse HackerNews feed (https://hnrss.org/newest). function hn() { python3 <(cat <