From 3ac8e0f994839f3c972033bcb12421081ebeb683 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 28 Sep 2021 22:50:56 +0200 Subject: zsh: move includes to XDG compliant locations .config/zsh/{functions,includes}/*: Move functions and includes to XDG compliant locations. .zshrc: Include functions and other includes from XDG compliant locations. Remove use of prepend-sudo function. --- .config/zsh/functions/02_utility.zsh | 75 ++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 .config/zsh/functions/02_utility.zsh (limited to '.config/zsh/functions/02_utility.zsh') diff --git a/.config/zsh/functions/02_utility.zsh b/.config/zsh/functions/02_utility.zsh new file mode 100644 index 0000000..05b77bc --- /dev/null +++ b/.config/zsh/functions/02_utility.zsh @@ -0,0 +1,75 @@ +# Makes a directory and changes to it. +function mkdcd { + [[ -n "$1" ]] && mkdir -p "$1" && builtin cd "$1" +} + +# Changes to a directory and lists its contents. +function cdls { + builtin cd "$argv[-1]" && ls "${(@)argv[1,-2]}" +} + +# Pushes an entry onto the directory stack and lists its contents. +function pushdls { + builtin pushd "$argv[-1]" && ls "${(@)argv[1,-2]}" +} + +# Pops an entry off the directory stack and lists its contents. +function popdls { + builtin popd "$argv[-1]" && ls "${(@)argv[1,-2]}" +} + +# Prints columns 1 2 3 ... n. +function slit { + awk "{ print ${(j:,:):-\$${^@}} }" +} + +# Finds files and executes a command on them. +function find-exec { + find . -type f -iname "*${1:-}*" -exec "${2:-file}" '{}' \; +} + +# Displays user owned processes status. +function psu { + ps -U "${1:-$LOGNAME}" -o 'pid,%cpu,%mem,command' "${(@)argv[2,-1]}" +} + +# Highlights make output. +function make { + if (( $+commands[colormake] )); then + colormake "$@" + else + command make "$@" + fi +} + +# Lists the contents of archives. +function lsarchive { + while (( $# > 0 )); do + if [[ ! -s "$1" ]]; then + print "$0: file not valid: $1" >&2 + shift + continue + fi + case "$1:l" in + (*.tar.gz|*.tgz) tar t${verbose:+v}vzf "$1" ;; + (*.tar.bz2|*.tbz|*.tbz2) tar t${verbose:+v}jf "$1" ;; + (*.tar.xz|*.txz) tar --xz --help &> /dev/null \ + && tar --xz -t${verbose:+v}f "$1" \ + || xzcat "$1" | tar t${verbose:+v}f - ;; + (*.tar.zma|*.tlz) tar --lzma --help &> /dev/null \ + && tar --lzma -t${verbose:+v}f "$1" \ + || lzcat "$1" | tar x${verbose:+v}f - ;; + (*.tar) tar t${verbose:+v}f "$1" ;; + (*.zip) unzip -l${verbose:+v} "$1" ;; + (*.rar) unrar &> /dev/null \ + && unrar ${${verbose:+v}:-l} "$1" \ + || rar ${${verbose:+v}:-l} "$1" ;; + (*.7z) 7za l "$1" ;; + (*) + print "$0: cannot list: $1" >&2 + success=1 + ;; + esac + shift + done +} -- cgit v1.2.3-54-g00ecf