2 # a generic accept-line wrapper {{{
4 # This widget can prevent unwanted autocorrections from command-name
5 # to _command-name, rehash automatically on enter and call any number
6 # of builtin and user-defined widgets in different contexts.
8 # For a broader description, see:
9 # <http://bewatermyfriend.org/posts/2007/12-26.11-50-38-tooltime.html>
11 # The code is imported from the file 'zsh/functions/accept-line' from
12 # <http://ft.bewatermyfriend.org/comp/zsh/zsh-dotfiles.tar.bz2>, which
13 # distributed under the same terms as zsh itself.
15 # A newly added command will may not be found or will cause false
16 # correction attempts, if you got auto-correction set. By setting the
17 # following style, we force accept-line() to rehash, if it cannot
18 # find the first word on the command line in the $command[] hash.
19 zstyle ':acceptline:*' rehash true
21 function Accept-Line() {
27 zstyle -a ":acceptline:${alcontext}" actions subs
29 (( ${#subs} < 1 )) && return 0
32 for sub in ${subs} ; do
33 [[ ${sub} == 'accept-line' ]] && sub='.accept-line'
36 (( aldone > 0 )) && break
40 function Accept-Line-getdefault() {
44 zstyle -s ":acceptline:${alcontext}" default_action default_action
45 case ${default_action} in
50 printf ${default_action}
55 function accept-line() {
59 local buf com fname format msg default_action
63 cmdline=(${(z)BUFFER})
67 zstyle -t ":acceptline:${alcontext}" rehash \
68 && [[ -z ${commands[$com]} ]] \
71 if [[ -n ${reswords[(r)$com]} ]] \
72 || [[ -n ${aliases[$com]} ]] \
73 || [[ -n ${functions[$com]} ]] \
74 || [[ -n ${builtins[$com]} ]] \
75 || [[ -n ${commands[$com]} ]] ; then
77 # there is something sensible to execute, just do it.
81 default_action=$(Accept-Line-getdefault)
82 zstyle -T ":acceptline:${alcontext}" call_default \
83 && zle ${default_action}
88 || [[ -o correctall ]] \
89 && [[ -n ${functions[$fname]} ]] ; then
91 # nothing there to execute but there is a function called
92 # _command_name; a completion widget. Makes no sense to
93 # call it on the commandline, but the correct{,all} options
94 # will ask for it nevertheless, so warn the user.
95 if [[ ${LASTWIDGET} == 'accept-line' ]] ; then
96 # Okay, we warned the user before, he called us again,
101 default_action=$(Accept-Line-getdefault)
102 zstyle -T ":acceptline:${alcontext}" call_default \
103 && zle ${default_action}
107 # prepare warning message for the user, configurable via zstyle.
108 zstyle -s ":acceptline:${alcontext}" compwarnfmt msg
110 if [[ -z ${msg} ]] ; then
111 msg="%c will not execute and completion %f exists."
114 zformat -f msg "${msg}" "c:${com}" "f:${fname}"
118 elif [[ -n ${buf//[$' \t\n']##/} ]] ; then
119 # If we are here, the commandline contains something that is not
120 # executable, which is neither subject to _command_name correction
121 # and is not empty. might be a variable assignment
125 default_action=$(Accept-Line-getdefault)
126 zstyle -T ":acceptline:${alcontext}" call_default \
127 && zle ${default_action}
131 # If we got this far, the commandline only contains whitespace, or is empty.
135 default_action=$(Accept-Line-getdefault)
136 zstyle -T ":acceptline:${alcontext}" call_default \
137 && zle ${default_action}
145 # power completion - abbreviation expansion {{{
146 # power completion / abbreviation expansion / buffer expansion
147 # see http://zshwiki.org/home/examples/zleiab for details
148 # less risky than the global aliases but powerful as well
149 # just type the abbreviation key and afterwards ',.' to expand it
152 setopt interactivecomments
154 # key # value (#d additional doc string)
160 'G' '|& grep --color=auto '
162 'Hl' ' --help |& less -r' #d (Display help in pager)
166 'N' '&>/dev/null' #d (No Output)
167 'R' '| tr A-z N-za-m' #d (ROT13)
173 'co' './configure && make && sudo make install'
181 if (( NOABBREVIATION > 0 )) ; then
182 LBUFFER="${LBUFFER},."
186 matched_chars='[.-|_a-zA-Z0-9]#'
187 LBUFFER=${LBUFFER%%(#m)[.-|_a-zA-Z0-9]#}
188 LBUFFER+=${abk[$MATCH]:-$MATCH}
192 bindkey ",." globalias