summaryrefslogtreecommitdiff
path: root/Functions/Zftp/zfuget
diff options
context:
space:
mode:
Diffstat (limited to 'Functions/Zftp/zfuget')
-rw-r--r--Functions/Zftp/zfuget51
1 files changed, 16 insertions, 35 deletions
diff --git a/Functions/Zftp/zfuget b/Functions/Zftp/zfuget
index 482da42e9..c1033c930 100644
--- a/Functions/Zftp/zfuget
+++ b/Functions/Zftp/zfuget
@@ -25,8 +25,9 @@
emulate -L zsh
+[[ $curcontext = :zf* ]] || local curcontext=:zfuget
local loc rem locstats remstats doit tmpfile=${TMPPREFIX}zfuget$$
-local rstat remlist verbose optlist opt bad i silent nglob time
+local rstat remlist opt opt_v opt_s opt_G opt_t
integer stat do_close
zfuget_print_time() {
@@ -43,40 +44,20 @@ zfuget_print () {
print ", $locstats[1] bytes)"
}
-while [[ $1 = -* ]]; do
- if [[ $1 = - || $1 = -- ]]; then
- shift;
- break;
- fi
- optlist=${1#-}
- for (( i = 1; i <= $#optlist; i++)); do
- opt=$optlist[$i]
- case $optlist[$i] in
- v) verbose=1
- ;;
- s) silent=1
- ;;
- G) nglob=1
- ;;
- t) time=1
- ;;
- *) print option $opt not recognised >&2
- ;;
- esac
- done
- shift
+while getopts :vsGt opt; do
+ [[ $opt = "?" ]] && print "zfuget: bad option: -$OPTARG" >&2 && return 1
+ eval "opt_$opt=1"
done
+(( OPTIND > 1 )) && shift $(( OPTIND - 1 ))
-[[ -n $bad ]] && return 1
-
-zfautocheck
+zfautocheck || return 1
for remlist in $*; do
# zfcd directory hack to put the front back to ~
if [[ $remlist == $HOME || $remlist == $HOME/* ]]; then
remlist="~${remlist#$HOME}"
fi
- if [[ $nglob != 1 ]]; then
+ if [[ $opt_n != 1 ]]; then
zfrglob remlist
fi
if (( $#remlist )); then
@@ -99,11 +80,11 @@ for remlist in $*; do
stat=1
continue
fi
- [[ $verbose = 1 ]] && zfuget_print
+ [[ $opt_v = 1 ]] && zfuget_print
if (( $locstats[1] != $remstats[1] )); then
# Files have different sizes
- if [[ $locstats[2] > $remstats[2] && $silent != 1 ]]; then
- [[ $verbose != 1 ]] && zfuget_print
+ if [[ $locstats[2] > $remstats[2] && $opt_s != 1 ]]; then
+ [[ $opt_v != 1 ]] && zfuget_print
print "Local file $loc more recent than remote," 1>&2
print -n "but sizes are different. Transfer anyway [y/n]? " 1>&2
read -q doit
@@ -111,24 +92,24 @@ for remlist in $*; do
else
# Files have same size
if [[ $locstats[2] < $remstats[2] ]]; then
- if [[ $silent != 1 ]]; then
- [[ $verbose != 1 ]] && zfuget_print
+ if [[ $opt_s != 1 ]]; then
+ [[ $opt_v != 1 ]] && zfuget_print
print "Local file $loc has same size as remote," 1>&2
print -n "but local file is older. Transfer anyway [y/n]? " 1>&2
read -q doit
fi
else
# presumably same file, so don't get it.
- [[ $verbose = 1 ]] && print Not transferring
+ [[ $opt_v = 1 ]] && print Not transferring
doit=n
fi
fi
else
- [[ $verbose = 1 ]] && print New file $loc
+ [[ $opt_v = 1 ]] && print New file $loc
fi
if [[ $doit = y ]]; then
if zftp get $rem >$loc; then
- if [[ $time = 1 ]]; then
+ if [[ $opt_t = 1 ]]; then
# if $remstats is set, it's second element is the remote time
zfrtime $loc $rem $remstats[2]
fi