magic space binding
[zsh.git] / .zsh / 30_Options.zsh
1 # -*- mode: sh;-*-
2
3 ## Zsh options
4 #
5 # see man zshoptions(1) for more details ;-)
6 #
7
8 function SetOPT() {
9 SetOPTifExists $1 on
10 }
11 function UnsetOPT() {
12 SetOPTifExists $1 off
13 }
14
15 function SetOPTifExists() {
16 local option=${(L)1//_/} # lowercase and no '_'
17
18 case "$option" in
19 "no"*)
20 option=${option/no/}
21 # resets $1 and $2
22 set $option off
23 ;;
24 esac
25
26 if ( echo ${(k)options} | grep $option >/dev/null ); then
27 # option exists, set it.
28 case "$2" in
29 on)
30 debug "$fg_bold[cyan]setopt$reset_color $option"
31 setopt $option
32 ;;
33 off)
34 debug "$fg_bold[cyan]unsetopt$reset_color $option"
35 unsetopt $option
36 ;;
37 esac
38 else
39 debug "$option not supported by this version of zsh !"
40 fi
41 }
42
43 # These are the options that apply to noninteractive shells.
44 # Ones in capitals are variations from the default ZSH behaviour.
45
46 # Treat the `#', `~' and `^' characters as part of patterns for filename
47 # generation, etc. (An initial unquoted `~' always produces named
48 # directory expansion.)
49 SetOPT EXTENDED_GLOB
50
51 # Do not require a leading `.' in a filename to be matched explicitly.
52 SetOPT GLOBDOTS
53
54 # If numeric filenames are matched by a filename generation pattern,
55 # sort the filenames numerically rather than lexicographically.
56 SetOPT NUMERIC_GLOB_SORT
57
58 # Don't push multiple copies of the same directory onto the directory
59 # stack.
60 SetOPT PUSHD_IGNORE_DUPS
61
62 # Exchanges the meanings of `+' and `-' when used with a number to
63 # specify a directory in the stack.
64 SetOPT PUSHD_MINUS
65
66 # Do not print the directory stack after pushd or popd.
67 SetOPT PUSHDSILENT
68
69 # Have pushd with no arguments act like `pushd $HOME'.
70 SetOPT PUSHDTOHOME
71
72 # If a completion is performed with the cursor within a word, and a full
73 # completion is inserted, the cursor is moved to the end of the word.
74 # That is, the cursor is moved to the end of the word if either a single
75 # match is inserted or menu completion is performed.
76 SetOPT ALWAYS_TO_END
77
78 # If a command is issued that can't be executed as a normal command, and
79 # the command is the name of a directory, perform the cd command to that
80 # directory.
81 SetOPT AUTO_CD
82
83 # Any parameter that is set to the absolute name of a directory
84 # immediately becomes a name for that directory, that will be used by
85 # the `%~' and related prompt sequences, and will be available when
86 # completion is performed on a word starting with `~'. (Otherwise, the
87 # parameter must be used in the form `~param' first.)
88 SetOPT AUTO_NAME_DIRS
89
90 # Make cd push the old directory onto the directory stack.
91 SetOPT AUTO_PUSHD
92
93 # Treat single word simple commands without redirection as candidates
94 # for resumption of an existing job.
95 SetOPT AUTO_RESUME
96
97 # Expand expressions in braces which would not otherwise undergo brace
98 # expansion to a lexically ordered list of all the characters. See the
99 # section `Brace Expansion'.
100 SetOPT BRACE_CCL
101
102 # Prevents aliases on the command line from being internally substituted
103 # before completion is attempted. The effect is to make the alias a
104 # distinct command for completion purposes.
105 SetOPT COMPLETE_ALIASES
106
107 # If unset, the cursor is set to the end of the word if completion is
108 # started. Otherwise it stays there and completion is done from both
109 # ends.
110 SetOPT COMPLETE_IN_WORD
111
112 # Try to correct the spelling of commands. Note that, when the
113 # HASH_LIST_ALL option is not set or when some directories in the path
114 # are not readable, this may falsely report spelling errors the first
115 # time some commands are used.
116 #
117 # The shell variable CORRECT_IGNORE may be set to a pattern to match
118 # words that will never be offered as corrections.
119 SetOPT CORRECT
120
121 # Do not enter command lines into the history list if they are
122 # duplicates of the previous event.
123 SetOPT HIST_IGNORE_DUPS
124
125 # If a new command line being added to the history list duplicates an
126 # older one, the older command is removed from the list (even if it is
127 # not the previous event).
128 SetOPT HIST_IGNORE_ALL_DUPS
129
130 # Remove the history (fc -l) command from the history list when invoked.
131 # Note that the command lingers in the internal history until the next
132 # command is entered before it vanishes, allowing you to briefly reuse
133 # or edit the line.
134 SetOPT HIST_NO_STORE
135
136 # Remove superfluous blanks from each command line being added to the
137 # history list.
138 SetOPT HIST_REDUCE_BLANKS
139
140 # This options works like APPEND_HISTORY except that new history lines
141 # are added to the $HISTFILE incrementally (as soon as they are
142 # entered), rather than waiting until the shell exits. The file will
143 # still be periodically re-written to trim it when the number of lines
144 # grows 20% beyond the value specified by $SAVEHIST (see also the
145 # HIST_SAVE_BY_COPY option).
146 SetOPT INC_APPEND_HISTORY
147
148 # When searching for history entries in the line editor, do not display
149 # duplicates of a line previously found, even if the duplicates are not
150 # contiguous.
151 SetOPT HIST_FIND_NO_DUPS
152
153 # Remove command lines from the history list when the first character on
154 # the line is a space, or when one of the expanded aliases contains a
155 # leading space. Only normal aliases (not global or suffix aliases)
156 # have this behaviour. Note that the command lingers in the internal
157 # history until the next command is entered before it vanishes, allowing
158 # you to briefly reuse or edit the line. If you want to make it vanish
159 # right away without entering another command, type a space and press
160 # return.
161 SetOPT HIST_IGNORE_SPACE
162
163 # Allow comments even in interactive shells.
164 SetOPT INTERACTIVE_COMMENTS
165
166 # List jobs in the long format by default.
167 SetOPT LONG_LIST_JOBS
168
169 # If set, parameter expansion, command substitution and arithmetic
170 # expansion are performed in prompts. Substitutions within prompts do
171 # not affect the command status.
172 SetOPT PROMPT_SUBST
173
174 # If the internal history needs to be trimmed to add the current command
175 # line, setting this option will cause the oldest history event that has
176 # a duplicate to be lost before losing a unique event from the list.
177 # You should be sure to set the value of HISTSIZE to a larger number
178 # than SAVEHIST in order to give you some room for the duplicated
179 # events, otherwise this option will behave just like
180 # HIST_IGNORE_ALL_DUPS once the history fills up with unique events.
181 SetOPT HIST_EXPIRE_DUPS_FIRST
182
183 # Try to make the completion list smaller (occupying less lines) by
184 # printing the matches in columns with different widths.
185 SetOPT LIST_PACKED
186
187 # This option both imports new commands from the history file, and also
188 # causes your typed commands to be appended to the history file (the
189 # latter is like specifying INC_APPEND_HISTORY). The history lines are
190 # also output with timestamps ala EXTENDED_HISTORY (which makes it
191 # easier to find the spot where we left off reading the file after it
192 # gets re-written).
193
194 # By default, history movement commands visit the imported lines as well
195 # as the local lines, but you can toggle this on and off with the
196 # set-local-history zle binding. It is also possible to create a zle
197 # widget that will make some commands ignore imported commands, and some
198 # include them.
199 is4 && SetOPT SHARE_HISTORY
200
201 # Save each command's beginning timestamp (in seconds since the epoch)
202 # and the duration (in seconds) to the history file.
203 SetOPT EXTENDED_HISTORY
204
205 # By default, shell history that is read in from files is split into
206 # words on all white space. This means that arguments with quoted
207 # whitespace are not correctly handled, with the consequence that ref‐
208 # erences to words in history lines that have been read from a file may
209 # be inaccurate. When this option is set, words read in from a history
210 # file are divided up in a similar fashion to normal shell command line
211 # handling. Although this produces more accurately delimited words, if
212 # the size of the history file is large this can be slow. Trial and
213 # error is necessary to decide.
214 SetOPT HIST_LEX_WORDS
215
216 # When writing out the history file, by default zsh uses ad-hoc file
217 # locking to avoid known problems with locking on some operating
218 # systems. With this option locking is done by means of the system's
219 # fcntl call, where this method is available. On recent operating
220 # systems this may provide better performance, in particular avoiding
221 # history corruption when files are stored on NFS.
222 SetOPT HIST_FCNTL_LOCK
223
224 # Allows `>' redirection to truncate existing files, and `>>' to create
225 # files. Otherwise `>!' or `>|' must be used to truncate a file, and
226 # `>>!' or `>>|' to create a file.
227 UnsetOPT CLOBBER
228
229 # If this option is set, passing the -x flag to the builtins declare,
230 # float, integer, readonly and typeset (but not local) will also set the
231 # -g flag; hence parameters exported to the environment will not be made
232 # local to the enclosing function, unless they were already or the flag
233 # +g is given explicitly. If the option is unset, exported parameters
234 # will be made local in just the same way as any other parameter.
235 UnsetOPT GLOBAL_EXPORT
236
237 # On an ambiguous completion, instead of listing possibilities or
238 # beeping, insert the first match immediately. Then when completion
239 # is requested again, remove the first match and insert the second
240 # match, etc. When there are no more matches, go back to the first one
241 # again. reverse-menu-complete may be used to loop through the list in
242 # the other direction. This option overrides AUTO_MENU.
243 UnsetOPT MENU_COMPLETE
244
245 # Beep on error in ZLE.
246 UnsetOPT BEEP
247
248 # If this option is unset, output flow control via start/stop characters
249 # (usually assigned to ^S/^Q) is disabled in the shell's editor.
250 UnsetOPT FLOW_CONTROL
251
252 # Do not exit on end-of-file. Require the use of exit or logout
253 # instead. However, ten consecutive EOFs will cause the shell to exit
254 # anyway, to avoid the shell hanging if its tty goes away.
255
256 # Also, if this option is set and the Zsh Line Editor is used, widgets
257 # implemented by shell functions can be bound to EOF (normally
258 # Control-D) without printing the normal warning message. This works
259 # only for normal widgets, not for completion widgets.
260 UnsetOPT IGNORE_EOF
261
262 # Beep on an ambiguous completion. More accurately, this forces the
263 # completion widgets to return status 1 on an ambiguous completion,
264 # which causes the shell to beep if the option BEEP is also set; this
265 # may be modified if completion is called from a user-defined widget.
266 UnsetOPT LIST_BEEP
267
268 # Remove any right prompt from display when accepting a command line.
269 # This may be useful with terminals with other cut/paste methods.
270 is41 && SetOPT TRANSIENT_RPROMPT
271
272 # Send the HUP signal to running jobs when the shell exits.
273 UnsetOPT HUP
274
275 # Run all background jobs at a lower priority.
276 UnsetOPT BG_NICE
277
278 unfunction -m SetOPT
279 unfunction -m UnsetOPT
280 unfunction -m SetOPTifExists