mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-05-22 04:51:12 +02:00
Merge 0b899f137b into cb64103161
This commit is contained in:
commit
48f6baa37b
2 changed files with 36 additions and 4 deletions
|
|
@ -53,5 +53,6 @@ local -a exts=(
|
|||
|
||||
_arguments \
|
||||
'(-r --remove)'{-r,--remove}'[Remove archive.]' \
|
||||
'(-t --to-directory)'{-t,--to-directory}'[Extract to a specific directory.]' \
|
||||
"*::archive file:_files -g '(#i)*.(${(j:|:)exts})(-.)'" \
|
||||
&& return 0
|
||||
|
|
|
|||
39
plugins/extract/extract.plugin.zsh
Normal file → Executable file
39
plugins/extract/extract.plugin.zsh
Normal file → Executable file
|
|
@ -9,14 +9,41 @@ Usage: extract [-option] [file ...]
|
|||
|
||||
Options:
|
||||
-r, --remove Remove archive after unpacking.
|
||||
-t, --to-directory <dir> Extract to a specific directory instead of the current one.
|
||||
EOF
|
||||
fi
|
||||
|
||||
local remove_archive=1
|
||||
if [[ "$1" == "-r" ]] || [[ "$1" == "--remove" ]]; then
|
||||
remove_archive=0
|
||||
shift
|
||||
fi
|
||||
local target_directory=""
|
||||
|
||||
while (( $# > 0 )); do
|
||||
case "$1" in
|
||||
-r|--remove)
|
||||
remove_archive=0
|
||||
shift
|
||||
;;
|
||||
-t|--to-directory)
|
||||
shift
|
||||
if (( $# == 0 )); then
|
||||
echo "extract: -t/--to-directory requires a directory argument" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
target_directory="$1"
|
||||
shift
|
||||
|
||||
if [[ ! -d "$target_directory" ]]; then
|
||||
echo "extract: '$target_directory' is not a valid directory" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
target_directory="${target_directory%/}"
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
local pwd="$PWD"
|
||||
while (( $# > 0 )); do
|
||||
|
|
@ -35,6 +62,10 @@ EOF
|
|||
extract_dir="${extract_dir:r}"
|
||||
fi
|
||||
|
||||
if [[ -n "$target_directory" ]]; then
|
||||
extract_dir="$target_directory/${extract_dir:t}"
|
||||
fi
|
||||
|
||||
# If there's a file or directory with the same name as the archive
|
||||
# add a random string to the end of the extract directory
|
||||
if [[ -e "$extract_dir" ]]; then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue