X-Git-Url: https://git.madduck.net/etc/zsh.git/blobdiff_plain/e45b0db3d66ca9e041622db3d801d026fb4d3724..33230b65afa1076218abff057d0bbcc7486af0a8:/.zsh/zshrc/80-zle_magic_abbreviations?ds=sidebyside diff --git a/.zsh/zshrc/80-zle_magic_abbreviations b/.zsh/zshrc/80-zle_magic_abbreviations new file mode 100644 index 0000000..fc831cf --- /dev/null +++ b/.zsh/zshrc/80-zle_magic_abbreviations @@ -0,0 +1,51 @@ +typeset -Ag zle_abbrevs +zle_abbrevs=( +# '...' '../..' +# '....' '../../..' +# '.....' '../../../..' +# '......' '../../../../..' + 'WC' '| wc' + 'GR' '|& grep ' + 'HD' '| head' + 'HL' ' --help |& less -r' + 'LS' '| less' + 'LR' '|& less -r' + 'NL' '&>/dev/null' + 'SL' '| sort | less' + 'SU' '| sort -u' + 'TL' '| tail' + 'VI' '|& vim -' + 'ND' '*(/om[1])' + 'NF' '*(.om[1])' +) +# the ...## abbrevs are gone in favour of rationalise-dot + +magic-abbrev-expand() { + emulate -L zsh + setopt extendedglob + local MATCH MBEGIN MEND + LBUFFER=${LBUFFER%%(#m)[.A-Z]#} + LBUFFER+=${zle_abbrevs[$MATCH]:-$MATCH} +} + +no-magic-abbrev-expand() { + emulate -L zsh + LBUFFER+=' ' +} + +zle -N magic-abbrev-expand +zle -N no-magic-abbrev-expand + +magic_space_functions+=magic-abbrev-expand +accept_line_functions+=magic-abbrev-expand + +bindkey "^x " no-magic-abbrev-expand +bindkey -M isearch " " self-insert + +function help-show-magic-abbrevs() { + zle -M "$(print "Available abbreviations for expansion:"; print -a -C 2 ${(kv)zle_abbrevs})" +} +zle -N help-show-magic-abbrevs +bindkey '\e?' help-show-magic-abbrevs + +# vim:ft=zsh