1
0
Fork 0
mirror of synced 2024-05-25 03:25:19 -04:00

[archive] Check unrar with commands array

“unrar-free returns the error code 1 when run without arguments, thus
failing the presence check.” as reported at sorin-ionescu/prezto#1383

Reformat code and use one-liners instead of if/then/fi. And we don’t
need to separate local definitions from assignments anymore starting
from zsh 5.2.
This commit is contained in:
Eric Nielsen 2018-02-07 18:27:59 -05:00
parent 2d1aea3b74
commit 6af7892f91
3 changed files with 12 additions and 29 deletions

View file

@ -2,8 +2,6 @@
# Creates archive files # Creates archive files
# #
local archive_name dir_to_archive
if (( ${#} != 2 )); then if (( ${#} != 2 )); then
print "usage: ${0} [archive_name.ext] [/path/to/include/in/archive]" >&2 print "usage: ${0} [archive_name.ext] [/path/to/include/in/archive]" >&2
return 1 return 1
@ -13,9 +11,9 @@ fi
# so we don't need any argc check here. # so we don't need any argc check here.
# strip the path, just in case one is provided for some reason # strip the path, just in case one is provided for some reason
archive_name="${1:t}" local archive_name="${1:t}"
# use absolute paths, and follow symlinks # use absolute paths, and follow symlinks
dir_to_archive="${2}" local dir_to_archive="${2}"
# if the directory doesn't exist, quit. Nothing to archive # if the directory doesn't exist, quit. Nothing to archive
if [[ ! -e "${dir_to_archive}" ]]; then if [[ ! -e "${dir_to_archive}" ]]; then

View file

@ -2,8 +2,6 @@
# Unarchives files # Unarchives files
# #
local archive_name
if (( ${#} != 1 )); then if (( ${#} != 1 )); then
print "usage: ${0} [archive.ext]" >&2 print "usage: ${0} [archive.ext]" >&2
return 1 return 1
@ -15,7 +13,7 @@ if [[ ! -s ${1} ]]; then
fi fi
# strip the path, just in case one is provided for some reason # strip the path, just in case one is provided for some reason
archive_name="${1:t}" local archive_name="${1:t}"
# using unpigz/pbunzip2 provides little to decompression time; the benefit is mainly in compression time. # using unpigz/pbunzip2 provides little to decompression time; the benefit is mainly in compression time.
# setting it as an alias in the init.zsh file should be sufficient here. # setting it as an alias in the init.zsh file should be sufficient here.
@ -34,8 +32,7 @@ case "${archive_name}" in
(*.lzma) unlzma "${archive_name}" ;; (*.lzma) unlzma "${archive_name}" ;;
(*.Z) uncompress "${archive_name}" ;; (*.Z) uncompress "${archive_name}" ;;
(*.zip) unzip "${archive_name}";; (*.zip) unzip "${archive_name}";;
(*.rar) unrar &> /dev/null \ (*.rar) (( $+{commands[unrar]} )) && unrar x -ad "${archive_name}" \
&& unrar x -ad "${archive_name}" \
|| rar x -ad "${archive_name}" ;; || rar x -ad "${archive_name}" ;;
(*.7z|*.001) 7za x "${archive_name}" ;; (*.7z|*.001) 7za x "${archive_name}" ;;
(*) print "${0}: unknown archive type: ${archive_name}" ;; (*) print "${0}: unknown archive type: ${archive_name}" ;;

View file

@ -7,23 +7,11 @@
# #
# pigz # pigz
# #
(( ${+commands[pigz]} )) && alias gzip='pigz'
if (( ${+commands[pigz]} )); then (( ${+commands[unpigz]} )) && alias gunzip='unpigz'
alias gzip='pigz'
fi
if (( ${+commands[unpigz]} )); then
alias gunzip='unpigz'
fi
# #
# pbzip2 # pbzip2
# #
(( ${+commands[pbzip2]} )) && alias bzip2='pbzip2'
if (( ${+commands[pbzip2]} )); then (( ${+commands[pbunzip2]} )) && alias bunzip2='pbunzip2'
alias bzip2='pbzip2'
fi
if (( ${+commands[pbunzip2]} )); then
alias bunzip2='pbunzip2'
fi