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