diff options
Diffstat (limited to 'Functions')
-rw-r--r-- | Functions/Zftp/zfautocheck | 4 | ||||
-rw-r--r-- | Functions/Zftp/zfinit | 13 | ||||
-rw-r--r-- | Functions/Zftp/zfrglob | 7 | ||||
-rw-r--r-- | Functions/Zftp/zftp_progress | 45 |
4 files changed, 58 insertions, 11 deletions
diff --git a/Functions/Zftp/zfautocheck b/Functions/Zftp/zfautocheck index abb994061..d06beca4f 100644 --- a/Functions/Zftp/zfautocheck +++ b/Functions/Zftp/zfautocheck @@ -15,6 +15,10 @@ # a successful open. local lastsession=$zflastsession +# Unset the delay counter from the progress meter in case there was an +# abnormal exit. +(( ${+zftpseconds} )) && unset zftpseconds + if [[ -z $ZFTP_HOST ]]; then zfopen || return 1 [[ $1 = *d* ]] || do_close=1 diff --git a/Functions/Zftp/zfinit b/Functions/Zftp/zfinit index 2a5fd9b47..0bc619277 100644 --- a/Functions/Zftp/zfinit +++ b/Functions/Zftp/zfinit @@ -2,6 +2,11 @@ emulate -L zsh [[ $1 = -n ]] || zmodload -e zftp || zmodload -ia zftp +if [[ ${+zfconfig} = 0 ]]; then + typeset -gA zfconfig + zfconfig=(progress bar update 1) +fi + alias zfcd='noglob zfcd' alias zfget='noglob zfget' alias zfls='noglob zfls' @@ -13,15 +18,15 @@ autoload -U zfdir zfgcp zfget zfget_match zfgoto zfhere zfinit zfls autoload -U zfmark zfopen zfparams zfpcp zfput zfrglob zfrtime zfstat autoload -U zftp_chpwd zftp_progress zftype zfuget zfuput -# only way of getting that noglob out of the way: this is unnecessary with -# widget-based completion and can be commented out. -setopt completealiases - # # zftp completions: only use these if new-style completion is not # active. # if [[ ${#_patcomps} -eq 0 || ${_patcomps[(i)zf*]} -gt ${#_patcomps} ]]; then + # only way of getting that noglob out of the way: this is unnecessary with + # widget-based completion + setopt completealiases + compctl -f -x 'p[1]' \ -k '(open params user login type ascii binary mode put putat get getat append appendat ls dir local remote mkdir rmdir delete diff --git a/Functions/Zftp/zfrglob b/Functions/Zftp/zfrglob index f9d67b3f2..fad0c3849 100644 --- a/Functions/Zftp/zfrglob +++ b/Functions/Zftp/zfrglob @@ -9,7 +9,8 @@ # stick with a single directory. This is the default. # (2) Use remote globbing, i.e. pass it to ls at the site. # Faster, but only works with UNIX, and only basic globbing. -# We do this if $zfrglob is non-null. +# We do this if zfconfig[remote_glob] (or $zfrglob for +# backward compatibility) is non-null. # There is only one argument, the variable containing the # pattern to be globbed. We set this back to an array containing @@ -20,6 +21,10 @@ setopt extendedglob local pat dir nondir files i +if [[ -n ${zfconfig[remote_glob]} ]]; then + local zfrglob=1 +fi + eval pat=\$$1 # Check if we really need to do anything. Look for standard diff --git a/Functions/Zftp/zftp_progress b/Functions/Zftp/zftp_progress index e2b5084c4..344d1c9c1 100644 --- a/Functions/Zftp/zftp_progress +++ b/Functions/Zftp/zftp_progress @@ -1,18 +1,51 @@ # function zftp_progress { # Basic progress metre, showing the percent of the file transferred. -# You want growing bars? You gotta write growing bars. +# You want growing bars? You gottem. +# zfconfig keys: +# progress +# empty or `none' no progress meter +# `bar' use a growing bar of inverse video +# `percent' or other non-blank show the percentage transferred +# If size of remote file is not available, `bar' or `percent' just show +# bytes. +# update +# Minimum time in seconds between updates of the progress display. # Don't show progress unless stderr is a terminal -[[ ! -t 2 ]] && return 0 +[[ ! -t 2 || ${zfconfig[progress]} = (|none) ]] && return 0 -if [[ $ZFTP_TRANSFER = *F ]]; then - print 1>&2 -elif [[ -n $ZFTP_TRANSFER ]]; then +# Tunable parameters. +# How many seconds to wait before printing an updated progress report. +integer update=${zfconfig[update]:-1} +# What style: either bar for growing bars, or anything else for simple +# percentage. For bar we need to have the terminal width in COLUMNS, +# which is often set automatically, but you never know. +local style=${zfconfig[progress]} + +if [[ -n $ZFTP_TRANSFER ]]; then + # avoid a `parameter unset' message + [[ $ZFTP_TRANSFER != *F ]] && + (( ${+zftpseconds} )) && (( SECONDS - zftpseconds < update )) && return if [[ -n $ZFTP_SIZE ]]; then local frac="$(( ZFTP_COUNT * 100 / ZFTP_SIZE ))%" - print -n "\r$ZFTP_FILE ($ZFTP_SIZE bytes): $ZFTP_TRANSFER $frac" 1>&2 + if [[ $style = bar && ${+COLUMNS} = 1 && $COLUMNS -gt 0 ]]; then + if (( ! ${+zftpseconds} )); then + print "$ZFTP_FILE ($ZFTP_SIZE bytes): $ZFTP_TRANSFER" 1>&2 + fi + integer maxwidth=$(( COLUMNS - 7 )) + local width="$(( ZFTP_COUNT * maxwidth / ZFTP_SIZE ))" + print -nP "\r%S${(l:width:):-}%s${(l:maxwidth-width:):-}: ${frac}%%" 1>&2 + else + print -n "\r$ZFTP_FILE ($ZFTP_SIZE bytes): $ZFTP_TRANSFER $frac" 1>&2 + fi else print -n "\r$ZFTP_FILE: $ZFTP_TRANSFER $ZFTP_COUNT" 1>&2 fi + if [[ $ZFTP_TRANSFER = *F && ${+zftpseconds} = 1 ]]; then + unset zftpseconds + print 1>&2 + else + zftpseconds=$SECONDS + fi fi # } |