Skip to content

Instantly share code, notes, and snippets.

@kenoss kenoss/gist:8985182
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.