Fixed vim and zsh
This commit is contained in:
43
zsh/modules/archive/functions/archive
Normal file
43
zsh/modules/archive/functions/archive
Normal file
@ -0,0 +1,43 @@
|
||||
#
|
||||
# Creates archive files
|
||||
#
|
||||
|
||||
local archive_name dir_to_archive
|
||||
|
||||
if (( ${#} != 2 )); then
|
||||
print "usage: ${0} [archive_name.ext] [/path/to/include/in/archive]" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
# 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}"
|
||||
# use absolute paths, and follow symlinks
|
||||
dir_to_archive="${2}"
|
||||
|
||||
# if the directory doesn't exist, quit. Nothing to archive
|
||||
if [[ ! -e "${dir_to_archive}" ]]; then
|
||||
print "${0}: file or directory not valid: ${dir_to_archive}" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
# pigz and pbzip2 are aliased in the init.zsh file. This provides a significant speedup, resulting in a
|
||||
# near-liner decrease in compression time based on on the number of available cores.
|
||||
|
||||
case "${archive_name}" in
|
||||
(*.tar.gz|*.tgz) tar -cvf "${archive_name}" --use-compress-program="${_gzip_bin}" "${dir_to_archive}" ;;
|
||||
(*.tar.bz2|*.tbz|*.tbz2) tar -cvf "${archive_name}" --use-compress-program="${_bzip2_bin}" "${dir_to_archive}" ;;
|
||||
(*.tar.xz|*.txz) tar --xz --help &> /dev/null && tar -cvJf "${archive_name}" "${dir_to_archive}" ;;
|
||||
(*.tar.lzma|*.tlz) tar --lzma --help &> /dev/null && tar -cvf "${archive_name}" --lzma "${dir_to_archive}" ;;
|
||||
(*.tar) tar -cvf "${archive_name}" "${dir_to_archive}" ;;
|
||||
(*.zip) zip -r "${archive_name}" "${dir_to_archive}" ;;
|
||||
(*.rar) rar a "${archive_name}" "${dir_to_archive}" ;;
|
||||
(*.7z) 7za a "${archive_name}" "${dir_to_archive}" ;;
|
||||
(*.gz) print "${0}: .gz is only useful for single files, and does not capture permissions. Use .tar.gz" ;;
|
||||
(*.bz2) print "${0}: .bzip2 is only useful for single files, and does not capture permissions. Use .tar.bz2" ;;
|
||||
(*.xz) print "${0}: .xz is only useful for single files, and does not capture permissions. Use .tar.xz" ;;
|
||||
(*.lzma) print "${0}: .lzma is only useful for single files, and does not capture permissions. Use .tar.lzma" ;;
|
||||
(*) print "${0}: unknown archive type: ${archive_name}" ;;
|
||||
esac
|
BIN
zsh/modules/archive/functions/archive.zwc
Normal file
BIN
zsh/modules/archive/functions/archive.zwc
Normal file
Binary file not shown.
42
zsh/modules/archive/functions/unarchive
Normal file
42
zsh/modules/archive/functions/unarchive
Normal file
@ -0,0 +1,42 @@
|
||||
#
|
||||
# Unarchives files
|
||||
#
|
||||
|
||||
local archive_name
|
||||
|
||||
if (( ${#} != 1 )); then
|
||||
print "usage: ${0} [archive.ext]" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ ! -s ${1} ]]; then
|
||||
print "archive \"${1}\" was not found or has size 0." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
# strip the path, just in case one is provided for some reason
|
||||
archive_name="${1:t}"
|
||||
|
||||
# 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.
|
||||
|
||||
case "${archive_name}" in
|
||||
(*.tar.gz|*.tgz) tar -xvzf "${archive_name}" ;;
|
||||
(*.tar.bz2|*.tbz|*.tbz2) tar -xvjf "${archive_name}" ;;
|
||||
(*.tar.xz|*.txz) tar --xz --help &> /dev/null && tar --xz -xvf "${archive_name}" \
|
||||
|| xzcat "${archive_name}" | tar xvf - ;;
|
||||
(*.tar.zma|*.tlz) tar --lzma --help &> /dev/null && tar --lzma -xvf "${archive_name}" \
|
||||
|| lzcat "${archive_name}" | tar xvf - ;;
|
||||
(*.tar) tar xvf "${archive_name}" ;;
|
||||
(*.gz) gunzip "${archive_name}" ;;
|
||||
(*.bz2) bunzip2 "${archive_name}" ;;
|
||||
(*.xz) unxz "${archive_name}" ;;
|
||||
(*.lzma) unlzma "${archive_name}" ;;
|
||||
(*.Z) uncompress "${archive_name}" ;;
|
||||
(*.zip) unzip "${archive_name}";;
|
||||
(*.rar) unrar &> /dev/null \
|
||||
&& unrar x -ad "${archive_name}" \
|
||||
|| rar x -ad "${archive_name}" ;;
|
||||
(*.7z) 7za x "${archive_name}" ;;
|
||||
(*) print "${0}: unknown archive type: ${archive_name}" ;;
|
||||
esac
|
BIN
zsh/modules/archive/functions/unarchive.zwc
Normal file
BIN
zsh/modules/archive/functions/unarchive.zwc
Normal file
Binary file not shown.
Reference in New Issue
Block a user