home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / ap / zsh / zsh-2.4 / zsh-2 / zsh-2.4.306 / func / zed < prev   
Text File  |  1993-05-06  |  1KB  |  66 lines

  1. # zed():  Peter Stephenson <pws@s-a.amtp.liv.ac.uk>
  2. # No other shell could do this.
  3. # Edit small files with the command line editor.
  4. # Use ^X^W to save, ^C to abort.
  5. # Option -f: edit shell functions.  (Also if called as fned.)
  6. #
  7. # Completion: use
  8. # compctl -f -x 'w[1,-f]' -F -- zed
  9.  
  10. local var nb fun
  11.  
  12. [[ $1 = -f || $0 = fned ]] && fun=1
  13. [[ $1 = -(|-|f) ]] && shift
  14.  
  15. [[ -z "$1" ]] && echo 'Usage: "zed filename" or "zed -f function"' && return 1
  16.  
  17. # catch interrupts
  18. TRAPINT() {
  19.   bindkey "^M" accept-line
  20.   [[ $nb = 1 ]] || unsetopt nobanghist
  21.   trap - INT
  22.   (($1 > 0)) && return $[128+$1]
  23. }
  24.  
  25. # don't mangle !'s
  26. [[ -o nobanghist ]] && nb=1
  27. setopt nobanghist
  28.  
  29. bindkey "^M" self-insert-unmeta
  30. # Depending on your stty's, you may be able to use ^J as accept-line, else:
  31. bindkey "^X^W" accept-line
  32.  
  33. if [[ $fun = 1 ]]; then
  34.   var="$(functions $1)"
  35.   # If function is undefined but autoloadable, load it
  36.   if [[ $var = undefined* ]]; then
  37.     local dir
  38.     for dir in $fpath; do
  39.       if [[ -f $dir/$1 ]]; then
  40.     var="$1() {
  41. $(<$dir/$1)
  42. }"
  43.     break
  44.       fi
  45.     done
  46.   elif [[ -z $var ]]; then
  47.     var="$1() {
  48. }"
  49.   fi
  50.   vared var
  51.   # remember there\'s a memory leak in eval...
  52.   eval function "$var"
  53. else
  54.   [[ -f $1 ]] && var="$(<$1)"
  55.   vared var
  56.   (( $? == 0 )) && print -R "$var" >! $1
  57. fi
  58.  
  59. bindkey "^X^W" undefined-key
  60.  
  61. # Restore setup
  62. TRAPINT 0
  63. return 0
  64.  
  65. # End of zed
  66.