commit d960a2fa1e49d19110ebcc2ad902366e38752958 parent 6557688f72fc325edd15bd194c0ef75d4d80aab2 Author: Bharatvaj <bharatvaj@yahoo.com> Date: Sun, 24 Jul 2022 21:54:16 +0530 extract_archive: Handle any-case for extension quickopen: Handle when ${FUZZER} is not set Diffstat:
M | .config/sh/functions | | | 33 | ++++++++++++++++++--------------- |
1 file changed, 18 insertions(+), 15 deletions(-)
diff --git a/.config/sh/functions b/.config/sh/functions @@ -4,17 +4,17 @@ extract_archive () { test $# -lt 1 && { printf "Usage: $0 <archive>\n"; exit 1; } test -f $1 || { printf "$0: $1: No such file \n"; exit 1; } - case $1 in - *.Z) 7z x $1 ;; - *.bz2) bzip2 -d $1 ;; - *.gz) gunzip -d $1 ;; - *.rar) unrar x $1 ;; - *.tar) tar -xvf $1 ;; - *.tar.bz2) tar -jxvf $1 ;; - *.tar.gz) tar -zxvf $1 ;; - *.tgz) tar -zxvf $1 ;; - *.zip) unzip $1 ;; - *) echo "'$1' Error. Unsupported filetype." ;; + lowercase_ext=$(printf "%s" "$1" | rev | cut -d '.' -f1 | tr '[:upper:]' '[:lower:]' | rev) + case $lowercase_ext in + z) 7z x "$1" ;; + bz2) bzip2 -d "$1" ;; + bz) bzip2 -d "$1" ;; + gz) gunzip -d "$1" ;; + rar) unrar x "$1" ;; + tar) tar -xvf "$1" ;; + tgz) tar -zxvf "$1" ;; + zip) unzip "$1" ;; + *) printf "'$1' Error. Unsupported filetype.\n" >&2 ;; esac } @@ -33,8 +33,11 @@ thwart() { } quickopen() { - test -z "${FUZZER}" && printf '${FUZZER} not set\n' - test "$#" -lt 1 && print "usage: $0 <command> [find -type]" - test -z "$2" && 2=f - ${1} "$(find . -type $2 -maxdepth 3 2>/dev/null | ${FUZZER})" + if ! type "${FUZZER}" 2>/dev/null; then + printf '${FUZZER} not available\n' + else + test "$#" -lt 1 && print "usage: $0 <command> [find -type]" + test -z "$2" && 2=f + ${1} "$(find . -type $2 -maxdepth 3 2>/dev/null | ${FUZZER})" + fi }