mirror of
https://github.com/notwa/rc
synced 2024-06-26 09:07:12 -07:00
reformat archive scripts to better fit in
This commit is contained in:
parent
bf684554e6
commit
bd81dc0b28
74
sh/archive
74
sh/archive
|
@ -1,15 +1,20 @@
|
|||
#
|
||||
# Creates archive file
|
||||
#
|
||||
# Authors:
|
||||
# Matt Hamilton <m@tthamilton.com>
|
||||
#
|
||||
#!/usr/bin/env zsh
|
||||
# YES_ZSH
|
||||
# NO_BASH
|
||||
# NO_DASH
|
||||
# NO_ASH
|
||||
|
||||
# function archive {
|
||||
archive() {
|
||||
#
|
||||
# Creates archive file
|
||||
#
|
||||
# Authors:
|
||||
# Matt Hamilton <m@tthamilton.com>
|
||||
#
|
||||
|
||||
local archive_name path_to_archive _gzip_bin _bzip2_bin _xz_bin _zstd_bin
|
||||
local archive_name path_to_archive _gzip_bin _bzip2_bin _xz_bin _zstd_bin
|
||||
|
||||
if (( $# < 2 )); then
|
||||
if (( $# < 2 )); then
|
||||
cat >&2 <<EOF
|
||||
usage: $0 [archive_name.zip] [/path/to/include/into/archive ...]
|
||||
|
||||
|
@ -19,43 +24,43 @@ Where 'archive.zip' uses any of the following extensions:
|
|||
|
||||
There is no '-v' switch; all operations are verbose.
|
||||
EOF
|
||||
return 1
|
||||
fi
|
||||
return 1
|
||||
fi
|
||||
|
||||
# we are quitting (above) if there are not exactly 2 vars,
|
||||
# so we don't need any argc check here.
|
||||
# we are quitting (above) if there are not exactly 2 vars,
|
||||
# so we don't need any argc check here.
|
||||
|
||||
# strip the path, just in case one is provided for some reason
|
||||
archive_name="${1:t}"
|
||||
# let paths be handled by actual archive helper
|
||||
path_to_archive="${@:2}"
|
||||
# strip the path, just in case one is provided for some reason
|
||||
archive_name="${1:t}"
|
||||
# let paths be handled by actual archive helper
|
||||
path_to_archive="${@:2}"
|
||||
|
||||
# here, we check for dropin/multi-threaded replacements
|
||||
# this should eventually be moved to modules/archive/init.zsh
|
||||
# as a global alias
|
||||
if (( $+commands[pigz] )); then
|
||||
# here, we check for dropin/multi-threaded replacements
|
||||
# this should eventually be moved to modules/archive/init.zsh
|
||||
# as a global alias
|
||||
if (( $+commands[pigz] )); then
|
||||
_gzip_bin='pigz'
|
||||
else
|
||||
else
|
||||
_gzip_bin='gzip'
|
||||
fi
|
||||
fi
|
||||
|
||||
if (( $+commands[pixz] )); then
|
||||
if (( $+commands[pixz] )); then
|
||||
_xz_bin='pixz'
|
||||
else
|
||||
else
|
||||
_xz_bin='xz'
|
||||
fi
|
||||
fi
|
||||
|
||||
if (( $+commands[lbzip2] )); then
|
||||
if (( $+commands[lbzip2] )); then
|
||||
_bzip2_bin='lbzip2'
|
||||
elif (( $+commands[pbzip2] )); then
|
||||
elif (( $+commands[pbzip2] )); then
|
||||
_bzip2_bin='pbzip2'
|
||||
else
|
||||
else
|
||||
_bzip2_bin='bzip2'
|
||||
fi
|
||||
fi
|
||||
|
||||
_zstd_bin='zstd'
|
||||
_zstd_bin='zstd'
|
||||
|
||||
case "${archive_name}" in
|
||||
case "${archive_name}" in
|
||||
(*.tar.gz|*.tgz) tar -cvf "${archive_name}" --use-compress-program="${_gzip_bin}" "${=path_to_archive}" ;;
|
||||
(*.tar.bz2|*.tbz|*.tbz2) tar -cvf "${archive_name}" --use-compress-program="${_bzip2_bin}" "${=path_to_archive}" ;;
|
||||
(*.tar.xz|*.txz) tar -cvf "${archive_name}" --use-compress-program="${_xz_bin}" "${=path_to_archive}" ;;
|
||||
|
@ -70,6 +75,7 @@ case "${archive_name}" in
|
|||
(*.xz) print "\n.xz is only useful for single files, and does not capture permissions. Use .tar.xz" ;;
|
||||
(*.lzma) print "\n.lzma is only useful for single files, and does not capture permissions. Use .tar.lzma" ;;
|
||||
(*) print "\nunknown archive type for archive: ${archive_name}" ;;
|
||||
esac
|
||||
esac
|
||||
}
|
||||
|
||||
# }
|
||||
[ -n "${preload+-}" ] || archive "$@"
|
||||
|
|
37
sh/lsarchive
37
sh/lsarchive
|
@ -1,15 +1,20 @@
|
|||
#
|
||||
# Lists the contents of archives.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
#!/usr/bin/env zsh
|
||||
# YES_ZSH
|
||||
# NO_BASH
|
||||
# NO_DASH
|
||||
# NO_ASH
|
||||
|
||||
# function lsarchive {
|
||||
lsarchive() {
|
||||
#
|
||||
# Lists the contents of archives.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
local verbose
|
||||
local verbose
|
||||
|
||||
if (( $# == 0 )); then
|
||||
if (( $# == 0 )); then
|
||||
cat >&2 <<EOF
|
||||
usage: $0 [-option] [file ...]
|
||||
|
||||
|
@ -18,14 +23,15 @@ options:
|
|||
|
||||
Report bugs to <sorin.ionescu@gmail.com>.
|
||||
EOF
|
||||
fi
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ "$1" == "-v" || "$1" == "--verbose" ]]; then
|
||||
if [[ "$1" == "-v" || "$1" == "--verbose" ]]; then
|
||||
verbose=0
|
||||
shift
|
||||
fi
|
||||
fi
|
||||
|
||||
while (( $# > 0 )); do
|
||||
while (( $# > 0 )); do
|
||||
if [[ ! -s "$1" ]]; then
|
||||
print "$0: file not valid: $1" >&2
|
||||
shift
|
||||
|
@ -57,6 +63,7 @@ while (( $# > 0 )); do
|
|||
esac
|
||||
|
||||
shift
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# }
|
||||
[ -n "${preload+-}" ] || lsarchive "$@"
|
||||
|
|
77
sh/unarchive
77
sh/unarchive
|
@ -1,20 +1,25 @@
|
|||
#
|
||||
# Extracts the contents of archives.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
#!/usr/bin/env zsh
|
||||
# YES_ZSH
|
||||
# NO_BASH
|
||||
# NO_DASH
|
||||
# NO_ASH
|
||||
|
||||
# function unarchive {
|
||||
unarchive() {
|
||||
#
|
||||
# Extracts the contents of archives.
|
||||
#
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
#
|
||||
|
||||
local remove_archive
|
||||
local success
|
||||
local file_name
|
||||
local file_path
|
||||
local extract_dir
|
||||
local _gzip_bin _bzip2_bin _xz_bin _zstd_bin
|
||||
local remove_archive
|
||||
local success
|
||||
local file_name
|
||||
local file_path
|
||||
local extract_dir
|
||||
local _gzip_bin _bzip2_bin _xz_bin _zstd_bin
|
||||
|
||||
if (( $# == 0 )); then
|
||||
if (( $# == 0 )); then
|
||||
cat >&2 <<EOF
|
||||
usage: $0 [-option] [file ...]
|
||||
|
||||
|
@ -23,40 +28,41 @@ options:
|
|||
|
||||
Report bugs to <sorin.ionescu@gmail.com>.
|
||||
EOF
|
||||
fi
|
||||
return 1
|
||||
fi
|
||||
|
||||
remove_archive=1
|
||||
if [[ "$1" == "-r" || "$1" == "--remove" ]]; then
|
||||
remove_archive=1
|
||||
if [[ "$1" == "-r" || "$1" == "--remove" ]]; then
|
||||
remove_archive=0
|
||||
shift
|
||||
fi
|
||||
fi
|
||||
|
||||
# here, we check for dropin/multi-threaded replacements
|
||||
# this should eventually be moved to modules/archive/init.zsh
|
||||
# as a global alias
|
||||
if (( $+commands[pigz] )); then
|
||||
# here, we check for dropin/multi-threaded replacements
|
||||
# this should eventually be moved to modules/archive/init.zsh
|
||||
# as a global alias
|
||||
if (( $+commands[pigz] )); then
|
||||
_gzip_bin='pigz'
|
||||
else
|
||||
else
|
||||
_gzip_bin='gzip'
|
||||
fi
|
||||
fi
|
||||
|
||||
if (( $+commands[pixz] )); then
|
||||
if (( $+commands[pixz] )); then
|
||||
_xz_bin='pixz'
|
||||
else
|
||||
else
|
||||
_xz_bin='xz'
|
||||
fi
|
||||
fi
|
||||
|
||||
if (( $+commands[lbzip2] )); then
|
||||
if (( $+commands[lbzip2] )); then
|
||||
_bzip2_bin='lbzip2'
|
||||
elif (( $+commands[pbzip2] )); then
|
||||
elif (( $+commands[pbzip2] )); then
|
||||
_bzip2_bin='pbzip2'
|
||||
else
|
||||
else
|
||||
_bzip2_bin='bzip2'
|
||||
fi
|
||||
fi
|
||||
|
||||
_zstd_bin='zstd'
|
||||
_zstd_bin='zstd'
|
||||
|
||||
while (( $# > 0 )); do
|
||||
while (( $# > 0 )); do
|
||||
if [[ ! -s "$1" ]]; then
|
||||
print "$0: file not valid: $1" >&2
|
||||
shift
|
||||
|
@ -106,6 +112,7 @@ while (( $# > 0 )); do
|
|||
(( success = $success > 0 ? $success : $? ))
|
||||
(( $success == 0 )) && (( $remove_archive == 0 )) && rm "$1"
|
||||
shift
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# }
|
||||
[ -n "${preload+-}" ] || unarchive "$@"
|
||||
|
|
Loading…
Reference in New Issue
Block a user