Skip to content

Latest commit

 

History

History
1487 lines (1211 loc) · 45.3 KB

File metadata and controls

1487 lines (1211 loc) · 45.3 KB

Configuration files w/ literate programming

ZSH

Parameters

Parameters used by the shell [100%]

DIRSTACKSIZE

The directory stack has normally unlimited size; if you want to restrict its size, set this variable to the value you want; you may also want to avoid duplicates in your stack, see OPTION_PUSHD_IGNORE_DUPS for details.

Here is an example of how DIRSTACKSIZE is used by ZSH:

% setopt AUTO_PUSHD   # We want directories to be pushed automatically onto the stack (in this example)
% dirs -v             # Displays contents of the directory stack; only the current direcory is in there right now.
0       ~
% for i in {1..2}; do # Let's change the directory a few times (for demonstration purposes)
    cd /tmp
    cd ~
  done
% dirs -v
  0       ~
  1       /tmp
  2       ~
  3       /tmp
  4       ~
% DIRSTACKSIZE=3
% dirs -v             # No effect yet; you must issue a CD command to update the stack
  0       ~
  1       /tmp
  2       ~
  3       /tmp
  4       ~
% cd /tmp
% dirs -v             # Now it's in effect; the stacksize is 3, everything beyond got truncated
  0       /tmp
  1       ~
  2       /tmp
DIRSTACKSIZE=10

Options [35/156]

Changing Directories [100%]

AUTO_CD (-J)

If this option is enabled, cd can be omitted almost always changing directories; the only case where it is still required is if the directory name happens to be equal to a command name. This option is very convenient to quickly change directories, for instance going one directory up becomes just .. instead of cd ...

% mkdir directory
% directory
zsh: command not found: directory
% setopt AUTO_CD
% directory  # Now equivalent to 'cd directory'
% mkdir dir  # We create a directory that has the name of a command
% dir        # This is not equivalent to 'cd dir' because command 'dir' exists!
dir directory
setopt AUTO_CD
setopt NO_AUTO_CD

AUTO_PUSHD (-N)

If enabled, any cd command pushes the new directory onto the directory stack automatically; this comes in handy if you want to navigate between several directories without having to hassle with the stack by yourself.

The see the contents of the stack, use the dirs -v command.

The stack itself is by default unlimited in size; it can, however, be restricted by the DIRSTACK parameter. This is often useful when AUTO_PUSHD is used. In case you don’t want duplicate directories, set the PUSHD_IGNORE_DUPS option.

% dirs -v           # Displays contents of directory stack
  0       ~
% cd /tmp
% dirs -v
  0       /tmp
% setopt AUTO_PUSHD
% cd ~
% dirs -v
  0       ~
  1       /tmp
setopt AUTO_PUSHD
setopt NO_AUTO_PUSHD

CDABLE_VARS (-T)

If set, any argument given to a cd command (or an implied cd if the #OPTION_AUTO_CD option is set) that is neither a directory nor starts with a slash will be expanded as if it were preceded by a ”~”. That is, you can assign directory names to a variable and then cd into that directory by passing the variable name as the argument:

% dir=/tmp/      # Assign directory name to a variable
% cd dir         # Note: We really mean "dir" here, not $dir!
cd: no such file or directory: dir
% setopt CDABLE_VARS # Now activate this option
% cd dir         # Now it works - we will switch to /tmp now, displayed as ~dir.
~dir
% pwd
/tmp

This feature is very helpful if there are directories that you need to cd into frequently, such as folders containing projects you’re working on.

setopt CDABLE_VARS
unsetopt CDABLE_VARS

CHASE_DOTS

This option resolves directories to its physical directory if .. is encountered anyhwere in the path (or if only cd .. is used). This means that the working directory is fully resolved once .. is encountered.

This option is similar to #OPTION_CHASE_LINKS. But as the name suggests, CHASE_LINKS is an option used to resolve symbolic links to the physical directory whereas this option works on standard directories as well.

% unsetopt CHASE_DOTS
% mkdir /tmp/example/
% ln -s /home/ch /tmp/example/link
% cd /tmp/example/link
% cd ..
% pwd
/tmp/example
% setopt CHASE_DOTS
% cd /tmp/example/link # Changes to /home/ch, but that is not yet resolved as no .. has been found
% cd ..
% pwd
/home
unsetopt CHASE_DOTS
unsetopt CDABLE_DOTS

CHASE_LINKS (-w)

If this option is set, if you pass a symlink to cd (or even a symlink as a part of the path you pass), each symlink will be resolved to the actual folder.

% ls -ald *(@) # Show all symlinks in the current folder
lrwxrwxrwx 1 ch ch 24 Jun 22 19:56 homedir -> /home/ch
% unsetopt CHASE_LINKS
% cd homedir
% pwd
homedir
% cd # assume that this command brings me back to the previously active directory (cd -1)
% setopt CHASE_LINKS
% cd homedir
% pwd
/home/ch

Note: You can also achieve this behavior by passing the -P option to cd.

unsetopt CHASE_LINKS
unsetopt CDABLE_VARS

POSIX_CD

Changes the behavior of the cd, chdir, pushd commands for increased POSIX standard compliance.

If POSIX_CD is not set, the behavior of the cd command is described in the manual under zsh: 17 Shell Builtin Commands.

If POSIX_CD is set, the behavior is changed in several ways:

  1. cd will now first test if any directory in the cdpath / CDPATH variable contain the directory and if so, will change to that directory. Any directory under the current working directory is ignored - i.e., the directories listed in cdpath have a higher priority.
  2. cd will no longer take arguments of the form {+|-}n, i.e., navigating the directory stack is no longer possible. (See related options such as #PUSHD_MINUS.)
% unsetopt POSIX_CD
% mkdir /tmp/foo
% mkdir /tmp/foo/bar
% mkdir /tmp/bar
% cdpath=(/tmp)
% cd /tmp/foo
% cd bar
% pwd
/tmp/foo/bar
% cd /tmp/foo
% setopt POSIX_CD
% cd bar
% pwd
/tmp/bar
unsetopt POSIX_CD
unsetopt POSIX_CD

PUSHD_IGNORE_DUPS

If set, this option prevents any directory to be at two different positions in the stack; that is, every entry is unique. This option is especially useful if AUTO_PUSHD is set.

The following example demonstrates that duplicates are prevented:

% dirs -v
  0       ~
% setopt PUSHD_IGNORE_DUPS
% cd /tmp
% dirs -v
  0       /tmp
  1       ~
% cd ~
% dirs -v       # Here, the existing entry for ~ was removed and a new entry was pushed onto the stack
  0       ~
  1       /tmp
setopt PUSHD_IGNORE_DUPS
setopt NO_PUSHD_IGNORE_DUPS

PUSHD_MINUS

The cd and popd builtins can use the directory stack by the +/- arguments. For instance, cd +1 switches to the directory represented by the second element on the directory stack (as counting starts from

  1. and cd -1 does the same but starts counting upwards from the bottom

of the stack. (So cd -1 is the second last element.)

(Note: The content of the directory stack can be displayed with the dirs builtin; use dirs -v if you want to see explicitly the position of each element.)

The meaning of + and - in this context can be reversed by activating this option:

% pushd /tmp
/tmp ~
% pushd /bin
/bin /tmp ~
% pushd /boot
/boot /bin /tmp ~
% setopt PUSHD_MINUS
% cd -1
/bin
setopt PUSHD_MINUS
setopt NO_PUSHD_MINUS

PUSHD_SILENT (-E)

If unset (as is the default), ZSH will print the content of the directory stack every time pushd or popd is used; with this option enabled, any output will be suppressed.

% cd /bin
% pushd
~ /bin
% setopt PUSHD_SILENT
% cd /tmp
% pushd                     # Doesn't output anything anymore
% dirs -v
0       /bin
1       /tmp
setopt PUSHD_SILENT
setopt NO_PUSHD_SILENT

PUSHD_TO_HOME (-D)

If enabled, executing pushd without any parameters is the same as executing pushd $HOME; this is also the case (even with this option disabled) if the directory stack contains only one entry:

% cd /tmp
% dirs
/tmp
% setopt NO_PUSHD_TO_HOME
% pushd
~ /tmp
% pwd
/home/ch

If there is more than one entry on the stack and this option is unset, then calling pushd will simply swap the first two entries on the stack:

% pushd /tmp
/tmp ~
% pushd /bin
/bin /tmp ~
% pwd
/bin
% pushd
/tmp /bin ~
% pwd
/tmp

This behavior changes when this option is enabled:

% setopt PUSHD_TO_HOME
% pushd /tmp
/tmp ~
% pushd /bin
/bin /tmp ~
% pushd
~ /bin /tmp ~

Note: If you don’t want the stack to contain duplicates as in the example above, use the PUSHD_IGNORE_DUPS option.

Completion [75%]

cf. Section 16.2.2 http://zsh.sourceforge.net/Doc/Release/Options.html#Options

STARTED ALWAYS_LAST_PROMPT <Default>

Check userguide 6.2.2

STARTED ALWAYS_TO_END

Check 6.2.4 in the userguide.

AUTO_LIST (-9) <Default>

Show menu completion by default if completion results are ambiguous (otherwise you may have to press some keys, such as ^D); this option does not select an entry on displaying the menu; see option MENU_COMPLETE for that.

setopt AUTO_LIST
setopt AUTO_LIST

STARTED AUTO_MENU <D>

Check userguide 6.2.1

AUTO_NAME_DIRS

STARTED AUTO_PARAM_KEYS <D>

Check 6.2.4 of the user guide.

STARTED AUTO_PARAM_SLASH <D>

Check 6.2.4 of the user guide.

STARTED AUTO_REMOVE_SLASH <D>

Check 6.2.4 of the user guide. This tells in the last sentence what it does NOT do.

STARTED BASH_AUTO_LIST

Check userguide 6.2.1

COMPLETE_ALIASES

If this option is enabled, aliases will not have the same completion as the command they are referring to as they are not internally substituted when completion is attempted; hence, aliases look like distinct commands to the completion.

setopt NO_COMPLETE_ALIASES

COMPLETE_IN_WORD

If enabled, completion can be called from within a word; the completion will then try and take both everything before and everything after the cursor into account: The position of the cursor determines where the completion is attempted.

% setopt NO_COMPLETE_IN_WORD # Disable this option first; default behavior
% ls te*
terr  test1
% vi te<CURSOR:TAB>1 # Offers terr and test1 as completion
% setopt COMPLETE_IN_WORD
% vi te<CURSOR:TAB>1 # Completes to test1, as terr has no "1" at the end
setopt COMPLETE_IN_WORD
setopt NO_COMPLETE_IN_WORD

GLOB_COMPLETE

If this option is set, expanding a (glob) pattern will not insert all the matches but instead generates a list that can be cycled through like MENU_COMPLETE.

A * is added to the end of the word or at the position of the cursor, if COMPLETE_IN_WORD is set; furthermore, as pattern matching is used, this option also affects any completion for options, user names etc.

Note: If pattern matching is employed, you cannot use matching control to include constraints such as case-insensitivity or anchored matching. However, this limitation only applies when the current word contains a pattern; simply turning on the GLOB_COMPLETE option does not have this effect.

% setopt NO_GLOB_COMPLETE # Disable this option first; default behavior
% ls example*
example1 example2
% cat example<TAB>   # becomes cat example1 example2
% setopt GLOB_COMPLETE
% cat example<TAB>   # asks for completion: Only example1 or example2 is selected.
setopt NO_GLOB_COMPLETE

HASH_LIST_ALL <D>

This option is required for completion.

To understand why, consider what happens when you want to execute a command: first, ZSH determines the exact path of the command by searching all directories listed in the PATH variable (with directories listed in the order of priority, i.e., from highest priority to lowest priority). To speed up consecutive searches, ZSH fills a hash-table with key-value pairs for every directory listed in PATH that it has previously searched, where the key is the command and the value is the path of the first occurrence of that command (i.e., only the very first occurrence in a folder in PATH). That is, when you execute the next command, ZSH first checks if the command is already known by searching the hash-table and only restarts scanning all directories if it has not yet been added.

ZSH doesn‘t need to search all folders but only until the first match for the command has been found. As a consequence, not all commands are added to the hash table until all directories have been scanned. To enforce searching all directories immediately, and not just until the first match, HASH_LIST_ALL can be set, even though the first scan is a bit slower since more directories are fully scanned.

Note that, if HASH_LIST_ALL is not activated, then command completion is not available - as there is no guarantee that all directories have been scanned, no guarantee exists that all commands are available for completion.

Note: This hash-table can be printed using the hash built-in command (and regenerated using the rehash command).

% hash
# output reduced to only the last few lines
zless=/usr/bin/zless
zmore=/usr/bin/zmore
znew=/usr/bin/znew
zsh=/usr/bin/zsh
zsh5=/usr/bin/zsh5
zstd=/usr/bin/zstd
zstdcat=/usr/bin/zstdcat
zstdgrep=/usr/bin/zstdgrep
zstdless=/usr/bin/zstdless
zstdmt=/usr/bin/zstdmt

(See also A User’s Guide to the Z-Shell for some more information.)

setopt HASH_LIST_ALL
setopt HASH_LIST_ALL

STARTED LIST_AMBIGUOUS <D>

Check userguide 6.2.1

STARTED LIST_BEEP <D>

Check userguide 6.2.1

LIST_PACKED

If set, this option reduces the size of the completion menu by making its columnwidth dynamic; that is, the width of columns will be determined by the content of the columns and each two columns might have different widths.

setopt LIST_PACKED
setopt NO_LIST_PACKED

STARTED LIST_ROWS_FIRST

Check userguide 6.2.5

STARTED LIST_TYPES (-X) <D>

Check 5.9.6 of the user guide and 6.2.5.

MENU_COMPLETE (-Y)

On an ambiguous completion, do not beep and show a menu with matches; the first match is inserted immediately. If completion is requested again, cycle through matches, and remove any changes made by a prior match. When there are no more matches, go back to the first one. reverse-menu-complete may be used to loop through the list in the other direction. This option overrides AUTO_MENU.

% setopt MENU_COMPLETE
% ls te*
terr  test1
% vi te<TAB> # selects 'terr' immediately
setopt NO_MENU_COMPLETE
setopt NO_MENU_COMPLETE

STARTED REC_EXACT (-S)

Check userguide 6.2.1

This option does not seem to have any effect if

zstyle ':completion:*' accept-exact false

was set explicitly before.

Expansion and globbing [21%]

BAD_PATTERN (+2) <C> <Z>

STARTED BARE_GLOB_QUAL <Z>

Check 5.9.6 of the user guide.

BRACE_CCL

CASE_GLOB <D>

CASE_MATCH <D>

CSH_NULL_GLOB <C>

STARTED EQUALS <Z>

Check userguide 5.8; if set, “ls =ls” will be equivalent to “ls `which ls`”

STARTED EXTENDED_GLOB

Check 5.9.4 in the user guide.

FORCE_FLOAT

GLOB (+F, ksh: +f) <D>

If disabled, globbing (filename generation) will be completely disabled; i.e., using print file* actually prints file* instead of all files starting with the prefix file.
setopt GLOB
setopt GLOB

GLOB_ASSIGN <C>

GLOB_DOTS (-4)

If activated, files with a leading ‘.’ are also matched by globbing, except for .. (parent directory) and . (current directory). This also means that the ‘.’ does not need to be explicitly specified to enable completion.

% setopt NO_GLOB_DOTS # Disable this option first; default behavior
% touch .example
% ls *example
zsh: no matches found: *example
% vi example<TAB>   # Does not complete to .example
% setopt GLOB_DOTS
% ls *example
.example
% vi example<TAB>   # Completes to .example
setopt GLOB_DOTS
setopt NO_GLOB_DOTS

GLOB_SUBST= <C> <K> <S>

If a parameter (variable) gets expanded, any character resulting from this operation is being treated as eligible for file expansion and filename generation.

Note: Braces (and contained commas) do not become eligible for expansion.

% setopt NO_GLOB_SUBST
% export TEST="*"
% ls *
testfile1 testfile2
% ls $TEST<TAB> # Becomes ls \*
% setopt GLOB_SUBST
% ls $TEST<TAB> # Becomes ls testfile1 testfile2
setopt NO_GLOB_SUBST

HIST_SUBST_PATTERN

IGNORE_BRACES (-I) <S>

IGNORE_CLOSE_BRACES

KSH_GLOB <K>

STARTED MAGIC_EQUAL_SUBST

Check userguide 5.8

MARK_DIRS (-8, ksh: -X)

MULTIBYTE <C> <K> <Z>

NOMATCH (+3) <C> <Z>

If enabled, this option prints an error message if a filename generation pattern does not match anything. This also applies to file expansion of an initial '~' or '’=. However, if disabled, any pattern that does not match will be left unchanged, i.e., it will be passed as an argument to the command:

% setopt NOMATCH                  # Default in ZSH
% ls test*                        # Error: ls not executed
zsh: no matches found: test*
% print -- test*                  # Error: print not executed
zsh: no matches found: test*
% setopt NO_NOMATCH               # Disables this option
% ls test*                        # ls is now executed with test* a parameter
ls: cannot access test*: No such file or directory
% print -- test*                  # print is now executed
test*
setopt NOMATCH
setopt NOMATCH

NULL_GLOB (-G)

% cd ~
% ls test*
zsh: no matches found: test*
% setopt NULL_GLOB           # Activate this option
% ls test*                   # Removes the pattern, hence issues 'ls' only
bin Documents Downloads Games Pictures Public

If activated, this option removes any filename generation pattern that does not match anything; hence, no error will be reported as done by the NOMATCH option, as this option is completely overriden.

setopt NO_NULL_GLOB
setopt NO_NULL_GLOB

NUMERIC_GLOB_SORT

RC_EXPAND_PARAM (-P)

Check userguide 5.4.5

REMATCH_PCRE <Z>

STARTED SH_GLOB <K> <S>

See 5.9.3 “Parentheses” in the user guide.

UNSET (+u, ksh: +u) <K> <S> <Z>

WARN_CREATE_GLOBAL

History [0%]

APPEND_HISTORY <D>

BANG_HIST (+K) <C> <Z>

EXTENDED_HISTORY <C>

HIST_ALLOW_CLOBBER

HIST_BEEP <D>

HIST_EXPIRE_DUPS_FIRST

HIST_FCNTL_LOCK

HIST_FIND_NO_DUPS

HIST_IGNORE_ALL_DUPS

HIST_IGNORE_DUPS (-h)

HIST_IGNORE_SPACE (-g)

HIST_LEX_WORDS

HIST_NO_FUNCTIONS

HIST_NO_STORE

HIST_REDUCE_BLANKS

HIST_SAVE_BY_COPY <D>

HIST_SAVE_NO_DUPS

HIST_VERIFY

INC_APPEND_HISTORY

INC_APPEND_HISTORY_TIME

SHARE_HISTORY <K>

Initialisation [25%]

ALL_EXPORT (-a, ksh: -a)

If set, all parameters that are subsequently defined will be exported, even if the export keyword is not explicitly given. This means that the parameters will be accessible from any other command (they can find the variable in their environment) started from this zsh instance; they will not remain purely local.

This option might be useful for you if you start many subshells that should have exactly the same environment as the starting shell.

% TEST=5
% zsh            # Start a 2nd shell
% echo $TEST     # Empty!

% exit           # Close the 2nd shell
% setopt ALL_EXPORT
% FOO=5
% zsh
% echo $FOO      # Found FOO!
5
setopt NO_ALL_EXPORT
setopt NO_ALL_EXPORT

GLOBAL_EXPORT (<Z>)

GLOBAL_RCS (-d) <D>

RCS (+f) <D>

Input/Output [15%]

ALIASES <D>

With this option you can disable aliases (as they are enabled by default); see the corresponding manual page for details on what aliases are and what they do.

setopt ALIASES

CLOBBER (+C, ksh: +C) <D>

CORRECT (-0)

CORRECT_ALL (-O)

DVORAK

FLOW_CONTROL <D>

IGNORE_EOF (-7)

INTERACTIVE_COMMENTS (-k) <K> <S>

HASH_CMDS <D>

HASH_DIRS <D>

HASH_EXECUTABLES_ONLY

MAIL_WARNING (-U)

PATH_DIRS (-Q)

PATH_SCRIPT <K> <S>

PRINT_EIGHT_BIT

PRINT_EXIT_VALUE (-1)

STARTED RC_QUOTES

Within single-quoted strings, ” will mean the same as ‘.

RM_STAR_SILENT (-H) <K> <S>

ZSH tries to protect the user from accidentally deleting all files in a directory; that is, ZSH complains when rm is used and a * occurs in your filematching pattern; ZSH does not complain, however, if you deliberately expand this pattern (as you will see exactly which files are selected).

% rm ./*
zsh: sure you want to delete all the files in /tmp/test/. [yn]?

This is helpful to prevent you from wiping your data accidentally; in case you don’t want to confirm that you’re really sure, turn this option on - ZSH will not ask again.

setopt NO_RM_STAR_SILENT

RM_STAR_WAIT

If #RM_STAR_SILENT is not set (that is, you need to confirm if you try to issue rm * and friends), setting this option makes you wait for ten seconds before you can even answer “yes” or “no”.

The motivation for this option is to prevent the user from hitting “yes” in a reflex.

Note: If you expand the *, you do not have to wait ten seconds to delete the files you want. This is helpful if you really want to use the *.

% rm ./*
zsh: sure you want to delete all the files in /tmp/test/.? (waiting ten seconds)
[yn] # This line only appears after ten seconds!
setopt NO_RM_STAR_SILENT

SHORT_LOOPS <C> <Z>

SUN_KEYBOARD_HACK (-L)

Job Control [88%]

AUTO_CONTINUE

When starting jobs from your shell, they are owned by that shell and exhibit behavior that is often dependent on the shell‘s process; for instance, if you send a SIGHUP (signal hang up) to the shell, that signal would also be send to all jobs executed under that shell. (See the output of the jobs command if there are any.)

zsh─┬─eog───5*[{eog}]
    └─some_other_process

If you want to remove a process from a shell‘s job list (and hence change the way it responds to, e.g., a SIGHUP) you can use the builtin disown to do so. Once you have disowned the process, you can no longer use bg and fg on that process to run it in the background or the foreground.

What AUTO_CONTINUE does is that it automatically sends a SIGCONT (signal continue) to the process when disown is used.

% unsetopt AUTO_CONTINUE
% eog .
# Now I press Control-Z in order to move the process to the background; this is because I have
# used the following in my config:
# zle -N foreground-vi
# bindkey '^Z' foreground-vi
zsh: suspended  eog .
% jobs
[1]  + suspended  eog .
% # Typing exit here would kill the subprocess as well
% # Typing kill %1 would kill the subprocess (but not the shell)
% disown %1
disown: warning: job is suspended, use `kill -CONT -82336' to resume
# The process is still halted, hence cannot be used. However, you could send a SIGCONT manually to
# the process to continue it: kill -CONT -82336
% jobs # No output, as no more jobs are active
% kill %1
kill: %1: no such job
% kill 82336 # Kill the above process
# And now for the opposite ...
% setopt AUTO_CONTINUE
% eog .
^Z # See above (foreground-vi)
zsh: suspended  eog .
% disown %1
[1]  + continued  eog . # The CONT signal is now sent automatically
% jobs
% # Still no jobs!
setopt AUTO_CONTINUE
setopt NO_AUTO_CONTINUE

AUTO_RESUME (-W)

Simple commands (i.e., just the command-name, nothing else) that do not use redirection will be used to resume background jobs of that same command. For instance, if you have an instance of top in the background and re-execute the top command (without any arguments or redirection), the sleeping process will be resumed; if this option is not set, top would be executed a second time.

 % setopt NO_AUTO_RESUME
 % top  # Now CTRL-Z 
 % top  # CTRL-Z again
 % ps
 PID TTY          TIME CMD
 7191 pts/9    00:00:00 zsh
 7192 pts/9    00:00:00 top
 7193 pts/9    00:00:00 top
 7194 pts/9    00:00:00 ps
 % killall top
 % setopt AUTO_RESUME 
 % top  # CTRL-Z
 % top  # CTRL-Z
 % ps   # Only one (not two!) top instance running!
 PID TTY          TIME CMD
7191 pts/9    00:00:00 zsh
7237 pts/9    00:00:00 top
7238 pts/9    00:00:00 ps
setopt NO_AUTO_RESUME
setopt NO_AUTO_RESUME

BG_NICE (-6) <C> <Z>

If set, all jobs that will be started in the background will be nice towards other jobs, that is, they will run at a lower priority. (See man 1 nice for details.)

This option, however, does not change the level of niceness for jobs that were started and then moved to the background (for instance, by pressing CTRL-Z).

% setopt BG_NICE    # This is the default
% top               # Now press CTRL-Z; top will not be "nice"
% ps au 
USER PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
ch  6257  0.2  0.0  25228  4224 pts/8    T    17:55   0:00 top
% kill top
% top &             # Start top in the background
% ps au             # This will output "N" in the "STAT" column
ch  6385  0.0  0.0  16320  3612 pts/8    TN   17:58   0:00 top
% kill top
% setopt NO_BG_NICE
% top &             # Start top in the background
% ps au             # top will not be nice any more!
ch  6463  0.3  0.0  25112  4224 pts/8    T    18:00   0:00 top
setopt BG_NICE
setopt BG_NICE

CHECK_JOBS <Z>

Reports status of suspended and background jobs when trying to exit the shell. If disabled, jobs will be killed automatically if #OPTION_HUP is activated.

Hint: if the previous command line contains the jobs command, this check is omitted. (Hook functions as defined under Special Functions in the manual (see zsh: 9 Functions)

% setopt CHECK_JOBS
% eog . &
[1] 86845
% exit
zsh: you have running jobs.
% # exit # second exit command would actually exit
% setopt NO_CHECK_JOBS
% exit
zsh: warning: 1 jobs SIGHUPed
setopt CHECK_JOBS
setopt CHECK_JOBS

HUP <Z>

This option is enabled by default in ZSH and will cause ZSH to send the HUP (hang up) signal to be sent to any background process if the shell is going to terminate (i.e., you used one of exit~, logout, bye etc. or a non-interactive shell started background jobs).

That is, with this option unset, jobs will continue to run normall when the shell exits.

# First shell
% setopt NO_HUP
% sleep 500 &
[1] 20931               
% exit
zsh: you have running jobs.
% exit                      # 2nd exit = exits. See also CHECK_JOBS option.

# Executed in a 2nd shell!
% ps auxw | grep "sleep"
ch 20988  0.0  0.0  13064   608 pts/8    SN   01:04   0:00 sleep 500


# Start a new shell...
% setopt HUP
% sleep 500 &
[1] 21168               
% exit
zsh: you have running jobs.
% exit                      # 2nd exit = exits. See also CHECK_JOBS option.

# Executed in a 2nd shell!
% ps auxw | grep "sleep"    # Returns nothing, as process was killed!
                            # (for you, it may return 20931 from above...)
%                           # Yup, nothing there...
setopt HUP
setopt HUP

LONG_LIST_JOBS (-R)

If activated, jobs will be listed using the long format; that is, when the job terminates, ZSH will also tell you the process id this job had.

This option has no effect if the MONITOR option is turned off.

% setopt LONG_LIST_JOBS
% sleep 5 &
[1] 20241               
% 
[1]  + 20241 done       sleep 5     # Includes process id!
% setopt NO_LONG_LIST_JOBS
% sleep 5 &
[1] 20330               
% 
[1]  + done       sleep 5           # ... not anymore!
setopt LONG_LIST_JOBS
setopt NO_LONG_LIST_JOBS

MONITOR (-m, ksh: -m)

In ZSH, this option is enabled by default for interactive shells (that is, shells that accept commands from you instead of reading them from a file). It’s behavior is quite simply:

If activated, starting a job and putting it in the background right away by using the & sign at the end of the command will notify you about the job number (a value local to this shell) and the process number this new process was given by the operating system. You will furthermore be notified when this process ends (you can determine when you want to be notified by (un-)setting the NOTIFY option).

% setopt MONITOR
% sleep 3 &
[1] 20058               # This output line was caused by this option
% seto                  # We start typing... but we're interrupted
[1]  + done       sleep 3
% setopt NO_MONITOR     # ... but we can continue typing after "seto"!
% sleep 5 &
%                       # Nothing happens; we won't get notifications
setopt MONITOR
setopt MONITOR

NOTIFY (-5, ksh: -b) <Z>

Reports the status of background jobs immediately (i.e., jobs you’ve started from this shell by for instance adding the & character at the end of your command). If disabled, you will only be notified about the termination of your job when a new prompt is printed.

% setopt NOTIFY     # It's always enabled by default 
% sleep 3 &
[1] 19316
%                   # Don't do anything now, just wait 3seconds...
[1]  + done       sleep 3
%                   # We didn't do anything; but a new prompt was printed!
% setopt NO_NOTIFY  # Now disable it...
% sleep 3 &         
%                   # Nothing will appear now, until you hit return..
[1]  + done       sleep 3
setopt NOTIFY
setopt NOTIFY

POSIX_JOBS <K> <S>

Prompting [0%]

PROMPT_BANG <K>

PROMPT_CR (+V) <D>

PROMPT_SP <D>

PROMPT_PERCENT <C> <Z>

PROMPT_SUBST <K> <S>

TRANSIENT_RPROMPT

Scripts and functions [0%]

C_BASES

C_PRECEDENCES

DEBUG_BEFORE_CMD

ERR_EXIT (-e, ksh: -e)

ERR_RETURN

EVAL_LINENO <Z>

EXEC (+n, ksh: +n) <D>

FUNCTION_ARGZERO <C> <Z>

LOCAL_LOOPS

LOCAL_OPTIONS <K>

LOCAL_PATTERNS

LOCAL_TRAPS <K>

MULTI_FUNC_DEF <Z>

MULTIOS <Z>

OCTAL_ZEROES <S>

PIPE_FAIL

SOURCE_TRACE

TYPESET_SILENT

VERBOSE (-v, ksh: -v)

XTRACE (-x, ksh: -x)

Shell emulation [4%]

BASH_REMATCH

BSD_ECHO <S>

CONTINUE_ON_ERROR

CSH_JUNKIE_HISTORY <C>

CSH_JUNKIE_LOOPS <C>

CSH_JUNKIE_QUOTES <C>

CSH_NULLCMD <C>

KSH_ARRAYS <K> <S>

KSH_AUTOLOAD <K> <S>

KSH_OPTION_PRINT <K>

KSH_TYPESET <K>

KSH_ZERO_SUBSCRIPT

POSIX_ALIASES <K> <S>

POSIX_ARGZERO

POSIX_BUILTINS <K> <S>

POSIX_IDENTIFIERS <K> <S>

POSIX_STRINGS <K> <S>

POSIX_TRAPS <K> <S>

SH_FILE_EXPANSION <K> <S>

SH_NULLCMD <K> <S>

SH_OPTION_LETTERS <K> <S>

Many options in ZSH also have one-letter shortcuts assigned to them, making it very quick to enable/disable specific options; in fact, there are two different sets of one-letter options. The first one is the “default” zsh set and used by default; the second one is used to emulate sh/ksh options.

Take for example the NOTIFY option: The default one-char option is -5, but if SH_OPTION_LETTERS is set, the one-character option becomes -b.

% setopt NO_SH_OPTION_LETTERS   # Default
% setopt -b                     # Try to set the NOTIFY option
setopt: bad option: -b
% setopt SH_OPTION_LETTERS
% setopt -b                     # This command was now successful
setopt NO_SH_OPTION_LETTERS
setopt NO_SH_OPTION_LETTERS

SH_WORD_SPLIT (-y) <K> <S>

See userguide 5.4.4

TRAPS_ASYNC

Shell State [0%]

INTERACTIVE (-i, ksh: -i)

LOGIN (-l, ksh: -l)

PRIVILEGED (-p, ksh: -p)

RESTRICTED (-r)

SHIN_STDIN (-s, ksh: -s)

SINGLE_COMMAND (-t, ksh: -t)

ZLE [16%]

BEEP (+B) <D>

COMBINING_CHARS

EMACS

STARTED OVERSTRIKE

This option starts ZSH in overstrike mode; to quote Wikipedia:

In typography, overstrike is a method of printing characters that are missing from the printer’s character set. The character was created by placing one character on another one — for example, overstriking “L” with “-” resulted in printing a “Ł” character.

setopt NO_OVERSTRIKE
setopt NO_OVERSTRIKE

SINGLE_LINE_ZLE (-M) <K>

VI

This option changes the ZSH keybindings (for interactive shells) to behave like VI; for emacs users, option EMACS is

This option, if enabled, does the same as

% bindkey -v          # Enables the vi-keymap
% unsetopt EMACS      

Unsetting this option, on the other hand, has no effect.

Please note that just because this option is set, the vi-keybindings are not guaranteed to be enabled (i.e., your scripts must not rely on this option to determine whether the vi-keymap is activated or not):

% setopt VI
% bindkey -lL main 
bindkey -A viins main
% bindkey -e
% bindkey -lL main 
bindkey -A emacs main
% [[ -o VI ]] && print "VI still enabled!"
VI still enabled!

This option is just provided for compatibility reasons; you should always prefer to use the bindkey builtin.

setopt VI
setopt NO_VI

ZLE (-Z)

Option aliases

These are aliases for the options above, as seen in section 16.3 of the manual.

Migrate these aliases to the options above, use the :PROPERTIES: drawer and define a property such as “ALIAS”.

BRACE_EXPAND

Equivalent to unsetting #OPTION_IGNORE_BRACES, i.e., setopt NO_IGNORE_BRACES. (Used for ksh and bash compatibility.)

DOT_GLOB

Equivalent to setting #OPTION_GLOB_DOTS, i.e., setopt GLOB_DOTS. (Used for bash compatibility.)

HASH_ALL

Equivalent to setting #OPTION_HASH_CMDS, i.e., setopt HASH_CMDS. (Used for bash compatibility.)

HIST_APPEND

Equivalent to setting #OPTION_APPEND_HISTORY, i.e., setopt APPEND_HISTORY. (Used for bash compatibility.)

HIST_EXPAND

Equivalent to setting #OPTION_BANG_HIST, i.e., setopt BANG_HIST. (Used for bash compatibility.)

LOG

Equivalent to unsetting #OPTION_HIST_NO_FUNCTIONS, i.e., setopt NO_HIST_NO_FUNCTIONS. (Used for ksh compatibility.)

MAIL_WARN

Equivalent to setting #OPTION_MAIL_WARNING, i.e., setopt MAIL_WARNING. (Used for bash compatibility.)

ONE_CMD

Equivalent to setting #OPTION_SINGLE_COMMAND, i.e., setopt SINGLE_COMMAND. (Used for bash compatibility.)

PHYSICAL

Equivalent to setting #OPTION_CHASE_LINKS, i.e., setopt CHASE_LINKS. (Used for ksh and bash compatibility.)

PROMPT_VARS

Equivalent to setting #OPTION_PROMPT_SUBST, i.e., setopt PROMPT_SUBST. (Used for bash compatibility.)

STDIN

Equivalent to setting #OPTION_SHIN_STDIN, i.e., setopt SHIN_STDIN. (Used for ksh compatibility.)

TRACK_ALL

Equivalent to setting #OPTION_HASH_CMDS, i.e., setopt HASH_CMDS. (Used for ksh compatibility.)

Single letter options

Migrate these aliases to the options above, use the :PROPERTIES: drawer and define a property such as “SINGLE_LETTER”.

The single letters are already present in the headlines above, such as (-4) etc.