mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-11-20 05:53:52 +01:00
78 lines
1.6 KiB
Plaintext
78 lines
1.6 KiB
Plaintext
#
|
|
# zed
|
|
#
|
|
# No other shell could do this.
|
|
# Edit small files with the command line editor.
|
|
# Use ^X^W to save, ^C to abort.
|
|
# Option -f: edit shell functions. (Also if called as fned.)
|
|
#
|
|
# Completion: use
|
|
# compctl -f -x 'w[1,-f]' -F -- zed
|
|
#
|
|
|
|
local var fun
|
|
# We do not want timeout while we are editing a file
|
|
integer TMOUT=0
|
|
|
|
[[ $1 = -f || $0 = fned ]] && fun=1
|
|
[[ $1 = -(|-|f) ]] && shift
|
|
|
|
[[ -z "$1" ]] && echo 'Usage: "zed filename" or "zed -f function"' && return 1
|
|
|
|
local curcontext=zed:::
|
|
|
|
zstyle -m ":completion:zed:*" insert-tab '*' ||
|
|
zstyle ":completion:zed:*" insert-tab yes
|
|
|
|
if ! bindkey -M zed >&/dev/null; then
|
|
# Make the zed keymap a copy of the current main.
|
|
bindkey -N zed main
|
|
|
|
# Assign some default keys.
|
|
# Depending on your stty's, you may be able to use ^J as accept-line, else:
|
|
|
|
# The following isn't useful if we are copying viins, but that's
|
|
# a nicety.
|
|
bindkey -M zed '^x^w' accept-line
|
|
bindkey -M zed '^M' self-insert-unmeta
|
|
fi
|
|
if ! bindkey -M zed-vicmd >&/dev/null; then
|
|
bindkey -N zed-vicmd vicmd
|
|
|
|
bindkey -M zed-vicmd "ZZ" accept-line
|
|
fi
|
|
|
|
# don't mangle !'s
|
|
setopt localoptions nobanghist
|
|
|
|
if ((fun)) then
|
|
var="$(functions $1)"
|
|
# If function is undefined but autoloadable, load it
|
|
if [[ $var = *\#\ undefined* ]] then
|
|
local dir
|
|
for dir in $fpath; do
|
|
if [[ -f $dir/$1 ]] then
|
|
var="$1() {
|
|
$(<$dir/$1)
|
|
}"
|
|
break
|
|
fi
|
|
done
|
|
elif [[ -z $var ]] then
|
|
var="$1() {
|
|
}"
|
|
fi
|
|
vared -M zed -m zed-vicmd var && eval function "$var"
|
|
else
|
|
[[ -f $1 ]] && var="$(<$1)"
|
|
while vared -M zed -m zed-vicmd var
|
|
do
|
|
(print -r -- "$var" >| $1) && break
|
|
echo -n -e '\a'
|
|
done
|
|
fi
|
|
|
|
return 0
|
|
|
|
# End of zed
|