.. _intro_zsh_options:

Options
=======

Some options have already been mentioned; here are a few more:

.. _AUTO_CD:

.. index:: single: AUTO_CD

Using the :literal:`AUTO_CD` option, you can simply type the name of a directory, and it will become the current directory.

.. code-block:: text
   :caption: AUTO_CD without cd
   :name: options_auto_cd

   % cd /
   % setopt autocd
   % bin
   % pwd
   /bin
   % ../etc
   % pwd
   /etc

.. _CDABLE_VARS:

.. index:: single: CDABLE_VARS

With :literal:`CDABLE_VARS`, if the argument to :literal:`cd` is the name of a parameter whose value is a valid directory, it will become the current directory.

.. code-block:: text
   :caption: CDABLE_VARS via parameter
   :name: options_cdable_vars

   % setopt cdablevars
   % foo=/tmp
   % cd foo
   /tmp

.. _CORRECT:

.. index:: single: CORRECT

.. _CORRECT_ALL:

.. index:: single: CORRECT_ALL

:literal:`CORRECT` turns on spelling correction for commands, and the :literal:`CORRECT_ALL` option turns on spelling correction for all arguments.

.. code-block:: text
   :caption: CORRECT and CORRECT_ALL
   :name: options_correct

   % setopt correct
   % sl
   zsh: correct `sl' to `ls' [nyae]? y
   % setopt correctall
   % ls x.v11r4
   zsh: correct `x.v11r4' to `X.V11R4' [nyae]? n
   /usr/princton/src/x.v11r4 not found
   % ls /etc/paswd
   zsh: correct to `/etc/paswd' to `/etc/passwd' [nyae]? y
   /etc/passwd

If you press :literal:`y` when the shell asks you if you want to correct a word, it will be corrected.  If you press :literal:`n`, it will be left alone. Pressing :literal:`a` aborts the command, and pressing :literal:`e` brings the line up for editing again, in case you agree the word is spelled wrong but you don't like the correction.

Normally, a quoted expression may contain a newline:

.. code-block:: text
   :caption: Newlines in quoted strings
   :name: options_quoted_newlines

   % echo '
   > foo
   > '
   
   foo
   
   %

.. _CSH_JUNKIE_QUOTES:

.. index:: single: CSH_JUNKIE_QUOTES

With :literal:`CSH_JUNKIE_QUOTES` set, this is invalid, as it is in csh.

.. code-block:: text
   :caption: CSH_JUNKIE_QUOTES rejects
   :name: options_csh_junkie_quotes

   % setopt cshjunkiequotes
   % ls 'foo
   zsh: unmatched '

.. _GLOB_DOTS:

.. index:: single: GLOB_DOTS

:literal:`GLOB_DOTS` lets files beginning with a :literal:`.` be matched without explicitly specifying the dot. This can also be specified for a particular pattern by appending (D) to it.

.. code-block:: text
   :caption: GLOB_DOTS matches dots
   :name: options_glob_dots

   % ls -d *x*
   Mailboxes
   % ls -d *x*(D)
   .exrc         .pnewsexpert  .xserverrc
   .mushexpert   .xinitrc      Mailboxes
   % setopt globdots
   % ls -d *x*
   .exrc         .pnewsexpert  .xserverrc
   .mushexpert   .xinitrc      Mailboxes

.. _HIST_IGNORE_DUPS:

.. index:: single: HIST_IGNORE_DUPS

.. _HIST_IGNORE_SPACE:

.. index:: single: HIST_IGNORE_SPACE

:literal:`HIST_IGNORE_DUPS` prevents the current line from being saved in the history if it is the same as the previous one; :literal:`HIST_IGNORE_SPACE` prevents the current line from being saved if it begins with a space.

.. code-block:: text
   :caption: HIST_IGNORE_DUPS and SPACE
   :name: options_hist_ignore

   % PROMPT='%h> '
   39> setopt histignoredups
   40> echo foo
   foo
   41> echo foo
   foo
   41> echo foo
   foo
   41> echo bar
   bar
   42> setopt histignorespace
   43>  echo foo
   foo
   43>  echo fubar
   fubar
   43>  echo fubar
   fubar

.. _IGNORE_BRACES:

.. index:: single: IGNORE_BRACES

:literal:`IGNORE_BRACES` turns off csh-style brace expansion.

.. code-block:: text
   :caption: IGNORE_BRACES disables braces
   :name: options_ignore_braces

   % echo x{y{z,a},{b,c}d}e
   xyze xyae xbde xcde
   % setopt ignorebraces
   % echo x{y{z,a},{b,c}d}e
   x{y{z,a},{b,c}d}e

.. _IGNORE_EOF:

.. index:: single: IGNORE_EOF

:literal:`IGNORE_EOF` forces the user to type :literal:`exit` or :literal:`logout`, instead of just pressing :kbd:`Ctrl+D`.

.. code-block:: text
   :caption: IGNORE_EOF requires exit
   :name: options_ignore_eof

   % setopt ignoreeof
   % ^D
   zsh: use 'exit' to exit.

.. _INTERACTIVE_COMMENTS:

.. index:: single: INTERACTIVE_COMMENTS

:literal:`INTERACTIVE_COMMENTS` turns on interactive comments; comments begin with a :literal:`#`.

.. code-block:: text
   :caption: INTERACTIVE_COMMENTS with #
   :name: options_interactive_comments

   % setopt interactivecomments
   % date # this is a comment
   Fri May 24 06:54:14 EDT 1991

.. _NO_BEEP:

.. index:: single: NO_BEEP

:literal:`NO_BEEP` makes sure the shell never beeps.

.. _NO_CLOBBER:

.. index:: single: NO_CLOBBER

:literal:`NO_CLOBBER` prevents you from accidentally overwriting an existing file.

.. code-block:: text
   :caption: NO_CLOBBER blocks overwrite
   :name: options_no_clobber

   % setopt noclobber
   % cat /dev/null >~/.zshrc
   zsh: file exists: /u/pfalstad/.zshrc

If you really do want to clobber a file, you can use the :literal:`>!` operator. To make things easier in this case, the :literal:`>` is stored in the history list as a :literal:`>!`:

.. code-block:: text
   :caption: Force overwrite with >!
   :name: options_force_clobber

   % cat /dev/null >! ~/.zshrc
   % cat /etc/motd > ~/.zshrc
   zsh: file exists: /u/pfalstad/.zshrc
   % !!
   cat /etc/motd >! ~/.zshrc
   % ...

.. _RC_QUOTES:

.. index:: single: RC_QUOTES

:literal:`RC_QUOTES` lets you use a more elegant method for including single quotes in a singly quoted string:

.. code-block:: text
   :caption: RC_QUOTES doubled quotes
   :name: options_rc_quotes

   % echo '"don'\''t do that."'
   "don't do that."
   % echo '"don''t do that."'
   "dont do that."
   % setopt rcquotes
   % echo '"don''t do that."'
   "don't do that."

.. _SUN_KEYBOARD_HACK:

.. index:: single: SUN_KEYBOARD_HACK

Finally, :literal:`SUN_KEYBOARD_HACK` wins the award for the strangest option. If a line ends with :literal:`\``, and there are an odd number of them on the line, the shell will ignore the trailing :literal:`\``.  This is provided for keyboards whose RETURN key is too small, and too close to the :literal:`\`` key.

.. code-block:: text
   :caption: SUN_KEYBOARD_HACK trailing backtick
   :name: options_sun_keyboard_hack

   % setopt sunkeyboardhack
   % date`
   Fri May 24 06:55:38 EDT 1991
