diff options
author | Tanaka Akira <akr@users.sourceforge.net> | 1999-09-02 16:44:59 +0000 |
---|---|---|
committer | Tanaka Akira <akr@users.sourceforge.net> | 1999-09-02 16:44:59 +0000 |
commit | 6e1759433b3d8e861e6146fcf9bd7a70735ec675 (patch) | |
tree | 8e736c83a6a4b0a314af123aa8660f8cdeefe3d0 | |
parent | 8b3e5404ce0fad4ebe457eb521b0b487221faf6a (diff) | |
download | zsh-6e1759433b3d8e861e6146fcf9bd7a70735ec675.tar.gz zsh-6e1759433b3d8e861e6146fcf9bd7a70735ec675.tar.xz zsh-6e1759433b3d8e861e6146fcf9bd7a70735ec675.zip |
zsh-workers/7632
-rw-r--r-- | Doc/Zsh/zftpsys.yo | 75 | ||||
-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 |
5 files changed, 113 insertions, 31 deletions
diff --git a/Doc/Zsh/zftpsys.yo b/Doc/Zsh/zftpsys.yo index 50fa2a800..3c8f90cdd 100644 --- a/Doc/Zsh/zftpsys.yo +++ b/Doc/Zsh/zftpsys.yo @@ -425,22 +425,56 @@ fits in well. ) findex(zftp_progress, supplied version) item(tt(zftp_progress))( -This function shows the status of the transfer as the percentage of the -total so far transferred. It will not write anything unless the output is -going to a terminal; however, if you transfer files in the background, you -should tt(unfunction) this first. (Background file transfers don't work on -all OSes.) Note also that if you alter it, any output em(must) be to -standard error, as standard output may be a file being received. +This function shows the status of the transfer. It will not write anything +unless the output is going to a terminal; however, if you transfer files in +the background, you should turn off progress reports by hand using +`tt(zfconfig[progress]=none)'. (Background file transfers don't work on all +OSes.) Note also that if you alter it, any output em(must) be to standard +error, as standard output may be a file being received. The form of the +progess meter, or whether it is used at all, can be configured without +altering the function, as described in the next section. ) enditem() texinode(Miscellaneous Features)()(Zftp Functions)(Zftp Function System) sect(Miscellaneous Features) +subsect(Configuration) +cindex(zftp function system, configuration) +pindex(zfconfig) + +The tt(zfinit) function defines an associative array tt(zfconfig). +Elements of this may subsequently be set to change the behaviour of the +tt(zftp) functions using standard syntax (for example, +`tt(zfconfig[progress]=percent)'. The following keys are understood. + +startitem() +item(tt(progress))( +Controls the way that tt(zftp_progress) reports on the progress of a +transfer. If empty, unset, or `tt(none)', no progress report is made; if +`tt(bar)' (the default), a growing bar of inverse video is shown; if +`tt(percent)' (or any other string, though this may change in future), the +percentage of the file transferred is shown. The bar meter requires that +the width of the terminal be available via the tt($COLUMNS) parameter +(normally this is set automatically). If the size of the file being +transferred is not available, tt(bar) and tt(percent) meters will simply +show the number of bytes transferred so far. +) +item(tt(update))( +Specifies the minimum time interval between updates of the progress meter +in seconds. No update is made unless new data has been received, so the +actual time interval is limited only by tt($ZFTP_TIMEOUT). +) +item(tt(remote_glob))( +If set to a non-zero length, filename generation (globbing) is +performed on the remote machine instead of by zsh itself; see below. +) +enditem() + subsect(Remote globbing) cindex(zftp function system, remote globbing) -The commands for retrieving files usually perform filename expansion +The commands for retrieving files usually perform filename generation (globbing) on their arguments; this can be turned off by passing the option tt(-G) to each of the commands. Normally this operates by retrieving a complete list of files for the directory in question, then matching these @@ -452,14 +486,15 @@ remote server does not support the UNIX directory semantics, directory handling is problematic and it is recommended that globbing only be used within the current directory. The list of files in the current directory, if retrieved, will be cached, so that subsequent globs in the same -directory without an intervening tt(zfcd) are fast. +directory without an intervening tt(zfcd) are much faster. -If the variable tt($zfrglob) is set to a non-zero length, globbing is -instead performed on the remote host: the server is asked for a list of -matching files. This is highly dependent on how the server is implemented, -though typically UNIX servers will provide support for basic glob -patterns. This may in some cases be faster, as it avoids retrieving the -entire list of directory contents. +If the key tt(remote_glob) of the tt(zfconfig) associative array (see +above) is set to a non-zero length, globbing is instead performed on the +remote host: the server is asked for a list of matching files. This is +highly dependent on how the server is implemented, though typically UNIX +servers will provide support for basic glob patterns. This may in some +cases be faster, as it avoids retrieving the entire list of directory +contents. subsect(Automatic and temporary reopening) cindex(zftp function system, automatic reopening) @@ -500,9 +535,9 @@ will open the connection in the directory tt(/pub) and leave it open. subsect(Completion) -Completion of remote files, directories and bookmarks is supported. The -older, tt(compctl)-style completion is defined when tt(zfinit) is called; -support for the new widget-based completion system is provided in the -function tt(Completion/Builtins/_zftp), which should be installed with the -other functions of the completion system and hence should automatically be -available. +Completion of local and remote files, directories and bookmarks is +supported. The older, tt(compctl)-style completion is defined when +tt(zfinit) is called; support for the new widget-based completion system is +provided in the function tt(Completion/Builtins/_zftp), which should be +installed with the other functions of the completion system and hence +should automatically be available. 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 # } |