Skip to content

Instantly share code, notes, and snippets.

@kenoss
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenoss/8985182 to your computer and use it in GitHub Desktop.
Save kenoss/8985182 to your computer and use it in GitHub Desktop.
If point is end of line, expand abbreviation. If not, go to the end of line.
typeset -A myabbrev
myabbrev=(
"DN" "&> /dev/null"
"L" "| $PAGER "
"G" "| grep "
"S" "| sed '_|_'"
"R" " rm "
"M" " mkdir "
"C" " cat "
"TX" " tar -xvzf "
"TC" " tar -cvzf "
"RS" "rsync -av --exclude '\#*' --exclude '*~' "
"FX" "find _|_ -print0 | xargs -0 "
"PWD" ""
)
my-expand-abbrev() {
if [ -z "$RBUFFER" ] ; then
my-expand-abbrev-aux
else
zle end-of-line
fi
}
my-expand-abbrev-aux() {
local init last value addleft addright
init=$(echo -nE "$LBUFFER" | sed -e "s/[_a-zA-Z0-9]*$//")
last=$(echo -nE "$LBUFFER" | sed -e "s/.*[^_a-zA-Z0-9]\([_a-zA-Z0-9]*\)$/\1/")
value=${myabbrev[$last]}
if [[ $value = *_\|_* ]] ; then
addleft=${value%%_\|_*}
addright=${value#*_\|_}
else
addleft=$value
addright=""
fi
if [ "$last" = "PWD" ] ; then
LBUFFER=""
RBUFFER="$PWD"
else
LBUFFER=$init${addleft:-$last }
RBUFFER=$addright$RBUFFER
fi
}
zle -N my-expand-abbrev
bindkey "^e" my-expand-abbrev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment