diff options
author | Tanaka Akira <akr@users.sourceforge.net> | 1999-06-27 05:33:04 +0000 |
---|---|---|
committer | Tanaka Akira <akr@users.sourceforge.net> | 1999-06-27 05:33:04 +0000 |
commit | 346825df86466cf151be61b9429ef2c1734e66ea (patch) | |
tree | bd3e1ccd947b47f974c62b4113c5276416de2c9f /Functions/Zftp/zfmark | |
parent | a2159285e80508bb682d90a71270fbddada8bd05 (diff) | |
download | zsh-346825df86466cf151be61b9429ef2c1734e66ea.tar.gz zsh-346825df86466cf151be61b9429ef2c1734e66ea.tar.xz zsh-346825df86466cf151be61b9429ef2c1734e66ea.zip |
zsh-3.1.5-pws-24 zsh-3.1.5-pws-24
Diffstat (limited to 'Functions/Zftp/zfmark')
-rw-r--r-- | Functions/Zftp/zfmark | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/Functions/Zftp/zfmark b/Functions/Zftp/zfmark index e69de29bb..8d35ce45a 100644 --- a/Functions/Zftp/zfmark +++ b/Functions/Zftp/zfmark @@ -0,0 +1,49 @@ +# zfmark [bname] +# Set a bookmark for the current zftp connection, or use the +# information about the last session if there isn't one. +# A bookmark includes both the host *and* the directory on that host. +# +# Without bname, list the current bookmarks and their locations. + +emulate -L zsh +setopt extendedglob + +# Set ZFTP_BMFILE if not already set. This should agree with +# the corresponding line in zfgoto. +: ${ZFTP_BMFILE:=${ZDOTDIR:-$HOME}/.zfbkmarks} + +typeset -A bkmarks +local line + +if [[ -f $ZFTP_BMFILE ]]; then + # read in file: could optimise this by recording last read time + # comparing with file + while read -r line; do + # ignore blank and comment lines + [[ $line = [[:blank:]]# || $line = [[:blank:]]#'#'* ]] && continue + bkmarks[${line%% *}]="${line#* }" + done <$ZFTP_BMFILE +fi + +if (( $# == 0 )); then + for line in ${(ko)bkmarks}; do + print -r- "$line ${bkmarks[$line]}" + done + return 0 +elif (( $# > 1 )); then + print "Usage: zfmark [bookmark]" >&2 + return 1 +fi + +if [[ -n $ZFTP_HOST ]]; then + bkmarks[$1]="${ZFTP_USER}@${ZFTP_HOST}:${ZFTP_PWD}" +elif [[ -n $zflastsession ]]; then + bkmarks[$1]="${zflastuser}@${zflastsession}" +else + print "No current or recent ZFTP session to bookmark." >&2 + return 1 +fi + +for line in ${(ko)bkmarks}; do + print -r- "$line ${bkmarks[$line]}" +done >$ZFTP_BMFILE |