Last active
August 29, 2015 13:56
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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