Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: 3.1.6-pws-2: zftp configuration and progress



Before I do anything about FTP sessions, here is an update for the zftp
function system.  There are two major changes:  the progress meter can now
do growing bars, like ncftp, and there is a zfconfig associative array for
configuring that and a couple of other things.

--- Doc/Zsh/zftpsys.yo.zfbak	Wed Jul 28 16:20:23 1999
+++ Doc/Zsh/zftpsys.yo	Thu Sep  2 14:25:29 1999
@@ -425,22 +425,56 @@
 )
 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 @@
 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 @@
 
 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.
--- Functions/Zftp/zfautocheck.zfbak	Thu Sep  2 13:53:16 1999
+++ Functions/Zftp/zfautocheck	Thu Sep  2 13:53:32 1999
@@ -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
--- Functions/Zftp/zfinit.zfbak	Thu Sep  2 13:53:16 1999
+++ Functions/Zftp/zfinit	Thu Sep  2 13:53:32 1999
@@ -2,6 +2,11 @@
 
 [[ $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 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
--- Functions/Zftp/zfrglob.zfbak	Thu Sep  2 13:53:16 1999
+++ Functions/Zftp/zfrglob	Thu Sep  2 13:53:32 1999
@@ -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
@@ -19,6 +20,10 @@
 setopt extendedglob
 
 local pat dir nondir files i
+
+if [[ -n ${zfconfig[remote_glob]} ]]; then
+  local zfrglob=1
+fi
 
 eval pat=\$$1
 
--- Functions/Zftp/zftp_progress.zfbak	Thu Sep  2 13:53:16 1999
+++ Functions/Zftp/zftp_progress	Thu Sep  2 13:53:32 1999
@@ -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
 # }


-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy



Messages sorted by: Reverse Date, Date, Thread, Author