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