zsh-manual-mdbook/zsh_manual/book/print.html

30093 lines
1.6 MiB
HTML
Raw Normal View History

2021-05-11 02:29:21 +02:00
<!DOCTYPE HTML>
<html lang="en" class="sidebar-visible no-js light">
<head>
<!-- Book generated using mdBook -->
<meta charset="UTF-8">
<title>Zsh Manual</title>
<meta name="robots" content="noindex" />
<!-- Custom HTML head -->
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#ffffff" />
<link rel="icon" href="favicon.svg">
<link rel="shortcut icon" href="favicon.png">
<link rel="stylesheet" href="css/variables.css">
<link rel="stylesheet" href="css/general.css">
<link rel="stylesheet" href="css/chrome.css">
<link rel="stylesheet" href="css/print.css" media="print">
<!-- Fonts -->
<link rel="stylesheet" href="FontAwesome/css/font-awesome.css">
<link rel="stylesheet" href="fonts/fonts.css">
<!-- Highlight.js Stylesheets -->
<link rel="stylesheet" href="highlight.css">
<link rel="stylesheet" href="tomorrow-night.css">
<link rel="stylesheet" href="ayu-highlight.css">
<!-- Custom theme stylesheets -->
2022-09-01 07:20:37 +02:00
<link rel="stylesheet" href="./theme/catppuccin.css">
<link rel="stylesheet" href="./theme/catppuccin-highlight.css">
2021-05-11 02:29:21 +02:00
</head>
<body>
<!-- Provide site root to javascript -->
<script type="text/javascript">
var path_to_root = "";
var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";
</script>
<!-- Work around some values being stored in localStorage wrapped in quotes -->
<script type="text/javascript">
try {
var theme = localStorage.getItem('mdbook-theme');
var sidebar = localStorage.getItem('mdbook-sidebar');
if (theme.startsWith('"') && theme.endsWith('"')) {
localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
}
if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
}
} catch (e) { }
</script>
<!-- Set the theme before any content is loaded, prevents flash -->
<script type="text/javascript">
var theme;
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
if (theme === null || theme === undefined) { theme = default_theme; }
var html = document.querySelector('html');
html.classList.remove('no-js')
html.classList.remove('light')
html.classList.add(theme);
html.classList.add('js');
</script>
<!-- Hide / unhide sidebar before it is displayed -->
<script type="text/javascript">
var html = document.querySelector('html');
var sidebar = 'hidden';
if (document.body.clientWidth >= 1080) {
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
sidebar = sidebar || 'visible';
}
html.classList.remove('sidebar-visible');
html.classList.add("sidebar-" + sidebar);
</script>
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
<div class="sidebar-scrollbox">
2022-08-24 15:22:41 +02:00
<ol class="chapter"><li class="chapter-item expanded "><a href="The-Z-Shell-Manual.html"><strong aria-hidden="true">1.</strong> The Z Shell Manual</a></li><li class="chapter-item expanded "><a href="Introduction.html"><strong aria-hidden="true">2.</strong> Introduction</a></li><li class="chapter-item expanded "><a href="Roadmap.html"><strong aria-hidden="true">3.</strong> Roadmap</a></li><li class="chapter-item expanded "><a href="Invocation.html"><strong aria-hidden="true">4.</strong> Invocation</a></li><li class="chapter-item expanded "><a href="Files.html"><strong aria-hidden="true">5.</strong> Files</a></li><li class="chapter-item expanded "><a href="Shell-Grammar.html"><strong aria-hidden="true">6.</strong> Shell Grammar</a></li><li class="chapter-item expanded "><a href="Redirection.html"><strong aria-hidden="true">7.</strong> Redirection</a></li><li class="chapter-item expanded "><a href="Command-Execution.html"><strong aria-hidden="true">8.</strong> Command Execution</a></li><li class="chapter-item expanded "><a href="Functions.html"><strong aria-hidden="true">9.</strong> Functions</a></li><li class="chapter-item expanded "><a href="Jobs-&-Signals.html"><strong aria-hidden="true">10.</strong> Jobs & Signals</a></li><li class="chapter-item expanded "><a href="Arithmetic-Evaluation.html"><strong aria-hidden="true">11.</strong> Arithmetic Evaluation</a></li><li class="chapter-item expanded "><a href="Conditional-Expressions.html"><strong aria-hidden="true">12.</strong> Conditional Expressions</a></li><li class="chapter-item expanded "><a href="Prompt-Expansion.html"><strong aria-hidden="true">13.</strong> Prompt Expansion</a></li><li class="chapter-item expanded "><a href="Expansion.html"><strong aria-hidden="true">14.</strong> Expansion</a></li><li class="chapter-item expanded "><a href="Parameters.html"><strong aria-hidden="true">15.</strong> Parameters</a></li><li class="chapter-item expanded "><a href="Options.html"><strong aria-hidden="true">16.</strong> Options</a></li><li class="chapter-item expanded "><a href="Shell-Builtin-Commands.html"><strong aria-hidden="true">17.</strong> Shell Builtin Commands</a></li><li class="chapter-item expanded "><a href="Zsh-Line-Editor.html"><strong aria-hidden="true">18.</strong> Zsh Line Editor</a></li><li class="chapter-item expanded "><a href="Completion-Widgets.html"><strong aria-hidden="true">19.</strong> Completion Widgets</a></li><li class="chapter-item expanded "><a href="Completion-System.html"><strong aria-hidden="true">20.</strong> Completion System</a></li><li class="chapter-item expanded "><a href="Completion-Using-compctl.html"><strong aria-hidden="true">21.</strong> Completion Using compctl</a></li><li class="chapter-item expanded "><a href="Zsh-Modules.html"><strong aria-hidden="true">22.</strong> Zsh Modules</a></li><li class="chapter-item expanded "><a href="Calendar-Function-System.html"><strong aria-hidden="true">23.</strong> Calendar Function System</a></li><li class="chapter-item expanded "><a href="TCP-Function-System.html"><strong aria-hidden="true">24.</strong> TCP Function System</a></li><li class="chapter-item expanded "><a href="Zftp-Function-System.html"><strong aria-hidden="true">25.</strong> Zftp Function System</a></li><li class="chapter-item expanded "><a href="User-Contributions.html"><strong aria-hidden="true">26.</strong> User Contributions</a></li></ol>
2021-05-11 02:29:21 +02:00
</div>
<div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
</nav>
<div id="page-wrapper" class="page-wrapper">
<div class="page">
2022-08-24 15:22:41 +02:00
<div id="menu-bar-hover-placeholder"></div>
2021-05-11 02:29:21 +02:00
<div id="menu-bar" class="menu-bar sticky bordered">
<div class="left-buttons">
<button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
<i class="fa fa-bars"></i>
</button>
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
<i class="fa fa-paint-brush"></i>
</button>
<ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
<li role="none"><button role="menuitem" class="theme" id="light">Light (default)</button></li>
<li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
<li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
<li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
<li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
2022-09-01 07:20:37 +02:00
<li role="none"><button role="menuitem" class="theme" id="latte">Latte</button></li>
<li role="none"><button role="menuitem" class="theme" id="frappe">Frappé</button></li>
<li role="none"><button role="menuitem" class="theme" id="macchiato">Macchiato</button></li>
<li role="none"><button role="menuitem" class="theme" id="mocha">Mocha</button></li>
2021-05-11 02:29:21 +02:00
</ul>
<button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
<i class="fa fa-search"></i>
</button>
</div>
<h1 class="menu-title">Zsh Manual</h1>
<div class="right-buttons">
<a href="print.html" title="Print this book" aria-label="Print this book">
<i id="print-button" class="fa fa-print"></i>
</a>
2021-05-17 17:00:52 +02:00
2021-05-11 02:29:21 +02:00
</div>
</div>
<div id="search-wrapper" class="hidden">
<form id="searchbar-outer" class="searchbar-outer">
2021-05-17 17:00:52 +02:00
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
2021-05-11 02:29:21 +02:00
</form>
<div id="searchresults-outer" class="searchresults-outer hidden">
<div id="searchresults-header" class="searchresults-header"></div>
<ul id="searchresults">
</ul>
</div>
</div>
<!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
<script type="text/javascript">
document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
});
</script>
<div id="content" class="content">
<main>
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="The-Z-Shell-Manual.html#1-the-z-shell-manual">1 The Z Shell Manual</a>
<ul>
<li><a href="The-Z-Shell-Manual.html#11-producing-documentation-from-zshtexi">1.1 Producing documentation from zsh.texi</a></li>
</ul>
</li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2022-08-24 15:22:41 +02:00
<p><span id="The-Z-Shell-Manual"></span> <span
id="The-Z-Shell-Manual-1"></span></p>
2021-05-11 02:29:21 +02:00
<h1 id="1-the-z-shell-manual"><a class="header" href="#1-the-z-shell-manual">1 The Z Shell Manual</a></h1>
2022-08-24 15:22:41 +02:00
<p>This document has been produced from the texinfo file zsh.texi, included
in the Doc sub-directory of the Zsh distribution.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Producing-documentation-from-zsh_002etexi"></span></p>
<h2 id="11-producing-documentation-from-zshtexi"><a class="header" href="#11-producing-documentation-from-zshtexi">1.1 Producing documentation from zsh.texi</a></h2>
<p>The texinfo source may be converted into several formats:</p>
<p>The Info manual<br />
2022-08-24 15:22:41 +02:00
The Info format allows searching for topics, commands, functions, etc.
from the many Indices. The command makeinfo zsh.texi is used to
produce the Info documentation.</p>
2021-05-11 02:29:21 +02:00
<p>The printed manual<br />
2022-08-24 15:22:41 +02:00
The command texi2dvi zsh.texi will output zsh.dvi which can then be
processed with dvips and optionally gs (Ghostscript) to produce a nicely
formatted printed manual.</p>
2021-05-11 02:29:21 +02:00
<p>The HTML manual<br />
An HTML version of this manual is available at the Zsh web site via:</p>
2022-08-24 15:22:41 +02:00
<p><a href="https://zsh.sourceforge.io/Doc/">https://zsh.sourceforge.io/Doc/</a>.</p>
<p>(The HTML version is produced with texi2html, which may be obtained from
<a href="http://www.nongnu.org/texi2html/">http://www.nongnu.org/texi2html/</a>. The command is texi2html output .
ifinfo split=chapter node-files zsh.texi. If necessary, upgrade to
version 1.78 of texi2html.)</p>
2021-05-11 02:29:21 +02:00
<p>For those who do not have the necessary tools to process texinfo,
precompiled documentation (PostScript, dvi, PDF, info and HTML formats)
is available from the zsh archive site or its mirrors, in the file
2022-08-24 15:22:41 +02:00
zsh-doc.tar.gz. (See <a href="Introduction.html#Availability">Availability</a> for
a list of sites.)</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="Introduction.html#2-introduction">2 Introduction</a>
<ul>
<li><a href="Introduction.html#21-author">2.1 Author</a></li>
<li><a href="Introduction.html#22-availability">2.2 Availability</a></li>
<li><a href="Introduction.html#23-mailing-lists">2.3 Mailing Lists</a></li>
<li><a href="Introduction.html#24-the-zsh-faq">2.4 The Zsh FAQ</a></li>
<li><a href="Introduction.html#25-the-zsh-web-page">2.5 The Zsh Web Page</a></li>
<li><a href="Introduction.html#26-the-zsh-userguide">2.6 The Zsh Userguide</a></li>
<li><a href="Introduction.html#27-see-also">2.7 See Also</a></li>
</ul>
</li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<p><span id="Introduction"></span> <span id="Introduction-1"></span></p>
<h1 id="2-introduction"><a class="header" href="#2-introduction">2 Introduction</a></h1>
<p><span id="index-introduction"></span></p>
<p>Zsh is a UNIX command interpreter (shell) usable as an interactive login
shell and as a shell script command processor. Of the standard shells,
zsh most closely resembles ksh but includes many enhancements. It does
not provide compatibility with POSIX or other shells in its default
operating mode: see the section
<a href="Invocation.html#Compatibility">Compatibility</a>.</p>
<p>Zsh has command line editing, builtin spelling correction, programmable
command completion, shell functions (with autoloading), a history
mechanism, and a host of other features.</p>
<hr />
<p><span id="Author"></span> <span id="Author-1"></span></p>
<h2 id="21-author"><a class="header" href="#21-author">2.1 Author</a></h2>
<p><span id="index-author"></span></p>
2022-08-24 15:22:41 +02:00
<p>Zsh was originally written by Paul Falstad. Zsh is now maintained by the
members of the zsh-workers mailing list &lt;zsh-workers@zsh.org&gt;. The
development is currently coordinated by Peter Stephenson &lt;pws@zsh.org&gt;.
The coordinator can be contacted at &lt;coordinator@zsh.org&gt;, but matters
relating to the code should generally go to the mailing list.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Availability"></span> <span id="Availability-1"></span></p>
<h2 id="22-availability"><a class="header" href="#22-availability">2.2 Availability</a></h2>
<p>Zsh is available from the following HTTP and anonymous FTP site.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-FTP-sites-for-zsh"></span> <span
id="index-acquiring-zsh-by-FTP"></span> <span
id="index-availability-of-zsh"></span></p>
<p><a href="ftp://ftp.zsh.org/pub/">ftp://ftp.zsh.org/pub/</a><br />
<a href="https://www.zsh.org/pub/">https://www.zsh.org/pub/</a></p>
2021-05-11 02:29:21 +02:00
<p>The up-to-date source code is available via Git from Sourceforge. See
2022-08-24 15:22:41 +02:00
<a href="https://sourceforge.net/projects/zsh/">https://sourceforge.net/projects/zsh/</a> for details. A summary of
2021-05-11 02:29:21 +02:00
instructions for the archive can be found at
2022-08-24 15:22:41 +02:00
<a href="https://zsh.sourceforge.io/">https://zsh.sourceforge.io/</a>.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Mailing-Lists"></span> <span id="Mailing-Lists-1"></span></p>
<h2 id="23-mailing-lists"><a class="header" href="#23-mailing-lists">2.3 Mailing Lists</a></h2>
<p><span id="index-mailing-lists"></span></p>
2022-08-24 15:22:41 +02:00
<p>Zsh has several mailing lists:</p>
<p>&lt;zsh-announce@zsh.org&gt;<br />
Announcements about releases, major changes in the shell and the monthly
posting of the Zsh FAQ. (moderated)</p>
<p>&lt;zsh-users@zsh.org&gt;<br />
2021-05-11 02:29:21 +02:00
User discussions.</p>
2022-08-24 15:22:41 +02:00
<p>&lt;zsh-workers@zsh.org&gt;<br />
2021-05-11 02:29:21 +02:00
Hacking, development, bug reports and patches.</p>
2022-08-24 15:22:41 +02:00
<p>&lt;zsh-security@zsh.org&gt;<br />
Private mailing list (the general public cannot subscribe to it) for
discussing bug reports with security implications, i.e., potential
vulnerabilities.</p>
<p>If you find a security problem in zsh itself, please mail this address.</p>
2021-05-11 02:29:21 +02:00
<p>To subscribe or unsubscribe, send mail to the associated administrative
address for the mailing list.</p>
2022-08-24 15:22:41 +02:00
<p>&lt;zsh-announce-subscribe@zsh.org&gt;</p>
<p>&lt;zsh-users-subscribe@zsh.org&gt;</p>
<p>&lt;zsh-workers-subscribe@zsh.org&gt;</p>
<p>&lt;zsh-announce-unsubscribe@zsh.org&gt;</p>
<p>&lt;zsh-users-unsubscribe@zsh.org&gt;</p>
<p>&lt;zsh-workers-unsubscribe@zsh.org&gt;</p>
2021-05-11 02:29:21 +02:00
<p>YOU ONLY NEED TO JOIN ONE OF THE MAILING LISTS AS THEY ARE NESTED. All
submissions to zsh-announce are automatically forwarded to zsh-users.
All submissions to zsh-users are automatically forwarded to zsh-workers.</p>
<p>If you have problems subscribing/unsubscribing to any of the mailing
2022-08-24 15:22:41 +02:00
lists, send mail to &lt;listmaster@zsh.org&gt;.</p>
2021-05-11 02:29:21 +02:00
<p>The mailing lists are archived; the archives can be accessed via the
2022-08-24 15:22:41 +02:00
administrative addresses listed above. There is also a hypertext archive
available at <a href="https://www.zsh.org/mla/">https://www.zsh.org/mla/</a>.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="The-Zsh-FAQ"></span> <span id="The-Zsh-FAQ-1"></span></p>
<h2 id="24-the-zsh-faq"><a class="header" href="#24-the-zsh-faq">2.4 The Zsh FAQ</a></h2>
<p>Zsh has a list of Frequently Asked Questions (FAQ), maintained by Peter
2022-08-24 15:22:41 +02:00
Stephenson &lt;pws@zsh.org&gt;. It is regularly posted to the newsgroup
2021-05-11 02:29:21 +02:00
comp.unix.shell and the zsh-announce mailing list. The latest version
can be found at any of the Zsh FTP sites, or at
2022-08-24 15:22:41 +02:00
<a href="https://www.zsh.org/FAQ/">https://www.zsh.org/FAQ/</a>. The contact address for FAQ-related matters
is &lt;faqmaster@zsh.org&gt;.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-Zsh-Web-Page"></span> <span
id="The-Zsh-Web-Page-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="25-the-zsh-web-page"><a class="header" href="#25-the-zsh-web-page">2.5 The Zsh Web Page</a></h2>
2022-08-24 15:22:41 +02:00
<p>Zsh has a web page which is located at <a href="https://www.zsh.org/">https://www.zsh.org/</a>. The
contact address for web-related matters is &lt;webmaster@zsh.org&gt;.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-Zsh-Userguide"></span> <span
id="The-Zsh-Userguide-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="26-the-zsh-userguide"><a class="header" href="#26-the-zsh-userguide">2.6 The Zsh Userguide</a></h2>
<p>A userguide is currently in preparation. It is intended to complement
the manual, with explanations and hints on issues where the manual can
be cabbalistic, hierographic, or downright mystifying (for example, the
word hierographic does not exist). It can be viewed in its current
2022-08-24 15:22:41 +02:00
state at <a href="https://zsh.sourceforge.io/Guide/">https://zsh.sourceforge.io/Guide/</a>. At the time of writing,
2021-05-11 02:29:21 +02:00
chapters dealing with startup files and their contents and the new
completion system were essentially complete.</p>
<hr />
<p><span id="See-Also"></span> <span id="See-Also-1"></span></p>
<h2 id="27-see-also"><a class="header" href="#27-see-also">2.7 See Also</a></h2>
2022-08-24 15:22:41 +02:00
<p>sh(1), csh(1), tcsh(1), rc(1), bash(1), ksh(1)</p>
2021-05-11 02:29:21 +02:00
<p>IEEE Standard for information Technology - Part 2: Shell and Utilities,
IEEE Inc, 1993, ISBN 1-55937-255-9.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="Roadmap.html#3-roadmap">3 Roadmap</a>
<ul>
<li><a href="Roadmap.html#31-when-the-shell-starts">3.1 When the shell starts</a></li>
<li><a href="Roadmap.html#32-interactive-use">3.2 Interactive Use</a>
<ul>
<li><a href="Roadmap.html#321-completion">3.2.1 Completion</a></li>
<li><a href="Roadmap.html#322-extending-the-line-editor">3.2.2 Extending the line editor</a></li>
</ul>
</li>
<li><a href="Roadmap.html#33-options">3.3 Options</a></li>
<li><a href="Roadmap.html#34-pattern-matching">3.4 Pattern Matching</a></li>
<li><a href="Roadmap.html#35-general-comments-on-syntax">3.5 General Comments on Syntax</a></li>
<li><a href="Roadmap.html#36-programming">3.6 Programming</a></li>
</ul>
</li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<p><span id="Roadmap"></span> <span id="Roadmap-1"></span></p>
<h1 id="3-roadmap"><a class="header" href="#3-roadmap">3 Roadmap</a></h1>
<p><span id="index-roadmap"></span></p>
<p>The Zsh Manual, like the shell itself, is large and often complicated.
This section of the manual provides some pointers to areas of the shell
that are likely to be of particular interest to new users, and indicates
where in the rest of the manual the documentation is to be found.</p>
<hr />
<p><span id="When-the-shell-starts"></span></p>
<h2 id="31-when-the-shell-starts"><a class="header" href="#31-when-the-shell-starts">3.1 When the shell starts</a></h2>
<p>When it starts, the shell reads commands from various files. These can
be created or edited to customize the shell. See
<a href="Files.html#Files">Files</a>.</p>
<p>If no personal initialization files exist for the current user, a
function is run to help you change some of the most common settings. It
2022-08-24 15:22:41 +02:00
wont appear if your administrator has disabled the zsh/newuser module.
The function is designed to be self-explanatory. You can run it by hand
with autoload -Uz zsh-newuser-install; zsh-newuser-install -f. See
also <a href="User-Contributions.html#User-Configuration-Functions">User Configuration
2021-05-11 02:29:21 +02:00
Functions</a>.</p>
<hr />
<p><span id="Interactive-Use"></span></p>
<h2 id="32-interactive-use"><a class="header" href="#32-interactive-use">3.2 Interactive Use</a></h2>
<p>Interaction with the shell uses the builtin Zsh Line Editor, ZLE. This
is described in detail in <a href="Zsh-Line-Editor.html#Zsh-Line-Editor">Zsh Line
Editor</a>.</p>
<p>The first decision a user must make is whether to use the Emacs or Vi
editing mode as the keys for editing are substantially different. Emacs
editing mode is probably more natural for beginners and can be selected
2022-08-24 15:22:41 +02:00
explicitly with the command bindkey -e.</p>
2021-05-11 02:29:21 +02:00
<p>A history mechanism for retrieving previously typed lines (most simply
with the Up or Down arrow keys) is available; note that, unlike other
shells, zsh will not save these lines when the shell exits unless you
set appropriate variables, and the number of history lines retained by
default is quite small (30 lines). See the description of the shell
2022-08-24 15:22:41 +02:00
variables (referred to in the documentation as parameters) HISTFILE,
HISTSIZE and SAVEHIST in <a href="Parameters.html#Parameters-Used-By-The-Shell">Parameters Used By The
2021-05-11 02:29:21 +02:00
Shell</a>. Note that its
currently only possible to read and write files saving history when the
shell is interactive, i.e. it does not work from scripts.</p>
<p>The shell now supports the UTF-8 character set (and also others if
supported by the operating system). This is (mostly) handled
transparently by the shell, but the degree of support in terminal
emulators is variable. There is some discussion of this in the shell
2022-08-24 15:22:41 +02:00
FAQ, <a href="https://www.zsh.org/FAQ/">https://www.zsh.org/FAQ/</a>. Note in particular that for combining
characters to be handled the option COMBINING_CHARS needs to be set.
2021-05-11 02:29:21 +02:00
Because the shell is now more sensitive to the definition of the
character set, note that if you are upgrading from an older version of
2022-08-24 15:22:41 +02:00
the shell you should ensure that the appropriate variable, either LANG
(to affect all aspects of the shells operation) or LC_CTYPE (to affect
only the handling of character sets) is set to an appropriate value.
This is true even if you are using a single-byte character set including
extensions of ASCII such as ISO-8859-1 or ISO-8859-15. See the
description of LC_CTYPE in <a href="Parameters.html#Parameters">Parameters</a>.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Completion-1"></span></p>
<h3 id="321-completion"><a class="header" href="#321-completion">3.2.1 Completion</a></h3>
<p>Completion is a feature present in many shells. It allows the user to
type only a part (usually the prefix) of a word and have the shell fill
in the rest. The completion system in zsh is programmable. For example,
the shell can be set to complete email addresses in arguments to the
2022-08-24 15:22:41 +02:00
mail command from your ~/.abook/addressbook; usernames, hostnames, and
2021-05-11 02:29:21 +02:00
even remote paths in arguments to scp, and so on. Anything that can be
written in or glued together with zsh can be the source of what the line
editor offers as possible completions.</p>
2022-08-24 15:22:41 +02:00
<p>Zsh has two completion systems, an old, so called compctl completion
2021-05-11 02:29:21 +02:00
(named after the builtin command that serves as its complete and only
2022-08-24 15:22:41 +02:00
user interface), and a new one, referred to as compsys, organized as
2021-05-11 02:29:21 +02:00
library of builtin and user-defined functions. The two systems differ in
their interface for specifying the completion behavior. The new system
is more customizable and is supplied with completions for many commonly
used commands; it is therefore to be preferred.</p>
<p>The completion system must be enabled explicitly when the shell starts.
For more information see <a href="Completion-System.html#Completion-System">Completion
System</a>.</p>
<hr />
<p><span id="Extending-the-line-editor"></span></p>
<h3 id="322-extending-the-line-editor"><a class="header" href="#322-extending-the-line-editor">3.2.2 Extending the line editor</a></h3>
<p>Apart from completion, the line editor is highly extensible by means of
shell functions. Some useful functions are provided with the shell; they
provide facilities such as:</p>
2022-08-24 15:22:41 +02:00
<p>insert-composed-char<br />
2021-05-11 02:29:21 +02:00
composing characters not found on the keyboard</p>
2022-08-24 15:22:41 +02:00
<p>match-words-by-style<br />
2021-05-11 02:29:21 +02:00
configuring what the line editor considers a word when moving or
deleting by word</p>
2022-08-24 15:22:41 +02:00
<p>history-beginning-search-backward-end, etc.<br />
2021-05-11 02:29:21 +02:00
alternative ways of searching the shell history</p>
2022-08-24 15:22:41 +02:00
<p>replace-string, replace-pattern<br />
functions for replacing strings or patterns globally in the command line</p>
<p>edit-command-line<br />
2021-05-11 02:29:21 +02:00
edit the command line with an external editor.</p>
<p>See <a href="User-Contributions.html#ZLE-Functions">ZLE Functions</a> for
descriptions of these.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Options-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="33-options"><a class="header" href="#33-options">3.3 Options</a></h2>
<p>The shell has a large number of options for changing its behaviour.
These cover all aspects of the shell; browsing the full documentation is
the only good way to become acquainted with the many possibilities. See
<a href="Options.html#Options">Options</a>.</p>
<hr />
<p><span id="Pattern-Matching"></span></p>
<h2 id="34-pattern-matching"><a class="header" href="#34-pattern-matching">3.4 Pattern Matching</a></h2>
<p>The shell has a rich set of patterns which are available for file
matching (described in the documentation as filename generation and
also known for historical reasons as globbing) and for use when
programming. These are described in <a href="Expansion.html#Filename-Generation">Filename
Generation</a>.</p>
<p>Of particular interest are the following patterns that are not commonly
supported by other systems of pattern matching:</p>
2022-08-24 15:22:41 +02:00
<p>**<br />
2021-05-11 02:29:21 +02:00
for matching over multiple directories</p>
2022-08-24 15:22:41 +02:00
<p>|<br />
2021-05-11 02:29:21 +02:00
for matching either of two alternatives</p>
2022-08-24 15:22:41 +02:00
<p>~, ^<br />
the ability to exclude patterns from matching when the EXTENDED_GLOB
option is set</p>
<p>(<code>...</code>)<br />
2021-05-11 02:29:21 +02:00
glob qualifiers, included in parentheses at the end of the pattern,
2022-08-24 15:22:41 +02:00
which select files by type (such as directories) or attribute (such as
size).</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="General-Comments-on-Syntax"></span></p>
<h2 id="35-general-comments-on-syntax"><a class="header" href="#35-general-comments-on-syntax">3.5 General Comments on Syntax</a></h2>
<p>Although the syntax of zsh is in ways similar to the Korn shell, and
therefore more remotely to the original UNIX shell, the Bourne shell,
its default behaviour does not entirely correspond to those shells.
General shell syntax is introduced in <a href="Shell-Grammar.html#Shell-Grammar">Shell
Grammar</a>.</p>
<p>One commonly encountered difference is that variables substituted onto
the command line are not split into words. See the description of the
2022-08-24 15:22:41 +02:00
shell option SH_WORD_SPLIT in <a href="Expansion.html#Parameter-Expansion">Parameter
2021-05-11 02:29:21 +02:00
Expansion</a>. In zsh, you can either
2022-08-24 15:22:41 +02:00
explicitly request the splitting (e.g. ${=foo}) or use an array when you
want a variable to expand to more than one word. See <a href="Parameters.html#Array-Parameters">Array
2021-05-11 02:29:21 +02:00
Parameters</a>.</p>
<hr />
<p><span id="Programming"></span></p>
<h2 id="36-programming"><a class="header" href="#36-programming">3.6 Programming</a></h2>
<p>The most convenient way of adding enhancements to the shell is typically
by writing a shell function and arranging for it to be autoloaded.
Functions are described in <a href="Functions.html#Functions">Functions</a>. Users
changing from the C shell and its relatives should notice that aliases
are less used in zsh as they dont perform argument substitution, only
simple text replacement.</p>
<p>A few general functions, other than those for the line editor described
above, are provided with the shell and are described in <a href="User-Contributions.html#User-Contributions">User
Contributions</a>. Features
include:</p>
2022-08-24 15:22:41 +02:00
<p>promptinit<br />
2021-05-11 02:29:21 +02:00
a prompt theme system for changing prompts easily, see <a href="User-Contributions.html#Prompt-Themes">Prompt
Themes</a></p>
2022-08-24 15:22:41 +02:00
<p>zsh-mime-setup<br />
a MIME-handling system which dispatches commands according to the suffix
of a file as done by graphical file managers</p>
<p>zcalc<br />
2021-05-11 02:29:21 +02:00
a calculator</p>
2022-08-24 15:22:41 +02:00
<p>zargs<br />
a version of xargs that makes the find command redundant</p>
<p>zmv<br />
2021-05-11 02:29:21 +02:00
a command for renaming files by means of shell patterns.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="Invocation.html#4-invocation">4 Invocation</a>
<ul>
<li><a href="Invocation.html#41-invocation">4.1 Invocation</a></li>
<li><a href="Invocation.html#42-compatibility">4.2 Compatibility</a></li>
<li><a href="Invocation.html#43-restricted-shell">4.3 Restricted Shell</a></li>
</ul>
</li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2022-08-24 15:22:41 +02:00
<p><span id="Invocation"></span> <span id="Invocation-2"></span></p>
2021-05-11 02:29:21 +02:00
<h1 id="4-invocation"><a class="header" href="#4-invocation">4 Invocation</a></h1>
<p><span id="index-invocation"></span></p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Invocation-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="41-invocation"><a class="header" href="#41-invocation">4.1 Invocation</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-shell-options"></span> <span
id="index-options_002c-shell"></span> <span
id="index-shell-flags"></span> <span id="index-flags_002c-shell"></span></p>
2021-05-11 02:29:21 +02:00
<p>The following flags are interpreted by the shell when invoked to
determine where the shell will read commands from:</p>
2022-08-24 15:22:41 +02:00
<p>-c<br />
2021-05-11 02:29:21 +02:00
Take the first argument as a command to execute, rather than reading
2022-08-24 15:22:41 +02:00
commands from a script or standard input. If any further arguments are
given, the first one is assigned to $0, rather than being used as a
positional parameter.</p>
<p>-i<br />
Force shell to be interactive. It is still possible to specify a script
to execute.</p>
<p>-s<br />
Force shell to read commands from the standard input. If the -s flag is
not present and an argument is given, the first argument is taken to be
the pathname of a script to execute.</p>
2021-05-11 02:29:21 +02:00
<p>If there are any remaining arguments after option processing, and
2022-08-24 15:22:41 +02:00
neither of the options -c or -s was supplied, the first argument is
2021-05-11 02:29:21 +02:00
taken as the file name of a script containing shell commands to be
2022-08-24 15:22:41 +02:00
executed. If the option PATH_SCRIPT is set, and the file name does not
contain a directory path (i.e. there is no / in the name), first the
current directory and then the command path given by the variable PATH
2021-05-11 02:29:21 +02:00
are searched for the script. If the option is not set or the file name
2022-08-24 15:22:41 +02:00
contains a / it is used directly.</p>
2021-05-11 02:29:21 +02:00
<p>After the first one or two arguments have been appropriated as described
above, the remaining arguments are assigned to the positional
parameters.</p>
2022-08-24 15:22:41 +02:00
<p>For further options, which are common to invocation and the set builtin,
see <a href="Options.html#Options">Options</a>.</p>
<p>The long option --emulate followed (in a separate word) by an
2021-05-11 02:29:21 +02:00
emulation mode may be passed to the shell. The emulation modes are those
2022-08-24 15:22:41 +02:00
described for the emulate builtin, see <a href="Shell-Builtin-Commands.html#Shell-Builtin-Commands">Shell Builtin
2021-05-11 02:29:21 +02:00
Commands</a>. The
2022-08-24 15:22:41 +02:00
--emulate option must precede any other options (which might otherwise
be overridden), but following options are honoured, so may be used to
modify the requested emulation mode. Note that certain extra steps are
taken to ensure a smooth emulation when this option is used compared
with the emulate command within the shell: for example, variables that
conflict with POSIX usage such as path are not defined within the shell.</p>
<p>Options may be specified by name using the -o option. -o acts like a
2021-05-11 02:29:21 +02:00
single-letter option, but takes a following string as the option name.
For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zsh -x -o shwordsplit scr
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>runs the script scr, setting the XTRACE option by the corresponding
letter -x and the SH_WORD_SPLIT option by name. Options may be turned
<em>off</em> by name by using +o instead of -o. -o can be stacked up with
preceding single-letter options, so for example -xo shwordsplit or
-xoshwordsplit is equivalent to -x -o shwordsplit.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-long-option"></span></p>
<p>Options may also be specified by name in GNU long option style,
2022-08-24 15:22:41 +02:00
--<code>option-name</code>. When this is done, - characters in the option name
are permitted: they are translated into _, and thus ignored. So, for
example, zsh --sh-word-split invokes zsh with the SH_WORD_SPLIT option
turned on. Like other option syntaxes, options can be turned off by
replacing the initial - with a +; thus +-sh-word-split is
equivalent to --no-sh-word-split. Unlike other option syntaxes,
GNU-style long options cannot be stacked with any other options, so for
example -x-shwordsplit is an error, rather than being treated like -x
--shwordsplit.</p>
<p><span id="index-_002d_002dversion"></span> <span
id="index-_002d_002dhelp"></span></p>
<p>The special GNU-style option --version is handled; it sends to
2021-05-11 02:29:21 +02:00
standard output the shells version information, then exits
2022-08-24 15:22:41 +02:00
successfully. --help is also handled; it sends to standard output a
list of options that can be used when invoking the shell, then exits
2021-05-11 02:29:21 +02:00
successfully.</p>
<p>Option processing may be finished, allowing following arguments that
2022-08-24 15:22:41 +02:00
start with - or + to be treated as normal arguments, in two ways.
Firstly, a lone - (or +) as an argument by itself ends option
processing. Secondly, a special option -- (or +-), which may be
specified on its own (which is the standard POSIX usage) or may be
stacked with preceding options (so -x- is equivalent to -x --).
Options are not permitted to be stacked after -- (so -x-f is an
error), but note the GNU-style option form discussed above, where
--shwordsplit is permitted and does not end option processing.</p>
2021-05-11 02:29:21 +02:00
<p>Except when the sh/ksh emulation single-letter options are in effect,
2022-08-24 15:22:41 +02:00
the option -b (or +b) ends option processing. -b is like --,
except that further single-letter options can be stacked after the -b
and will take effect as normal.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Compatibility"></span> <span id="Compatibility-1"></span></p>
<h2 id="42-compatibility"><a class="header" href="#42-compatibility">4.2 Compatibility</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-compatibility"></span> <span
id="index-sh-compatibility"></span> <span
id="index-ksh-compatibility"></span></p>
<p>Zsh tries to emulate sh or ksh when it is invoked as sh or ksh
2021-05-11 02:29:21 +02:00
respectively; more precisely, it looks at the first letter of the name
2022-08-24 15:22:41 +02:00
by which it was invoked, excluding any initial r (assumed to stand for
restricted), and if that is b, s or k it will emulate sh or ksh.
Furthermore, if invoked as su (which happens on certain systems when the
shell is executed by the su command), the shell will try to find an
alternative name from the SHELL environment variable and perform
emulation based on that.</p>
2021-05-11 02:29:21 +02:00
<p>In sh and ksh compatibility modes the following parameters are not
2022-08-24 15:22:41 +02:00
special and not initialized by the shell: ARGC, argv, cdpath, fignore,
fpath, HISTCHARS, mailpath, MANPATH, manpath, path, prompt, PROMPT,
PROMPT2, PROMPT3, PROMPT4, psvar, status.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-ENV_002c-use-of"></span></p>
<p>The usual zsh startup/shutdown scripts are not executed. Login shells
2022-08-24 15:22:41 +02:00
source /etc/profile followed by $HOME/.profile. If the ENV environment
variable is set on invocation, $ENV is sourced after the profile
scripts. The value of ENV is subjected to parameter expansion, command
substitution, and arithmetic expansion before being interpreted as a
pathname. Note that the PRIVILEGED option also affects the execution of
startup files.</p>
<p>The following options are set if the shell is invoked as sh or ksh:
NO_BAD_PATTERN, NO_BANG_HIST, NO_BG_NICE, NO_EQUALS,
NO_FUNCTION_ARGZERO, GLOB_SUBST, NO_GLOBAL_EXPORT, NO_HUP,
INTERACTIVE_COMMENTS, KSH_ARRAYS, NO_MULTIOS, NO_NOMATCH, NO_NOTIFY,
POSIX_BUILTINS, NO_PROMPT_PERCENT, RM_STAR_SILENT, SH_FILE_EXPANSION,
SH_GLOB, SH_OPTION_LETTERS, SH_WORD_SPLIT. Additionally the BSD_ECHO and
IGNORE_BRACES options are set if zsh is invoked as sh. Also, the
KSH_OPTION_PRINT, LOCAL_OPTIONS, PROMPT_BANG, PROMPT_SUBST and
SINGLE_LINE_ZLE options are set if zsh is invoked as ksh.</p>
<p>Please note that, whilst reasonable efforts are taken to address
incompatibilities when they arise, zsh does not guarantee complete
emulation of other shells, nor POSIX compliance. For more information on
the differences between zsh and other shells, please refer to chapter 2
of the shell FAQ, <a href="https://www.zsh.org/FAQ/">https://www.zsh.org/FAQ/</a>.</p>
<hr />
<p><span id="Restricted-Shell"></span> <span
id="Restricted-Shell-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="43-restricted-shell"><a class="header" href="#43-restricted-shell">4.3 Restricted Shell</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-restricted-shell"></span> <span
id="index-RESTRICTED"></span></p>
2021-05-11 02:29:21 +02:00
<p>When the basename of the command used to invoke zsh starts with the
2022-08-24 15:22:41 +02:00
letter r or the -r command line option is supplied at invocation,
the shell becomes restricted. Emulation mode is determined after
stripping the letter r from the invocation name. The following are
disabled in restricted mode:</p>
<ul>
<li>changing directories with the cd builtin</li>
<li>changing or unsetting the EGID, EUID, GID, HISTFILE, HISTSIZE, IFS,
LD_AOUT_LIBRARY_PATH, LD_AOUT_PRELOAD, LD_LIBRARY_PATH, LD_PRELOAD,
MODULE_PATH, module_path, PATH, path, SHELL, UID and USERNAME
parameters</li>
<li>specifying command names containing /</li>
<li>specifying command pathnames using hash</li>
2021-05-11 02:29:21 +02:00
<li>redirecting output to files</li>
2022-08-24 15:22:41 +02:00
<li>using the exec builtin command to replace the shell with another
2021-05-11 02:29:21 +02:00
command</li>
2022-08-24 15:22:41 +02:00
<li>using jobs -Z to overwrite the shell process argument and
2021-05-11 02:29:21 +02:00
environment space</li>
2022-08-24 15:22:41 +02:00
<li>using the ARGV0 parameter to override argv[0] for external
2021-05-11 02:29:21 +02:00
commands</li>
2022-08-24 15:22:41 +02:00
<li>turning off restricted mode with set +r or unsetopt RESTRICTED</li>
2021-05-11 02:29:21 +02:00
</ul>
<p>These restrictions are enforced after processing the startup files. The
2022-08-24 15:22:41 +02:00
startup files should set up PATH to point to a directory of commands
2021-05-11 02:29:21 +02:00
which can be safely invoked in the restricted environment. They may also
add further restrictions by disabling selected builtins.</p>
2022-08-24 15:22:41 +02:00
<p>Restricted mode can also be activated any time by setting the RESTRICTED
option. This immediately enables all the restrictions described above
even if the shell still has not processed all startup files.</p>
2021-05-11 02:29:21 +02:00
<p>A shell <em>Restricted Mode</em> is an outdated way to restrict what users may
do: modern systems have better, safer and more reliable ways to confine
user actions, such as <em>chroot jails</em>, <em>containers</em> and <em>zones</em>.</p>
<p>A restricted shell is very difficult to implement safely. The feature
may be removed in a future version of zsh.</p>
<p>It is important to realise that the restrictions only apply to the
shell, not to the commands it runs (except for some shell builtins).
While a restricted shell can only run the restricted list of commands
2022-08-24 15:22:41 +02:00
accessible via the predefined PATH variable, it does not prevent those
commands from running any other command.</p>
<p>As an example, if env is among the list of <em>allowed</em> commands, then it
allows the user to run any command as env is not a shell</p>
2021-05-11 02:29:21 +02:00
<p>So when implementing a restricted shell framework it is important to be
fully aware of what actions each of the <em>allowed</em> commands or features
(which may be regarded as <em>modules</em>) can perform.</p>
<p>Many commands can have their behaviour affected by environment
variables. Except for the few listed above, zsh does not restrict the
setting of environment variables.</p>
2022-08-24 15:22:41 +02:00
<p>If a perl, python, bash, or other general purpose interpreted
script it treated as a restricted command, the user can work around the
restriction by setting specially crafted PERL5LIB, PYTHONPATH,
BASHENV (etc.) environment variables. On GNU systems, any command can
be made to run arbitrary code when performing character set conversion
(including zsh itself) by setting a GCONV_PATH environment variable.
Those are only a few examples.</p>
<p>Bear in mind that, contrary to some other shells, readonly is not a
2021-05-11 02:29:21 +02:00
security feature in zsh as it can be undone and so cannot be used to
mitigate the above.</p>
<p>A restricted shell only works if the allowed commands are few and
carefully written so as not to grant more access to users than intended.
It is also important to restrict what zsh module the user may load as
2022-08-24 15:22:41 +02:00
some of them, such as zsh/system, zsh/mapfile and zsh/files, allow
bypassing most of the restrictions.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="Files.html#5-files">5 Files</a>
<ul>
<li><a href="Files.html#51-startupshutdown-files">5.1 Startup/Shutdown Files</a></li>
<li><a href="Files.html#52-files">5.2 Files</a></li>
</ul>
</li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2022-08-24 15:22:41 +02:00
<p><span id="Files"></span> <span id="Files-2"></span></p>
2021-05-11 02:29:21 +02:00
<h1 id="5-files"><a class="header" href="#5-files">5 Files</a></h1>
<hr />
<p><span id="Startup_002fShutdown-Files"></span></p>
<h2 id="51-startupshutdown-files"><a class="header" href="#51-startupshutdown-files">5.1 Startup/Shutdown Files</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-files_002c-startup"></span> <span
id="index-startup-files"></span> <span
id="index-files_002c-shutdown"></span> <span
id="index-shutdown-files"></span> <span
id="index-RCS_002c-use-of"></span> <span
id="index-GLOBAL_005fRCS_002c-use-of"></span> <span
id="index-NO_005fRCS_002c-use-of"></span> <span
id="index-NO_005fGLOBAL_005fRCS_002c-use-of"></span> <span
id="index-ZDOTDIR_002c-use-of"></span> <span id="index-zshenv"></span></p>
<p>Commands are first read from /etc/zshenv; this cannot be overridden.
Subsequent behaviour is modified by the RCS and GLOBAL_RCS options; the
former affects all startup files, while the second only affects global
startup files (those shown here with an path starting with a /). If one
of the options is unset at any point, any subsequent startup file(s) of
the corresponding type will not be read. It is also possible for a file
in $ZDOTDIR to re-enable GLOBAL_RCS. Both RCS and GLOBAL_RCS are set by
default.</p>
<p>Commands are then read from $ZDOTDIR/.zshenv. <span
id="index-LOGIN_002c-use-of"></span> <span id="index-zprofile"></span>
If the shell is a login shell, commands are read from /etc/zprofile and
then $ZDOTDIR/.zprofile. <span id="index-zshrc"></span> Then, if the
shell is interactive, commands are read from /etc/zshrc and then
$ZDOTDIR/.zshrc. <span id="index-zlogin"></span> Finally, if the shell
is a login shell, /etc/zlogin and $ZDOTDIR/.zlogin are read.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zlogout"></span></p>
2022-08-24 15:22:41 +02:00
<p>When a login shell exits, the files $ZDOTDIR/.zlogout and then
/etc/zlogout are read. This happens with either an explicit exit via the
exit or logout commands, or an implicit exit by reading end-of-file from
the terminal. However, if the shell terminates due to execing another
process, the logout files are not read. These are also affected by the
RCS and GLOBAL_RCS options. Note also that the RCS option affects the
saving of history files, i.e. if RCS is unset when the shell exits, no
history file will be saved.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-HOME_002c-use-of"></span></p>
2022-08-24 15:22:41 +02:00
<p>If ZDOTDIR is unset, HOME is used instead. Files listed above as being
in /etc may be in another directory, depending on the installation.</p>
<p>As /etc/zshenv is run for all instances of zsh, it is important that it
be kept as small as possible. In particular, it is a good idea to put
2021-05-11 02:29:21 +02:00
code that does not need to be run for every single shell behind a test
2022-08-24 15:22:41 +02:00
of the form if [[ -o rcs ]]; then ... so that it will not be
executed when zsh is invoked with the -f option.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Files-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="52-files"><a class="header" href="#52-files">5.2 Files</a></h2>
<p><span id="index-files-used"></span></p>
2022-08-24 15:22:41 +02:00
<p>$ZDOTDIR/.zshenv</p>
<p>$ZDOTDIR/.zprofile</p>
<p>$ZDOTDIR/.zshrc</p>
<p>$ZDOTDIR/.zlogin</p>
<p>$ZDOTDIR/.zlogout</p>
<p>${TMPPREFIX}* (default is /tmp/zsh*)</p>
<p>/etc/zshenv</p>
<p>/etc/zprofile</p>
<p>/etc/zshrc</p>
<p>/etc/zlogin</p>
<p>/etc/zlogout (installation-specific - /etc is the default)</p>
<p>Any of these files may be pre-compiled with the zcompile builtin command
(<a href="Shell-Builtin-Commands.html#Shell-Builtin-Commands">Shell Builtin
2021-05-11 02:29:21 +02:00
Commands</a>). If a
2022-08-24 15:22:41 +02:00
compiled file exists (named for the original file plus the .zwc
2021-05-11 02:29:21 +02:00
extension) and it is newer than the original file, the compiled file
will be used instead.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="Shell-Grammar.html#6-shell-grammar">6 Shell Grammar</a>
<ul>
<li><a href="Shell-Grammar.html#61-simple-commands--pipelines">6.1 Simple Commands &amp; Pipelines</a></li>
<li><a href="Shell-Grammar.html#62-precommand-modifiers">6.2 Precommand Modifiers</a></li>
<li><a href="Shell-Grammar.html#63-complex-commands">6.3 Complex Commands</a></li>
<li><a href="Shell-Grammar.html#64-alternate-forms-for-complex-commands">6.4 Alternate Forms For Complex Commands</a></li>
<li><a href="Shell-Grammar.html#65-reserved-words">6.5 Reserved Words</a></li>
<li><a href="Shell-Grammar.html#66-errors">6.6 Errors</a></li>
<li><a href="Shell-Grammar.html#67-comments">6.7 Comments</a></li>
<li><a href="Shell-Grammar.html#68-aliasing">6.8 Aliasing</a>
<ul>
<li><a href="Shell-Grammar.html#681-alias-difficulties">6.8.1 Alias difficulties</a></li>
</ul>
</li>
<li><a href="Shell-Grammar.html#69-quoting">6.9 Quoting</a></li>
</ul>
</li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<p><span id="Shell-Grammar"></span> <span id="Shell-Grammar-1"></span></p>
<h1 id="6-shell-grammar"><a class="header" href="#6-shell-grammar">6 Shell Grammar</a></h1>
2022-08-24 15:22:41 +02:00
<p><span id="index-shell-grammar"></span> <span
id="index-grammar_002c-shell"></span></p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Simple-Commands-_0026-Pipelines"></span> <span
id="Simple-Commands-_0026-Pipelines-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="61-simple-commands--pipelines"><a class="header" href="#61-simple-commands--pipelines">6.1 Simple Commands &amp; Pipelines</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-simple-commands"></span> <span
id="index-commands_002c-simple"></span></p>
2021-05-11 02:29:21 +02:00
<p>A <em>simple command</em> is a sequence of optional parameter assignments
followed by blank-separated words, with optional redirections
interspersed. For a description of assignment, see the beginning of
<a href="Parameters.html#Parameters">Parameters</a>.</p>
<p>The first word is the command to be executed, and the remaining words,
if any, are arguments to the command. If a command name is given, the
parameter assignments modify the environment of the command when it is
executed. The value of a simple command is its exit status, or 128 plus
the signal number if terminated by a signal. For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">echo foo
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>is a simple command with arguments.</p>
<p><span id="index-pipeline"></span></p>
<p>A <em>pipeline</em> is either a simple command, or a sequence of two or more
2022-08-24 15:22:41 +02:00
simple commands where each command is separated from the next by | or
|&amp;. Where commands are separated by |, the standard output of the
first command is connected to the standard input of the next. |&amp; is
shorthand for 2&gt;&amp;1 |, which connects both the standard output and the
standard error of the command to the standard input of the next. The
2021-05-11 02:29:21 +02:00
value of a pipeline is the value of the last command, unless the
2022-08-24 15:22:41 +02:00
pipeline is preceded by ! in which case the value is the logical
2021-05-11 02:29:21 +02:00
inverse of the value of the last command. For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">echo foo | sed 's/foo/bar/'
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>is a pipeline, where the output (foo plus a newline) of the first
2021-05-11 02:29:21 +02:00
command will be passed to the input of the second.</p>
<p><span id="index-coproc"></span> <span id="index-coprocess"></span></p>
2022-08-24 15:22:41 +02:00
<p>If a pipeline is preceded by coproc, it is executed as a coprocess; a
two-way pipe is established between it and the parent shell. The shell
can read from or write to the coprocess by means of the &gt;&amp;p and &lt;&amp;p
redirection operators or with print -p and read -p. A pipeline
cannot be preceded by both coproc and !. If job control is active,
the coprocess can be treated in other than input and output as an
ordinary background job.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-sublist"></span></p>
<p>A <em>sublist</em> is either a single pipeline, or a sequence of two or more
2022-08-24 15:22:41 +02:00
pipelines separated by &amp;&amp; or ||. If two pipelines are separated by
&amp;&amp;, the second pipeline is executed only if the first succeeds
(returns a zero status). If two pipelines are separated by ||, the
2021-05-11 02:29:21 +02:00
second is executed only if the first fails (returns a nonzero status).
Both operators have equal precedence and are left associative. The value
of the sublist is the value of the last pipeline executed. For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">dmesg | grep panic &amp;&amp; print yes
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>is a sublist consisting of two pipelines, the second just a simple
2022-08-24 15:22:41 +02:00
command which will be executed if and only if the grep command returns a
zero status. If it does not, the value of the sublist is that return
status, else it is the status returned by the print (almost certainly
2021-05-11 02:29:21 +02:00
zero).</p>
<p><span id="index-list"></span></p>
<p>A <em>list</em> is a sequence of zero or more sublists, in which each sublist
2022-08-24 15:22:41 +02:00
is terminated by ;, &amp;, &amp;|, &amp;!, or a newline. This terminator
may optionally be omitted from the last sublist in the list when the
list appears as a complex command inside (...) or {...}. When a
sublist is terminated by ; or newline, the shell waits for it to
finish before executing the next sublist. If a sublist is terminated by
a &amp;, &amp;|, or &amp;!, the shell executes the last pipeline in it in the
background, and does not wait for it to finish (note the difference from
other shells which execute the whole sublist in the background). A
backgrounded pipeline returns a status of zero.</p>
2021-05-11 02:29:21 +02:00
<p>More generally, a list can be seen as a set of any shell commands
whatsoever, including the complex commands below; this is implied
wherever the word list appears in later descriptions. For example, the
commands in a shell function form a special sort of list.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Precommand-Modifiers"></span> <span
id="Precommand-Modifiers-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="62-precommand-modifiers"><a class="header" href="#62-precommand-modifiers">6.2 Precommand Modifiers</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-precommand-modifiers"></span> <span
id="index-modifiers_002c-precommand"></span></p>
2021-05-11 02:29:21 +02:00
<p>A simple command may be preceded by a <em>precommand modifier</em>, which will
alter how the command is interpreted. These modifiers are shell builtin
2022-08-24 15:22:41 +02:00
commands with the exception of nocorrect which is a reserved word.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_002d"></span></p>
2022-08-24 15:22:41 +02:00
<p>-</p>
<p>The command is executed with a - prepended to its argv[0] string.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-builtin"></span></p>
2022-08-24 15:22:41 +02:00
<p>builtin</p>
2021-05-11 02:29:21 +02:00
<p>The command word is taken to be the name of a builtin command, rather
than a shell function or external command.</p>
<p><span id="index-command"></span></p>
2022-08-24 15:22:41 +02:00
<p>command [ -pvV ]</p>
2021-05-11 02:29:21 +02:00
<p>The command word is taken to be the name of an external command, rather
2022-08-24 15:22:41 +02:00
than a shell function or builtin. If the POSIX_BUILTINS option is set,
2021-05-11 02:29:21 +02:00
builtins will also be executed but certain special properties of them
2022-08-24 15:22:41 +02:00
are suppressed. The -p flag causes a default path to be searched instead
of that in $path. With the -v flag, command is similar to whence and
with -V, it is equivalent to whence -v.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-exec"></span></p>
2022-08-24 15:22:41 +02:00
<p>exec [ -cl ] [ -a <code>argv0</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>The following command together with any arguments is run in place of the
current process, rather than as a sub-process. The shell does not fork
2022-08-24 15:22:41 +02:00
and is replaced. The shell does not invoke TRAPEXIT, nor does it source
zlogout files. The options are provided for compatibility with other
shells.</p>
<p>The -c option clears the environment.</p>
<p>The -l option is equivalent to the - precommand modifier, to treat the
replacement command as a login shell; the command is executed with a -
prepended to its argv[0] string. This flag has no effect if used
together with the -a option.</p>
<p>The -a option is used to specify explicitly the argv[0] string (the
2021-05-11 02:29:21 +02:00
name of the command as seen by the process itself) to be used by the
replacement command and is directly equivalent to setting a value for
2022-08-24 15:22:41 +02:00
the ARGV0 environment variable.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-nocorrect"></span></p>
2022-08-24 15:22:41 +02:00
<p>nocorrect</p>
2021-05-11 02:29:21 +02:00
<p>Spelling correction is not done on any of the words. This must appear
before any other precommand modifier, as it is interpreted immediately,
before any parsing is done. It has no effect in non-interactive shells.</p>
<p><span id="index-noglob"></span></p>
2022-08-24 15:22:41 +02:00
<p>noglob</p>
2021-05-11 02:29:21 +02:00
<p>Filename generation (globbing) is not performed on any of the words.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Complex-Commands"></span> <span
id="Complex-Commands-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="63-complex-commands"><a class="header" href="#63-complex-commands">6.3 Complex Commands</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-complex-commands"></span> <span
id="index-commands_002c-complex"></span></p>
2021-05-11 02:29:21 +02:00
<p>A <em>complex command</em> in zsh is one of the following:</p>
<p><span id="index-if"></span> <span id="index-if-construct"></span></p>
2022-08-24 15:22:41 +02:00
<p>if <code>list</code> then <code>list</code> [ elif <code>list</code> then <code>list</code> ] ... [ else <code>list</code>
] fi</p>
<p>The if <code>list</code> is executed, and if it returns a zero exit status, the
then <code>list</code> is executed. Otherwise, the elif <code>list</code> is executed and if
its status is zero, the then <code>list</code> is executed. If each elif <code>list</code>
returns nonzero status, the else <code>list</code> is executed.</p>
<p><span id="index-for"></span> <span id="index-for-loops"></span> <span
id="index-loops_002c-for"></span></p>
<p>for <code>name</code> ... [ in <code>word</code> ... ] <code>term</code> do <code>list</code> done</p>
2021-05-11 02:29:21 +02:00
<p>Expand the list of <code>word</code>s, and set the parameter <code>name</code> to each of them
2022-08-24 15:22:41 +02:00
in turn, executing <code>list</code> each time. If the in <code>word</code> is omitted, use
the positional parameters instead of the <code>word</code>s.</p>
<p>The <code>term</code> consists of one or more newline or ; which terminate the
<code>word</code>s, and are optional when the in <code>word</code> is omitted.</p>
2021-05-11 02:29:21 +02:00
<p>More than one parameter <code>name</code> can appear before the list of <code>word</code>s. If
<code>N</code> <code>name</code>s are given, then on each execution of the loop the next <code>N</code>
<code>word</code>s are assigned to the corresponding parameters. If there are more
<code>name</code>s than remaining <code>word</code>s, the remaining parameters are each set to
the empty string. Execution of the loop ends when there is no remaining
2022-08-24 15:22:41 +02:00
<code>word</code> to assign to the first <code>name</code>. It is only possible for in to
2021-05-11 02:29:21 +02:00
appear as the first <code>name</code> in the list, else it will be treated as
marking the end of the list.</p>
2022-08-24 15:22:41 +02:00
<p>for (( [<code>expr1</code>] ; [<code>expr2</code>] ; [<code>expr3</code>] )) do <code>list</code> done</p>
2021-05-11 02:29:21 +02:00
<p>The arithmetic expression <code>expr1</code> is evaluated first (see <a href="Arithmetic-Evaluation.html#Arithmetic-Evaluation">Arithmetic
Evaluation</a>). The
arithmetic expression <code>expr2</code> is repeatedly evaluated until it evaluates
to zero and when non-zero, <code>list</code> is executed and the arithmetic
expression <code>expr3</code> evaluated. If any expression is omitted, then it
behaves as if it evaluated to 1.</p>
<p><span id="index-while"></span> <span id="index-while-loops"></span>
<span id="index-loops_002c-while"></span></p>
2022-08-24 15:22:41 +02:00
<p>while <code>list</code> do <code>list</code> done</p>
<p>Execute the do <code>list</code> as long as the while <code>list</code> returns a zero exit
status.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-until"></span> <span id="index-until-loops"></span>
<span id="index-loops_002c-until"></span></p>
2022-08-24 15:22:41 +02:00
<p>until <code>list</code> do <code>list</code> done</p>
<p>Execute the do <code>list</code> as long as until <code>list</code> returns a nonzero exit
2021-05-11 02:29:21 +02:00
status.</p>
<p><span id="index-repeat"></span> <span id="index-repeat-loops"></span>
<span id="index-loops_002c-repeat"></span></p>
2022-08-24 15:22:41 +02:00
<p>repeat <code>word</code> do <code>list</code> done</p>
2021-05-11 02:29:21 +02:00
<p><code>word</code> is expanded and treated as an arithmetic expression, which must
evaluate to a number <code>n</code>. <code>list</code> is then executed <code>n</code> times.</p>
2022-08-24 15:22:41 +02:00
<p>The repeat syntax is disabled by default when the shell starts in a mode
emulating another shell. It can be enabled with the command enable -r
repeat</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-case"></span> <span id="index-case-selection"></span>
<span id="index-selection_002c-case"></span></p>
2022-08-24 15:22:41 +02:00
<p>case <code>word</code> in [ [(] <code>pattern</code> [ | <code>pattern</code> ] ... ) <code>list</code>
(;;|;&amp;|;|) ] ... esac</p>
2021-05-11 02:29:21 +02:00
<p>Execute the <code>list</code> associated with the first <code>pattern</code> that matches
<code>word</code>, if any. The form of the patterns is the same as that used for
filename generation. See <a href="Expansion.html#Filename-Generation">Filename
Generation</a>.</p>
2022-08-24 15:22:41 +02:00
<p>Note further that, unless the SH_GLOB option is set, the whole pattern
2021-05-11 02:29:21 +02:00
with alternatives is treated by the shell as equivalent to a group of
patterns within parentheses, although white space may appear about the
parentheses and the vertical bar and will be stripped from the pattern
at those points. White space may appear elsewhere in the pattern; this
2022-08-24 15:22:41 +02:00
is not stripped. If the SH_GLOB option is set, so that an opening
2021-05-11 02:29:21 +02:00
parenthesis can be unambiguously treated as part of the case syntax, the
expression is parsed into separate words and these are treated as strict
alternatives (as in other shells).</p>
2022-08-24 15:22:41 +02:00
<p>If the <code>list</code> that is executed is terminated with ;&amp; rather than ;;, the
following list is also executed. The rule for the terminator of the
following list ;;, ;&amp; or ;| is applied unless the esac is reached.</p>
<p>If the <code>list</code> that is executed is terminated with ;| the shell
2021-05-11 02:29:21 +02:00
continues to scan the <code>pattern</code>s looking for the next match, executing
the corresponding <code>list</code>, and applying the rule for the corresponding
2022-08-24 15:22:41 +02:00
terminator ;;, ;&amp; or ;|. Note that <code>word</code> is not re-expanded; all
2021-05-11 02:29:21 +02:00
applicable <code>pattern</code>s are tested with the same <code>word</code>.</p>
<p><span id="index-select"></span> <span id="index-user-selection"></span>
<span id="index-selection_002c-user"></span></p>
2022-08-24 15:22:41 +02:00
<p>select <code>name</code> [ in <code>word</code> ... <code>term</code> ] do <code>list</code> done</p>
<p>where <code>term</code> is one or more newline or ; to terminate the <code>word</code>s. <span
id="index-REPLY_002c-use-of"></span> Print the set of <code>word</code>s, each
preceded by a number. If the in <code>word</code> is omitted, use the positional
parameters. The PROMPT3 prompt is printed and a line is read from the
line editor if the shell is interactive and that is active, or else
standard input. If this line consists of the number of one of the listed
<code>word</code>s, then the parameter <code>name</code> is set to the <code>word</code> corresponding to
this number. If this line is empty, the selection list is printed again.
Otherwise, the value of the parameter <code>name</code> is set to null. The
contents of the line read from standard input is saved in the parameter
REPLY. <code>list</code> is executed for each selection until a break or
end-of-file is encountered.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-subshell"></span></p>
2022-08-24 15:22:41 +02:00
<p>( <code>list</code> )</p>
<p>Execute <code>list</code> in a subshell. Traps set by the trap builtin are reset to
their default values while executing <code>list</code>; an exception is that
ignored signals will continue to be ignored if the option POSIXTRAPS is
set.</p>
<p>{ <code>list</code> }</p>
2021-05-11 02:29:21 +02:00
<p>Execute <code>list</code>.</p>
<p><span id="index-always"></span> <span id="index-always-blocks"></span>
<span id="index-try-blocks"></span></p>
2022-08-24 15:22:41 +02:00
<p>{ <code>try-list</code> } always { <code>always-list</code> }</p>
<p>First execute <code>try-list</code>. Regardless of errors, or break or continue
2021-05-11 02:29:21 +02:00
commands encountered within <code>try-list</code>, execute <code>always-list</code>. Execution
then continues from the result of the execution of <code>try-list</code>; in other
2022-08-24 15:22:41 +02:00
words, any error, or break or continue command is treated in the normal
way, as if <code>always-list</code> were not present. The two chunks of code are
referred to as the try block and the always block.</p>
<p>Optional newlines or semicolons may appear after the always; note,
2021-05-11 02:29:21 +02:00
however, that they may <em>not</em> appear between the preceding closing brace
2022-08-24 15:22:41 +02:00
and the always.</p>
2021-05-11 02:29:21 +02:00
<p>An error in this context is a condition such as a syntax error which
causes the shell to abort execution of the current function, script, or
list. Syntax errors encountered while the shell is parsing the code do
not cause the <code>always-list</code> to be executed. For example, an erroneously
2022-08-24 15:22:41 +02:00
constructed if block in <code>try-list</code> would cause the shell to abort during
parsing, so that <code>always-list</code> would not be executed, while an erroneous
substitution such as ${*foo*} would cause a run-time error, after
which <code>always-list</code> would be executed.</p>
2021-05-11 02:29:21 +02:00
<p>An error condition can be tested and reset with the special integer
2022-08-24 15:22:41 +02:00
variable TRY_BLOCK_ERROR. Outside an <code>always-list</code> the value is
irrelevant, but it is initialised to -1. Inside <code>always-list</code>, the value
is 1 if an error occurred in the <code>try-list</code>, else 0. If TRY_BLOCK_ERROR
is set to 0 during the <code>always-list</code>, the error condition caused by the
<code>try-list</code> is reset, and shell execution continues normally after the
end of <code>always-list</code>. Altering the value during the <code>try-list</code> is not
useful (unless this forms part of an enclosing always block).</p>
<p>Regardless of TRY_BLOCK_ERROR, after the end of <code>always-list</code> the normal
shell status $? is the value returned from <code>try-list</code>. This will be
non-zero if there was an error, even if TRY_BLOCK_ERROR was set to zero.</p>
2021-05-11 02:29:21 +02:00
<p>The following executes the given code, ignoring any errors it causes.
This is an alternative to the usual convention of protecting code by
executing it in a subshell.</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">{
2021-05-11 02:29:21 +02:00
# code which may cause an error
} always {
# This code is executed regardless of the error.
(( TRY_BLOCK_ERROR = 0 ))
}
# The error condition has been reset.
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>When a try block occurs outside of any function, a return or a exit
encountered in <code>try-list</code> does <em>not</em> cause the execution of
<code>always-list</code>. Instead, the shell exits immediately after any EXIT trap
has been executed. Otherwise, a return command encountered in <code>try-list</code>
will cause the execution of <code>always-list</code>, just like break and continue.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-function"></span></p>
2022-08-24 15:22:41 +02:00
<p>function [ -T ] <code>word</code> ... [ () ] [ <code>term</code> ] { <code>list</code> }</p>
<p><code>word</code> ... () [ <code>term</code> ] { <code>list</code> }</p>
<p><code>word</code> ... () [ <code>term</code> ] <code>command</code></p>
<p>where <code>term</code> is one or more newline or ;. Define a function which is
2021-05-11 02:29:21 +02:00
referenced by any one of <code>word</code>. Normally, only one <code>word</code> is provided;
multiple <code>word</code>s are usually only useful for setting traps. The body of
2022-08-24 15:22:41 +02:00
the function is the <code>list</code> between the { and }. See
2021-05-11 02:29:21 +02:00
<a href="Functions.html#Functions">Functions</a>.</p>
2022-08-24 15:22:41 +02:00
<p>The options of function have the following meanings:</p>
<p>-T<br />
Enable tracing for this function, as though with functions -T. See the
documentation of the -f option to the typeset builtin, in <a href="Shell-Builtin-Commands.html#Shell-Builtin-Commands">Shell Builtin
Commands</a>.</p>
<p>If the option SH_GLOB is set for compatibility with other shells, then
2021-05-11 02:29:21 +02:00
whitespace may appear between the left and right parentheses when there
is a single <code>word</code>; otherwise, the parentheses will be treated as
forming a globbing pattern in that case.</p>
<p>In any of the forms above, a redirection may appear outside the function
body, for example</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">func() { ... } 2&gt;&amp;1
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>The redirection is stored with the function and applied whenever the
function is executed. Any variables in the redirection are expanded at
the point the function is executed, but outside the function scope.</p>
<p><span id="index-timing"></span> <span id="index-time"></span></p>
2022-08-24 15:22:41 +02:00
<p>time [ <code>pipeline</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>The <code>pipeline</code> is executed, and timing statistics are reported on the
2022-08-24 15:22:41 +02:00
standard error in the form specified by the TIMEFMT parameter. If
2021-05-11 02:29:21 +02:00
<code>pipeline</code> is omitted, print statistics about the shell process and its
children.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-conditional-expression"></span> <span
id="index-_005b_005b"></span></p>
<p>[[ <code>exp</code> ]]</p>
2021-05-11 02:29:21 +02:00
<p>Evaluates the conditional expression <code>exp</code> and return a zero exit status
if it is true. See <a href="Conditional-Expressions.html#Conditional-Expressions">Conditional
Expressions</a> for a
description of <code>exp</code>.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Alternate-Forms-For-Complex-Commands"></span> <span
id="Alternate-Forms-For-Complex-Commands-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="64-alternate-forms-for-complex-commands"><a class="header" href="#64-alternate-forms-for-complex-commands">6.4 Alternate Forms For Complex Commands</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-alternate-forms-for-complex-commands"></span> <span
id="index-commands_002c-alternate-forms-for-complex"></span></p>
2021-05-11 02:29:21 +02:00
<p>Many of zshs complex commands have alternate forms. These are
non-standard and are likely not to be obvious even to seasoned shell
programmers; they should not be used anywhere that portability of shell
code is a concern.</p>
2022-08-24 15:22:41 +02:00
<p>The short versions below only work if <code>sublist</code> is of the form { <code>list</code>
} or if the SHORT_LOOPS option is set. For the if, while and until
commands, in both these cases the test part of the loop must also be
suitably delimited, such as by [[ <code>...</code> ]] or (( <code>...</code> )), else
the end of the test will not be recognized. For the for, repeat, case
and select commands no such special form for the arguments is necessary,
but the other condition (the special form of <code>sublist</code> or use of the
SHORT_LOOPS option) still applies. The SHORT_REPEAT option is available
to enable the short version only for the repeat command.</p>
<p>if <code>list</code> { <code>list</code> } [ elif <code>list</code> { <code>list</code> } ] ... [ else { <code>list</code> } ]<br />
An alternate form of if. The rules mean that</p>
<div class="example">
<pre><code class="language-zsh">if [[ -o ignorebraces ]] {
2021-05-11 02:29:21 +02:00
print yes
}
</code></pre>
</div>
<p>works, but</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">if true { # Does not work!
2021-05-11 02:29:21 +02:00
print yes
}
</code></pre>
</div>
<p>does <em>not</em>, since the test is not suitably delimited.</p>
2022-08-24 15:22:41 +02:00
<p>if <code>list</code> <code>sublist</code><br />
A short form of the alternate if. The same limitations on the form of
<code>list</code> apply as for the previous form.</p>
<p>for <code>name</code> ... ( <code>word</code> ... ) <code>sublist</code><br />
A short form of for.</p>
<p>for <code>name</code> ... [ in <code>word</code> ... ] <code>term</code> <code>sublist</code><br />
where <code>term</code> is at least one newline or ;. Another short form of for.</p>
<p>for (( [<code>expr1</code>] ; [<code>expr2</code>] ; [<code>expr3</code>] )) <code>sublist</code><br />
A short form of the arithmetic for command.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-foreach"></span></p>
2022-08-24 15:22:41 +02:00
<p>foreach <code>name</code> ... ( <code>word</code> ... ) <code>list</code> end<br />
Another form of for.</p>
<p>while <code>list</code> { <code>list</code> }<br />
An alternative form of while. Note the limitations on the form of <code>list</code>
mentioned above.</p>
<p>until <code>list</code> { <code>list</code> }<br />
An alternative form of until. Note the limitations on the form of <code>list</code>
mentioned above.</p>
<p>repeat <code>word</code> <code>sublist</code><br />
This is a short form of repeat.</p>
<p>case <code>word</code> { [ [(] <code>pattern</code> [ | <code>pattern</code> ] ... ) <code>list</code> (;;|;&amp;|;|) ] ... }<br />
An alternative form of case.</p>
<p>select <code>name</code> [ in <code>word</code> ... <code>term</code> ] <code>sublist</code><br />
where <code>term</code> is at least one newline or ;. A short form of select.</p>
<p>function <code>word</code> ... [ () ] [ <code>term</code> ] <code>sublist</code><br />
This is a short form of function.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Reserved-Words"></span> <span id="Reserved-Words-1"></span></p>
<h2 id="65-reserved-words"><a class="header" href="#65-reserved-words">6.5 Reserved Words</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-reserved-words"></span> <span
id="index-disable_002c-use-of"></span></p>
2021-05-11 02:29:21 +02:00
<p>The following words are recognized as reserved words when used as the
2022-08-24 15:22:41 +02:00
first word of a command unless quoted or disabled using disable -r:</p>
<p>do done esac then elif else fi for case if while function repeat time
until select coproc nocorrect foreach end ! [[ { } declare export
float integer local readonly typeset</p>
<p>Additionally, } is recognized in any position if neither the
IGNORE_BRACES option nor the IGNORE_CLOSE_BRACES option is set.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Errors"></span> <span id="Errors-1"></span></p>
<h2 id="66-errors"><a class="header" href="#66-errors">6.6 Errors</a></h2>
<p><span id="index-errors_002c-handling-of"></span></p>
<p>Certain errors are treated as fatal by the shell: in an interactive
shell, they cause control to return to the command line, and in a
non-interactive shell they cause the shell to be aborted. In older
versions of zsh, a non-interactive shell running a script would not
abort completely, but would resume execution at the next command to be
read from the script, skipping the remainder of any functions or shell
constructs such as loops or conditions; this somewhat illogical
2022-08-24 15:22:41 +02:00
behaviour can be recovered by setting the option CONTINUE_ON_ERROR.</p>
2021-05-11 02:29:21 +02:00
<p>Fatal errors found in non-interactive shells include:</p>
<ul>
<li>Failure to parse shell options passed when invoking the shell</li>
2022-08-24 15:22:41 +02:00
<li>Failure to change options with the set builtin</li>
2021-05-11 02:29:21 +02:00
<li>Parse errors of all sorts, including failures to parse mathematical
expressions</li>
2022-08-24 15:22:41 +02:00
<li>Failures to set or modify variable behaviour with typeset, local,
declare, export, integer, float</li>
2021-05-11 02:29:21 +02:00
<li>Execution of incorrectly positioned loop control structures
2022-08-24 15:22:41 +02:00
(continue, break)</li>
2021-05-11 02:29:21 +02:00
<li>Attempts to use regular expression with no regular expression module
available</li>
2022-08-24 15:22:41 +02:00
<li>Disallowed operations when the RESTRICTED options is set</li>
2021-05-11 02:29:21 +02:00
<li>Failure to create a pipe needed for a pipeline</li>
<li>Failure to create a multio</li>
<li>Failure to autoload a module needed for a declared shell feature</li>
<li>Errors creating command or process substitutions</li>
<li>Syntax errors in glob qualifiers</li>
2022-08-24 15:22:41 +02:00
<li>File generation errors where not caught by the option BAD_PATTERN</li>
2021-05-11 02:29:21 +02:00
<li>All bad patterns used for matching within case statements</li>
2022-08-24 15:22:41 +02:00
<li>File generation failures where not caused by NO_MATCH or similar
2021-05-11 02:29:21 +02:00
options</li>
<li>All file generation errors where the pattern was used to create a
multio</li>
<li>Memory errors where detected by the shell</li>
<li>Invalid subscripts to shell variables</li>
<li>Attempts to assign read-only variables</li>
<li>Logical errors with variables such as assignment to the wrong type</li>
<li>Use of invalid variable names</li>
<li>Errors in variable substitution syntax</li>
2022-08-24 15:22:41 +02:00
<li>Failure to convert characters in $... expressions</li>
2021-05-11 02:29:21 +02:00
</ul>
2022-08-24 15:22:41 +02:00
<p>If the POSIX_BUILTINS option is set, more errors associated with shell
2021-05-11 02:29:21 +02:00
builtin commands are treated as fatal, as specified by the POSIX
standard.</p>
<hr />
<p><span id="Comments"></span> <span id="Comments-1"></span></p>
<h2 id="67-comments"><a class="header" href="#67-comments">6.7 Comments</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-comments"></span> <span
id="index-INTERACTIVE_005fCOMMENTS_002c-use-of"></span> <span
id="index-histchars_002c-use-of"></span></p>
2021-05-11 02:29:21 +02:00
<p>In non-interactive shells, or in interactive shells with the
2022-08-24 15:22:41 +02:00
INTERACTIVE_COMMENTS option set, a word beginning with the third
character of the histchars parameter (# by default) causes that word
and all the following characters up to a newline to be ignored.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Aliasing"></span> <span id="Aliasing-1"></span></p>
<h2 id="68-aliasing"><a class="header" href="#68-aliasing">6.8 Aliasing</a></h2>
<p><span id="index-aliasing"></span></p>
<p>Every eligible <em>word</em> in the shell input is checked to see if there is
an alias defined for it. If so, it is replaced by the text of the alias
if it is in command position (if it could be the first word of a simple
command), or if the alias is global. If the replacement text ends with a
space, the next word in the shell input is always eligible for purposes
2022-08-24 15:22:41 +02:00
of alias expansion.</p>
<p>It is an error for the function name, <code>word</code>, in the sh-compatible
function definition syntax <code>word</code> () ... to be a word that resulted
from alias expansion, unless the ALIAS_FUNC_DEF option is set.</p>
<p><span id="index-alias_002c-use-of"></span> <span
id="index-aliases_002c-global"></span></p>
<p>An alias is defined using the alias builtin; global aliases may be
defined using the -g option to that builtin.</p>
2021-05-11 02:29:21 +02:00
<p>A <em>word</em> is defined as:</p>
<ul>
<li>Any plain string or glob pattern</li>
<li>Any quoted string, using any quoting method (note that the quotes
must be part of the alias definition for this to be eligible)</li>
<li>Any parameter reference or command substitution</li>
<li>Any series of the foregoing, concatenated without whitespace or
other tokens between them</li>
2022-08-24 15:22:41 +02:00
<li>Any reserved word (case, do, else, etc.)</li>
2021-05-11 02:29:21 +02:00
<li>With global aliasing, any command separator, any redirection
2022-08-24 15:22:41 +02:00
operator, and ( or ) when not part of a glob pattern</li>
2021-05-11 02:29:21 +02:00
</ul>
<p>Alias expansion is done on the shell input before any other expansion
except history expansion. Therefore, if an alias is defined for the word
2022-08-24 15:22:41 +02:00
foo, alias expansion may be avoided by quoting part of the word, e.g.
\foo. Any form of quoting works, although there is nothing to prevent
an alias being defined for the quoted form such as \foo as well.</p>
<p>In particular, note that quoting must be used when using unalias to
remove global aliases:</p>
<div class="example">
<pre><code class="language-zsh">% alias -g foo=bar
% unalias foo
% unalias \foo
%
</code></pre>
</div>
<p>When POSIX_ALIASES is set, only plain unquoted strings are eligible for
aliasing. The alias builtin does not reject ineligible aliases, but they
are not expanded.</p>
2021-05-11 02:29:21 +02:00
<p>For use with completion, which would remove an initial backslash
followed by a character that isnt special, it may be more convenient to
2022-08-24 15:22:41 +02:00
quote the word by starting with a single quote, i.e. foo; completion
2021-05-11 02:29:21 +02:00
will automatically add the trailing single quote.</p>
<hr />
<p><span id="Alias-difficulties"></span></p>
<h3 id="681-alias-difficulties"><a class="header" href="#681-alias-difficulties">6.8.1 Alias difficulties</a></h3>
<p>Although aliases can be used in ways that bend normal shell syntax, not
every string of non-white-space characters can be used as an alias.</p>
<p>Any set of characters not listed as a word above is not a word, hence no
attempt is made to expand it as an alias, no matter how it is defined
2022-08-24 15:22:41 +02:00
(i.e. via the builtin or the special parameter aliases described in <a href="Zsh-Modules.html#The-zsh_002fparameter-Module">The
zsh/parameter Module</a>).
However, as noted in the case of POSIX_ALIASES above, the shell does not
attempt to deduce whether the string corresponds to a word at the time
the alias is created.</p>
<p>For example, an expression containing an = at the start of a command
line is an assignment and cannot be expanded as an alias; a lone = is
2021-05-11 02:29:21 +02:00
not an assignment but can only be set as an alias using the parameter,
2022-08-24 15:22:41 +02:00
as otherwise the = is taken part of the syntax of the builtin command.</p>
<p>It is not presently possible to alias the (( token that introduces
2021-05-11 02:29:21 +02:00
arithmetic expressions, because until a full statement has been parsed,
2022-08-24 15:22:41 +02:00
it cannot be distinguished from two consecutive ( tokens introducing
nested subshells. Also, if a separator such as &amp;&amp; is aliased, \&amp;&amp; turns
into the two tokens \&amp; and &amp;, each of which may have been aliased
separately. Similarly for \&lt;&lt;, \&gt;|, etc.</p>
2021-05-11 02:29:21 +02:00
<p>There is a commonly encountered problem with aliases illustrated by the
following code:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">alias echobar='echo bar'; echobar
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>This prints a message that the command echobar could not be found. This
happens because aliases are expanded when the code is read in; the
entire line is read in one go, so that when echobar is executed it is
2021-05-11 02:29:21 +02:00
too late to expand the newly defined alias. This is often a problem in
2022-08-24 15:22:41 +02:00
shell scripts, functions, and code executed with source or ..
2021-05-11 02:29:21 +02:00
Consequently, use of functions rather than aliases is recommended in
non-interactive code.</p>
<hr />
<p><span id="Quoting"></span> <span id="Quoting-1"></span></p>
<h2 id="69-quoting"><a class="header" href="#69-quoting">6.9 Quoting</a></h2>
<p><span id="index-quoting"></span></p>
<p>A character may be <em>quoted</em> (that is, made to stand for itself) by
2022-08-24 15:22:41 +02:00
preceding it with a \. \ followed by a newline is ignored.</p>
<p>A string enclosed between $ and is processed the same way as the
string arguments of the print builtin, and the resulting string is
considered to be entirely quoted. A literal character can be
included in the string by using the \ escape.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-RC_005fQUOTES_002c-use-of"></span></p>
2022-08-24 15:22:41 +02:00
<p>All characters enclosed between a pair of single quotes () that is not
preceded by a $ are quoted. A single quote cannot appear within single
quotes unless the option RC_QUOTES is set, in which case a pair of
single quotes are turned into a single quote. For example,</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">print ''''
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>outputs nothing apart from a newline if RC_QUOTES is not set, but one
2021-05-11 02:29:21 +02:00
single quote if it is set.</p>
2022-08-24 15:22:41 +02:00
<p>Inside double quotes (&quot;&quot;), parameter and command substitution occur, and
\ quotes the characters \, , &quot;, $, and the first character
of $histchars (default !).</p>
<hr />
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="Redirection.html#7-redirection">7 Redirection</a>
<ul>
<li><a href="Redirection.html#71-opening-file-descriptors-using-parameters">7.1 Opening file descriptors using parameters</a></li>
<li><a href="Redirection.html#72-multios">7.2 Multios</a></li>
<li><a href="Redirection.html#73-redirections-with-no-command">7.3 Redirections with no command</a></li>
</ul>
</li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<p><span id="Redirection"></span> <span id="Redirection-1"></span></p>
<h1 id="7-redirection"><a class="header" href="#7-redirection">7 Redirection</a></h1>
2022-08-24 15:22:41 +02:00
<p><span id="index-redirection"></span> <span
id="index-file-descriptors"></span> <span
id="index-descriptors_002c-file"></span></p>
<p>If a command is followed by &amp; and job control is not active, then the
default standard input for the command is the empty file /dev/null.
2021-05-11 02:29:21 +02:00
Otherwise, the environment for the execution of a command contains the
file descriptors of the invoking shell as modified by input/output
specifications.</p>
<p>The following may appear anywhere in a simple command or may precede or
follow a complex command. Expansion occurs before <code>word</code> or <code>digit</code> is
used except as noted below. If the result of substitution on <code>word</code>
produces more than one filename, redirection occurs for each separate
filename in turn.</p>
2022-08-24 15:22:41 +02:00
<p>&lt; <code>word</code><br />
Open file <code>word</code> for reading as standard input. It is an error to open a
file in this fashion if it does not exist.</p>
<p>&lt;&gt; <code>word</code><br />
Open file <code>word</code> for reading and writing as standard input. If the file
does not exist then it is created.</p>
<p>&gt; <code>word</code><br />
Open file <code>word</code> for writing as standard output. If the file does not
exist then it is created. If the file exists, and the CLOBBER option is
unset, this causes an error; otherwise, it is truncated to zero length.</p>
<p>&gt;| <code>word</code><br />
&gt;! <code>word</code><br />
Same as &gt;, except that the file is truncated to zero length if it
exists, regardless of CLOBBER.</p>
<p>&gt;&gt; <code>word</code><br />
Open file <code>word</code> for writing in append mode as standard output. If the
file does not exist, and the CLOBBER and APPEND_CREATE options are both
unset, this causes an error; otherwise, the file is created.</p>
<p>&gt;&gt;| <code>word</code><br />
&gt;&gt;! <code>word</code><br />
Same as &gt;&gt;, except that the file is created if it does not exist,
regardless of CLOBBER and APPEND_CREATE.</p>
<p>&lt;&lt;[-] <code>word</code><br />
The shell input is read up to a line that is the same as <code>word</code>, or to
an end-of-file. No parameter expansion, command substitution or filename
generation is performed on <code>word</code>. The resulting document, called a
<em>here-document</em>, becomes the standard input.</p>
<p>If any character of <code>word</code> is quoted with single or double quotes or a
\, no interpretation is placed upon the characters of the document.
Otherwise, parameter and command substitution occurs, \ followed by a
newline is removed, and \ must be used to quote the characters \,
$, and the first character of <code>word</code>.</p>
<p>Note that <code>word</code> itself does not undergo shell expansion. Backquotes in
<code>word</code> do not have their usual effect; instead they behave similarly to
double quotes, except that the backquotes themselves are passed through
unchanged. (This information is given for completeness and it is not
recommended that backquotes be used.) Quotes in the form $<code>...</code> have
their standard effect of expanding backslashed references to special
characters.</p>
<p>If &lt;&lt;- is used, then all leading tabs are stripped from <code>word</code> and
2021-05-11 02:29:21 +02:00
from the document.</p>
2022-08-24 15:22:41 +02:00
<p>&lt;&lt;&lt; <code>word</code><br />
Perform shell expansion on <code>word</code> and pass the result to standard input.
This is known as a <em>here-string</em>. Compare the use of <code>word</code> in
here-documents above, where <code>word</code> does not undergo shell expansion. The
result will have a trailing newline after it.</p>
<p>&lt;&amp; <code>number</code><br />
&gt;&amp; <code>number</code><br />
The standard input/output is duplicated from file descriptor <code>number</code>
(see dup2(2)).</p>
<p>&lt;&amp; -<br />
&gt;&amp; -<br />
2021-05-11 02:29:21 +02:00
Close the standard input/output.</p>
2022-08-24 15:22:41 +02:00
<p>&lt;&amp; p<br />
&gt;&amp; p<br />
2021-05-11 02:29:21 +02:00
The input/output from/to the coprocess is moved to the standard
input/output.</p>
2022-08-24 15:22:41 +02:00
<p>&gt;&amp; <code>word</code><br />
&amp;&gt; <code>word</code><br />
(Except where &gt;&amp; <code>word</code> matches one of the above syntaxes; &amp;&gt; can
always be used to avoid this ambiguity.) Redirects both standard output
and standard error (file descriptor 2) in the manner of &gt; <code>word</code>. Note
that this does <em>not</em> have the same effect as &gt; <code>word</code> 2&gt;&amp;1 in the
presence of multios (see the section below).</p>
<p>&gt;&amp;| <code>word</code><br />
&gt;&amp;! <code>word</code><br />
&amp;&gt;| <code>word</code><br />
&amp;&gt;! <code>word</code><br />
Redirects both standard output and standard error (file descriptor 2) in
the manner of &gt;| <code>word</code>.</p>
<p>&gt;&gt;&amp; <code>word</code><br />
&amp;&gt;&gt; <code>word</code><br />
Redirects both standard output and standard error (file descriptor 2) in
the manner of &gt;&gt; <code>word</code>.</p>
<p>&gt;&gt;&amp;| <code>word</code><br />
&gt;&gt;&amp;! <code>word</code><br />
&amp;&gt;&gt;| <code>word</code><br />
&amp;&gt;&gt;! <code>word</code><br />
Redirects both standard output and standard error (file descriptor 2) in
the manner of &gt;&gt;| <code>word</code>.</p>
2021-05-11 02:29:21 +02:00
<p>If one of the above is preceded by a digit, then the file descriptor
referred to is that specified by the digit instead of the default 0 or</p>
<ol>
<li>The order in which redirections are specified is significant. The
shell evaluates each redirection in terms of the (<em>file descriptor</em>,
<em>file</em>) association at the time of evaluation. For example:</li>
</ol>
<blockquote>
2022-08-24 15:22:41 +02:00
<p>... 1&gt;<code>fname</code> 2&gt;&amp;1</p>
2021-05-11 02:29:21 +02:00
</blockquote>
<p>first associates file descriptor 1 with file <code>fname</code>. It then associates
file descriptor 2 with the file associated with file descriptor 1 (that
is, <code>fname</code>). If the order of redirections were reversed, file
descriptor 2 would be associated with the terminal (assuming file
descriptor 1 had been) and then file descriptor 1 would be associated
with file <code>fname</code>.</p>
2022-08-24 15:22:41 +02:00
<p>The |&amp; command separator described in <a href="Shell-Grammar.html#Simple-Commands-_0026-Pipelines">Simple Commands &amp;
2021-05-11 02:29:21 +02:00
Pipelines</a> is a
2022-08-24 15:22:41 +02:00
shorthand for 2&gt;&amp;1 |.</p>
<p>The various forms of process substitution, &lt;(<code>list</code>), and =(<code>list</code>)
for input and &gt;(<code>list</code>) for output, are often used together with
redirection. For example, if <code>word</code> in an output redirection is of the
form &gt;(<code>list</code>) then the output is piped to the command represented by
<code>list</code>. See <a href="Expansion.html#Process-Substitution">Process Substitution</a>.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Opening-file-descriptors-using-parameters"></span></p>
<h2 id="71-opening-file-descriptors-using-parameters"><a class="header" href="#71-opening-file-descriptors-using-parameters">7.1 Opening file descriptors using parameters</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-file-descriptors_002c-use-with-parameters"></span> <span
id="index-parameters_002c-for-using-file-descriptors"></span></p>
2021-05-11 02:29:21 +02:00
<p>When the shell is parsing arguments to a command, and the shell option
2022-08-24 15:22:41 +02:00
IGNORE_BRACES is not set, a different form of redirection is allowed:
2021-05-11 02:29:21 +02:00
instead of a digit before the operator there is a valid shell identifier
enclosed in braces. The shell will open a new file descriptor that is
guaranteed to be at least 10 and set the parameter named by the
identifier to the file descriptor opened. No whitespace is allowed
between the closing brace and the redirection character. For example:</p>
<blockquote>
2022-08-24 15:22:41 +02:00
<p>... {myfd}&gt;&amp;1</p>
2021-05-11 02:29:21 +02:00
</blockquote>
<p>This opens a new file descriptor that is a duplicate of file descriptor
2022-08-24 15:22:41 +02:00
1 and sets the parameter myfd to the number of the file descriptor,
2021-05-11 02:29:21 +02:00
which will be at least 10. The new file descriptor can be written to
2022-08-24 15:22:41 +02:00
using the syntax &gt;&amp;$myfd. The file descriptor remains open in subshells</p>
<p>The syntax {<code>varid</code>}&gt;&amp;-, for example {myfd}&gt;&amp;-, may be used to close a
file descriptor opened in this fashion. Note that the parameter given by
<code>varid</code> must previously be set to a file descriptor in this case.</p>
2021-05-11 02:29:21 +02:00
<p>It is an error to open or close a file descriptor in this fashion when
the parameter is readonly. However, it is not an error to read or write
2022-08-24 15:22:41 +02:00
a file descriptor using &lt;&amp;$<code>param</code> or &gt;&amp;$<code>param</code> if <code>param</code> is
2021-05-11 02:29:21 +02:00
readonly.</p>
2022-08-24 15:22:41 +02:00
<p>If the option CLOBBER is unset, it is an error to open a file descriptor
using a parameter that is already set to an open file descriptor
previously allocated by this mechanism. Unsetting the parameter before
using it for allocating a file descriptor avoids the error.</p>
2021-05-11 02:29:21 +02:00
<p>Note that this mechanism merely allocates or closes a file descriptor;
it does not perform any redirections from or to it. It is usually
convenient to allocate a file descriptor prior to use as an argument to
2022-08-24 15:22:41 +02:00
exec. The syntax does not in any case work when used around complex
2021-05-11 02:29:21 +02:00
commands such as parenthesised subshells or loops, where the opening
brace is interpreted as part of a command list to be executed in the
current shell.</p>
<p>The following shows a typical sequence of allocation, use, and closing
of a file descriptor:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">integer myfd
2021-05-11 02:29:21 +02:00
exec {myfd}&gt;~/logs/mylogfile.txt
print This is a log message. &gt;&amp;$myfd
exec {myfd}&gt;&amp;-
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Note that the expansion of the variable in the expression &gt;&amp;$myfd
2021-05-11 02:29:21 +02:00
occurs at the point the redirection is opened. This is after the
expansion of command arguments and after any redirections to the left on
the command line have been processed.</p>
<hr />
<p><span id="Multios"></span></p>
<h2 id="72-multios"><a class="header" href="#72-multios">7.2 Multios</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-multios"></span> <span
id="index-MULTIOS_002c-use-of"></span></p>
2021-05-11 02:29:21 +02:00
<p>If the user tries to open a file descriptor for writing more than once,
the shell opens the file descriptor as a pipe to a process that copies
its input to all the specified outputs, similar to tee, provided the
2022-08-24 15:22:41 +02:00
MULTIOS option is set, as it is by default. Thus:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">date &gt;foo &gt;bar
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>writes the date to two files, named foo and bar. Note that a pipe is
an implicit redirection; thus</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">date &gt;foo | cat
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>writes the date to the file foo, and also pipes it to cat.</p>
2021-05-11 02:29:21 +02:00
<p>Note that the shell opens all the files to be used in the multio process
immediately, not at the point they are about to be written.</p>
<p>Note also that redirections are always expanded in order. This happens
2022-08-24 15:22:41 +02:00
regardless of the setting of the MULTIOS option, but with the option in
effect there are additional consequences. For example, the meaning of
the expression &gt;&amp;1 will change after a previous redirection:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">date &gt;&amp;1 &gt;output
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>In the case above, the &gt;&amp;1 refers to the standard output at the start
of the line; the result is similar to the tee command. However,
2021-05-11 02:29:21 +02:00
consider:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">date &gt;output &gt;&amp;1
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>As redirections are evaluated in order, when the &gt;&amp;1 is encountered the
standard output is set to the file output and another copy of the output
is therefore sent to that file. This is unlikely to be what is intended.</p>
<p>If the MULTIOS option is set, the word after a redirection operator is
2021-05-11 02:29:21 +02:00
also subjected to filename generation (globbing). Thus</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">: &gt; *
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>will truncate all files in the current directory, assuming theres at
2022-08-24 15:22:41 +02:00
least one. (Without the MULTIOS option, it would create an empty file
called *.) Similarly, you can do</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">echo exit 0 &gt;&gt; *.sh
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>If the user tries to open a file descriptor for reading more than once,
the shell opens the file descriptor as a pipe to a process that copies
all the specified inputs to its output in the order specified, provided
2022-08-24 15:22:41 +02:00
the MULTIOS option is set. It should be noted that each file is opened
2021-05-11 02:29:21 +02:00
immediately, not at the point where it is about to be read: this
2022-08-24 15:22:41 +02:00
behaviour differs from cat, so if strictly standard behaviour is needed,
cat should be used instead.</p>
2021-05-11 02:29:21 +02:00
<p>Thus</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">sort &lt;foo &lt;fubar
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>or even</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">sort &lt;f{oo,ubar}
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>is equivalent to cat foo fubar | sort.</p>
2021-05-11 02:29:21 +02:00
<p>Expansion of the redirection argument occurs at the point the
redirection is opened, at the point described above for the expansion of
2022-08-24 15:22:41 +02:00
the variable in &gt;&amp;$myfd.</p>
2021-05-11 02:29:21 +02:00
<p>Note that a pipe is an implicit redirection; thus</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">cat bar | sort &lt;foo
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>is equivalent to cat bar foo | sort (note the order of the inputs).</p>
<p>If the MULTIOS option is <em>un</em>set, each redirection replaces the previous
redirection for that file descriptor. However, all files redirected to
are actually opened, so</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">echo Hello &gt; bar &gt; baz
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>when MULTIOS is unset will truncate bar, and write Hello into baz.</p>
2021-05-11 02:29:21 +02:00
<p>There is a problem when an output multio is attached to an external
program. A simple example shows this:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">cat file &gt;file1 &gt;file2
2021-05-11 02:29:21 +02:00
cat file1 file2
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Here, it is possible that the second cat will not display the full
contents of file1 and file2 (i.e. the original contents of file repeated
twice).</p>
<p>The reason for this is that the multios are spawned after the cat
2021-05-11 02:29:21 +02:00
process is forked from the parent shell, so the parent shell does not
wait for the multios to finish writing data. This means the command as
2022-08-24 15:22:41 +02:00
shown can exit before file1 and file2 are completely written. As a
workaround, it is possible to run the cat process as part of a job in
2021-05-11 02:29:21 +02:00
the current shell:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">{ cat file } &gt;file &gt;file2
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Here, the {<code>...</code>} job will pause to wait for both files to be written.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Redirections-with-no-command"></span></p>
<h2 id="73-redirections-with-no-command"><a class="header" href="#73-redirections-with-no-command">7.3 Redirections with no command</a></h2>
<p>When a simple command consists of one or more redirection operators and
zero or more parameter assignments, but no command name, zsh can behave
in several ways.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-NULLCMD_002c-use-of"></span> <span
id="index-CSH_005fNULLCMD_002c-use-of"></span></p>
<p>If the parameter NULLCMD is not set or the option CSH_NULLCMD is set, an
error is caused. This is the csh behavior and CSH_NULLCMD is set by
default when emulating csh.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-SH_005fNULLCMD_002c-use-of"></span></p>
2022-08-24 15:22:41 +02:00
<p>If the option SH_NULLCMD is set, the builtin : is inserted as a
2021-05-11 02:29:21 +02:00
command with the given redirections. This is the default when emulating
sh or ksh.</p>
<p><span id="index-READNULLCMD_002c-use-of"></span></p>
2022-08-24 15:22:41 +02:00
<p>Otherwise, if the parameter NULLCMD is set, its value will be used as a
command with the given redirections. If both NULLCMD and READNULLCMD are
set, then the value of the latter will be used instead of that of the
former when the redirection is an input. The default for NULLCMD is
cat and for READNULLCMD is more. Thus</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">&lt; file
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>shows the contents of file on standard output, with paging if that is a
terminal. NULLCMD and READNULLCMD may refer to shell functions.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="Command-Execution.html#8-command-execution">8 Command Execution</a></li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2022-08-24 15:22:41 +02:00
<p><span id="Command-Execution"></span> <span
id="Command-Execution-1"></span></p>
2021-05-11 02:29:21 +02:00
<h1 id="8-command-execution"><a class="header" href="#8-command-execution">8 Command Execution</a></h1>
2022-08-24 15:22:41 +02:00
<p><span id="index-command-execution"></span> <span
id="index-execution_002c-of-commands"></span> <span
id="index-command-not-found_002c-handling-of"></span> <span
id="index-command_005fnot_005ffound_005fhandler"></span></p>
2021-05-11 02:29:21 +02:00
<p>If a command name contains no slashes, the shell attempts to locate it.
If there exists a shell function by that name, the function is invoked
as described in <a href="Functions.html#Functions">Functions</a>. If there exists a
shell builtin by that name, the builtin is invoked.</p>
<p><span id="index-path_002c-use-of"></span></p>
2022-08-24 15:22:41 +02:00
<p>Otherwise, the shell searches each element of $path for a</p>
<p>If execution fails: an error message is printed, and one of the
following values is returned.</p>
<p>127</p>
<p>The search was unsuccessful. The error message is command not found:
<code>cmd</code>.</p>
<p>126</p>
<p>directory or special file, or is not a script and is in a format
unrecognized by the operating system. The exact conditions and error
message are operating system-dependent; see execve(2).</p>
2021-05-11 02:29:21 +02:00
<p>and the file is not a directory, it is assumed to be a shell script.
2022-08-24 15:22:41 +02:00
/bin/sh is spawned to execute it. If the program is a file beginning
with #!, the remainder of the first line specifies an interpreter for
the program. The shell will execute the specified interpreter on
2021-05-11 02:29:21 +02:00
operating systems that do</p>
2022-08-24 15:22:41 +02:00
<p>If no external command is found but a function command_not_found_handler
exists the shell executes this function with all command line arguments.
The return status of the function becomes the status of the command.
2021-05-11 02:29:21 +02:00
Note that the handler is executed in a subshell forked to execute an
external command, hence changes to directories, shell parameters, etc.
have no effect on the main shell.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="Functions.html#9-functions">9 Functions</a>
<ul>
<li><a href="Functions.html#91-autoloading-functions">9.1 Autoloading Functions</a></li>
<li><a href="Functions.html#92-anonymous-functions">9.2 Anonymous Functions</a></li>
<li><a href="Functions.html#93-special-functions">9.3 Special Functions</a>
<ul>
<li><a href="Functions.html#931-hook-functions">9.3.1 Hook Functions</a></li>
<li><a href="Functions.html#932-trap-functions">9.3.2 Trap Functions</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2022-08-24 15:22:41 +02:00
<p><span id="Functions"></span> <span id="Functions-4"></span></p>
2021-05-11 02:29:21 +02:00
<h1 id="9-functions"><a class="header" href="#9-functions">9 Functions</a></h1>
2022-08-24 15:22:41 +02:00
<p><span id="index-functions"></span> <span
id="index-function_002c-use-of"></span></p>
<p>Shell functions are defined with the function reserved word or the
special syntax <code>funcname</code> (). Shell functions are read in and stored
2021-05-11 02:29:21 +02:00
internally. Alias names are resolved when the function is read.
Functions are executed like commands with the arguments passed as
positional parameters. (See <a href="Command-Execution.html#Command-Execution">Command
Execution</a>.)</p>
<p>Functions execute in the same process as the caller and share all files
2022-08-24 15:22:41 +02:00
and present working directory with the caller. A trap on EXIT set inside
a function is executed after the function completes in the environment
of the caller.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-return_002c-use-of"></span></p>
2022-08-24 15:22:41 +02:00
<p>The return builtin is used to return from function calls.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-functions_002c-use-of"></span></p>
2022-08-24 15:22:41 +02:00
<p>Function identifiers can be listed with the functions builtin. <span
id="index-unfunction_002c-use-of"></span> Functions can be undefined
with the unfunction builtin.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Autoloading-Functions"></span></p>
<h2 id="91-autoloading-functions"><a class="header" href="#91-autoloading-functions">9.1 Autoloading Functions</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-autoloading-functions"></span> <span
id="index-functions_002c-autoloading"></span> <span
id="index-autoload_002c-use-of"></span> <span
id="index-fpath_002c-use-of"></span></p>
<p>A function can be marked as <em>undefined</em> using the autoload builtin (or
functions -u or typeset -fu). Such a function has no body. When the
function is first executed, the shell searches for its definition using
the elements of the fpath variable. Thus to define functions for
2021-05-11 02:29:21 +02:00
autoloading, a typical sequence is:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">fpath=(~/myfuncs $fpath)
2021-05-11 02:29:21 +02:00
autoload myfunc1 myfunc2 ...
</code></pre>
</div>
<p>The usual alias expansion during reading will be suppressed if the
2022-08-24 15:22:41 +02:00
autoload builtin or its equivalent is given the option -U. This is
2021-05-11 02:29:21 +02:00
recommended for the use of functions supplied with the zsh distribution.
<span id="index-zcompile_002c-use-of"></span> Note that for functions
2022-08-24 15:22:41 +02:00
precompiled with the zcompile builtin command the flag -U must be
provided when the .zwc file is created, as the corresponding information
is compiled into the latter.</p>
<p>For each <code>element</code> in fpath, the shell looks for three possible files,
2021-05-11 02:29:21 +02:00
the newest of which is used to load the definition for the function:</p>
2022-08-24 15:22:41 +02:00
<p><code>element</code>.zwc<br />
A file created with the zcompile builtin command, which is expected to
contain the definitions for all functions in the directory named
<code>element</code>. The file is treated in the same manner as a directory
containing files for functions and is searched for the definition of the
function. If the definition is not found, the search for a definition
proceeds with the other two possibilities described below.</p>
<p>If <code>element</code> already includes a .zwc extension (i.e. the extension was
explicitly given by the user), <code>element</code> is searched for the definition
of the function without comparing its age to that of other files; in
fact, there does not need to be any directory named <code>element</code> without
the suffix. Thus including an element such as /usr/local/funcs.zwc in
fpath will speed up the search for functions, with the disadvantage that
functions included must be explicitly recompiled by hand before the
shell notices any changes.</p>
<p><code>element</code>/<code>function</code>.zwc<br />
A file created with zcompile, which is expected to contain the
definition for <code>function</code>. It may include other function definitions as
well, but those are neither loaded nor executed; a file found in this
way is searched <em>only</em> for the definition of <code>function</code>.</p>
<p><code>element</code>/<code>function</code><br />
A file of zsh command text, taken to be the definition for <code>function</code>.</p>
2021-05-11 02:29:21 +02:00
<p>In summary, the order of searching is, first, in the <em>parents of</em>
2022-08-24 15:22:41 +02:00
directories in fpath for the newer of either a compiled directory or a
directory in fpath; second, if more than one of these contains a
definition for the function that is sought, the leftmost in the fpath is
chosen; and third, within a directory, the newer of either a compiled
2021-05-11 02:29:21 +02:00
function or an ordinary function definition is used.</p>
<p><span id="index-KSH_005fAUTOLOAD_002c-use-of"></span></p>
2022-08-24 15:22:41 +02:00
<p>If the KSH_AUTOLOAD option is set, or the file contains only a simple
2021-05-11 02:29:21 +02:00
definition of the function, the files contents will be executed. This
will normally define the function in question, but may also perform
initialization, which is executed in the context of the function
execution, and may therefore define local parameters. It is an error if
the function is not defined by loading the file.</p>
2022-08-24 15:22:41 +02:00
<p>Otherwise, the function body (with no surrounding <code>funcname</code>()
{<code>...</code>}) is taken to be the complete contents of the file. This
2021-05-11 02:29:21 +02:00
processing of the file results in the function being re-defined, the
function itself is not re-executed. To force the shell to perform
initialization and then call the function defined, the file should
contain initialization code (which will be executed then discarded) in
addition to a complete function definition (which will be retained for
subsequent calls to the function), and a call to the shell function,
including any arguments, at the end.</p>
2022-08-24 15:22:41 +02:00
<p>For example, suppose the autoload file func contains</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">func() { print This is func; }
2021-05-11 02:29:21 +02:00
print func is initialized
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>then func; func with KSH_AUTOLOAD set will produce both messages on
the first call, but only the message This is func on the second and
subsequent calls. Without KSH_AUTOLOAD set, it will produce the
2021-05-11 02:29:21 +02:00
initialization message on the first call, and the other message on the
second and subsequent calls.</p>
<p>It is also possible to create a function that is not marked as
2022-08-24 15:22:41 +02:00
autoloaded, but which loads its own definition by searching fpath, by
using autoload -X within a shell function. For example, the following
are equivalent:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">myfunc() {
2021-05-11 02:29:21 +02:00
autoload -X
}
myfunc args...
</code></pre>
</div>
<p>and</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">unfunction myfunc # if myfunc was defined
2021-05-11 02:29:21 +02:00
autoload myfunc
myfunc args...
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>In fact, the functions command outputs builtin autoload -X as the body
of an autoloaded function. This is done so that</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">eval &quot;$(functions)&quot;
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>produces a reasonable result. A true autoloaded function can be
2022-08-24 15:22:41 +02:00
identified by the presence of the comment # undefined in the body,
2021-05-11 02:29:21 +02:00
because all comments are discarded from defined functions.</p>
2022-08-24 15:22:41 +02:00
<p>To load the definition of an autoloaded function myfunc without
executing myfunc, use:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">autoload +X myfunc
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<hr />
<p><span id="Anonymous-Functions"></span></p>
<h2 id="92-anonymous-functions"><a class="header" href="#92-anonymous-functions">9.2 Anonymous Functions</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-anonymous-functions"></span> <span
id="index-functions_002c-anonymous"></span></p>
2021-05-11 02:29:21 +02:00
<p>If no name is given for a function, it is anonymous and is handled
2022-08-24 15:22:41 +02:00
specially. Either form of function definition may be used: a () with
no preceding name, or a function with an immediately following open
2021-05-11 02:29:21 +02:00
brace. The function is executed immediately at the point of definition
2022-08-24 15:22:41 +02:00
and is not stored for future use. The function name is set to (anon).</p>
2021-05-11 02:29:21 +02:00
<p>Arguments to the function may be specified as words following the
closing brace defining the function, hence if there are none no
2022-08-24 15:22:41 +02:00
arguments (other than $0) are set. This is a difference from the way
2021-05-11 02:29:21 +02:00
other functions are parsed: normal function definitions may be followed
2022-08-24 15:22:41 +02:00
by certain keywords such as else or fi, which will be treated as
2021-05-11 02:29:21 +02:00
arguments to anonymous functions, so that a newline or semicolon is
needed to force keyword interpretation.</p>
<p>Note also that the argument list of any enclosing script or function is
hidden (as would be the case for any other function called at this
point).</p>
<p>Redirections may be applied to the anonymous function in the same manner
as to a current-shell structure enclosed in braces. The main use of
anonymous functions is to provide a scope for local variables. This is
particularly convenient in start-up files as these do not provide their
own local variable scope.</p>
<p>For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">variable=outside
2021-05-11 02:29:21 +02:00
function {
local variable=inside
print &quot;I am $variable with arguments $*&quot;
} this and that
print &quot;I am $variable&quot;
</code></pre>
</div>
<p>outputs the following:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">I am inside with arguments this and that
2021-05-11 02:29:21 +02:00
I am outside
</code></pre>
</div>
<p>Note that function definitions with arguments that expand to nothing,
2022-08-24 15:22:41 +02:00
for example name=; function $name { <code>...</code> }, are not treated as
anonymous functions. Instead, they are treated as normal function
2021-05-11 02:29:21 +02:00
definitions where the definition is silently discarded.</p>
<hr />
<p><span id="Special-Functions"></span></p>
<h2 id="93-special-functions"><a class="header" href="#93-special-functions">9.3 Special Functions</a></h2>
<p>Certain functions, if defined, have special meaning to the shell.</p>
<hr />
<p><span id="Hook-Functions"></span></p>
<h3 id="931-hook-functions"><a class="header" href="#931-hook-functions">9.3.1 Hook Functions</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-functions_002c-hook"></span> <span
id="index-hook-functions"></span></p>
2021-05-11 02:29:21 +02:00
<p>For the functions below, it is possible to define an array that has the
2022-08-24 15:22:41 +02:00
same name as the function with _functions appended. Any element in
2021-05-11 02:29:21 +02:00
such an array is taken as the name of a function to execute; it is
2022-08-24 15:22:41 +02:00
executed in the same context and with the same arguments and same
initial value of $? as the basic function. For example, if
$chpwd_functions is an array containing the values mychpwd,
chpwd_save_dirstack, then the shell attempts to execute the functions
chpwd, mychpwd and chpwd_save_dirstack, in that order. Any
function that does not exist is silently ignored. A function found by
this mechanism is referred to elsewhere as a <em>hook function</em>. An error
in any function causes subsequent functions not to be run. Note further
that an error in a precmd hook causes an immediately following periodic
function not to run (though it may run at the next opportunity).</p>
<p><span id="index-chpwd"></span> <span
id="index-chpwd_005ffunctions"></span></p>
<p>chpwd</p>
2021-05-11 02:29:21 +02:00
<p>Executed whenever the current working directory is changed.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-periodic"></span> <span
id="index-periodic_005ffunctions"></span></p>
<p>periodic</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-PERIOD"></span></p>
2022-08-24 15:22:41 +02:00
<p>If the parameter PERIOD is set, this function is executed every $PERIOD
seconds, just before a prompt. Note that if multiple functions are
defined using the array periodic_functions only one period is applied to
the complete set of functions, and the scheduled time is not reset if
the list of functions is altered. Hence the set of functions is always
called together.</p>
<p><span id="index-precmd"></span> <span
id="index-precmd_005ffunctions"></span></p>
<p>precmd</p>
2021-05-11 02:29:21 +02:00
<p>Executed before each prompt. Note that precommand functions are not
re-executed simply because the command line is redrawn, as happens, for
example, when a notification about an exiting job is displayed.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-preexec"></span> <span
id="index-preexec_005ffunctions"></span></p>
<p>preexec</p>
2021-05-11 02:29:21 +02:00
<p>Executed just after a command has been read and is about to be executed.
If the history mechanism is active (regardless of whether the line was
discarded from the history buffer), the string that the user typed is
passed as the first argument, otherwise it is an empty string. The
actual command that will be executed (including expanded aliases) is
passed in two different forms: the second argument is a single-line,
size-limited version of the command (with things like function bodies
elided); the third argument contains the full text that is being
executed.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-zshaddhistory"></span> <span
id="index-zshaddhistory_005ffunctions"></span></p>
<p>zshaddhistory</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-history_002c-hook-when-line-is-saved"></span></p>
<p>Executed when a history line has been read interactively, but before it
is executed. The sole argument is the complete history line (so that any
terminating newline will still be present).</p>
<p>If any of the hook functions returns status 1 (or any non-zero value
other than 2, though this is not guaranteed for future versions of the
shell) the history line will not be saved, although it lingers in the
history until the next line is executed, allowing you to reuse or edit
it immediately.</p>
<p>If any of the hook functions returns status 2 the history line will be
saved on the internal history list, but not written to the history file.
In case of a conflict, the first non-zero status value is taken.</p>
2022-08-24 15:22:41 +02:00
<p>A hook function may call fc -p <code>...</code> to switch the history context so
that the history is saved in a different file from that in the global
HISTFILE parameter. This is handled specially: the history context is
automatically restored after the processing of the history line is
finished.</p>
2021-05-11 02:29:21 +02:00
<p>The following example function works with one of the options
2022-08-24 15:22:41 +02:00
INC_APPEND_HISTORY or SHARE_HISTORY set, in order that the line is
2021-05-11 02:29:21 +02:00
written out immediately after the history entry is added. It first adds
the history line to the normal history with the newline stripped, which
is usually the correct behaviour. Then it switches the history context
so that the line will be written to a history file in the current
directory.</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zshaddhistory() {
2021-05-11 02:29:21 +02:00
print -sr -- ${1%%$'\n'}
fc -p .zsh_local_history
}
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p><span id="index-zshexit"></span> <span
id="index-zshexit_005ffunctions"></span></p>
<p>zshexit</p>
2021-05-11 02:29:21 +02:00
<p>Executed at the point where the main shell is about to exit normally.
2022-08-24 15:22:41 +02:00
This is not called by exiting subshells, nor when the exec precommand
modifier is used before an external command. Also, unlike TRAPEXIT, it
2021-05-11 02:29:21 +02:00
is not called when functions exit.</p>
<hr />
<p><span id="Trap-Functions"></span></p>
<h3 id="932-trap-functions"><a class="header" href="#932-trap-functions">9.3.2 Trap Functions</a></h3>
<p>The functions below are treated specially but do not have corresponding
hook arrays.</p>
2022-08-24 15:22:41 +02:00
<p>TRAP<code>NAL</code><br />
<span id="index-signals_002c-trapping"></span> <span
id="index-trapping-signals"></span></p>
2021-05-11 02:29:21 +02:00
<p>If defined and non-null, this function will be executed whenever the
2022-08-24 15:22:41 +02:00
shell catches a signal SIG<code>NAL</code>, where <code>NAL</code> is a signal name as
specified for the kill builtin. The signal number will be passed as the
first parameter to the function.</p>
<p>If a function of this form is defined and null, the shell and processes
spawned by it will ignore SIG<code>NAL</code>.</p>
<p>The return status from the function is handled specially. If it is zero,
the signal is assumed to have been handled, and execution continues
normally. Otherwise, the shell will behave as interrupted except that
the return status of the trap is retained.</p>
<p>Programs terminated by uncaught signals typically return the status 128
plus the signal number. Hence the following causes the handler for
SIGINT to print a message, then mimic the usual effect of the signal.</p>
<div class="example">
<pre><code class="language-zsh">TRAPINT() {
2021-05-11 02:29:21 +02:00
print &quot;Caught SIGINT, aborting.&quot;
return $(( 128 + $1 ))
}
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The functions TRAPZERR, TRAPDEBUG and TRAPEXIT are never executed inside
other traps.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-TRAPDEBUG"></span></p>
2022-08-24 15:22:41 +02:00
<p>TRAPDEBUG<br />
If the option DEBUG_BEFORE_CMD is set (as it is by default), executed
before each command; otherwise executed after each command. See the
description of the trap builtin in <a href="Shell-Builtin-Commands.html#Shell-Builtin-Commands">Shell Builtin
2021-05-11 02:29:21 +02:00
Commands</a> for
details of additional features provided in debug traps.</p>
<p><span id="index-TRAPEXIT"></span></p>
2022-08-24 15:22:41 +02:00
<p>TRAPEXIT<br />
2021-05-11 02:29:21 +02:00
Executed when the shell exits, or when the current function exits if
2022-08-24 15:22:41 +02:00
defined inside a function. The value of $? at the start of execution is
the exit status of the shell or the return status of the function
exiting.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-TRAPZERR"></span> <span id="index-TRAPERR"></span></p>
2022-08-24 15:22:41 +02:00
<p>TRAPZERR<br />
2021-05-11 02:29:21 +02:00
Executed whenever a command has a non-zero exit status. However, the
2022-08-24 15:22:41 +02:00
function is not executed if the command occurred in a sublist followed
by &amp;&amp; or ||; only the final command in a sublist of this type
causes the trap to be executed. The function TRAPERR acts the same as
TRAPZERR on systems where there is no SIGERR (this is the usual case).</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-trap_002c-use-of"></span></p>
2022-08-24 15:22:41 +02:00
<p>The functions beginning TRAP may alternatively be defined with the
trap builtin: this may be preferable for some uses. Setting a trap with
one form removes any trap of the other form for the same signal;
2021-05-11 02:29:21 +02:00
removing a trap in either form removes all traps for the same signal.
The forms</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">TRAPNAL() {
2021-05-11 02:29:21 +02:00
# code
}
</code></pre>
</div>
<p>(function traps) and</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">trap '
2021-05-11 02:29:21 +02:00
# code
' NAL
</code></pre>
</div>
<p>(list traps) are equivalent in most ways, the exceptions being the
following:</p>
<ul>
<li>Function traps have all the properties of normal functions,
appearing in the list of functions and being called with their own
function context rather than the context where the trap was
triggered.</li>
<li>The return status from function traps is special, whereas a return
from a list trap causes the surrounding context to return with the
given status.</li>
<li>Function traps are not reset within subshells, in accordance with
zsh behaviour; list traps are reset, in accordance with POSIX
behaviour.</li>
</ul>
<hr />
2022-08-24 15:22:41 +02:00
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
2022-08-24 15:22:41 +02:00
<li><a href="Jobs-&amp;-Signals.html#10-jobs--signals">10 Jobs &amp; Signals</a>
2021-05-11 02:29:21 +02:00
<ul>
2022-08-24 15:22:41 +02:00
<li><a href="Jobs-&amp;-Signals.html#101-jobs">10.1 Jobs</a></li>
<li><a href="Jobs-&amp;-Signals.html#102-signals">10.2 Signals</a></li>
2021-05-11 02:29:21 +02:00
</ul>
</li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2022-08-24 15:22:41 +02:00
<p><span id="Jobs-_0026-Signals"></span> <span
id="Jobs-_0026-Signals-1"></span></p>
2021-05-11 02:29:21 +02:00
<h1 id="10-jobs--signals"><a class="header" href="#10-jobs--signals">10 Jobs &amp; Signals</a></h1>
<hr />
<p><span id="Jobs"></span></p>
<h2 id="101-jobs"><a class="header" href="#101-jobs">10.1 Jobs</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-jobs"></span> <span
id="index-MONITOR_002c-use-of"></span></p>
<p>If the MONITOR option is set, an interactive shell associates a <em>job</em>
2021-05-11 02:29:21 +02:00
with each pipeline. command, and assigns them small integer numbers.
2022-08-24 15:22:41 +02:00
When a job is started asynchronously with &amp;, the shell prints a line
2021-05-11 02:29:21 +02:00
to standard error which looks like:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">[1] 1234
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>indicating that the job which was started asynchronously was job number
1 and had one (top-level) process, whose process ID was 1234.</p>
2022-08-24 15:22:41 +02:00
<p>If a job is started with &amp;| or &amp;!, then that job is immediately
2021-05-11 02:29:21 +02:00
disowned. After startup, it to the job control features described here.</p>
<p>If you are running a job and wish to do something else you may hit the
2022-08-24 15:22:41 +02:00
key ^Z (control-Z) which sends a TSTP signal to the current job: this
key may be redefined by the susp option of the external stty command.
<span id="index-jobs_002c-suspending"></span> <span
id="index-suspending-jobs"></span> The shell will then normally indicate
that the job has been suspended, and print another prompt. You can
then manipulate the state of this job, <span
id="index-bg_002c-use-of"></span> putting it in the background with the
bg command, or run some other commands and then eventually bring the job
back into the foreground with <span id="index-fg_002c-use-of"></span>
the foreground command fg. A ^Z takes effect immediately and is like an
interrupt in that pending output and unread input are discarded when it
is typed.</p>
2021-05-11 02:29:21 +02:00
<p>A job being run in the background will suspend if it tries to read from
the terminal.</p>
<p>Note that if the job running in the foreground is a shell function, then
suspending it will have the effect of causing the shell to fork. This is
necessary to separate the functions state from that of the parent shell
performing the job control, so that the latter can return to the command
2022-08-24 15:22:41 +02:00
line prompt. As a result, even if fg is used to continue the job the
2021-05-11 02:29:21 +02:00
function will no longer be part of the parent shell, and any variables
set by the function will not be visible in the parent shell. Thus the
behaviour is different from the case where the function was never
suspended. Zsh is different from many other shells in this regard.</p>
2022-08-24 15:22:41 +02:00
<p>One additional side effect is that use of disown with a job created by
2021-05-11 02:29:21 +02:00
suspending shell code in this fashion is delayed: the job can only be
disowned once any process started from the parent shell has terminated.
At that point, the disowned job disappears silently from the job list.</p>
<p>The same behaviour is found when the shell is executing code as the
2022-08-24 15:22:41 +02:00
right hand side of a pipeline or any complex shell construct such as if,
for, etc., in order that the entire block of code can be managed as a
single job. <span id="index-background-jobs_002c-I_002fO"></span> <span
id="index-jobs_002c-background_002c-I_002fO"></span> Background jobs are
normally allowed to produce output, but this can be disabled by giving
the command stty tostop. If you set this tty option, then background
jobs will suspend when they try to produce output like they do when they
try to read input.</p>
<p>When a command is suspended and continued later with the fg or wait
2021-05-11 02:29:21 +02:00
builtins, zsh restores tty modes that were in effect when it was
suspended. This (intentionally) does not apply if the command is
2022-08-24 15:22:41 +02:00
continued via kill -CONT, nor when it is continued with bg.</p>
<p><span id="index-jobs_002c-referring-to"></span> <span
id="index-referring-to-jobs"></span></p>
2021-05-11 02:29:21 +02:00
<p>There are several ways to refer to jobs in the shell. A job can be
referred to by the process ID of any process of the job or by one of the
following:</p>
2022-08-24 15:22:41 +02:00
<p>%<code>number</code><br />
2021-05-11 02:29:21 +02:00
The job with the given number.</p>
2022-08-24 15:22:41 +02:00
<p>%<code>string</code><br />
2021-05-11 02:29:21 +02:00
The last job whose command line begins with <code>string</code>.</p>
2022-08-24 15:22:41 +02:00
<p>%?<code>string</code><br />
2021-05-11 02:29:21 +02:00
The last job whose command line contains <code>string</code>.</p>
2022-08-24 15:22:41 +02:00
<p>%%<br />
2021-05-11 02:29:21 +02:00
Current job.</p>
2022-08-24 15:22:41 +02:00
<p>%+<br />
Equivalent to %%.</p>
<p>%-<br />
2021-05-11 02:29:21 +02:00
Previous job.</p>
2022-08-24 15:22:41 +02:00
<p>The shell learns immediately whenever a process changes state. <span
id="index-NOTIFY_002c-use-of"></span> It normally informs you whenever a
job becomes blocked so that no further progress is possible. If the
NOTIFY option is not set, it waits until just before it prints a prompt
before it informs you. All such notifications are sent directly to the
terminal, not to the standard output or standard error.</p>
2021-05-11 02:29:21 +02:00
<p>When the monitor mode is on, each background job that completes triggers
2022-08-24 15:22:41 +02:00
any trap set for CHLD.</p>
2021-05-11 02:29:21 +02:00
<p>When you try to leave the shell while jobs are running or suspended, you
will be warned that You have suspended (running) jobs. You may use the
2022-08-24 15:22:41 +02:00
jobs command to see what they are. If you do this or immediately try to
exit again, the shell will not warn you a second time; the suspended
jobs will be terminated, and the running jobs will be sent a SIGHUP
signal, if the HUP option is set. <span
id="index-HUP_002c-use-of"></span></p>
<p><span id="index-jobs_002c-disowning"></span> <span
id="index-disowning-jobs"></span> <span
id="index-disown_002c-use-of"></span></p>
2021-05-11 02:29:21 +02:00
<p>To avoid having the shell terminate the running jobs, either use the
2022-08-24 15:22:41 +02:00
nohup(1) command or the disown builtin.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Signals"></span></p>
<h2 id="102-signals"><a class="header" href="#102-signals">10.2 Signals</a></h2>
2022-08-24 15:22:41 +02:00
<p>The INT and QUIT signals for an invoked command are ignored if the
command is followed by &amp; and the MONITOR option is not active. The
shell itself always ignores the QUIT signal. Otherwise, signals have the
values inherited by the shell from its parent (but see the TRAP<code>NAL</code>
special functions in <a href="Functions.html#Functions">Functions</a>).</p>
<p><span id="index-exiting-shell_002c-and-asynchronous-jobs"></span> <span
id="index-asynchronous-jobs_002c-and-exiting-shell"></span> <span
id="index-jobs_002c-asynchronous_002c-and-exiting-shell"></span></p>
2021-05-11 02:29:21 +02:00
<p>Certain jobs are run asynchronously by the shell other than those
explicitly put into the background; even in cases where the shell would
2022-08-24 15:22:41 +02:00
usually wait for such jobs, an explicit exit command or exit due to the
option ERR_EXIT will cause the shell to exit without waiting. Examples
of such asynchronous jobs are process substitution, see <a href="Expansion.html#Process-Substitution">Process
Substitution</a>, and the handler
processes for multios, see the section <em>Multios</em> in
2021-05-11 02:29:21 +02:00
<a href="Redirection.html#Redirection">Redirection</a>.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="Arithmetic-Evaluation.html#11-arithmetic-evaluation">11 Arithmetic Evaluation</a></li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2022-08-24 15:22:41 +02:00
<p><span id="Arithmetic-Evaluation"></span> <span
id="Arithmetic-Evaluation-1"></span></p>
2021-05-11 02:29:21 +02:00
<h1 id="11-arithmetic-evaluation"><a class="header" href="#11-arithmetic-evaluation">11 Arithmetic Evaluation</a></h1>
2022-08-24 15:22:41 +02:00
<p><span id="index-arithmetic-evaluation"></span> <span
id="index-evaluation_002c-arithmetic"></span> <span
id="index-let_002c-use-of"></span></p>
2021-05-11 02:29:21 +02:00
<p>The shell can perform integer and floating point arithmetic, either
2022-08-24 15:22:41 +02:00
using the builtin let, or via a substitution of the form $((<code>...</code>)). For
integers, the shell is usually compiled to use 8-byte precision where
this is available, otherwise precision is 4 bytes. This can be tested,
for example, by giving the command print - $(( 12345678901 )); if the
number appears unchanged, the precision is at least 8 bytes. Floating
point arithmetic always uses the double type with whatever
corresponding precision is provided by the compiler and the library.</p>
<p>The let builtin command takes arithmetic expressions as arguments; each
is evaluated separately. Since many of the arithmetic operators, as well
as spaces, require quoting, an alternative form is provided: for any
command which begins with a ((, all the characters until a matching
)) are treated as a double-quoted expression and arithmetic expansion
performed as for an argument of let. More precisely, ((<code>...</code>)) is
equivalent to let &quot;<code>...</code>&quot;. The return status is 0 if the arithmetic
value of the expression is non-zero, 1 if it is zero, and 2 if an error
occurred.</p>
2021-05-11 02:29:21 +02:00
<p>For example, the following statement</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">(( val = 2 + 1 ))
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>is equivalent to</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">let &quot;val = 2 + 1&quot;
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>both assigning the value 3 to the shell variable val and returning a
2021-05-11 02:29:21 +02:00
zero status.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-arithmetic-base"></span> <span
id="index-bases_002c-in-arithmetic"></span></p>
<p>Integers can be in bases other than 10. A leading 0x or 0X denotes
hexadecimal and a leading 0b or 0B binary. Integers may also be of
the form <code>base</code>#<code>n</code>, where <code>base</code> is a decimal number between two and
thirty-six representing the arithmetic base and <code>n</code> is a number in that
base (for example, 16#ff is 255 in hexadecimal). The <code>base</code># may also
be omitted, in which case base 10 is used. For backwards compatibility
the form [<code>base</code>]<code>n</code> is also accepted.</p>
<p>An integer expression or a base given in the form <code>base</code>#<code>n</code> may
contain underscores (_) after the leading digit for visual guidance;
these are ignored in computation. Examples are 1_000_000 or 0xffff_ffff
which are equivalent to 1000000 and 0xffffffff respectively.</p>
2021-05-11 02:29:21 +02:00
<p>It is also possible to specify a base to be used for output in the form
2022-08-24 15:22:41 +02:00
[#<code>base</code>], for example [#16]. This is used when outputting
2021-05-11 02:29:21 +02:00
arithmetical substitutions or when assigning to scalar parameters, but
an explicitly defined integer or floating point parameter will not be
affected. If an integer variable is implicitly defined by an arithmetic
expression, any base specified in this way will be set as the variables
2022-08-24 15:22:41 +02:00
output arithmetic base as if the option -i <code>base</code> to the typeset
2021-05-11 02:29:21 +02:00
builtin had been used. The expression has no precedence and if it occurs
more than once in a mathematical expression, the last encountered is
used. For clarity it is recommended that it appear at the beginning of
an expression. As an example:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">typeset -i 16 y
2021-05-11 02:29:21 +02:00
print $(( [#8] x = 32, y = 32 ))
print $x $y
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>outputs first 8#40, the rightmost value in the given output base, and
then 8#40 16#20, because y has been explicitly declared to have output
base 16, while x (assuming it does not already exist) is implicitly
typed by the arithmetic evaluation, where it acquires the output base 8.</p>
2021-05-11 02:29:21 +02:00
<p>The <code>base</code> may be replaced or followed by an underscore, which may
itself be followed by a positive integer (if it is missing the value 3
is used). This indicates that underscores should be inserted into the
output string, grouping the number for visual clarity. The following
integer specifies the number of digits to group together. For example:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">setopt cbases
2021-05-11 02:29:21 +02:00
print $(( [#16_4] 65536 ** 2 ))
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>outputs 0x1_0000_0000.</p>
2021-05-11 02:29:21 +02:00
<p>The feature can be used with floating point numbers, in which case the
base must be omitted; grouping is away from the decimal point. For
example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zmodload zsh/mathfunc
2021-05-11 02:29:21 +02:00
print $(( [#_] sqrt(1e7) ))
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>outputs 3_162.277_660_168_379_5 (the number of decimal places shown
2021-05-11 02:29:21 +02:00
may vary).</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-C_005fBASES_002c-use-of"></span> <span
id="index-OCTAL_005fZEROES_002c-use-of"></span></p>
<p>If the C_BASES option is set, hexadecimal numbers are output in the
standard C format, for example 0xFF instead of the usual 16#FF. If
the option OCTAL_ZEROES is also set (it is not by default), octal
numbers will be treated similarly and hence appear as 077 instead of
8#77. This option has no effect on the output of bases other than
2021-05-11 02:29:21 +02:00
hexadecimal and octal, and these formats are always understood on input.</p>
2022-08-24 15:22:41 +02:00
<p>When an output base is specified using the [#<code>base</code>] syntax, an
2021-05-11 02:29:21 +02:00
appropriate base prefix will be output if necessary, so that the value
2022-08-24 15:22:41 +02:00
output is valid syntax for input. If the # is doubled, for example
[##16], then no base prefix is output.</p>
2021-05-11 02:29:21 +02:00
<p>Floating point constants are recognized by the presence of a decimal
point or an exponent. The decimal point may be the first character of
2022-08-24 15:22:41 +02:00
the constant, but the exponent character e or E may not, as it will be
taken for a parameter name. All numeric parts (before and after the
2021-05-11 02:29:21 +02:00
decimal point and in the exponent) may contain underscores after the
leading digit for visual guidance; these are ignored in computation.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-arithmetic-operators"></span> <span
id="index-operators_002c-arithmetic"></span></p>
2021-05-11 02:29:21 +02:00
<p>An arithmetic expression uses nearly the same syntax and associativity
of expressions as in C.</p>
<p>In the native mode of operation, the following operators are supported
(listed in decreasing order of precedence):</p>
2022-08-24 15:22:41 +02:00
<p>+ - ! ~ ++ <br />
2021-05-11 02:29:21 +02:00
unary plus/minus, logical NOT, complement, {pre,post}{in,de}crement</p>
2022-08-24 15:22:41 +02:00
<p>&lt;&lt; &gt;&gt;<br />
2021-05-11 02:29:21 +02:00
bitwise shift left, right</p>
2022-08-24 15:22:41 +02:00
<p>&amp;<br />
2021-05-11 02:29:21 +02:00
bitwise AND</p>
2022-08-24 15:22:41 +02:00
<p>^<br />
2021-05-11 02:29:21 +02:00
bitwise XOR</p>
2022-08-24 15:22:41 +02:00
<p>|<br />
2021-05-11 02:29:21 +02:00
bitwise OR</p>
2022-08-24 15:22:41 +02:00
<p>**<br />
2021-05-11 02:29:21 +02:00
exponentiation</p>
2022-08-24 15:22:41 +02:00
<p>* / %<br />
2021-05-11 02:29:21 +02:00
multiplication, division, modulus (remainder)</p>
2022-08-24 15:22:41 +02:00
<p>+ -<br />
2021-05-11 02:29:21 +02:00
addition, subtraction</p>
2022-08-24 15:22:41 +02:00
<p>&lt; &gt; &lt;= &gt;=<br />
2021-05-11 02:29:21 +02:00
comparison</p>
2022-08-24 15:22:41 +02:00
<p>== !=<br />
2021-05-11 02:29:21 +02:00
equality and inequality</p>
2022-08-24 15:22:41 +02:00
<p>&amp;&amp;<br />
2021-05-11 02:29:21 +02:00
logical AND</p>
2022-08-24 15:22:41 +02:00
<p>|| ^^<br />
2021-05-11 02:29:21 +02:00
logical OR, XOR</p>
2022-08-24 15:22:41 +02:00
<p>? :<br />
2021-05-11 02:29:21 +02:00
ternary operator</p>
2022-08-24 15:22:41 +02:00
<p>= += -= *= /= %= &amp;= ^= |= &lt;&lt;= &gt;&gt;= &amp;&amp;= ||= ^^= **=<br />
2021-05-11 02:29:21 +02:00
assignment</p>
2022-08-24 15:22:41 +02:00
<p>,<br />
2021-05-11 02:29:21 +02:00
comma operator</p>
2022-08-24 15:22:41 +02:00
<p>The operators &amp;&amp;, ||, &amp;&amp;=, and ||= are short-circuiting, and
only one of the latter two expressions in a ternary operator is
2021-05-11 02:29:21 +02:00
evaluated. Note the precedence of the bitwise AND, OR, and XOR
operators.</p>
2022-08-24 15:22:41 +02:00
<p>With the option C_PRECEDENCES the precedences (but no other properties)
of the operators are altered to be the same as those in most other
languages that support the relevant operators:</p>
<p>+ - ! ~ ++ <br />
2021-05-11 02:29:21 +02:00
unary plus/minus, logical NOT, complement, {pre,post}{in,de}crement</p>
2022-08-24 15:22:41 +02:00
<p>**<br />
2021-05-11 02:29:21 +02:00
exponentiation</p>
2022-08-24 15:22:41 +02:00
<p>* / %<br />
2021-05-11 02:29:21 +02:00
multiplication, division, modulus (remainder)</p>
2022-08-24 15:22:41 +02:00
<p>+ -<br />
2021-05-11 02:29:21 +02:00
addition, subtraction</p>
2022-08-24 15:22:41 +02:00
<p>&lt;&lt; &gt;&gt;<br />
2021-05-11 02:29:21 +02:00
bitwise shift left, right</p>
2022-08-24 15:22:41 +02:00
<p>&lt; &gt; &lt;= &gt;=<br />
2021-05-11 02:29:21 +02:00
comparison</p>
2022-08-24 15:22:41 +02:00
<p>== !=<br />
2021-05-11 02:29:21 +02:00
equality and inequality</p>
2022-08-24 15:22:41 +02:00
<p>&amp;<br />
2021-05-11 02:29:21 +02:00
bitwise AND</p>
2022-08-24 15:22:41 +02:00
<p>^<br />
2021-05-11 02:29:21 +02:00
bitwise XOR</p>
2022-08-24 15:22:41 +02:00
<p>|<br />
2021-05-11 02:29:21 +02:00
bitwise OR</p>
2022-08-24 15:22:41 +02:00
<p>&amp;&amp;<br />
2021-05-11 02:29:21 +02:00
logical AND</p>
2022-08-24 15:22:41 +02:00
<p>^^<br />
2021-05-11 02:29:21 +02:00
logical XOR</p>
2022-08-24 15:22:41 +02:00
<p>||<br />
2021-05-11 02:29:21 +02:00
logical OR</p>
2022-08-24 15:22:41 +02:00
<p>? :<br />
2021-05-11 02:29:21 +02:00
ternary operator</p>
2022-08-24 15:22:41 +02:00
<p>= += -= *= /= %= &amp;= ^= |= &lt;&lt;= &gt;&gt;= &amp;&amp;= ||= ^^= **=<br />
2021-05-11 02:29:21 +02:00
assignment</p>
2022-08-24 15:22:41 +02:00
<p>,<br />
2021-05-11 02:29:21 +02:00
comma operator</p>
<p>Note the precedence of exponentiation in both cases is below that of
2022-08-24 15:22:41 +02:00
unary operators, hence -3**2 evaluates as 9, not -9. Use
parentheses where necessary: -(3**2). This is for compatibility with
2021-05-11 02:29:21 +02:00
other shells.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-mathematical-functions_002c-use-of"></span> <span
id="index-functions_002c-math_002c-use-of"></span></p>
<p>Mathematical functions can be called with the syntax <code>func</code>(<code>args</code>),
where the function decides if the <code>args</code> is used as a string or a
comma-separated list of arithmetic expressions. The shell currently
defines no mathematical functions by default, but the module
zsh/mathfunc may be loaded with the zmodload builtin to provide standard
floating point mathematical functions.</p>
<p>An expression of the form ##<code>x</code> where <code>x</code> is any character sequence
such as a, ^A, or \M-\C-x gives the value of this character and
an expression of the form #<code>name</code> gives the value of the first
2021-05-11 02:29:21 +02:00
character of the contents of the parameter <code>name</code>. Character values are
according to the character set used in the current locale; for multibyte
2022-08-24 15:22:41 +02:00
character handling the option MULTIBYTE must be set. Note that this form
is different from $#<code>name</code>, a standard parameter substitution which
gives the length of the parameter <code>name</code>. #\ is accepted instead of
##, but its use is deprecated.</p>
2021-05-11 02:29:21 +02:00
<p>Named parameters and subscripted arrays can be referenced by name within
an arithmetic expression without using the parameter expansion syntax.
For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">((val2 = val1 * 2))
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>assigns twice the value of $val1 to the parameter named val2.</p>
2021-05-11 02:29:21 +02:00
<p>An internal integer representation of a named parameter can be specified
2022-08-24 15:22:41 +02:00
with the integer builtin. <span
id="index-parameters_002c-integer"></span> <span
id="index-integer-parameters"></span> <span
id="index-integer_002c-use-of"></span> Arithmetic evaluation is
2021-05-11 02:29:21 +02:00
performed on the value of each assignment to a named parameter declared
integer in this manner. Assigning a floating point number to an integer
results in rounding towards zero.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-parameters_002c-floating-point"></span> <span
id="index-floating-point-parameters"></span> <span
id="index-float_002c-use-of"></span></p>
<p>Likewise, floating point numbers can be declared with the float builtin;
there are two types, differing only in their output format, as described
for the typeset builtin. The output format can be bypassed by using
arithmetic substitution instead of the parameter substitution, i.e.
${<code>float</code>} uses the defined format, but $((<code>float</code>)) uses a generic
floating point format.</p>
2021-05-11 02:29:21 +02:00
<p>Promotion of integer to floating point values is performed where
2022-08-24 15:22:41 +02:00
necessary. In addition, if any operator which requires an integer (&amp;,
|, ^, &lt;&lt;, &gt;&gt; and their equivalents with assignment) is given
a floating point argument, it will be silently rounded towards zero
except for ~ which rounds down.</p>
2021-05-11 02:29:21 +02:00
<p>Users should beware that, in common with many other programming
languages but not software designed for calculation, the evaluation of
an expression in zsh is taken a term at a time and promotion of integers
to floating point does not occur in terms only containing integers. A
2022-08-24 15:22:41 +02:00
typical result of this is that a division such as 6/8 is truncated, in
this being rounded towards 0. The FORCE_FLOAT shell option can be used
2021-05-11 02:29:21 +02:00
in scripts or functions where floating point evaluation is required
throughout.</p>
<p>Scalar variables can hold integer or floating point values at different
times; there is no memory of the numeric type in this case.</p>
<p>If a variable is first assigned in a numeric context without previously
2022-08-24 15:22:41 +02:00
being declared, it will be implicitly typed as integer or float and
2021-05-11 02:29:21 +02:00
retain that type either until the type is explicitly changed or until
the end of the scope. This can have unforeseen consequences. For
example, in the loop</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">for (( f = 0; f &lt; 1; f += 0.1 )); do
2021-05-11 02:29:21 +02:00
# use $f
done
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>if f has not already been declared, the first assignment will cause it
to be created as an integer, and consequently the operation f += 0.1
2021-05-11 02:29:21 +02:00
will always cause the result to be truncated to zero, so that the loop
2022-08-24 15:22:41 +02:00
will fail. A simple fix would be to turn the initialization into f =
0.0. It is therefore best to declare numeric variables with explicit
2021-05-11 02:29:21 +02:00
types.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="Conditional-Expressions.html#12-conditional-expressions">12 Conditional Expressions</a></li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2022-08-24 15:22:41 +02:00
<p><span id="Conditional-Expressions"></span> <span
id="Conditional-Expressions-1"></span></p>
2021-05-11 02:29:21 +02:00
<h1 id="12-conditional-expressions"><a class="header" href="#12-conditional-expressions">12 Conditional Expressions</a></h1>
2022-08-24 15:22:41 +02:00
<p><span id="index-conditional-expressions"></span> <span
id="index-expressions_002c-conditional"></span></p>
<p>A <em>conditional expression</em> is used with the [[ compound command to
2021-05-11 02:29:21 +02:00
test attributes of files and to compare strings. Each expression can be
constructed from one or more of the following unary or binary
expressions:</p>
2022-08-24 15:22:41 +02:00
<p>-a <code>file</code><br />
2021-05-11 02:29:21 +02:00
true if <code>file</code> exists.</p>
2022-08-24 15:22:41 +02:00
<p>-b <code>file</code><br />
2021-05-11 02:29:21 +02:00
true if <code>file</code> exists and is a block special file.</p>
2022-08-24 15:22:41 +02:00
<p>-c <code>file</code><br />
2021-05-11 02:29:21 +02:00
true if <code>file</code> exists and is a character special file.</p>
2022-08-24 15:22:41 +02:00
<p>-d <code>file</code><br />
2021-05-11 02:29:21 +02:00
true if <code>file</code> exists and is a directory.</p>
2022-08-24 15:22:41 +02:00
<p>-e <code>file</code><br />
2021-05-11 02:29:21 +02:00
true if <code>file</code> exists.</p>
2022-08-24 15:22:41 +02:00
<p>-f <code>file</code><br />
2021-05-11 02:29:21 +02:00
true if <code>file</code> exists and is a regular file.</p>
2022-08-24 15:22:41 +02:00
<p>-g <code>file</code><br />
2021-05-11 02:29:21 +02:00
true if <code>file</code> exists and has its setgid bit set.</p>
2022-08-24 15:22:41 +02:00
<p>-h <code>file</code><br />
2021-05-11 02:29:21 +02:00
true if <code>file</code> exists and is a symbolic link.</p>
2022-08-24 15:22:41 +02:00
<p>-k <code>file</code><br />
2021-05-11 02:29:21 +02:00
true if <code>file</code> exists and has its sticky bit set.</p>
2022-08-24 15:22:41 +02:00
<p>-n <code>string</code><br />
2021-05-11 02:29:21 +02:00
true if length of <code>string</code> is non-zero.</p>
2022-08-24 15:22:41 +02:00
<p>-o <code>option</code><br />
true if option named <code>option</code> is on. <code>option</code> may be a single character,
in which case it is a single letter option name. (See <a href="Options.html#Specifying-Options">Specifying
Options</a>.)</p>
<p>When no option named <code>option</code> exists, and the POSIX_BUILTINS option
hasnt been set, return 3 with a warning. If that option is set, return
1 with no warning.</p>
<p>-p <code>file</code><br />
2021-05-11 02:29:21 +02:00
true if <code>file</code> exists and is a FIFO special file (named pipe).</p>
2022-08-24 15:22:41 +02:00
<p>-r <code>file</code><br />
2021-05-11 02:29:21 +02:00
true if <code>file</code> exists and is readable by current process.</p>
2022-08-24 15:22:41 +02:00
<p>-s <code>file</code><br />
2021-05-11 02:29:21 +02:00
true if <code>file</code> exists and has size greater than zero.</p>
2022-08-24 15:22:41 +02:00
<p>-t <code>fd</code><br />
2021-05-11 02:29:21 +02:00
true if file descriptor number <code>fd</code> is open and associated with a
terminal device. (note: <code>fd</code> is not optional)</p>
2022-08-24 15:22:41 +02:00
<p>-u <code>file</code><br />
2021-05-11 02:29:21 +02:00
true if <code>file</code> exists and has its setuid bit set.</p>
2022-08-24 15:22:41 +02:00
<p>-v <code>varname</code><br />
2021-05-11 02:29:21 +02:00
true if shell variable <code>varname</code> is set.</p>
2022-08-24 15:22:41 +02:00
<p>-w <code>file</code><br />
-x <code>file</code><br />
-z <code>string</code><br />
2021-05-11 02:29:21 +02:00
true if length of <code>string</code> is zero.</p>
2022-08-24 15:22:41 +02:00
<p>-L <code>file</code><br />
2021-05-11 02:29:21 +02:00
true if <code>file</code> exists and is a symbolic link.</p>
2022-08-24 15:22:41 +02:00
<p>-O <code>file</code><br />
2021-05-11 02:29:21 +02:00
true if <code>file</code> exists and is owned by the effective user ID of this
process.</p>
2022-08-24 15:22:41 +02:00
<p>-G <code>file</code><br />
true if <code>file</code> exists and its group matches the effective group ID of
this process.</p>
<p>-S <code>file</code><br />
2021-05-11 02:29:21 +02:00
true if <code>file</code> exists and is a socket.</p>
2022-08-24 15:22:41 +02:00
<p>-N <code>file</code><br />
2021-05-11 02:29:21 +02:00
true if <code>file</code> exists and its access time is not newer than its
modification time.</p>
2022-08-24 15:22:41 +02:00
<p><code>file1</code> -nt <code>file2</code><br />
2021-05-11 02:29:21 +02:00
true if <code>file1</code> exists and is newer than <code>file2</code>.</p>
2022-08-24 15:22:41 +02:00
<p><code>file1</code> -ot <code>file2</code><br />
2021-05-11 02:29:21 +02:00
true if <code>file1</code> exists and is older than <code>file2</code>.</p>
2022-08-24 15:22:41 +02:00
<p><code>file1</code> -ef <code>file2</code><br />
2021-05-11 02:29:21 +02:00
true if <code>file1</code> and <code>file2</code> exist and refer to the same file.</p>
2022-08-24 15:22:41 +02:00
<p><code>string</code> = <code>pattern</code><br />
<code>string</code> == <code>pattern</code><br />
2021-05-11 02:29:21 +02:00
true if <code>string</code> matches <code>pattern</code>. The two forms are exactly
2022-08-24 15:22:41 +02:00
equivalent. The = form is the traditional shell syntax (and hence the
only one generally used with the test and [ builtins); the == form
provides compatibility with other sorts of computer language.</p>
<p><code>string</code> != <code>pattern</code><br />
2021-05-11 02:29:21 +02:00
true if <code>string</code> does not match <code>pattern</code>.</p>
2022-08-24 15:22:41 +02:00
<p><code>string</code> =~ <code>regexp</code><br />
true if <code>string</code> matches the regular expression <code>regexp</code>. If the option
RE_MATCH_PCRE is set <code>regexp</code> is tested as a PCRE regular expression
using the zsh/pcre module, else it is tested as a POSIX extended regular
expression using the zsh/regex module. Upon successful match, some
variables will be updated; no variables are changed if the matching
fails.</p>
<p>If the option BASH_REMATCH is not set the scalar parameter MATCH is set
to the substring that matched the pattern and the integer parameters
MBEGIN and MEND to the index of the start and end, respectively, of the
match in <code>string</code>, such that if <code>string</code> is contained in variable var
the expression ${var[$MBEGIN,$MEND]} is identical to $MATCH. The
setting of the option KSH_ARRAYS is respected. Likewise, the array match
is set to the substrings that matched parenthesised subexpressions and
the arrays mbegin and mend to the indices of the start and end
positions, respectively, of the substrings within <code>string</code>. The arrays
are not set if there were no parenthesised subexpressions. For example,
if the string a short string is matched against the regular expression
s(...)t, then (assuming the option KSH_ARRAYS is not set) MATCH,
MBEGIN and MEND are short, 3 and 7, respectively, while match, mbegin
and mend are single entry arrays containing the strings hor, 4 and
6, respectively.</p>
<p>If the option BASH_REMATCH is set the array BASH_REMATCH is set to the
substring that matched the pattern followed by the substrings that
matched parenthesised subexpressions within the pattern.</p>
<p><code>string1</code> &lt; <code>string2</code><br />
true if <code>string1</code> comes before <code>string2</code> based on ASCII value of their
characters.</p>
<p><code>string1</code> &gt; <code>string2</code><br />
true if <code>string1</code> comes after <code>string2</code> based on ASCII value of their
characters.</p>
<p><code>exp1</code> -eq <code>exp2</code><br />
2021-05-11 02:29:21 +02:00
true if <code>exp1</code> is numerically equal to <code>exp2</code>. Note that for purely
2022-08-24 15:22:41 +02:00
numeric comparisons use of the ((<code>...</code>)) builtin described in
2021-05-11 02:29:21 +02:00
<a href="Arithmetic-Evaluation.html#Arithmetic-Evaluation">Arithmetic
2022-08-24 15:22:41 +02:00
Evaluation</a> is more
convenient than conditional expressions.</p>
<p><code>exp1</code> -ne <code>exp2</code><br />
2021-05-11 02:29:21 +02:00
true if <code>exp1</code> is numerically not equal to <code>exp2</code>.</p>
2022-08-24 15:22:41 +02:00
<p><code>exp1</code> -lt <code>exp2</code><br />
2021-05-11 02:29:21 +02:00
true if <code>exp1</code> is numerically less than <code>exp2</code>.</p>
2022-08-24 15:22:41 +02:00
<p><code>exp1</code> -gt <code>exp2</code><br />
2021-05-11 02:29:21 +02:00
true if <code>exp1</code> is numerically greater than <code>exp2</code>.</p>
2022-08-24 15:22:41 +02:00
<p><code>exp1</code> -le <code>exp2</code><br />
2021-05-11 02:29:21 +02:00
true if <code>exp1</code> is numerically less than or equal to <code>exp2</code>.</p>
2022-08-24 15:22:41 +02:00
<p><code>exp1</code> -ge <code>exp2</code><br />
2021-05-11 02:29:21 +02:00
true if <code>exp1</code> is numerically greater than or equal to <code>exp2</code>.</p>
2022-08-24 15:22:41 +02:00
<p>( <code>exp</code> )<br />
2021-05-11 02:29:21 +02:00
true if <code>exp</code> is true.</p>
2022-08-24 15:22:41 +02:00
<p>! <code>exp</code><br />
2021-05-11 02:29:21 +02:00
true if <code>exp</code> is false.</p>
2022-08-24 15:22:41 +02:00
<p><code>exp1</code> &amp;&amp; <code>exp2</code><br />
2021-05-11 02:29:21 +02:00
true if <code>exp1</code> and <code>exp2</code> are both true.</p>
2022-08-24 15:22:41 +02:00
<p><code>exp1</code> || <code>exp2</code><br />
2021-05-11 02:29:21 +02:00
true if either <code>exp1</code> or <code>exp2</code> is true.</p>
<p>For compatibility, if there is a single argument that is not
syntactically significant, typically a variable, the condition is
treated as a test for whether the expression expands as a string of
2022-08-24 15:22:41 +02:00
non-zero length. In other words, [[ $var ]] is the same as [[ -n
$var ]]. It is recommended that the second, explicit, form be used
where possible.</p>
2021-05-11 02:29:21 +02:00
<p>Normal shell expansion is performed on the <code>file</code>, <code>string</code> and
<code>pattern</code> arguments, but the result of each expansion is constrained to
be a single word, similar to the effect of double quotes.</p>
<p>Filename generation is not performed on any form of argument to
conditions. However, it can be forced in any case where normal shell
2022-08-24 15:22:41 +02:00
expansion is valid and when the option EXTENDED_GLOB is in effect by
using an explicit glob qualifier of the form (#q) at the end of the
string. A normal glob qualifier expression may appear between the q
2021-05-11 02:29:21 +02:00
and the closing parenthesis; if none appears the expression has no
effect beyond causing filename generation. The results of filename
generation are joined together to form a single word, as with the
results of other forms of expansion.</p>
2022-08-24 15:22:41 +02:00
<p>This special use of filename generation is only available with the [[
syntax. If the condition occurs within the [ or test builtin commands
then globbing occurs instead as part of normal command line expansion
before the condition is evaluated. In this case it may generate multiple
words which are likely to confuse the syntax of the test command.</p>
2021-05-11 02:29:21 +02:00
<p>For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">[[ -n file*(#qN) ]]
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>produces status zero if and only if there is at least one file in the
2022-08-24 15:22:41 +02:00
current directory beginning with the string file. The globbing
qualifier N ensures that the expression is empty if there is no matching
file.</p>
2021-05-11 02:29:21 +02:00
<p>Pattern metacharacters are active for the <code>pattern</code> arguments; the
patterns are the same as those used for filename generation, see
<a href="Expansion.html#Filename-Generation">Filename Generation</a>, but there is
2022-08-24 15:22:41 +02:00
no special behaviour of / nor initial dots, and no glob qualifiers are
allowed.</p>
2021-05-11 02:29:21 +02:00
<p>In each of the above expressions, if <code>file</code> is of the form
2022-08-24 15:22:41 +02:00
/dev/fd/<code>n</code>, where <code>n</code> is an integer, then the test applied to the
2021-05-11 02:29:21 +02:00
open file whose descriptor number is <code>n</code>, even if the underlying system
2022-08-24 15:22:41 +02:00
does not support the /dev/fd directory.</p>
2021-05-11 02:29:21 +02:00
<p>In the forms which do numeric comparison, the expressions <code>exp</code> undergo
2022-08-24 15:22:41 +02:00
arithmetic expansion as if they were enclosed in $((<code>...</code>)).</p>
2021-05-11 02:29:21 +02:00
<p>For example, the following:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">[[ ( -f foo || -f bar ) &amp;&amp; $report = y* ]] &amp;&amp; print File exists.
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>tests if either file foo or file bar exists, and if so, if the value of
the parameter report begins with y; if the complete condition is true,
the message File exists. is printed.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="Prompt-Expansion.html#13-prompt-expansion">13 Prompt Expansion</a>
<ul>
<li><a href="Prompt-Expansion.html#131-expansion-of-prompt-sequences">13.1 Expansion of Prompt Sequences</a></li>
<li><a href="Prompt-Expansion.html#132-simple-prompt-escapes">13.2 Simple Prompt Escapes</a>
<ul>
<li><a href="Prompt-Expansion.html#1321-special-characters">13.2.1 Special characters</a></li>
<li><a href="Prompt-Expansion.html#1322-login-information">13.2.2 Login information</a></li>
<li><a href="Prompt-Expansion.html#1323-shell-state">13.2.3 Shell state</a></li>
<li><a href="Prompt-Expansion.html#1324-date-and-time">13.2.4 Date and time</a></li>
<li><a href="Prompt-Expansion.html#1325-visual-effects">13.2.5 Visual effects</a></li>
</ul>
</li>
<li><a href="Prompt-Expansion.html#133-conditional-substrings-in-prompts">13.3 Conditional Substrings in Prompts</a></li>
</ul>
</li>
2022-08-24 15:22:41 +02:00
<li><a href="Prompt-Expansion.html#"></a></li>
2021-05-11 02:29:21 +02:00
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2022-08-24 15:22:41 +02:00
<p><span id="Prompt-Expansion"></span> <span
id="Prompt-Expansion-1"></span></p>
2021-05-11 02:29:21 +02:00
<h1 id="13-prompt-expansion"><a class="header" href="#13-prompt-expansion">13 Prompt Expansion</a></h1>
<hr />
<p><span id="Expansion-of-Prompt-Sequences"></span></p>
<h2 id="131-expansion-of-prompt-sequences"><a class="header" href="#131-expansion-of-prompt-sequences">13.1 Expansion of Prompt Sequences</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-prompt-expansion"></span> <span
id="index-expansion_002c-prompt"></span></p>
2021-05-11 02:29:21 +02:00
<p>Prompt sequences undergo a special form of expansion. This type of
2022-08-24 15:22:41 +02:00
expansion is also available using the -P option to the print builtin.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-PROMPT_005fSUBST_002c-use-of"></span></p>
2022-08-24 15:22:41 +02:00
<p>If the PROMPT_SUBST option is set, the prompt string is first subjected
to <em>parameter expansion</em>, <em>command substitution</em> and <em>arithmetic
expansion</em>. See <a href="Expansion.html#Expansion">Expansion</a>.</p>
2021-05-11 02:29:21 +02:00
<p>Certain escape sequences may be recognised in the prompt string.</p>
<p><span id="index-PROMPT_005fBANG_002c-use-of"></span></p>
2022-08-24 15:22:41 +02:00
<p>If the PROMPT_BANG option is set, a ! in the prompt is replaced by the
current history event number. A literal ! may then be represented as
!!.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-PROMPT_005fPERCENT_002c-use-of"></span></p>
2022-08-24 15:22:41 +02:00
<p>If the PROMPT_PERCENT option is set, certain escape sequences that start
with % are expanded. Many escapes are followed by a single character,
although some of these take an optional integer argument that should
appear between the % and the next character of the sequence. More
complicated escape sequences are available to provide conditional
2021-05-11 02:29:21 +02:00
expansion.</p>
<hr />
<p><span id="Simple-Prompt-Escapes"></span></p>
<h2 id="132-simple-prompt-escapes"><a class="header" href="#132-simple-prompt-escapes">13.2 Simple Prompt Escapes</a></h2>
<hr />
<p><span id="Special-characters"></span></p>
<h3 id="1321-special-characters"><a class="header" href="#1321-special-characters">13.2.1 Special characters</a></h3>
2022-08-24 15:22:41 +02:00
<p>%%<br />
A %.</p>
<p>%)<br />
A ).</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Login-information"></span></p>
<h3 id="1322-login-information"><a class="header" href="#1322-login-information">13.2.2 Login information</a></h3>
2022-08-24 15:22:41 +02:00
<p>%l<br />
The line (tty) the user is logged in on, without /dev/ prefix. If the
name starts with /dev/tty, that prefix is stripped.</p>
<p>%M<br />
2021-05-11 02:29:21 +02:00
The full machine hostname.</p>
2022-08-24 15:22:41 +02:00
<p>%m<br />
The hostname up to the first .. An integer may follow the % to
specify how many components of the hostname are desired. With a negative
integer, trailing components of the hostname are shown.</p>
<p>%n<br />
$USERNAME.</p>
<p>%y<br />
The line (tty) the user is logged in on, without /dev/ prefix. This
does not treat /dev/tty names specially.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Shell-state"></span></p>
<h3 id="1323-shell-state"><a class="header" href="#1323-shell-state">13.2.3 Shell state</a></h3>
2022-08-24 15:22:41 +02:00
<p>%#<br />
A # if the shell is running with privileges, a % if not. Equivalent
to %(!.#.%%). The definition of privileged, for these purposes, is
that either the effective user ID is zero, or, if POSIX.1e capabilities
are supported, that capability vectors.</p>
<p>%?<br />
The return status of the last command executed just before the prompt.</p>
<p>%_<br />
The status of the parser, i.e. the shell constructs (like if and
for) that have been started on the command line. If given an integer
number that many strings will be printed; zero or negative or no integer
means print as many as there are. This is most useful in prompts PS2 for
continuation lines and PS4 for debugging with the XTRACE option; in the
latter case it will also work non-interactively.</p>
<p>%^<br />
The status of the parser in reverse. This is the same as %_ other
than the order of strings. It is often used in RPS2.</p>
<p>%d<br />
%/<br />
Current working directory. If an integer follows the %, it specifies a
number of trailing components of the current working directory to show;
zero means the whole path. A negative integer specifies leading
components, i.e. %-1d specifies the first component.</p>
<p>%~<br />
As %d and %/, but if the current working directory starts with $HOME,
that part is replaced by a ~. Furthermore, if it has a named
directory as its prefix, that part is replaced by a ~ followed by the
name of the directory, but only if the result is shorter than the full
path; <a href="Expansion.html#Filename-Expansion">Filename Expansion</a>.</p>
<p>%e<br />
Evaluation depth of the current sourced file, shell function, or eval.
This is incremented or decremented every time the value of %N is set or
reverted to a previous value, respectively. This is most useful for
debugging as part of $PS4.</p>
<p>%h<br />
%!<br />
2021-05-11 02:29:21 +02:00
Current history event number.</p>
2022-08-24 15:22:41 +02:00
<p>%i<br />
The line number currently being executed in the script, sourced file, or
shell function given by %N. This is most useful for debugging as part of
$PS4.</p>
<p>%I<br />
The line number currently being executed in the file %x. This is similar
to %i, but the line number is always a line number in the file where the
code was defined, even if the code is a shell function.</p>
<p>%j<br />
2021-05-11 02:29:21 +02:00
The number of jobs.</p>
2022-08-24 15:22:41 +02:00
<p>%L<br />
The current value of $SHLVL.</p>
<p>%N<br />
2021-05-11 02:29:21 +02:00
The name of the script, sourced file, or shell function that zsh is
2022-08-24 15:22:41 +02:00
currently executing, whichever was started most recently. If there is
none, this is equivalent to the parameter $0. An integer may follow the
% to specify a number of trailing path components to show; zero means
the full path. A negative integer specifies leading components.</p>
<p>%x<br />
2021-05-11 02:29:21 +02:00
The name of the file containing the source code currently being
2022-08-24 15:22:41 +02:00
executed. This behaves as %N except that function and eval command names
are not shown, instead the file where they were defined.</p>
<p>%c<br />
%.<br />
%C<br />
2021-05-11 02:29:21 +02:00
Trailing component of the current working directory. An integer may
2022-08-24 15:22:41 +02:00
follow the % to get more than one component. Unless %C is used,
tilde contraction is performed first. These are deprecated as %c and %C
are equivalent to %1~ and %1/, respectively, while explicit positive
integers have the same effect as for the latter two sequences.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Date-and-time"></span></p>
<h3 id="1324-date-and-time"><a class="header" href="#1324-date-and-time">13.2.4 Date and time</a></h3>
2022-08-24 15:22:41 +02:00
<p>%D<br />
The date in <code>yy</code>-<code>mm</code>-<code>dd</code> format.</p>
<p>%T<br />
2021-05-11 02:29:21 +02:00
Current time of day, in 24-hour format.</p>
2022-08-24 15:22:41 +02:00
<p>%t<br />
%@<br />
2021-05-11 02:29:21 +02:00
Current time of day, in 12-hour, am/pm format.</p>
2022-08-24 15:22:41 +02:00
<p>%*<br />
2021-05-11 02:29:21 +02:00
Current time of day in 24-hour format, with seconds.</p>
2022-08-24 15:22:41 +02:00
<p>%w<br />
The date in <code>day</code>-<code>dd</code> format.</p>
<p>%W<br />
The date in <code>mm</code>/<code>dd</code>/<code>yy</code> format.</p>
<p>%D{<code>string</code>}<br />
<code>string</code> is formatted using the strftime function. See strftime(3) for
more details. Various zsh extensions provide numbers with no leading
zero or space if the number is a single digit:</p>
<p>%f<br />
2021-05-11 02:29:21 +02:00
a day of the month</p>
2022-08-24 15:22:41 +02:00
<p>%K<br />
2021-05-11 02:29:21 +02:00
the hour of the day on the 24-hour clock</p>
2022-08-24 15:22:41 +02:00
<p>%L<br />
2021-05-11 02:29:21 +02:00
the hour of the day on the 12-hour clock</p>
2022-08-24 15:22:41 +02:00
<p>In addition, if the system supports the POSIX gettimeofday system call,
%. provides decimal fractions of a second since the epoch with leading
zeroes. By default three decimal places are provided, but a number of
digits up to 9 may be given following the %; hence %6. outputs
microseconds, and %9. outputs nanoseconds. (The latter requires a
nanosecond-precision clock_gettime; systems lacking this will return a
value multiplied by the appropriate power of 10.) A typical example of
this is the format %D{%H:%M:%S.%.}.</p>
<p>The GNU extension %N is handled as a synonym for %9..</p>
<p>Additionally, the GNU extension that a - between the % and the format
character causes a leading zero or space to be stripped is handled
directly by the shell for the format characters d, f, H, k, l, m, M, S
and y; any other format characters are provided to the systems
strftime(3) with any leading - present, so the handling is system
dependent. Further GNU (or other) extensions are also passed to
strftime(3) and may work if the system supports them.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Visual-effects"></span></p>
<h3 id="1325-visual-effects"><a class="header" href="#1325-visual-effects">13.2.5 Visual effects</a></h3>
2022-08-24 15:22:41 +02:00
<p>%B (%b)<br />
2021-05-11 02:29:21 +02:00
Start (stop) boldface mode.</p>
2022-08-24 15:22:41 +02:00
<p>%E<br />
2021-05-11 02:29:21 +02:00
Clear to end of line.</p>
2022-08-24 15:22:41 +02:00
<p>%U (%u)<br />
2021-05-11 02:29:21 +02:00
Start (stop) underline mode.</p>
2022-08-24 15:22:41 +02:00
<p>%S (%s)<br />
2021-05-11 02:29:21 +02:00
Start (stop) standout mode.</p>
2022-08-24 15:22:41 +02:00
<p>%F (%f)<br />
Start (stop) using a different foreground colour, if supported by the
terminal. The colour may be specified two ways: either as a numeric
argument, as normal, or by a sequence in braces following the %F, for
example %F{red}. In the latter case the values allowed are as described
for the fg zle_highlight attribute; <a href="Zsh-Line-Editor.html#Character-Highlighting">Character
Highlighting</a>. This means
that numeric colours are allowed in the second format also.</p>
<p>%K (%k)<br />
2021-05-11 02:29:21 +02:00
Start (stop) using a different bacKground colour. The syntax is
2022-08-24 15:22:41 +02:00
identical to that for %F and %f.</p>
<p>%{...%}<br />
2021-05-11 02:29:21 +02:00
Include a string as a literal escape sequence. The string within the
braces should not change the cursor position. Brace pairs can nest.</p>
2022-08-24 15:22:41 +02:00
<p>A positive numeric argument between the % and the { is treated as
described for %G below.</p>
<p>%G<br />
Within a %{...%} sequence, include a glitch: that is, assume that a
single character width will be output. This is useful when outputting
characters that otherwise cannot be correctly handled by the shell, such
as the alternate character set on some terminals. The characters in
question can be included within a %{...%} sequence together with the
appropriate number of %G sequences to indicate the correct width. An
integer between the % and G indicates a character width other than
one. Hence %{<code>seq</code>%2G%} outputs <code>seq</code> and assumes it takes up the width
of two standard characters.</p>
<p>Multiple uses of %G accumulate in the obvious fashion; the position of
the %G is unimportant. Negative integers are not handled.</p>
<p>Note that when prompt truncation is in use it is advisable to divide up
output into single characters within each %{...%} group so that the
correct truncation point can be found.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Conditional-Substrings-in-Prompts"></span></p>
<h2 id="133-conditional-substrings-in-prompts"><a class="header" href="#133-conditional-substrings-in-prompts">13.3 Conditional Substrings in Prompts</a></h2>
2022-08-24 15:22:41 +02:00
<p>%v<br />
2021-05-11 02:29:21 +02:00
<span id="index-psvar_002c-use-of"></span></p>
2022-08-24 15:22:41 +02:00
<p>The value of the first element of the psvar array parameter. Following
the % with an integer gives that element of the array. Negative
integers count from the end of the array.</p>
<p>%(<code>x</code>.<code>true-text</code>.<code>false-text</code>)<br />
2021-05-11 02:29:21 +02:00
Specifies a ternary expression. The character following the <code>x</code> is
arbitrary; the same character is used to separate the text for the
2022-08-24 15:22:41 +02:00
true result from that for the false result. This separator may not
appear in the <code>true-text</code>, except as part of a %-escape sequence. A )
may appear in the <code>false-text</code> as %). <code>true-text</code> and <code>false-text</code> may
both contain arbitrarily-nested escape sequences, including further
ternary expressions.</p>
<p>The left parenthesis may be preceded or followed by a positive integer
<code>n</code>, which defaults to zero. A negative integer will be multiplied by
-1, except as noted below for l. The test character <code>x</code> may be any of
the following:</p>
<p>!<br />
2021-05-11 02:29:21 +02:00
True if the shell is running with privileges.</p>
2022-08-24 15:22:41 +02:00
<h1 id=""><a class="header" href="#"></a></h1>
<p>True if the effective uid of the current process is <code>n</code>.</p>
<p>?<br />
2021-05-11 02:29:21 +02:00
True if the exit status of the last command was <code>n</code>.</p>
2022-08-24 15:22:41 +02:00
<p>_<br />
2021-05-11 02:29:21 +02:00
True if at least <code>n</code> shell constructs were started.</p>
2022-08-24 15:22:41 +02:00
<p>C<br />
/<br />
True if the current absolute path has at least <code>n</code> elements relative to
the root directory, hence / is counted as 0 elements.</p>
<p>c<br />
.<br />
~<br />
True if the current path, with prefix replacement, has at least <code>n</code>
elements relative to the root directory, hence / is counted as 0
2021-05-11 02:29:21 +02:00
elements.</p>
2022-08-24 15:22:41 +02:00
<p>D<br />
2021-05-11 02:29:21 +02:00
True if the month is equal to <code>n</code> (January = 0).</p>
2022-08-24 15:22:41 +02:00
<p>d<br />
2021-05-11 02:29:21 +02:00
True if the day of the month is equal to <code>n</code>.</p>
2022-08-24 15:22:41 +02:00
<p>e<br />
2021-05-11 02:29:21 +02:00
True if the evaluation depth is at least <code>n</code>.</p>
2022-08-24 15:22:41 +02:00
<p>g<br />
2021-05-11 02:29:21 +02:00
True if the effective gid of the current process is <code>n</code>.</p>
2022-08-24 15:22:41 +02:00
<p>j<br />
2021-05-11 02:29:21 +02:00
True if the number of jobs is at least <code>n</code>.</p>
2022-08-24 15:22:41 +02:00
<p>L<br />
True if the SHLVL parameter is at least <code>n</code>.</p>
<p>l<br />
True if at least <code>n</code> characters have already been printed on the current
line. When <code>n</code> is negative, true if at least abs(<code>n</code>) characters remain
before the opposite margin (thus the left margin for RPROMPT).</p>
<p>S<br />
True if the SECONDS parameter is at least <code>n</code>.</p>
<p>T<br />
2021-05-11 02:29:21 +02:00
True if the time in hours is equal to <code>n</code>.</p>
2022-08-24 15:22:41 +02:00
<p>t<br />
2021-05-11 02:29:21 +02:00
True if the time in minutes is equal to <code>n</code>.</p>
2022-08-24 15:22:41 +02:00
<p>v<br />
True if the array psvar has at least <code>n</code> elements.</p>
<p>V<br />
True if element <code>n</code> of the array psvar is set and non-empty.</p>
<p>w<br />
2021-05-11 02:29:21 +02:00
True if the day of the week is equal to <code>n</code> (Sunday = 0).</p>
2022-08-24 15:22:41 +02:00
<p>%&lt;<code>string</code>&lt;<br />
%&gt;<code>string</code>&gt;<br />
%[<code>xstring</code>]<br />
Specifies truncation behaviour for the remainder of the prompt string.
The third, deprecated, form is equivalent to %<code>xstringx</code>, i.e. <code>x</code> may
be &lt; or &gt;. The <code>string</code> will be displayed in place of the truncated
portion of any string; note this does not undergo prompt expansion.</p>
2021-05-11 02:29:21 +02:00
<p>The numeric argument, which in the third form may appear immediately
2022-08-24 15:22:41 +02:00
after the [, specifies the maximum permitted length of the various
strings that can be displayed in the prompt. In the first two forms,
this numeric argument may be negative, in which case the truncation
length is determined by subtracting the absolute value of the numeric
argument from the number of character positions remaining on the current
prompt line. If this results in a zero or negative length, a length of 1
is used. In other words, a negative argument arranges that after
truncation at least <code>n</code> characters remain before the right margin (left
margin for RPROMPT).</p>
<p>The forms with &lt; truncate at the left of the string, and the forms
with &gt; truncate at the right of the string. For example, if the
current directory is /home/pike, the prompt %8&lt;..&lt;%/ will expand
to ..e/pike. In this string, the terminating character (&lt;, &gt; or
]), or in fact any character, may be quoted by a preceding \; note
when using print -P, however, that this must be doubled as the string is
also subject to standard print processing, in addition to any
backslashes removed by a double quoted string: the worst case is
therefore print -P &quot;%&lt;\\\\&lt;&lt;...&quot;.</p>
<p>If the <code>string</code> is longer than the specified truncation length, it will
appear in full, completely replacing the truncated string.</p>
2021-05-11 02:29:21 +02:00
<p>The part of the prompt string to be truncated runs to the end of the
2022-08-24 15:22:41 +02:00
string, or to the end of the next enclosing group of the %( construct,
or to the next truncation encountered at the same grouping level (i.e.
truncations inside a %( are separate), which ever comes first. In
particular, a truncation with argument zero (e.g., %&lt;&lt;) marks the
end of the range of the string to be truncated while turning off
truncation from there on. For example, the prompt %10&lt;...&lt;%~%&lt;&lt;%#
will print a truncated representation of the current directory,
followed by a % or #, followed by a space. Without the %&lt;&lt;,
those two characters would be included in the string to be truncated.
Note that %-0&lt;&lt; is not equivalent to %&lt;&lt; but specifies that the
2021-05-11 02:29:21 +02:00
prompt is truncated at the right margin.</p>
2022-08-24 15:22:41 +02:00
<p>Truncation applies only within each individual line of the prompt, as
delimited by embedded newlines (if any). If the total length of any line
of the prompt after truncation is greater than the terminal width, or if
the part to be truncated contains embedded newlines, truncation behavior
is undefined and may change in a future version of the shell. Use
%-<code>n</code>(l.<code>true-text</code>.<code>false-text</code>) to remove parts of the prompt when
the available space is less than <code>n</code>.</p>
<hr />
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="Expansion.html#14-expansion">14 Expansion</a>
<ul>
<li><a href="Expansion.html#141-history-expansion">14.1 History Expansion</a>
<ul>
<li><a href="Expansion.html#1411-overview">14.1.1 Overview</a></li>
<li><a href="Expansion.html#1412-event-designators">14.1.2 Event Designators</a></li>
<li><a href="Expansion.html#1413-word-designators">14.1.3 Word Designators</a></li>
<li><a href="Expansion.html#1414-modifiers">14.1.4 Modifiers</a></li>
</ul>
</li>
<li><a href="Expansion.html#142-process-substitution">14.2 Process Substitution</a></li>
<li><a href="Expansion.html#143-parameter-expansion">14.3 Parameter Expansion</a>
<ul>
<li><a href="Expansion.html#1431-parameter-expansion-flags">14.3.1 Parameter Expansion Flags</a></li>
</ul>
</li>
2022-08-24 15:22:41 +02:00
</ul>
</li>
<li><a href="Expansion.html#"></a>
<ul>
<li><a href="Expansion.html#1432-rules">14.3.2 Rules</a></li>
<li><a href="Expansion.html#1433-examples">14.3.3 Examples</a></li>
2021-05-11 02:29:21 +02:00
<li><a href="Expansion.html#144-command-substitution">14.4 Command Substitution</a></li>
<li><a href="Expansion.html#145-arithmetic-expansion">14.5 Arithmetic Expansion</a></li>
<li><a href="Expansion.html#146-brace-expansion">14.6 Brace Expansion</a></li>
<li><a href="Expansion.html#147-filename-expansion">14.7 Filename Expansion</a>
<ul>
<li><a href="Expansion.html#1471-dynamic-named-directories">14.7.1 Dynamic named directories</a></li>
<li><a href="Expansion.html#1472-static-named-directories">14.7.2 Static named directories</a></li>
<li><a href="Expansion.html#1473--expansion">14.7.3 = expansion</a></li>
<li><a href="Expansion.html#1474-notes">14.7.4 Notes</a></li>
</ul>
</li>
<li><a href="Expansion.html#148-filename-generation">14.8 Filename Generation</a>
<ul>
<li><a href="Expansion.html#1481-glob-operators">14.8.1 Glob Operators</a></li>
<li><a href="Expansion.html#1482-ksh-like-glob-operators">14.8.2 ksh-like Glob Operators</a></li>
<li><a href="Expansion.html#1483-precedence">14.8.3 Precedence</a></li>
<li><a href="Expansion.html#1484-globbing-flags">14.8.4 Globbing Flags</a></li>
<li><a href="Expansion.html#1485-approximate-matching">14.8.5 Approximate Matching</a></li>
<li><a href="Expansion.html#1486-recursive-globbing">14.8.6 Recursive Globbing</a></li>
<li><a href="Expansion.html#1487-glob-qualifiers">14.8.7 Glob Qualifiers</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<p><span id="Expansion"></span> <span id="Expansion-1"></span></p>
<h1 id="14-expansion"><a class="header" href="#14-expansion">14 Expansion</a></h1>
<p><span id="index-expansion"></span></p>
<p>The following types of expansions are performed in the indicated order
in five steps:</p>
<p><em>History Expansion</em><br />
This is performed only in interactive shells.</p>
<p><em>Alias Expansion</em><br />
2022-08-24 15:22:41 +02:00
Aliases are expanded immediately before the command line is parsed as
explained in <a href="Shell-Grammar.html#Aliasing">Aliasing</a>.</p>
2021-05-11 02:29:21 +02:00
<p><em>Process Substitution</em><br />
<em>Parameter Expansion</em><br />
<em>Command Substitution</em><br />
<em>Arithmetic Expansion</em><br />
<em>Brace Expansion</em><br />
2022-08-24 15:22:41 +02:00
These five are performed in left-to-right fashion. On each argument, any
of the five steps that are needed are performed one after the other.
Hence, for example, all the parts of parameter expansion are completed
before command substitution is started. After these expansions, all
unquoted occurrences of the characters \, and &quot; are removed.</p>
2021-05-11 02:29:21 +02:00
<p><em>Filename Expansion</em><br />
2022-08-24 15:22:41 +02:00
If the SH_FILE_EXPANSION option is set, the order of expansion is
2021-05-11 02:29:21 +02:00
modified for compatibility with sh and ksh. In that case <em>filename
2022-08-24 15:22:41 +02:00
expansion</em> is performed immediately after <em>alias expansion</em>, preceding
the set of five expansions mentioned above.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-globbing"></span></p>
<p><em>Filename Generation</em><br />
2022-08-24 15:22:41 +02:00
This expansion, commonly referred to as globbing, is always done last.</p>
2021-05-11 02:29:21 +02:00
<p>The following sections explain the types of expansion in detail.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="History-Expansion"></span> <span
id="History-Expansion-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="141-history-expansion"><a class="header" href="#141-history-expansion">14.1 History Expansion</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-history"></span> <span
id="index-history-expansion"></span> <span
id="index-expansion_002c-history"></span></p>
2021-05-11 02:29:21 +02:00
<p>History expansion allows you to use words from previous command lines in
the command line you are typing. This simplifies spelling corrections
and the repetition of complicated commands or arguments.</p>
<p><span id="index-HISTSIZE_002c-use-of"></span></p>
<p>Immediately before execution, each command is saved in the history list,
2022-08-24 15:22:41 +02:00
the size of which is controlled by the HISTSIZE parameter. The one most
recent command is always retained in any case. Each saved command in the
history list is called a history <em>event</em> and is assigned a number,
beginning with 1 (one) when the shell starts up. The history number that
you may see in your prompt (see <a href="Prompt-Expansion.html#Prompt-Expansion">Prompt
2021-05-11 02:29:21 +02:00
Expansion</a>) is the number that
is to be assigned to the <em>next</em> command.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Overview"></span> <span id="Overview-1"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="1411-overview"><a class="header" href="#1411-overview">14.1.1 Overview</a></h3>
<p><span id="index-histchars_002c-use-of-1"></span></p>
2022-08-24 15:22:41 +02:00
<p>A history expansion begins with the first character of the histchars
parameter, which is ! by default, and may occur anywhere on the
2021-05-11 02:29:21 +02:00
command line, including inside double quotes (but not inside single
2022-08-24 15:22:41 +02:00
quotes ... or C-style quotes $... nor when escaped with a
2021-05-11 02:29:21 +02:00
backslash).</p>
<p>The first character is followed by an optional event designator (<a href="Expansion.html#Event-Designators">Event
Designators</a>) and then an optional word designator
(<a href="Expansion.html#Word-Designators">Word Designators</a>); if neither of these designators
is present, no history expansion occurs.</p>
<p>Input lines containing history expansions are echoed after being
expanded, but before any other expansions take place and before the
command is executed. It is this expanded form that is recorded as the
history event for later references.</p>
<p>History expansions do not nest.</p>
<p>By default, a history reference with no event designator refers to the
same event as any preceding history reference on that command line; if
it is the only history reference in a command, it refers to the previous
command. <span id="index-CSH_005fJUNKIE_005fHISTORY_002c-use-of"></span>
2022-08-24 15:22:41 +02:00
However, if the option CSH_JUNKIE_HISTORY is set, then every history
2021-05-11 02:29:21 +02:00
reference with no event specification <em>always</em> refers to the previous
command.</p>
2022-08-24 15:22:41 +02:00
<p>For example, ! is the event designator for the previous command, so
!!:1 always refers to the first word of the previous command, and
!!$ always refers to the last word of the previous command. With
CSH_JUNKIE_HISTORY set, then !:1 and !$ function in the same manner
as !!:1 and !!$, respectively. Conversely, if CSH_JUNKIE_HISTORY is
unset, then !:1 and !$ refer to the first and last words,
respectively, of the same event referenced by the nearest other history
reference preceding them on the current command line, or to the previous
command if there is no preceding reference.</p>
<p>The character sequence ^<code>foo</code>^<code>bar</code> (where ^ is actually the second
character of the histchars parameter) repeats the last command,
2021-05-11 02:29:21 +02:00
replacing the string <code>foo</code> with <code>bar</code>. More precisely, the sequence
2022-08-24 15:22:41 +02:00
^<code>foo</code>^<code>bar</code>^ is synonymous with !!:s^<code>foo</code>^<code>bar</code>^, hence other
modifiers (see <a href="Expansion.html#Modifiers">Modifiers</a>) may follow the final ^. In
particular, ^<code>foo</code>^<code>bar</code>^:G performs a global substitution.</p>
<p>If the shell encounters the character sequence !&quot; in the input, the
2021-05-11 02:29:21 +02:00
history mechanism is temporarily disabled until the current list (see
<a href="Shell-Grammar.html#Shell-Grammar">Shell Grammar</a>) is fully parsed. The
2022-08-24 15:22:41 +02:00
!&quot; is removed from the input, and any subsequent ! characters have
no special significance.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-fc_002c-use-of"></span></p>
<p>A less convenient but more comprehensible form of command history
2022-08-24 15:22:41 +02:00
support is provided by the fc builtin.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Event-Designators"></span> <span
id="Event-Designators-1"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="1412-event-designators"><a class="header" href="#1412-event-designators">14.1.2 Event Designators</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-history-event-designators"></span> <span
id="index-event-designators_002c-history"></span></p>
2021-05-11 02:29:21 +02:00
<p>An event designator is a reference to a command-line entry in the
2022-08-24 15:22:41 +02:00
history list. In the list below, remember that the initial ! in each
item may be changed to another character by setting the histchars
2021-05-11 02:29:21 +02:00
parameter.</p>
2022-08-24 15:22:41 +02:00
<p>!<br />
Start a history expansion, except when followed by a blank, newline, =
or (. If followed immediately by a word designator (<a href="Expansion.html#Word-Designators">Word
Designators</a>), this forms a history reference with no
event designator (<a href="Expansion.html#Overview">Overview</a>).</p>
<p>!!<br />
2021-05-11 02:29:21 +02:00
Refer to the previous command. By itself, this expansion repeats the
previous command.</p>
2022-08-24 15:22:41 +02:00
<p>!<code>n</code><br />
2021-05-11 02:29:21 +02:00
Refer to command-line <code>n</code>.</p>
2022-08-24 15:22:41 +02:00
<p>!-<code>n</code><br />
2021-05-11 02:29:21 +02:00
Refer to the current command-line minus <code>n</code>.</p>
2022-08-24 15:22:41 +02:00
<p>!<code>str</code><br />
2021-05-11 02:29:21 +02:00
Refer to the most recent command starting with <code>str</code>.</p>
2022-08-24 15:22:41 +02:00
<p>!?<code>str</code>[?]<br />
Refer to the most recent command containing <code>str</code>. The trailing ? is
necessary if this reference is to be followed by a modifier or followed
by any text that is not to be considered part of <code>str</code>.</p>
<p>!#<br />
Refer to the current command line typed in so far. The line is treated
as if it were complete up to and including the word before the one with
the !# reference.</p>
<p>!{...}<br />
Insulate a history reference from adjacent characters (if necessary).</p>
<hr />
<p><span id="Word-Designators"></span> <span
id="Word-Designators-1"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="1413-word-designators"><a class="header" href="#1413-word-designators">14.1.3 Word Designators</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-history-word-designators"></span> <span
id="index-word-designators_002c-history"></span></p>
2021-05-11 02:29:21 +02:00
<p>A word designator indicates which word or words of a given command line
2022-08-24 15:22:41 +02:00
are to be included in a history reference. A : usually separates the
2021-05-11 02:29:21 +02:00
event specification from the word designator. It may be omitted only if
2022-08-24 15:22:41 +02:00
the word designator begins with a ^, $, *, - or %. Word
designators include:</p>
<p>0<br />
2021-05-11 02:29:21 +02:00
The first input word (command).</p>
<p><code>n</code><br />
The <code>n</code>th argument.</p>
2022-08-24 15:22:41 +02:00
<p>^<br />
The first argument. That is, 1.</p>
<p>$<br />
2021-05-11 02:29:21 +02:00
The last argument.</p>
2022-08-24 15:22:41 +02:00
<p>%<br />
The word matched by (the most recent) ?<code>str</code> search.</p>
<p><code>x</code>-<code>y</code><br />
A range of words; <code>x</code> defaults to 0.</p>
<p>*<br />
2021-05-11 02:29:21 +02:00
All the arguments, or a null value if there are none.</p>
2022-08-24 15:22:41 +02:00
<p><code>x</code>*<br />
Abbreviates <code>x</code>-$.</p>
<p><code>x</code>-<br />
Like <code>x</code>* but omitting word $.</p>
<p>Note that a % word designator works only when used in one of !%,
!:% or !?<code>str</code>?:%, and only when used after a !? expansion (possibly
in an earlier command). Anything else results in an error, although the
error may not be the most obvious one.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Modifiers"></span> <span id="Modifiers-1"></span></p>
<h3 id="1414-modifiers"><a class="header" href="#1414-modifiers">14.1.4 Modifiers</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-modifiers"></span> <span
id="index-colon-modifiers"></span> <span
id="index-history-modifiers"></span> <span
id="index-globbing-modifiers"></span> <span
id="index-parameter-modifiers"></span></p>
2021-05-11 02:29:21 +02:00
<p>After the optional word designator, you can add a sequence of one or
2022-08-24 15:22:41 +02:00
more of the following modifiers, each preceded by a :. These modifiers
also work on the result of <em>filename generation</em> and <em>parameter
expansion</em>, except where noted.</p>
<p>a<br />
Turn a file name into an absolute path: prepends the current directory,
if necessary; remove . path segments; and remove .. path segments
and the segments that immediately precede them.</p>
<p>This transformation is agnostic about what is in the filesystem, i.e. is
on the logical, not the physical directory. It takes place in the same
manner as when changing directories when neither of the options
CHASE_DOTS or CHASE_LINKS is set. For example, /before/here/../after
is always transformed to /before/after, regardless of whether
/before/here exists or what kind of object (dir, file, symlink, etc.)
it is.</p>
<p>A<br />
Turn a file name into an absolute path as the a modifier does, and
<em>then</em> pass the result through the realpath(3) library function to
resolve symbolic links.</p>
<p>Note: on systems that do not have a realpath(3) library function,
symbolic links are not resolved, so on those systems a and A are
equivalent.</p>
<p>Note: foo:A and realpath(foo) are different on some inputs. For
realpath(foo) semantics, see the P modifier.</p>
<p>c<br />
Resolve a command name into an absolute path by searching the command
path given by the PATH variable. This does not work for commands
containing directory parts. Note also that this does not usually work as
a glob qualifier unless a file of the same name is found in the current
directory.</p>
<p>e<br />
Remove all but the part of the filename extension following the .; see
the definition of the filename extension in the description of the r
modifier below. Note that according to that definition the result will
be empty if the string ends with a ..</p>
<p>h [ <code>digits</code> ]<br />
2021-05-11 02:29:21 +02:00
Remove a trailing pathname component, shortening the path by one
directory level: this is the head of the pathname. This works like
2022-08-24 15:22:41 +02:00
dirname. If the h is followed immediately (with no spaces or other
separator) by any number of decimal digits, and the value of the
resulting number is non-zero, that number of leading components is
preserved instead of the final component being removed. In an absolute
path the leading / is the first component, so, for example, if
var=/my/path/to/something, then ${var:h3} substitutes /my/path.
Consecutive /s are treated the same as a single /. In parameter
substitution, digits may only be used if the expression is in braces, so
for example the short form substitution $var:h2 is treated as ${var:h}2,
not as ${var:h2}. No restriction applies to the use of digits in history
substitution or globbing qualifiers. If more components are requested
than are present, the entire path is substituted (so this does not
trigger a failed modifier error in history expansion).</p>
<p>l<br />
2021-05-11 02:29:21 +02:00
Convert the words to all lowercase.</p>
2022-08-24 15:22:41 +02:00
<p>p<br />
2021-05-11 02:29:21 +02:00
Print the new command but do not execute it. Only works with history
expansion.</p>
2022-08-24 15:22:41 +02:00
<p>P<br />
Turn a file name into an absolute path, like realpath(3). The resulting
path will be absolute, will refer to the same directory entry as the
input filename, and none of its components will be symbolic links or
equal to . or ...</p>
<p>Unlike realpath(3), non-existent trailing components are permitted and
preserved.</p>
<p>q<br />
Quote the substituted words, escaping further substitutions. Works with
history expansion and parameter expansion, though for parameters it is
only useful if the resulting text is to be re-evaluated such as by eval.</p>
<p>Q<br />
2021-05-11 02:29:21 +02:00
Remove one level of quotes from the substituted words.</p>
2022-08-24 15:22:41 +02:00
<p>r<br />
2021-05-11 02:29:21 +02:00
Remove a filename extension leaving the root name. Strings with no
2022-08-24 15:22:41 +02:00
filename extension are not altered. A filename extension is a .
followed by any number of characters (including zero) that are neither
. nor / and that continue to the end of the string. For example, the
extension of foo.orig.c is .c, and dir.c/foo has no extension.</p>
<p>s/<code>l</code>/<code>r</code>[/]<br />
Substitute <code>r</code> for <code>l</code> as described below. The substitution is done only
for the first string that matches <code>l</code>. For arrays and for filename
generation, this applies to each word of the expanded text. See below
for further notes on substitutions.</p>
<p>The forms gs/<code>l</code>/<code>r</code> and s/<code>l</code>/<code>r</code>/:G perform global substitution,
i.e. substitute every occurrence of <code>r</code> for <code>l</code>. Note that the g or :G
must appear in exactly the position shown.</p>
2021-05-11 02:29:21 +02:00
<p>See further notes on this form of substitution below.</p>
2022-08-24 15:22:41 +02:00
<p>&amp;<br />
Repeat the previous s substitution. Like s, may be preceded immediately
by a g. In parameter expansion the &amp; must appear inside braces, and in
filename generation it must be quoted with a backslash.</p>
<p>t [ <code>digits</code> ]<br />
2021-05-11 02:29:21 +02:00
Remove all leading pathname components, leaving the final component
2022-08-24 15:22:41 +02:00
(tail). This works like basename. Any trailing slashes are first
removed. Decimal digits are handled as described above for (h), but in
this case that number of trailing components is preserved instead of the
default 1; 0 is treated the same as 1.</p>
<p>u<br />
2021-05-11 02:29:21 +02:00
Convert the words to all uppercase.</p>
2022-08-24 15:22:41 +02:00
<p>x<br />
Like q, but break into words at whitespace. Does not work with parameter
expansion.</p>
<p>The s/<code>l</code>/<code>r</code>/ substitution works as follows. By default the left-hand
side of substitutions are not patterns, but character strings. Any
character can be used as the delimiter in place of /. A backslash
quotes the delimiter character. The character &amp;, in the
2021-05-11 02:29:21 +02:00
right-hand-side <code>r</code>, is replaced by the text from the left-hand-side
2022-08-24 15:22:41 +02:00
<code>l</code>. The &amp; can be quoted with a backslash. A null <code>l</code> uses the
2021-05-11 02:29:21 +02:00
previous string either from the previous <code>l</code> or from the contextual scan
2022-08-24 15:22:41 +02:00
string <code>s</code> from !?<code>s</code>. You can omit the rightmost delimiter if a
newline immediately follows <code>r</code>; the rightmost ? in a context scan can
similarly be omitted. Note the same record of the last <code>l</code> and <code>r</code> is
maintained across all forms of expansion.</p>
<p>Note that if a &amp; is used within glob qualifiers an extra backslash is
needed as a &amp; is a special character in this case.</p>
2021-05-11 02:29:21 +02:00
<p>Also note that the order of expansions affects the interpretation of <code>l</code>
and <code>r</code>. When used in a history expansion, which occurs before any other
expansions, <code>l</code> and <code>r</code> are treated as literal strings (except as
2022-08-24 15:22:41 +02:00
explained for HIST_SUBST_PATTERN below). When used in parameter
2021-05-11 02:29:21 +02:00
expansion, the replacement of <code>r</code> into the parameters value is done
first, and then any additional process, parameter, command, arithmetic,
or brace references are applied, which may evaluate those substitutions
and expansions more than once if <code>l</code> appears more than once in the
starting value. When used in a glob qualifier, any substitutions or
expansions are performed once at the time the qualifier is parsed, even
2022-08-24 15:22:41 +02:00
before the :s expression itself is divided into <code>l</code> and <code>r</code> sides.</p>
<p>If the option HIST_SUBST_PATTERN is set, <code>l</code> is treated as a pattern of
the usual form described in <a href="Expansion.html#Filename-Generation">Filename Generation</a>.
This can be used in all the places where modifiers are available; note,
however, that in globbing qualifiers parameter substitution has already
taken place, so parameters in the replacement string should be quoted to
ensure they are replaced at the correct time. Note also that complicated
patterns used in globbing qualifiers may need the extended glob
qualifier notation (#q:s/<code>...</code>/<code>...</code>/) in order for the shell to
recognize the expression as a glob qualifier. Further, note that bad
patterns in the substitution are not subject to the NO_BAD_PATTERN
option so will cause an error.</p>
<p>When HIST_SUBST_PATTERN is set, <code>l</code> may start with a # to indicate that
the pattern must match at the start of the string to be substituted, and
a % may appear at the start or after an # to indicate that the pattern
must match at the end of the string to be substituted. The % or # may be
quoted with two backslashes.</p>
2021-05-11 02:29:21 +02:00
<p>For example, the following piece of filename generation code with the
2022-08-24 15:22:41 +02:00
EXTENDED_GLOB option:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">print -r -- *.c(#q:s/#%(#b)s(*).c/'S${match[1]}.C'/)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>takes the expansion of *.c and applies the glob qualifiers in the
(#q<code>...</code>) expression, which consists of a substitution modifier anchored
to the start and end of each word (#%). This turns on backreferences
((#b)), so that the parenthesised subexpression is available in the
replacement string as ${match[1]}. The replacement string is quoted so
that the parameter is not substituted before the start of filename
generation.</p>
<p>The following f, F, w and W modifiers work only with parameter expansion
and filename generation. They are listed here to provide a single point
of reference for all modifiers.</p>
<p>f<br />
Repeats the immediately (without a colon) following modifier until the
resulting word doesnt change any more.</p>
<p>F:<code>expr</code>:<br />
Like f, but repeats only <code>n</code> times if the expression <code>expr</code> evaluates to
<code>n</code>. Any character can be used instead of the :; if (, [, or {
is used as the opening delimiter, the closing delimiter should be ),
], or }, respectively.</p>
<p>w<br />
2021-05-11 02:29:21 +02:00
Makes the immediately following modifier work on each word in the
string.</p>
2022-08-24 15:22:41 +02:00
<p>W:<code>sep</code>:<br />
Like w but words are considered to be the parts of the string that are
separated by <code>sep</code>. Any character can be used instead of the :;
opening parentheses are handled specially, see above.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Process-Substitution"></span> <span
id="Process-Substitution-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="142-process-substitution"><a class="header" href="#142-process-substitution">14.2 Process Substitution</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-process-substitution"></span> <span
id="index-substitution_002c-process"></span></p>
<p>Each part of a command argument that takes the form &lt;(<code>list</code>),
&gt;(<code>list</code>) or =(<code>list</code>) is subject to process substitution. The
expression may be preceded or followed by other strings except that, to
prevent clashes with commonly occurring strings and patterns, the last
form must occur at the start of a command argument, and the forms are
only expanded when first parsing command or assignment arguments.
2021-05-11 02:29:21 +02:00
Process substitutions may be used following redirection operators; in
this case, the substitution must appear with no trailing string.</p>
2022-08-24 15:22:41 +02:00
<p>Note that &lt;&lt;(<code>list</code>) is not a special syntax; it is equivalent to
&lt; &lt;(<code>list</code>), redirecting standard input from the result of process
substitution. Hence all the following documentation applies. The second
form (with the space) is recommended for clarity.</p>
<p>In the case of the &lt; or &gt; forms, the shell runs the commands in <code>list</code>
as a subprocess of the job executing the shell command line. If the
system supports the /dev/fd mechanism, the command argument is the name
of the device file corresponding to a file descriptor; otherwise, if the
system supports named pipes (FIFOs), the command argument will be a
named pipe. If the form with &gt; is selected then writing on this special
file will provide input for <code>list</code>. If &lt; is used, then the file passed
as an argument will be connected to the output of the <code>list</code> process.
For example,</p>
<div class="example">
<pre><code class="language-zsh">paste &lt;(cut -f1 file1) &lt;(cut -f3 file2) |
2021-05-11 02:29:21 +02:00
tee &gt;(process1) &gt;(process2) &gt;/dev/null
</code></pre>
</div>
<p>cuts fields 1 and 3 from the files <code>file1</code> and <code>file2</code> respectively,
pastes the results together, and sends it to the processes <code>process1</code>
and <code>process2</code>.</p>
2022-08-24 15:22:41 +02:00
<p>If =(<code>...</code>) is used instead of &lt;(<code>...</code>), then the file passed as an
argument will be the name of a temporary file containing the output of
the <code>list</code> process. This may be used instead of the &lt; form for a
program that expects to lseek (see lseek(2)) on the input file.</p>
<p>There is an optimisation for substitutions of the form =(&lt;&lt;&lt;<code>arg</code>),
2021-05-11 02:29:21 +02:00
where <code>arg</code> is a single-word argument to the here-string redirection
2022-08-24 15:22:41 +02:00
&lt;&lt;&lt;. This form produces a file name containing the value of <code>arg</code>
2021-05-11 02:29:21 +02:00
after any substitutions have been performed. This is handled entirely
within the current shell. This is effectively the reverse of the special
2022-08-24 15:22:41 +02:00
form $(&lt;<code>arg</code>) which treats <code>arg</code> as a file name and replaces it with
the files contents.</p>
<p>The = form is useful as both the /dev/fd and the named pipe
implementation of &lt;(<code>...</code>) have drawbacks. In the former case, some
2021-05-11 02:29:21 +02:00
programmes may automatically close the file descriptor in question
before examining the file on the command line, particularly if this is
necessary for security reasons such as when the programme is running
setuid. In the second case, if the programme does not actually open the
file, the subshell attempting to read from or write to the pipe will (in
a typical implementation, different operating systems may have different
behaviour) block for ever and have to be killed explicitly. In both
cases, the shell actually supplies the information using a pipe, so that
2022-08-24 15:22:41 +02:00
programmes that expect to lseek (see lseek(2)) on the file will not
work.</p>
2021-05-11 02:29:21 +02:00
<p>Also note that the previous example can be more compactly and
2022-08-24 15:22:41 +02:00
efficiently written (provided the MULTIOS option is set) as:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">paste &lt;(cut -f1 file1) &lt;(cut -f3 file2) &gt; &gt;(process1) &gt; &gt;(process2)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>The shell uses pipes instead of FIFOs to implement the latter two
process substitutions in the above example.</p>
2022-08-24 15:22:41 +02:00
<p>There is an additional problem with &gt;(<code>process</code>); when this is attached
to an external command, the parent shell does not wait for <code>process</code> to
finish and hence an immediately following command cannot rely on the
results being complete. The problem and solution are the same as
described in the section <em>MULTIOS</em> in
2021-05-11 02:29:21 +02:00
<a href="Redirection.html#Redirection">Redirection</a>. Hence in a simplified
version of the example above:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">paste &lt;(cut -f1 file1) &lt;(cut -f3 file2) &gt; &gt;(process)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>(note that no MULTIOS are involved), <code>process</code> will be run
2021-05-11 02:29:21 +02:00
asynchronously as far as the parent shell is concerned. The workaround
is:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">{ paste &lt;(cut -f1 file1) &lt;(cut -f3 file2) } &gt; &gt;(process)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>The extra processes here are spawned from the parent shell which will
wait for their completion.</p>
<p>Another problem arises any time a job with a substitution that requires
2022-08-24 15:22:41 +02:00
a temporary file is disowned by the shell, including the case where &amp;!
or &amp;| appears at the end of a command containing a substitution. In
that case the temporary file will not be cleaned up as the shell no
longer has any memory of the job. A workaround is to use a subshell, for
example,</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">(mycmd =(myoutput)) &amp;!
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>as the forked subshell will wait for the command to finish then remove
the temporary file.</p>
<p>A general workaround to ensure a process substitution endures for an
appropriate length of time is to pass it as a parameter to an anonymous
shell function (a piece of shell code that is run immediately with
function scope). For example, this code:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">() {
2021-05-11 02:29:21 +02:00
print File $1:
cat $1
} =(print This be the verse)
</code></pre>
</div>
<p>outputs something resembling the following</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">File /tmp/zsh6nU0kS:
2021-05-11 02:29:21 +02:00
This be the verse
</code></pre>
</div>
<p>The temporary file created by the process substitution will be deleted
when the function exits.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Parameter-Expansion"></span> <span
id="Parameter-Expansion-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="143-parameter-expansion"><a class="header" href="#143-parameter-expansion">14.3 Parameter Expansion</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-parameter-expansion"></span> <span
id="index-expansion_002c-parameter"></span></p>
<p>The character $ is used to introduce parameter expansions. See
2021-05-11 02:29:21 +02:00
<a href="Parameters.html#Parameters">Parameters</a> for a description of
parameters, including arrays, associative arrays, and subscript notation
to access individual array elements.</p>
<p>Note in particular the fact that words of unquoted parameters are not
2022-08-24 15:22:41 +02:00
automatically split on whitespace unless the option SH_WORD_SPLIT is
2021-05-11 02:29:21 +02:00
set; see references to this option below for more details. This is an
important difference from other shells. However, as in other shells,
null words are elided from unquoted parameters expansions.</p>
<p>With default options, after the assignments:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">array=(&quot;first word&quot; &quot;&quot; &quot;third word&quot;)
2021-05-11 02:29:21 +02:00
scalar=&quot;only word&quot;
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>then $array substitutes two words, first word and third word, and
$scalar substitutes a single word only word. Note that second element
of array was elided. Scalar parameters can be elided too if their value
is null (empty). To avoid elision, use quoting as follows: &quot;$scalar&quot; for
scalars and &quot;${array[@]}&quot; or &quot;${(@)array}&quot; for arrays. (The last two
forms are equivalent.)</p>
<p>Parameter expansions can involve <em>flags</em>, as in ${(@kv)aliases}, and
other operators, such as ${PREFIX:-&quot;/usr/local&quot;}. Parameter expansions
can also be nested. These topics will be introduced below. The full
rules are complicated and are noted at the end.</p>
2021-05-11 02:29:21 +02:00
<p>In the expansions discussed below that require a pattern, the form of
the pattern is the same as that used for filename generation; see
<a href="Expansion.html#Filename-Generation">Filename Generation</a>. Note that these patterns,
along with the replacement text of any substitutions, are themselves
subject to parameter expansion, command substitution, and arithmetic
expansion. In addition to the following operations, the colon modifiers
described in <a href="Expansion.html#Modifiers">Modifiers</a> in <a href="Expansion.html#History-Expansion">History
Expansion</a> can be applied: for example,
2022-08-24 15:22:41 +02:00
${i:s/foo/bar/} performs string substitution on the expansion of
parameter $i.</p>
2021-05-11 02:29:21 +02:00
<p>In the following descriptions, <code>word</code> refers to a single word
substituted on the command line, not necessarily a space delimited word.</p>
2022-08-24 15:22:41 +02:00
<p>${<code>name</code>}<br />
The value, if any, of the parameter <code>name</code> is substituted. The braces
are required if the expansion is to be followed by a letter, digit, or
underscore that is not to be interpreted as part of <code>name</code>. In addition,
more complicated forms of substitution usually require the braces to be
present; exceptions, which only apply if the option KSH_ARRAYS is not
set, are a single subscript or any colon modifiers appearing after the
name, or any of the characters ^, =, ~, # or + appearing
before the name, all of which work with or without braces.</p>
<p>If <code>name</code> is an array parameter, and the KSH_ARRAYS option is not set,
then the value of each element of <code>name</code> is substituted, one element per
word. Otherwise, the expansion results in one word only; with
KSH_ARRAYS, this is the first element of an array. No field splitting is
done on the result unless the SH_WORD_SPLIT option is set. See also the
flags = and s:<code>string</code>:.</p>
<p>${+<code>name</code>}<br />
If <code>name</code> is the name of a set parameter 1 is substituted, otherwise
0 is substituted.</p>
<p>${<code>name</code>-<code>word</code>}<br />
${<code>name</code>:-<code>word</code>}<br />
If <code>name</code> is set, or in the second form is non-null, then substitute its
value; otherwise substitute <code>word</code>. In the second form <code>name</code> may be
omitted, in which case <code>word</code> is always substituted.</p>
<p>${<code>name</code>+<code>word</code>}<br />
${<code>name</code>:+<code>word</code>}<br />
2021-05-11 02:29:21 +02:00
If <code>name</code> is set, or in the second form is non-null, then substitute
<code>word</code>; otherwise substitute nothing.</p>
2022-08-24 15:22:41 +02:00
<p>${<code>name</code>=<code>word</code>}<br />
${<code>name</code>:=<code>word</code>}<br />
${<code>name</code>::=<code>word</code>}<br />
2021-05-11 02:29:21 +02:00
In the first form, if <code>name</code> is unset then set it to <code>word</code>; in the
2022-08-24 15:22:41 +02:00
second form, if <code>name</code> is unset or null then set it to <code>word</code>; and in
the third form, unconditionally set <code>name</code> to <code>word</code>. In all forms, the
value of the parameter is then substituted.</p>
<p>${<code>name</code>?<code>word</code>}<br />
${<code>name</code>:?<code>word</code>}<br />
In the first form, if <code>name</code> is set, or in the second form if <code>name</code> is
both set and non-null, then substitute its value; otherwise, print
<code>word</code> and exit from the shell. Interactive shells instead return to the
prompt. If <code>word</code> is omitted, then a standard message is printed.</p>
2021-05-11 02:29:21 +02:00
<p>In any of the above expressions that test a variable and substitute an
alternate <code>word</code>, note that you can use standard shell quoting in the
<code>word</code> value to selectively override the splitting done by the
2022-08-24 15:22:41 +02:00
SH_WORD_SPLIT option and the = flag, but not splitting by the
s:<code>string</code>: flag.</p>
2021-05-11 02:29:21 +02:00
<p>In the following expressions, when <code>name</code> is an array and the
2022-08-24 15:22:41 +02:00
substitution is not quoted, or if the (@) flag or the <code>name</code>[@]
2021-05-11 02:29:21 +02:00
syntax is used, matching and replacement is performed on each array
element separately.</p>
2022-08-24 15:22:41 +02:00
<p>${<code>name</code>#<code>pattern</code>}<br />
${<code>name</code>##<code>pattern</code>}<br />
2021-05-11 02:29:21 +02:00
If the <code>pattern</code> matches the beginning of the value of <code>name</code>, then
substitute the value of <code>name</code> with the matched portion deleted;
2022-08-24 15:22:41 +02:00
otherwise, just substitute the value of <code>name</code>. In the first form, the
smallest matching pattern is preferred; in the second form, the largest
matching pattern is preferred.</p>
<p>${<code>name</code>%<code>pattern</code>}<br />
${<code>name</code>%%<code>pattern</code>}<br />
If the <code>pattern</code> matches the end of the value of <code>name</code>, then substitute
the value of <code>name</code> with the matched portion deleted; otherwise, just
substitute the value of <code>name</code>. In the first form, the smallest matching
pattern is preferred; in the second form, the largest matching pattern
is preferred.</p>
<p>${<code>name</code>:#<code>pattern</code>}<br />
If the <code>pattern</code> matches the value of <code>name</code>, then substitute the empty
string; otherwise, just substitute the value of <code>name</code>. If <code>name</code> is an
array the matching array elements are removed (use the (M) flag to
remove the non-matched elements).</p>
<p>${<code>name</code>:|<code>arrayname</code>}<br />
If <code>arrayname</code> is the name (N.B., not contents) of an array variable,
then any elements contained in <code>arrayname</code> are removed from the
substitution of <code>name</code>. If the substitution is scalar, either because
<code>name</code> is a scalar variable or the expression is quoted, the elements of
<code>arrayname</code> are instead tested against the entire expression.</p>
<p>${<code>name</code>:*<code>arrayname</code>}<br />
2021-05-11 02:29:21 +02:00
Similar to the preceding substitution, but in the opposite sense, so
2022-08-24 15:22:41 +02:00
that entries present in both the original substitution and as elements
of <code>arrayname</code> are retained and others removed.</p>
<p>${<code>name</code>:^<code>arrayname</code>}<br />
${<code>name</code>:^^<code>arrayname</code>}<br />
2021-05-11 02:29:21 +02:00
Zips two arrays, such that the output array is twice as long as the
2022-08-24 15:22:41 +02:00
shortest (longest for :^^) of name and arrayname, with the elements
alternatingly being picked from them. For :^, if one of the input
arrays is longer, the output will stop when the end of the shorter array
is reached. Thus,</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">a=(1 2 3 4); b=(a b); print ${a:^b}
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>will output 1 a 2 b. For :^^, then the input is repeated until all
of the longer array has been used up and the above will output 1 a 2 b
3 a 4 b.</p>
<p>Either or both inputs may be a scalar, they will be treated as an array
of length 1 with the scalar as the only element. If either array is
empty, the other array is output with no extra elements inserted.</p>
<p>Currently the following code will output a b and 1 as two separate
elements, which can be unexpected. The second print provides a
workaround which should continue to work if this is changed.</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">a=(a b); b=(1 2); print -l &quot;${a:^b}&quot;; print -l &quot;${${a:^b}}&quot;
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>${<code>name</code>:<code>offset</code>}<br />
${<code>name</code>:<code>offset</code>:<code>length</code>}<br />
This syntax gives effects similar to parameter subscripting in the form
$<code>name</code>[<code>start</code>,<code>end</code>], but is compatible with other shells; note that
both <code>offset</code> and <code>length</code> are interpreted differently from the
components of a subscript.</p>
2021-05-11 02:29:21 +02:00
<p>If <code>offset</code> is non-negative, then if the variable <code>name</code> is a scalar
substitute the contents starting <code>offset</code> characters from the first
2022-08-24 15:22:41 +02:00
character of the string, and if <code>name</code> is an array substitute elements
starting <code>offset</code> elements from the first element. If <code>length</code> is given,
substitute that many characters or elements, otherwise the entire rest
of the scalar or array.</p>
<p>A positive <code>offset</code> is always treated as the offset of a character or
element in <code>name</code> from the first character or element of the array (this
is different from native zsh subscript notation). Hence 0 refers to the
first character or element regardless of the setting of the option
KSH_ARRAYS.</p>
<p>A negative offset counts backwards from the end of the scalar or array,
so that -1 corresponds to the last character or element, and so on.</p>
<p>When positive, <code>length</code> counts from the <code>offset</code> position toward the end
of the scalar or array. When negative, <code>length</code> counts back from the
end. If this results in a position smaller than <code>offset</code>, a diagnostic
is printed and nothing is substituted.</p>
<p>The option MULTIBYTE is obeyed, i.e. the offset and length count
2021-05-11 02:29:21 +02:00
multibyte characters where appropriate.</p>
2022-08-24 15:22:41 +02:00
<p><code>offset</code> and <code>length</code> undergo the same set of shell substitutions as for
scalar assignment; in addition, they are then subject to arithmetic
evaluation. Hence, for example</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">print ${foo:3}
2021-05-11 02:29:21 +02:00
print ${foo: 1 + 2}
print ${foo:$(( 1 + 2))}
print ${foo:$(echo 1 + 2)}
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>all have the same effect, extracting the string starting at the fourth
character of $foo if the substitution would otherwise return a scalar,
or the array starting at the fourth element if $foo would return an
array. Note that with the option KSH_ARRAYS $foo always returns a scalar
(regardless of the use of the offset syntax) and a form such as
${foo[*]:3} is required to extract elements of an array named foo.</p>
<p>If <code>offset</code> is negative, the - may not appear immediately after the : as
this indicates the ${<code>name</code>:-<code>word</code>} form of substitution. Instead, a
space may be inserted before the -. Furthermore, neither <code>offset</code> nor
<code>length</code> may begin with an alphabetic character or &amp; as these are used
to indicate history-style modifiers. To substitute a value from a
variable, the recommended approach is to precede it with a $ as this
signifies the intention (parameter substitution can easily be rendered
2021-05-11 02:29:21 +02:00
unreadable); however, as arithmetic substitution is performed, the
2022-08-24 15:22:41 +02:00
expression ${var: offs} does work, retrieving the offset from $offs.</p>
<p>For further compatibility with other shells there is a special case for
array offset 0. This usually accesses the first element of the array.
However, if the substitution refers to the positional parameter array,
e.g. $@ or $*, then offset 0 instead refers to $0, offset 1 refers to
$1, and so on. In other words, the positional parameter array is
effectively extended by prepending $0. Hence ${*:0:1} substitutes $0
and ${*:1:1} substitutes $1.</p>
<p>${<code>name</code>/<code>pattern</code>/<code>repl</code>}<br />
${<code>name</code>//<code>pattern</code>/<code>repl</code>}<br />
${<code>name</code>:/<code>pattern</code>/<code>repl</code>}<br />
2021-05-11 02:29:21 +02:00
Replace the longest possible match of <code>pattern</code> in the expansion of
parameter <code>name</code> by string <code>repl</code>. The first form replaces just the
2022-08-24 15:22:41 +02:00
first occurrence, the second form all occurrences, and the third form
replaces only if <code>pattern</code> matches the entire string. Both <code>pattern</code> and
<code>repl</code> are subject to double-quoted substitution, so that expressions
like ${name/$opat/$npat} will work, but obey the usual rule that pattern
characters in $opat are not treated specially unless either the option
GLOB_SUBST is set, or $opat is instead substituted as ${~opat}.</p>
<p>The <code>pattern</code> may begin with a #, in which case the <code>pattern</code> must
match at the start of the string, or %, in which case it must match at
the end of the string, or #% in which case the <code>pattern</code> must match
the entire string. The <code>repl</code> may be an empty string, in which case the
final / may also be omitted. To quote the final / in other cases it
should be preceded by a single backslash; this is not necessary if the
/ occurs inside a substituted parameter. Note also that the #, %
and #% are not active if they occur inside a substituted parameter,
even at the start.</p>
<p>If, after quoting rules apply, ${<code>name</code>} expands to an array, the
replacements act on each element individually. Note also the effect of
the I and S parameter expansion flags below; however, the flags M, R, B,
E and N are not useful.</p>
2021-05-11 02:29:21 +02:00
<p>For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">foo=&quot;twinkle twinkle little star&quot; sub=&quot;t*e&quot; rep=&quot;spy&quot;
2021-05-11 02:29:21 +02:00
print ${foo//${~sub}/$rep}
print ${(S)foo//${~sub}/$rep}
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Here, the ~ ensures that the text of $sub is treated as a pattern
rather than a plain string. In the first case, the longest match for
t*e is substituted and the result is spy star, while in the second
case, the shortest matches are taken and the result is spy spy lispy
star.</p>
<p>${#<code>spec</code>}<br />
If <code>spec</code> is one of the above substitutions, substitute the length in
characters of the result instead of the result itself. If <code>spec</code> is an
array expression, substitute the number of elements of the result. This
has the side-effect that joining is skipped even in quoted forms, which
may affect other sub-expressions in <code>spec</code>. Note that ^, =, and
~, below, must appear to the left of # when these forms are
combined.</p>
<p>If the option POSIX_IDENTIFIERS is not set, and <code>spec</code> is a simple name,
then the braces are optional; this is true even for special parameters
so e.g. $#- and $#* take the length of the string $- and the array $*
respectively. If POSIX_IDENTIFIERS is set, then braces are required for
the # to be treated in this fashion.</p>
<p>${^<code>spec</code>}<br />
${^^<code>spec</code>}<br />
<span id="index-RC_005fEXPAND_005fPARAM_002c-toggle"></span> <span
id="index-array-expansion-style_002c-rc"></span> <span
id="index-rc_002c-array-expansion-style"></span></p>
<p>Turn on the RC_EXPAND_PARAM option for the evaluation of <code>spec</code>; if the
^ is doubled, turn it off. When this option is set, array expansions
of the form <code>foo</code>${<code>xx</code>}<code>bar</code>, where the parameter <code>xx</code> is set to
(<code>a b c</code>), are substituted with <code>fooabar foobbar foocbar</code> instead of
the default <code>fooa b cbar</code>. Note that an empty array will therefore
cause all arguments to be removed.</p>
<p>Internally, each such expansion is converted into the equivalent list
for brace expansion. E.g., ${^var} becomes {$var[1],$var[2],...},
and is processed as described in <a href="Expansion.html#Brace-Expansion">Brace Expansion</a>
below: note, however, the expansion happens immediately, with any
explicit brace expansion happening later. If word splitting is also in
effect the $var[<code>N</code>] may themselves be split into different list
elements.</p>
<p>${=<code>spec</code>}<br />
${==<code>spec</code>}<br />
<span id="index-SH_005fWORD_005fSPLIT_002c-toggle"></span> <span
id="index-field-splitting_002c-sh-style_002c-parameter"></span> <span
id="index-sh_002c-field-splitting-style_002c-parameter"></span></p>
<p>Perform word splitting using the rules for SH_WORD_SPLIT during the
evaluation of <code>spec</code>, but regardless of whether the parameter appears in
double quotes; if the = is doubled, turn it off. <span
id="index-IFS_002c-use-of"></span> This forces parameter expansions to
be split into separate words before substitution, using IFS as a
delimiter. This is done by default in most other shells.</p>
2021-05-11 02:29:21 +02:00
<p>Note that splitting is applied to <code>word</code> in the assignment forms of
2022-08-24 15:22:41 +02:00
<code>spec</code> <em>before</em> the assignment to <code>name</code> is performed. This affects the
result of array assignments with the A flag.</p>
<p>${~<code>spec</code>}<br />
${~~<code>spec</code>}<br />
2021-05-11 02:29:21 +02:00
<span id="index-GLOB_005fSUBST_002c-toggle"></span></p>
2022-08-24 15:22:41 +02:00
<p>Turn on the GLOB_SUBST option for the evaluation of <code>spec</code>; if the ~
is doubled, turn it off. When this option is set, the string resulting
from the expansion will be interpreted as a pattern anywhere that is
possible, such as in filename expansion and filename generation and
pattern-matching contexts like the right hand side of the = and !=
operators in conditions.</p>
<p>In nested substitutions, note that the effect of the ~ applies to the
result of the current level of substitution. A surrounding pattern
operation on the result may cancel it. Hence, for example, if the
parameter foo is set to *, ${~foo//\*/*.c} is substituted by the
pattern *.c, which may be expanded by filename generation, but
${${~foo}//\*/*.c} substitutes to the string *.c, which will not be
further expanded.</p>
<p>If a ${...} type parameter expression or a $(...) type command
2021-05-11 02:29:21 +02:00
substitution is used in place of <code>name</code> above, it is expanded first and
the result is used as if it were the value of <code>name</code>. Thus it is
2022-08-24 15:22:41 +02:00
possible to perform nested operations: ${${foo#head}%tail} substitutes
the value of $foo with both head and tail deleted. The form with
$(...) is often useful in combination with the flags described next; see
the examples below. Each <code>name</code> or nested ${...} in a parameter
expansion may also be followed by a subscript expression as described in
<a href="Parameters.html#Array-Parameters">Array Parameters</a>.</p>
2021-05-11 02:29:21 +02:00
<p>Note that double quotes may appear around nested expressions, in which
case only the part inside is treated as quoted; for example,
2022-08-24 15:22:41 +02:00
${(f)&quot;$(foo)&quot;} quotes the result of $(foo), but the flag (f) (see
below) is applied using the rules for unquoted expansions. Note further
that quotes are themselves nested in this context; for example, in
&quot;${(@f)&quot;$(foo)&quot;}&quot;, there are two sets of quotes, one surrounding the
whole expression, the other (redundant) surrounding the $(foo) as
2021-05-11 02:29:21 +02:00
before.</p>
<hr />
<p><span id="Parameter-Expansion-Flags"></span></p>
<h3 id="1431-parameter-expansion-flags"><a class="header" href="#1431-parameter-expansion-flags">14.3.1 Parameter Expansion Flags</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-parameter-expansion-flags"></span> <span
id="index-flags_002c-parameter-expansion"></span> <span
id="index-substitution_002c-parameter_002c-flags"></span></p>
2021-05-11 02:29:21 +02:00
<p>If the opening brace is directly followed by an opening parenthesis, the
string up to the matching closing parenthesis will be taken as a list of
flags. In cases where repeating a flag is meaningful, the repetitions
2022-08-24 15:22:41 +02:00
need not be consecutive; for example, (q%q%q) means the same thing as
the more readable (%%qqq). The following flags are supported:</p>
<h1 id="-1"><a class="header" href="#-1"></a></h1>
<p>Evaluate the resulting words as numeric expressions and interpret these
as character codes. Output the corresponding characters. Note that this
form is entirely distinct from use of the # without parentheses.</p>
<p>If the MULTIBYTE option is set and the number is greater than 127 (i.e.
not an ASCII character) it is treated as a Unicode character.</p>
<p>%<br />
Expand all % escapes in the resulting words in the same way as in
2021-05-11 02:29:21 +02:00
prompts (see <a href="Prompt-Expansion.html#Prompt-Expansion">Prompt
Expansion</a>). If this flag is
given twice, full prompt expansion is done on the resulting words,
2022-08-24 15:22:41 +02:00
depending on the setting of the PROMPT_PERCENT, PROMPT_SUBST and
PROMPT_BANG options.</p>
<p>@<br />
2021-05-11 02:29:21 +02:00
In double quotes, array elements are put into separate words. E.g.,
2022-08-24 15:22:41 +02:00
&quot;${(@)foo}&quot; is equivalent to &quot;${foo[@]}&quot; and &quot;${(@)foo[1,2]}&quot;
is the same as &quot;$foo[1]&quot; &quot;$foo[2]&quot;. This is distinct from <em>field
splitting</em> by the f, s or z flags, which still applies within each array
element.</p>
<p>A<br />
Convert the substitution into an array expression, even if it otherwise
would be scalar. This has lower precedence than subscripting, so one
level of nested expansion is required in order that subscripts apply to
array elements. Thus ${${(A)<code>name</code>}[1]} yields the full value of
<code>name</code> when <code>name</code> is scalar.</p>
<p>This assigns an array parameter with ${...=...}, ${...:=...} or
${...::=...}. If this flag is repeated (as in AA), assigns an
associative array parameter. Assignment is made before sorting or
padding; if field splitting is active, the <code>word</code> part is split before
assignment. The <code>name</code> part may be a subscripted range for ordinary
arrays; when assigning an associative array, the <code>word</code> part <em>must</em> be
converted to an array, for example by using ${(AA)=<code>name</code>=...} to
activate field splitting.</p>
<p>Surrounding context such as additional nesting or use of the value in a
scalar assignment may cause the array to be joined back into a single
string again.</p>
<p>a<br />
Sort in array index order; when combined with O sort in reverse array
index order. Note that a is therefore equivalent to the default but
Oa is useful for obtaining an arrays elements in reverse order.</p>
<p>b<br />
2021-05-11 02:29:21 +02:00
Quote with backslashes only characters that are special to pattern
matching. This is useful when the contents of the variable are to be
2022-08-24 15:22:41 +02:00
tested using GLOB_SUBST, including the ${~<code>...</code>} switch.</p>
<p>Quoting using one of the q family of flags does not work for this
2021-05-11 02:29:21 +02:00
purpose since quotes are not stripped from non-pattern characters by
2022-08-24 15:22:41 +02:00
GLOB_SUBST. In other words,</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">pattern=${(q)str}
2021-05-11 02:29:21 +02:00
[[ $str = ${~pattern} ]]
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>works if $str is a*b but not if it is a b, whereas</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">pattern=${(b)str}
2021-05-11 02:29:21 +02:00
[[ $str = ${~pattern} ]]
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>is always true for any possible value of $str.</p>
<p>c<br />
With ${#<code>name</code>}, count the total number of characters in an array, as if
the elements were concatenated with spaces between them. This is not a
true join of the array, so other expressions used with this flag may
have an effect on the elements of the array before it is counted.</p>
<p>C<br />
Capitalize the resulting words. Words in this case refers to sequences
of alphanumeric characters separated by non-alphanumerics, <em>not</em> to
words that result from field splitting.</p>
<p>D<br />
Assume the string or array elements contain directories and attempt to
substitute the leading part of these by names. The remainder of the path
(the whole of it if the leading part was not substituted) is then quoted
so that the whole string can be used as a shell argument. This is the
reverse of ~ substitution: see <a href="Expansion.html#Filename-Expansion">Filename
2021-05-11 02:29:21 +02:00
Expansion</a>.</p>
2022-08-24 15:22:41 +02:00
<p>e<br />
2021-05-11 02:29:21 +02:00
Perform single word shell expansions, namely <em>parameter expansion</em>,
2022-08-24 15:22:41 +02:00
<em>command substitution</em> and <em>arithmetic expansion</em>, on the result. Such
expansions can be nested but too deep recursion may have</p>
<p>f<br />
Split the result of the expansion at newlines. This is a shorthand for
ps:\n:.</p>
<p>F<br />
Join the words of arrays together using newline as a separator. This is
a shorthand for pj:\n:.</p>
<p>g:<code>opts</code>:<br />
Process escape sequences like the echo builtin when no options are given
(g::). With the o option, octal escapes dont take a leading zero. With
the c option, sequences like ^X are also processed. With the e option,
processes \M-t and similar sequences like the print builtin. With
both of the o and e options, behaves like the print builtin except that
in none of these modes is \c interpreted.</p>
<p>i<br />
Sort case-insensitively. May be combined with n or O.</p>
<p>k<br />
If <code>name</code> refers to an associative array, substitute the <em>keys</em> (element
names) rather than the values of the elements. Used with subscripts
(including ordinary arrays), force indices or keys to be substituted
even if the subscript form refers to values. However, this flag may not
be combined with subscript ranges. With the KSH_ARRAYS option a
subscript [*] or [@] is needed to operate on the whole array,
as usual.</p>
<p>L<br />
2021-05-11 02:29:21 +02:00
Convert all letters in the result to lower case.</p>
2022-08-24 15:22:41 +02:00
<p>n<br />
Sort decimal integers numerically; if the first differing characters of
two test strings are not digits, sorting is lexical. + and - are not
treated specially; they are treated as any other non-digit. Integers
2021-05-11 02:29:21 +02:00
with more initial zeroes are sorted before those with fewer or none.
2022-08-24 15:22:41 +02:00
Hence the array foo+24 foo1 foo02 foo2 foo3 foo20 foo23 is sorted into
the order shown. May be combined with i or O.</p>
<p>-<br />
As n, but a leading minus sign indicates a negative decimal integer. A
leading minus sign not followed by an integer does not trigger numeric
sorting. Note that + signs are not handled specially (this may change
in the future).</p>
<p>o<br />
Sort the resulting words in ascending order; if this appears on its own
the sorting is lexical and case-sensitive (unless the locale renders it
case-insensitive). Sorting in ascending order is the default for other
forms of sorting, so this is ignored if combined with a, i, n or
-.</p>
<p>O<br />
Sort the resulting words in descending order; O without a, i, n
or - sorts in reverse lexical order. May be combined with a, i,
n or - to reverse the order of sorting.</p>
<p>P<br />
2021-05-11 02:29:21 +02:00
This forces the value of the parameter <code>name</code> to be interpreted as a
2022-08-24 15:22:41 +02:00
further parameter name, whose value will be used where appropriate. Note
that flags set with one of the typeset family of commands (in particular
case transformations) are not applied to the value of <code>name</code> used in
this fashion.</p>
<p>If used with a nested parameter or command substitution, the result of
that will be taken as a parameter name in the same way. For example, if
you have foo=bar and bar=baz, the strings ${(P)foo}, ${(P)${foo}},
and ${(P)$(echo bar)} will be expanded to baz.</p>
2021-05-11 02:29:21 +02:00
<p>Likewise, if the reference is itself nested, the expression with the
2022-08-24 15:22:41 +02:00
flag is treated as if it were directly replaced by the parameter name.
It is an error if this nested substitution produces an array with more
than one word. For example, if name=assoc where the parameter assoc is
an associative array, then ${${(P)name}[elt]} refers to the element
of the associative subscripted elt.</p>
<p>q<br />
Quote characters that are special to the shell in the resulting words
with $\<code>NNN</code> form, with separate quotes for each octet.</p>
<p>If this flag is given twice, the resulting words are quoted in single
quotes and if it is given three times, the words are quoted in double
characters is attempted. If the flag is given four times, the words are
quoted in single quotes preceded by a $. Note that in all three of these
forms quoting is done unconditionally, even if this does not change the
way the resulting string would be interpreted by the shell.</p>
<p>If a q- is given (only a single q may appear), a minimal form of single
quoting is used that only quotes the string if needed to protect special
characters. Typically this form gives the most readable output.</p>
<p>If a q+ is given, an extended form of minimal quoting is used that This
quoting is similar to that used by the output of values by the typeset
family of commands.</p>
<p>Q<br />
2021-05-11 02:29:21 +02:00
Remove one level of quotes from the resulting words.</p>
2022-08-24 15:22:41 +02:00
<p>t<br />
Use a string describing the type of the parameter where the value of the
parameter would usually appear. This string consists of keywords
separated by hyphens (-). The first keyword in the string describes
the main type, it can be one of scalar, array, integer, float or
association. The other keywords describe the type in more detail:</p>
<p>local<br />
2021-05-11 02:29:21 +02:00
for local parameters</p>
2022-08-24 15:22:41 +02:00
<p>left<br />
2021-05-11 02:29:21 +02:00
for left justified parameters</p>
2022-08-24 15:22:41 +02:00
<p>right_blanks<br />
2021-05-11 02:29:21 +02:00
for right justified parameters with leading blanks</p>
2022-08-24 15:22:41 +02:00
<p>right_zeros<br />
2021-05-11 02:29:21 +02:00
for right justified parameters with leading zeros</p>
2022-08-24 15:22:41 +02:00
<p>lower<br />
for parameters whose value is converted to all lower case when it is
expanded</p>
<p>upper<br />
for parameters whose value is converted to all upper case when it is
expanded</p>
<p>readonly<br />
2021-05-11 02:29:21 +02:00
for readonly parameters</p>
2022-08-24 15:22:41 +02:00
<p>tag<br />
2021-05-11 02:29:21 +02:00
for tagged parameters</p>
2022-08-24 15:22:41 +02:00
<p>tied<br />
for parameters tied to another parameter in the manner of PATH
(colon-separated list) and path (array), whether these are special
parameters or user-defined with typeset -T</p>
<p>export<br />
2021-05-11 02:29:21 +02:00
for exported parameters</p>
2022-08-24 15:22:41 +02:00
<p>unique<br />
for arrays which keep only the first occurrence of duplicated values</p>
<p>hide<br />
2021-05-11 02:29:21 +02:00
for parameters with the hide flag</p>
2022-08-24 15:22:41 +02:00
<p>hideval<br />
2021-05-11 02:29:21 +02:00
for parameters with the hideval flag</p>
2022-08-24 15:22:41 +02:00
<p>special<br />
2021-05-11 02:29:21 +02:00
for special parameters defined by the shell</p>
2022-08-24 15:22:41 +02:00
<p>u<br />
2021-05-11 02:29:21 +02:00
Expand only the first occurrence of each unique word.</p>
2022-08-24 15:22:41 +02:00
<p>U<br />
2021-05-11 02:29:21 +02:00
Convert all letters in the result to upper case.</p>
2022-08-24 15:22:41 +02:00
<p>v<br />
Used with k, substitute (as two consecutive words) both the key and the
value of each associative array element. Used with subscripts, force
values to be substituted even if the subscript form refers to indices or
keys.</p>
<p>V<br />
2021-05-11 02:29:21 +02:00
Make any special characters in the resulting words visible.</p>
2022-08-24 15:22:41 +02:00
<p>w<br />
With ${#<code>name</code>}, count words in arrays or strings; the s flag may be
used to set a word delimiter.</p>
<p>W<br />
Similar to w with the difference that empty words between repeated
2021-05-11 02:29:21 +02:00
delimiters are also counted.</p>
2022-08-24 15:22:41 +02:00
<p>X<br />
With this flag, parsing errors occurring with the Q, e and # flags or
the pattern matching forms such as ${<code>name</code>#<code>pattern</code>} are reported.
Without the flag, errors are silently ignored.</p>
<p>z<br />
Split the result of the expansion into words using shell parsing to find
the words, i.e. taking into account any quoting in the value. Comments
are not treated specially but as ordinary strings, similar to
interactive shells with the INTERACTIVE_COMMENTS option unset (however,
see the Z flag below for related options)</p>
<p>Note that this is done very late, even later than the (s) flag. So to
access single words in the result use nested expansions as in
${${(z)foo}[2]}. Likewise, to remove the quotes in the resulting
words use ${(Q)${(z)foo}}.</p>
<p>0<br />
Split the result of the expansion on null bytes. This is a shorthand for
ps:\0:.</p>
<p>The following flags (except p) are followed by one or more arguments as
shown. Any character, or the matching pairs (...), {...}, [...],
or &lt;...&gt;, may be used in place of a colon as delimiters, but note
that when a flag takes more than one argument, a matched pair of
delimiters must surround each argument.</p>
<p>p<br />
Recognize the same escape sequences as the print builtin in string
arguments to any of the flags described below that follow this argument.</p>
2021-05-11 02:29:21 +02:00
<p>Alternatively, with this option string arguments may be in the form
2022-08-24 15:22:41 +02:00
$<code>var</code> in which case the value of the variable is substituted. Note this
form is strict; the string argument does not undergo general parameter
expansion.</p>
2021-05-11 02:29:21 +02:00
<p>For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">sep=:
2021-05-11 02:29:21 +02:00
val=a:b:c
print ${(ps.$sep.)val}
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>splits the variable on a :.</p>
<p>~<br />
Strings inserted into the expansion by any of the flags below are to be
treated as patterns. This applies to the string arguments of flags that
follow ~ within the same set of parentheses. Compare with ~ outside
parentheses, which forces the entire substituted string to be treated as
a pattern. Hence, for example,</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">[[ &quot;?&quot; = ${(~j.|.)array} ]]
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>treats | as a pattern and succeeds if and only if $array contains the
string ? as an element. The ~ may be repeated to toggle the
behaviour; its effect only lasts to the end of the parenthesised group.</p>
<p>j:<code>string</code>:<br />
Join the words of arrays together using <code>string</code> as a separator. <span
id="index-SH_005fWORD_005fSPLIT_002c-use-of"></span> Note that this
occurs before field splitting by the s:<code>string</code>: flag or the
SH_WORD_SPLIT option.</p>
<p>l:<code>expr</code>::<code>string1</code>::<code>string2</code>:<br />
2021-05-11 02:29:21 +02:00
Pad the resulting words on the left. Each word will be truncated if
required and placed in a field <code>expr</code> characters wide.</p>
2022-08-24 15:22:41 +02:00
<p>The arguments :<code>string1</code>: and :<code>string2</code>: are optional; neither, the
first, or both may be given. Note that the same pairs of delimiters must
be used for each of the three arguments. The space to the left will be
filled with <code>string1</code> (concatenated as often as needed) or spaces if
<code>string1</code> is not given. If both <code>string1</code> and <code>string2</code> are given,
<code>string2</code> is inserted once directly to the left of each word, truncated
if necessary, before <code>string1</code> is used to produce any remaining padding.</p>
<p>If either of <code>string1</code> or <code>string2</code> is present but empty, i.e. there are
two delimiters together at that point, the first character of $IFS is
used instead.</p>
<p>If the MULTIBYTE option is in effect, the flag m may also be given, in
which case widths will be used for the calculation of padding; otherwise
individual multibyte characters are treated as occupying one unit of
width.</p>
<p>If the MULTIBYTE option is not in effect, each byte in the string is
treated as occupying one unit of width.</p>
<p>Control characters are always assumed to be one unit wide; this allows
the mechanism to be used for generating repetitions of control
characters.</p>
<p>m<br />
Only useful together with one of the flags l or r or with the # length
operator when the MULTIBYTE option is in effect. Use the character width
reported by the system in calculating how much of the string it occupies
or the overall unit, however certain Asian character sets and certain
special effects use wider characters; combining characters have zero
width. would actually be displayed will vary.</p>
<p>If the m is repeated, the character either counts zero (if it has effect
of counting the number of glyphs (visibly separate characters), except
for the case where combining characters themselves have non-zero width
(true in certain alphabets).</p>
<p>r:<code>expr</code>::<code>string1</code>::<code>string2</code>:<br />
As l, but pad the words on the right and insert <code>string2</code> immediately to
the right of the string to be padded.</p>
<p>Left and right padding may be used together. In this case the strategy
is to apply left padding to the first half width of each of the
resulting words, and right padding to the second half. If the string to
be padded has odd width the extra padding is applied on the left.</p>
<p>s:<code>string</code>:<br />
Force field splitting at the separator <code>string</code>. Note that a <code>string</code> of
two or more characters means that all of them must match in sequence;
this differs from the treatment of two or more characters in the IFS
parameter. See also the = flag and the SH_WORD_SPLIT option. An empty
string may also be given in which case every character will be a
separate element.</p>
<p>For historical reasons, the usual behaviour that empty array elements
are retained inside double quotes is disabled for arrays generated by
splitting; hence the following:</p>
<div class="example">
<pre><code class="language-zsh">line=&quot;one::three&quot;
2021-05-11 02:29:21 +02:00
print -l &quot;${(s.:.)line}&quot;
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>produces two lines of output for one and three and elides the empty
field. To override this behaviour, supply the (@) flag as well, i.e.
&quot;${(@s.:.)line}&quot;.</p>
<p>Z:<code>opts</code>:<br />
As z but takes a combination of option letters between a following pair
of delimiter characters. With no options the effect is identical to z.
The following options are available:</p>
<p>(Z+c+)<br />
causes comments to be parsed as a string and retained; any field in the
resulting array beginning with an unquoted comment character is a
comment.</p>
<p>(Z+C+)<br />
causes comments to be parsed and removed. The rule for comments is
standard: anything between a word starting with the third character of
$HISTCHARS, default #, up to the next newline is a comment.</p>
<p>(Z+n+)<br />
causes unquoted newlines to be treated as ordinary whitespace, else they
2021-05-11 02:29:21 +02:00
are treated as if they are shell code delimiters and converted to
2022-08-24 15:22:41 +02:00
semicolons.</p>
<p>Options are combined within the same set of delimiters, e.g. (Z+Cn+).</p>
<p>_:<code>flags</code>:<br />
The underscore (_) flag is reserved for future use. As of this revision
of zsh, there are no valid <code>flags</code>; anything following an underscore,
other than an empty pair of delimiters, is treated as an error, and the
flag itself has no effect.</p>
<p>The following flags are meaningful with the ${...#...} or ${...%...}
forms. The S, I, and * flags may also be used with the ${.../...}
forms.</p>
<p>S<br />
With # or ##, search for the match that starts closest to the start of
the string (a substring match). Of all matches at a particular
position, # selects the shortest and ## the longest:</p>
<div class="example">
<pre><code class="language-zsh">% str=&quot;aXbXc&quot;
2021-05-11 02:29:21 +02:00
% echo ${(S)str#X*}
abXc
% echo ${(S)str##X*}
a
%
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>With % or %%, search for the match that starts closest to the end of the
string:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">% str=&quot;aXbXc&quot;
2021-05-11 02:29:21 +02:00
% echo ${(S)str%X*}
aXbc
% echo ${(S)str%%X*}
aXb
%
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>(Note that % and %% dont search for the match that ends closest to the
end of the string, as one might expect.)</p>
<p>With substitution via ${.../...} or ${...//...}, specifies non-greedy
matching, i.e. that the shortest instead of the longest match should be
replaced:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">% str=&quot;abab&quot;
2021-05-11 02:29:21 +02:00
% echo ${str/*b/_}
_
% echo ${(S)str/*b/_}
_ab
%
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>I:<code>expr</code>:<br />
2021-05-11 02:29:21 +02:00
Search the <code>expr</code>th match (where <code>expr</code> evaluates to a number). This
2022-08-24 15:22:41 +02:00
only applies when searching for substrings, either with the S flag, or
with ${.../...} (only the <code>expr</code>th match is substituted) or ${...//...}
(all matches from the <code>expr</code>th on are substituted). The default is to
take the first match.</p>
2021-05-11 02:29:21 +02:00
<p>The <code>expr</code>th match is counted such that there is either one or zero
2022-08-24 15:22:41 +02:00
matches from each starting position in the string, although for global
substitution matches overlapping previous replacements are ignored. With
the ${...%...} and ${...%%...} forms, the starting position for the
match moves backwards from the end as the index increases, while with
the other forms it moves forward from the start.</p>
2021-05-11 02:29:21 +02:00
<p>Hence with the string</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">which switch is the right switch for Ipswich?
</code></pre>
</div>
<p>substitutions of the form ${(SI:<code>N</code>:)string#w*ch} as <code>N</code> increases from
1 will match and remove which, witch, witch and wich; the form
using ## will match and remove which switch is the right switch for
Ipswich, witch is the right switch for Ipswich, witch for Ipswich
and wich. The form using % will remove the same matches as for #,
but in reverse order, and the form using %% will remove the same
matches as for ## in reverse order.</p>
<p>*<br />
<span id="index-EXTENDED_005fGLOB_002c-enable"></span></p>
<p>Enable EXTENDED_GLOB for substitution via ${.../...} or ${...//...}.
Note that ** does not disable extendedglob.</p>
<p>B<br />
2021-05-11 02:29:21 +02:00
Include the index of the beginning of the match in the result.</p>
2022-08-24 15:22:41 +02:00
<p>E<br />
Include the index one character past the end of the match in the result
(note this is inconsistent with other uses of parameter index).</p>
<p>M<br />
2021-05-11 02:29:21 +02:00
Include the matched portion in the result.</p>
2022-08-24 15:22:41 +02:00
<p>N<br />
2021-05-11 02:29:21 +02:00
Include the length of the match in the result.</p>
2022-08-24 15:22:41 +02:00
<p>R<br />
2021-05-11 02:29:21 +02:00
Include the unmatched portion in the result (the <em>R</em>est).</p>
<hr />
<p><span id="Rules"></span></p>
<h3 id="1432-rules"><a class="header" href="#1432-rules">14.3.2 Rules</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-parameter-expansion-rules"></span> <span
id="index-rules_002c-parameter-expansion"></span> <span
id="index-substitution_002c-parameter_002c-rules"></span></p>
2021-05-11 02:29:21 +02:00
<p>Here is a summary of the rules for substitution; this assumes that
2022-08-24 15:22:41 +02:00
braces are present around the substitution, i.e. ${<code>...</code>}. Some
2021-05-11 02:29:21 +02:00
particular examples are given below. Note that the Zsh Development Group
accepts <em>no responsibility</em> for any brain damage which may occur during
the reading of the following rules.</p>
2022-08-24 15:22:41 +02:00
<p>1. <em>Nested substitution</em><br />
If multiple nested ${<code>...</code>} forms are present, substitution is performed
from the inside outwards. At each level, the substitution takes account
of whether the current value is a scalar or an array, whether the whole
substitution is in double quotes, and what flags are supplied to the
current level of substitution, just as if the nested substitution were
the outermost. The flags are not propagated up to enclosing
substitutions; the nested substitution will return either a scalar or an
array as determined by the flags, possibly adjusted for quoting. All the
following steps take place where applicable at all levels of
substitution.</p>
<p>Note that, unless the (P) flag is present, the flags and any
subscripts apply directly to the value of the nested substitution; for
example, the expansion ${${foo}} behaves exactly the same as ${foo}.
When the (P) flag is present in a nested substitution, the other
substitution rules are applied to the value <em>before</em> it is interpreted
as a name, so ${${(P)foo}} may differ from ${(P)foo}.</p>
<p>At each nested level of substitution, the substituted words undergo all
forms of single-word substitution (i.e. not filename generation),
including command substitution, arithmetic expansion and filename
expansion (i.e. leading ~ and =). Thus, for example, ${${:-=cat}:h}
expands to the directory where the cat program resides. (Explanation:
the internal substitution has no parameter but a default value =cat,
which is expanded by filename expansion to a full path; the outer
substitution then applies the modifier :h and takes the directory part
of the path.)</p>
<p>2. <em>Internal parameter flags</em><br />
Any parameter flags set by one of the typeset family of commands, in
particular the -L, -R, -Z, -u and -l options for padding and
capitalization, are applied directly to the parameter value. Note these
flags are options to the command, e.g. typeset -Z; they are not the
same as the flags used within parameter substitutions.</p>
<p>At the outermost level of substitution, the (P) flag (rule 4.) ignores
these transformations and uses the unmodified value of the parameter as
the name to be replaced. This is usually the desired behavior because
padding may make the value syntactically illegal as a parameter name,
but if capitalization changes are desired, use the ${${(P)foo}} form
(rule 25.).</p>
<p>3. <em>Parameter subscripting</em><br />
2021-05-11 02:29:21 +02:00
If the value is a raw parameter reference with a subscript, such as
2022-08-24 15:22:41 +02:00
${<code>var</code>[3]}, the effect of subscripting is applied directly to the
parameter. Subscripts are evaluated left to right; subsequent subscripts
apply to the scalar or array value yielded by the previous subscript.
Thus if var is an array, ${var[1][2]} is the second character of the
first word, but ${var[2,4][2]} is the entire third word (the second
word of the range of words two through four of the original array). Any
number of subscripts may appear. Flags such as (k) and (v) which
alter the result of subscripting are applied.</p>
<p>4. <em>Parameter name replacement</em><br />
At the outermost level of nesting only, the (P) flag is applied. This
treats the value so far as a parameter name (which may include a
subscript expression) and replaces that with the corresponding value.
This replacement occurs later if the (P) flag appears in a nested
substitution.</p>
<p>If the value so far names a parameter that has internal flags (rule 2.),
those internal flags are applied to the new value after replacement.</p>
<p>5. <em>Double-quoted joining</em><br />
2021-05-11 02:29:21 +02:00
If the value after this process is an array, and the substitution
2022-08-24 15:22:41 +02:00
appears in double quotes, and neither an (@) flag nor a # length
operator is present at the current level, then words of the value are
joined with the first character of the parameter $IFS, by default a
space, between each word (single word arrays are not modified). If the
(j) flag is present, that is used for joining instead of $IFS.</p>
<p>6. <em>Nested subscripting</em><br />
Any remaining subscripts (i.e. of a nested substitution) are evaluated
at this point, based on whether the value is an array or a scalar. As
with 3., multiple subscripts can appear. Note that ${foo[2,4][2]} is
thus equivalent to ${${foo[2,4]}[2]} and also to
&quot;${${(@)foo[2,4]}[2]}&quot; (the nested substitution returns an array in
both cases), but not to &quot;${${foo[2,4]}[2]}&quot; (the nested substitution
returns a scalar because of the quotes).</p>
<p>7. <em>Modifiers</em><br />
Any modifiers, as specified by a trailing #, %, / (possibly
doubled) or by a set of modifiers of the form :... (see
<a href="Expansion.html#Modifiers">Modifiers</a> in <a href="Expansion.html#History-Expansion">History Expansion</a>), are
applied to the words of the value at this level.</p>
<p>8. <em>Character evaluation</em><br />
Any (#) flag is applied, evaluating the result so far numerically as a
character.</p>
<p>9. <em>Length</em><br />
Any initial # modifier, i.e. in the form ${#<code>var</code>}, is used to
evaluate the length of the expression so far.</p>
<p>10. <em>Forced joining</em><br />
If the (j) flag is present, or no (j) flag is present but the string
is to be split as given by rule 11., and joining did not take place at
rule 5., any words in the value are joined together using the given
string or the first character of $IFS if none. Note that the (F) flag
implicitly supplies a string for joining in this manner.</p>
<p>11. <em>Simple word splitting</em><br />
If one of the (s) or (f) flags are present, or the = specifier was
present (e.g. ${=<code>var</code>}), the word is split on occurrences of the
specified string, or (for = with neither of the two flags present) any
of the characters in $IFS.</p>
<p>If no (s), (f) or = was given, but the word is not quoted and the
option SH_WORD_SPLIT is set, the word is split on occurrences of any of
the characters in $IFS. Note this step, too, takes place at all levels
of a nested substitution.</p>
<p>12. <em>Case modification</em><br />
Any case modification from one of the flags (L), (U) or (C) is
applied.</p>
<p>13. <em>Escape sequence replacement</em><br />
First any replacements from the (g) flag are performed, then any
prompt-style formatting from the (%) family of flags is applied.</p>
<p>14. <em>Quote application</em><br />
Any quoting or unquoting using (q) and (Q) and related flags is
applied.</p>
<p>15. <em>Directory naming</em><br />
Any directory name substitution using (D) flag is applied.</p>
<p>16. <em>Visibility enhancement</em><br />
Any modifications to make characters visible using the (V) flag are
applied.</p>
<p>17. <em>Lexical word splitting</em><br />
If the (z) flag or one of the forms of the (Z) flag is present, the
word is split as if it were a shell command line, so that quotation
marks and other metacharacters are used to decide what constitutes a
word. Note this form of splitting is entirely distinct from that
described by rule 11.: it does not use $IFS, and does not cause forced
joining.</p>
<p>18. <em>Uniqueness</em><br />
If the result is an array and the (u) flag was present, duplicate
elements are removed from the array.</p>
<p>19. <em>Ordering</em><br />
If the result is still an array and one of the (o) or (O) flags was
present, the array is reordered.</p>
<p>20. RC_EXPAND_PARAM<br />
At this point the decision is made whether any resulting array elements
are to be combined element by element with surrounding text, as given by
either the RC_EXPAND_PARAM option or the ^ flag.</p>
<p>21. <em>Re-evaluation</em><br />
Any (e) flag is applied to the value, forcing it to be re-examined for
new parameter substitutions, but also for command and arithmetic
substitutions.</p>
<p>22. <em>Padding</em><br />
Any padding of the value by the (l.<code>fill</code>.) or (r.<code>fill</code>.) flags is
applied.</p>
<p>23. <em>Semantic joining</em><br />
In contexts where expansion semantics requires a single word to result,
all words are rejoined with the first character of IFS between. So in
${(P)${(f)lines}} the value of ${lines} is split at newlines, but then
must be joined again before the (P) flag can be applied.</p>
2021-05-11 02:29:21 +02:00
<p>If a single word is not required, this rule is skipped.</p>
2022-08-24 15:22:41 +02:00
<p>24. <em>Empty argument removal</em><br />
2021-05-11 02:29:21 +02:00
If the substitution does not appear in double quotes, any resulting
2022-08-24 15:22:41 +02:00
zero-length argument, whether from a scalar or an element of an array,
is elided from the list of arguments inserted into the command line.</p>
<p>Strictly speaking, the removal happens later as the same happens with
other forms of substitution; the point to note here is simply that it
occurs after any of the above parameter operations.</p>
<p>25. <em>Nested parameter name replacement</em><br />
If the (P) flag is present and rule 4. has not applied, the value so
far is treated as a parameter name (which may include a subscript
expression) and replaced with the corresponding value, with internal
flags (rule 2.) applied to the new value.</p>
<hr />
<p><span id="Examples"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="1433-examples"><a class="header" href="#1433-examples">14.3.3 Examples</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-parameter-expansion_002c-examples"></span></p>
<p>The flag f is useful to split a double-quoted substitution line by line.
For example, ${(f)&quot;$(&lt;<code>file</code>)&quot;} substitutes the contents of <code>file</code>
divided so that each line is an element of the resulting array. Compare
this with the effect of $(&lt;<code>file</code>) alone, which divides the file up by
words, or the same inside double quotes, which makes the entire content
of the file a single string.</p>
2021-05-11 02:29:21 +02:00
<p>The following illustrates the rules for nested parameter expansions.
2022-08-24 15:22:41 +02:00
Suppose that $foo contains the array (bar baz):</p>
<p>&quot;${(@)${foo}[1]}&quot;<br />
This produces the result b. First, the inner substitution &quot;${foo}&quot;,
which has no array (@) flag, produces a single word result &quot;bar baz&quot;.
The outer substitution &quot;${(@)...[1]}&quot; detects that this is a scalar,
so that (despite the (@) flag) the subscript picks the first
character.</p>
<p>&quot;${${(@)foo}[1]}&quot;<br />
This produces the result bar. In this case, the inner substitution
&quot;${(@)foo}&quot; produces the array (bar baz). The outer substitution
&quot;${...[1]}&quot; detects that this is an array and picks the first word.
This is similar to the simple case &quot;${foo[1]}&quot;.</p>
<p>As an example of the rules for word splitting and joining, suppose $foo
contains the array (ax1 bx1). Then</p>
<p>${(s/x/)foo}<br />
produces the words a, 1 b and 1.</p>
<p>${(j/x/s/x/)foo}<br />
produces a, 1, b and 1.</p>
<p>${(s/x/)foo%%1*}<br />
produces a and b (note the extra space). As substitution occurs
before either joining or splitting, the operation first generates the
modified array (ax bx), which is joined to give &quot;ax bx&quot;, and then split
to give a, b and . The final empty string will then be elided, as
it is not in double quotes.</p>
<hr />
<p><span id="Command-Substitution"></span> <span
id="Command-Substitution-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="144-command-substitution"><a class="header" href="#144-command-substitution">14.4 Command Substitution</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-command-substitution"></span> <span
id="index-substitution_002c-command"></span></p>
2021-05-11 02:29:21 +02:00
<p>A command enclosed in parentheses preceded by a dollar sign, like
2022-08-24 15:22:41 +02:00
$(...), or quoted with grave accents, like ..., is replaced with
its standard output, with any trailing newlines deleted. If the
substitution is not enclosed in double quotes, the output is broken into
words using the IFS parameter. <span
id="index-IFS_002c-use-of-1"></span></p>
<p>The substitution $(cat <code>foo</code>) may be replaced by the faster
$(&lt;<code>foo</code>). In this case <code>foo</code> undergoes single word shell expansions
(<em>parameter expansion</em>, <em>command substitution</em> and <em>arithmetic
expansion</em>), but not filename generation.</p>
<p>If the option GLOB_SUBST is set, the result of any unquoted command
2021-05-11 02:29:21 +02:00
substitution, including the special form just mentioned, is eligible for
filename generation.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Arithmetic-Expansion"></span> <span
id="Arithmetic-Expansion-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="145-arithmetic-expansion"><a class="header" href="#145-arithmetic-expansion">14.5 Arithmetic Expansion</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-arithmetic-expansion"></span> <span
id="index-expansion_002c-arithmetic"></span></p>
<p>A string of the form $[<code>exp</code>] or $((<code>exp</code>)) is substituted with
the value of the arithmetic expression <code>exp</code>. <code>exp</code> is subjected to
2021-05-11 02:29:21 +02:00
<em>parameter expansion</em>, <em>command substitution</em> and <em>arithmetic expansion</em>
before it is evaluated. See <a href="Arithmetic-Evaluation.html#Arithmetic-Evaluation">Arithmetic
Evaluation</a>.</p>
<hr />
<p><span id="Brace-Expansion"></span> <span id="Brace-Expansion-1"></span></p>
<h2 id="146-brace-expansion"><a class="header" href="#146-brace-expansion">14.6 Brace Expansion</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-brace-expansion"></span> <span
id="index-expansion_002c-brace"></span></p>
<p>A string of the form <code>foo</code>{<code>xx</code>,<code>yy</code>,<code>zz</code>}<code>bar</code> is expanded to the
individual words <code>fooxxbar</code>, <code>fooyybar</code> and <code>foozzbar</code>.
2021-05-11 02:29:21 +02:00
Left-to-right order is preserved. This construct may be nested. Commas
may be quoted in order to include them literally in a word.</p>
2022-08-24 15:22:41 +02:00
<p>An expression of the form {<code>n1</code>..<code>n2</code>}, where <code>n1</code> and <code>n2</code> are
2021-05-11 02:29:21 +02:00
integers, is expanded to every number between <code>n1</code> and <code>n2</code> inclusive.
If either number begins with a zero, all the resulting numbers will be
padded with leading zeroes to that minimum width, but for negative
2022-08-24 15:22:41 +02:00
numbers the - character is also included in the width. If the numbers
2021-05-11 02:29:21 +02:00
are in decreasing order the resulting sequence will also be in
decreasing order.</p>
2022-08-24 15:22:41 +02:00
<p>An expression of the form {<code>n1</code>..<code>n2</code>..<code>n3</code>}, where <code>n1</code>, <code>n2</code>, and
<code>n3</code> are integers, is expanded as above, but only every <code>n3</code>th number
starting from <code>n1</code> is output. If <code>n3</code> is negative the numbers are output
in reverse order, this is slightly different from simply swapping <code>n1</code>
and <code>n2</code> in the case that the step <code>n3</code> doesnt evenly divide the range.
Zero padding can be specified in any of the three numbers, specifying it
in the third can be useful to pad for example {-99..100..01} which is
not possible to specify by putting a 0 on either of the first two
numbers (i.e. pad to two characters).</p>
<p>An expression of the form {<code>c1</code>..<code>c2</code>}, where <code>c1</code> and <code>c2</code> are single
characters (which may be multibyte characters), is expanded to every
character in the range from <code>c1</code> to <code>c2</code> in whatever character sequence
is used internally. For characters with code points below 128 this is US
ASCII (this is the only case most users will need). If any intervening
character is not If the character sequence is reversed, the output is in
reverse order, e.g. {d..a} is substituted as d c b a.</p>
2021-05-11 02:29:21 +02:00
<p>If a brace expression matches none of the above forms, it is left
2022-08-24 15:22:41 +02:00
unchanged, unless the option BRACE_CCL (an abbreviation for brace
character class) is set. <span
id="index-BRACE_005fCCL_002c-use-of"></span> In that case, it is
2021-05-11 02:29:21 +02:00
expanded to a list of the individual characters between the braces
sorted into the order of the characters in the ASCII character set
(multibyte characters are not currently handled). The syntax is similar
2022-08-24 15:22:41 +02:00
to a [...] expression in filename generation: - is treated specially
to denote a range of characters, but ^ or ! as the first character
is treated normally. For example, {abcdef0-9} expands to 16 words 0 1
2 3 4 5 6 7 8 9 a b c d e f.</p>
2021-05-11 02:29:21 +02:00
<p>Note that brace expansion is not part of filename generation (globbing);
2022-08-24 15:22:41 +02:00
an expression such as */{foo,bar} is split into two separate words
*/foo and */bar before filename generation takes place. In particular,
note that this is liable to produce a no match error if <em>either</em> of
the two expressions does not match; this is to be contrasted with
*/(foo|bar), which is treated as a single pattern but otherwise has
similar effects.</p>
<p>To combine brace expansion with array expansion, see the ${^<code>spec</code>} form
described in <a href="Expansion.html#Parameter-Expansion">Parameter Expansion</a> above.</p>
<hr />
<p><span id="Filename-Expansion"></span> <span
id="Filename-Expansion-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="147-filename-expansion"><a class="header" href="#147-filename-expansion">14.7 Filename Expansion</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-filename-expansion"></span> <span
id="index-expansion_002c-filename"></span></p>
<p>Each word is checked to see if it begins with an unquoted ~. If it
does, then the word up to a /, or the end of the word if there is no
/, is checked to see if it can be substituted in one of the ways
described here. If so, then the ~ and the checked portion are
2021-05-11 02:29:21 +02:00
replaced with the appropriate substitute value.</p>
2022-08-24 15:22:41 +02:00
<p>A ~ by itself is replaced by the value of $HOME. A ~ followed by a
+ or a - is replaced by current or previous working directory,
respectively.</p>
<p>A ~ followed by a number is replaced by the directory at that
position in the directory stack. ~0 is equivalent to ~+, and ~1
is the top of the stack. ~+ followed by a number is replaced by the
directory at that position in the directory stack. ~+0 is equivalent
to ~+, and ~+1 is the top of the stack. ~- followed by a number
is replaced by the directory that many positions from the bottom of the
stack. ~-0 is the bottom of the stack. <span
id="index-PUSHD_005fMINUS_002c-use-of"></span> The PUSHD_MINUS option
exchanges the effects of ~+ and ~- where they are followed by a
number.</p>
<hr />
<p><span id="Dynamic-named-directories"></span> <span
id="Dynamic-named-directories-1"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="1471-dynamic-named-directories"><a class="header" href="#1471-dynamic-named-directories">14.7.1 Dynamic named directories</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-directories_002c-named_002c-dynamic"></span> <span
id="index-named-directories_002c-dynamic"></span> <span
id="index-dynamic-named-directories"></span></p>
<p>If the function zsh_directory_name exists, or the shell variable
zsh_directory_name_functions exists and contains an array of function
2021-05-11 02:29:21 +02:00
names, then the functions are used to implement dynamic directory
naming. The functions are tried in order until one returns status zero,
so it is important that functions test whether they can handle the case
in question and return an appropriate status.</p>
2022-08-24 15:22:41 +02:00
<p>A ~ followed by a string <code>namstr</code> in unquoted square brackets is
2021-05-11 02:29:21 +02:00
treated specially as a dynamic directory name. Note that the first
unquoted closing square bracket always terminates <code>namstr</code>. The shell
2022-08-24 15:22:41 +02:00
function is passed two arguments: the string n (for name) and <code>namstr</code>.
It should either set the array reply to a single element which is the
directory corresponding to the name and return status zero (executing an
assignment as the last statement is usually sufficient), or it should
return status non-zero. In the former case the element of reply is used
as the directory; in the latter case the substitution is deemed to have
failed. If all functions fail and the option NOMATCH is set, an error
results.</p>
2021-05-11 02:29:21 +02:00
<p>The functions defined as above are also used to see if a directory can
be turned into a name, for example when printing the directory stack or
2022-08-24 15:22:41 +02:00
when expanding %~ in prompts. In this case each function is passed two
arguments: the string d (for directory) and the candidate for dynamic
2021-05-11 02:29:21 +02:00
naming. The function should either return non-zero status, if the
directory cannot be named by the function, or it should set the array
reply to consist of two elements: the first is the dynamic name for the
2022-08-24 15:22:41 +02:00
directory (as would appear within ~[<code>...</code>]), and the second is the
2021-05-11 02:29:21 +02:00
prefix length of the directory to be replaced. For example, if the trial
2022-08-24 15:22:41 +02:00
directory is /home/myname/src/zsh and the dynamic name for
/home/myname/src (which has 16 characters) is s, then the function sets</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">reply=(s 16)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>The directory name so returned is compared with possible static names
for parts of the directory path, as described below; it is used if the
prefix length matched (16 in the example) is longer than that matched by
any static name.</p>
2022-08-24 15:22:41 +02:00
<p>It is not a requirement that a function implements both n and d calls;
for example, it might be appropriate for certain dynamic forms of
2021-05-11 02:29:21 +02:00
expansion not to be contracted to names. In that case any call with the
2022-08-24 15:22:41 +02:00
first argument d should cause a non-zero status to be returned.</p>
<p>The completion system calls zsh_directory_name c followed by
equivalent calls to elements of the array zsh_directory_name_functions,
if it exists, in order to complete dynamic names for directories. The
code for this should be as for any other completion function as
described in <a href="Completion-System.html#Completion-System">Completion
2021-05-11 02:29:21 +02:00
System</a>.</p>
<p>As a working example, here is a function that expands any dynamic names
2022-08-24 15:22:41 +02:00
beginning with the string p: to directories below /home/pws/perforce. In
this simple case a static name for the directory would be just as
effective.</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zsh_directory_name() {
2021-05-11 02:29:21 +02:00
emulate -L zsh
setopt extendedglob
local -a match mbegin mend
if [[ $1 = d ]]; then
# turn the directory into a name
if [[ $2 = (#b)(/home/pws/perforce/)([^/]##)* ]]; then
typeset -ga reply
reply=(p:$match[2] $(( ${#match[1]} + ${#match[2]} )) )
else
return 1
fi
elif [[ $1 = n ]]; then
# turn the name into a directory
[[ $2 != (#b)p:(?*) ]] &amp;&amp; return 1
typeset -ga reply
reply=(/home/pws/perforce/$match[1])
elif [[ $1 = c ]]; then
# complete names
local expl
local -a dirs
dirs=(/home/pws/perforce/*(/:t))
dirs=(p:${^dirs})
_wanted dynamic-dirs expl 'dynamic directory' compadd -S\] -a dirs
return
else
return 1
fi
return 0
}
</code></pre>
</div>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Static-named-directories"></span> <span
id="Static-named-directories-1"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="1472-static-named-directories"><a class="header" href="#1472-static-named-directories">14.7.2 Static named directories</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-directories_002c-named_002c-static"></span> <span
id="index-named-directories_002c-static"></span> <span
id="index-static-named-directories"></span></p>
<p>A ~ followed by anything not already covered consisting of any number
of alphanumeric characters or underscore (_), hyphen (-), or dot
(.) is looked up as a named directory, and replaced by the value of
that named directory if found. Named directories are typically home
directories for users on the system. They may also be defined if the
text after the ~ is the name of a string shell parameter whose value
begins with a /. Note that trailing slashes will be removed from the
path to the directory (though the original parameter is not modified).</p>
<p>It is also possible to define directory names using the -d option to the
hash builtin.</p>
<p>When the shell prints a path (e.g. when expanding %~ in prompts or when
printing the directory stack), the path is checked to see if it has a
named directory as its prefix. If so, then the prefix portion is
replaced with a ~ followed by the name of the directory. The shorter
2021-05-11 02:29:21 +02:00
of the two ways of referring to the directory is used, i.e. either the
directory name or the full path; the name is used if they are the same
2022-08-24 15:22:41 +02:00
length. The parameters $PWD and $OLDPWD are never abbreviated in this
fashion.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="g_t_0060_003d_0027-expansion"></span> <span
id="g_t_0060_003d_0027-expansion-1"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="1473--expansion"><a class="header" href="#1473--expansion">14.7.3 = expansion</a></h3>
2022-08-24 15:22:41 +02:00
<p>If a word begins with an unquoted = and the EQUALS option is set, the
remainder of the word is taken as the name of a command. If a command
exists by that name, the word is replaced by the full pathname of the
command.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Notes"></span> <span id="Notes-1"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="1474-notes"><a class="header" href="#1474-notes">14.7.4 Notes</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-filename-expansion_002c-notes"></span></p>
2021-05-11 02:29:21 +02:00
<p>Filename expansion is performed on the right hand side of a parameter
2022-08-24 15:22:41 +02:00
assignment, including those appearing after commands of the typeset
2021-05-11 02:29:21 +02:00
family. In this case, the right hand side will be treated as a
2022-08-24 15:22:41 +02:00
colon-separated list in the manner of the PATH parameter, so that a ~
or an = following a : is eligible for expansion. All such behaviour
can be disabled by quoting the ~, the =, or the whole expression
(but not simply the colon); the EQUALS option is also respected.</p>
<p>If the option MAGIC_EQUAL_SUBST is set, any unquoted shell argument in
the form <code>identifier</code>=<code>expression</code> becomes eligible for file expansion
as described in the previous paragraph. Quoting the first = also
inhibits this.</p>
<hr />
<p><span id="Filename-Generation"></span> <span
id="Filename-Generation-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="148-filename-generation"><a class="header" href="#148-filename-generation">14.8 Filename Generation</a></h2>
<p><span id="index-filename-generation"></span></p>
2022-08-24 15:22:41 +02:00
<p>If a word contains an unquoted instance of one of the characters *,
(, |, &lt;, [, or ?, it is regarded as a pattern for filename
generation, unless the GLOB option is unset. <span
id="index-GLOB_002c-use-of"></span> If the EXTENDED_GLOB option is set,
<span id="index-EXTENDED_005fGLOB_002c-use-of"></span> the ^ and #
characters also denote a pattern; otherwise they are not treated
specially by the shell.</p>
2021-05-11 02:29:21 +02:00
<p>The word is replaced with a list of sorted filenames that match the
pattern. If no matching pattern is found, the shell gives an error
2022-08-24 15:22:41 +02:00
message, unless the NULL_GLOB option is set, <span
id="index-NULL_005fGLOB_002c-use-of"></span> in which case the word is
deleted; or unless the NOMATCH option is unset, in which case the word
is left unchanged. <span id="index-NOMATCH_002c-use-of"></span></p>
<p>In filename generation, the character / must be matched explicitly;
also, a . must be matched explicitly at the beginning of a pattern or
after a /, unless the GLOB_DOTS option is set. <span
id="index-GLOB_005fDOTS_002c-use-of"></span> No filename generation
pattern matches the files . or ... In other instances of pattern
matching, the / and . are not treated specially.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Glob-Operators"></span></p>
<h3 id="1481-glob-operators"><a class="header" href="#1481-glob-operators">14.8.1 Glob Operators</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-glob-operators"></span></p>
<p>*<br />
2021-05-11 02:29:21 +02:00
Matches any string, including the null string.</p>
2022-08-24 15:22:41 +02:00
<p>?<br />
2021-05-11 02:29:21 +02:00
Matches any character.</p>
2022-08-24 15:22:41 +02:00
<p>[...]<br />
2021-05-11 02:29:21 +02:00
Matches any of the enclosed characters. Ranges of characters can be
2022-08-24 15:22:41 +02:00
specified by separating two characters by a -. A - or ] may be
matched by including it as the first character in the list. <span
id="index-character-classes"></span> There are also several named
classes of characters, in the form [:<code>name</code>:] with the following
meanings. The first set use the macros provided by the operating system
to test for the given character combinations, including any
modifications due to local language settings, see ctype(3):</p>
<p>[:alnum:]<br />
2021-05-11 02:29:21 +02:00
The character is alphanumeric</p>
2022-08-24 15:22:41 +02:00
<p>[:alpha:]<br />
2021-05-11 02:29:21 +02:00
The character is alphabetic</p>
2022-08-24 15:22:41 +02:00
<p>[:ascii:]<br />
The character is 7-bit, i.e. is a single-byte character without the top
bit set.</p>
<p>[:blank:]<br />
2021-05-11 02:29:21 +02:00
The character is a blank character</p>
2022-08-24 15:22:41 +02:00
<p>[:cntrl:]<br />
2021-05-11 02:29:21 +02:00
The character is a control character</p>
2022-08-24 15:22:41 +02:00
<p>[:digit:]<br />
2021-05-11 02:29:21 +02:00
The character is a decimal digit</p>
2022-08-24 15:22:41 +02:00
<p>[:graph:]<br />
[:lower:]<br />
2021-05-11 02:29:21 +02:00
The character is a lowercase letter</p>
2022-08-24 15:22:41 +02:00
<p>[:print:]<br />
[:punct:]<br />
[:space:]<br />
2021-05-11 02:29:21 +02:00
The character is whitespace</p>
2022-08-24 15:22:41 +02:00
<p>[:upper:]<br />
2021-05-11 02:29:21 +02:00
The character is an uppercase letter</p>
2022-08-24 15:22:41 +02:00
<p>[:xdigit:]<br />
2021-05-11 02:29:21 +02:00
The character is a hexadecimal digit</p>
2022-08-24 15:22:41 +02:00
<p>Another set of named classes is handled internally by the shell and is
not sensitive to the locale:</p>
<p>[:IDENT:]<br />
The character is allowed to form part of a shell identifier, such as a
parameter name; this test respects the POSIX_IDENTIFIERS option</p>
<p>[:IFS:]<br />
The character is used as an input field separator, i.e. is contained in
the IFS parameter</p>
<p>[:IFSSPACE:]<br />
The character is an IFS white space character; see the documentation for
IFS in <a href="Parameters.html#Parameters-Used-By-The-Shell">Parameters Used By The
2021-05-11 02:29:21 +02:00
Shell</a>.</p>
2022-08-24 15:22:41 +02:00
<p>[:INCOMPLETE:]<br />
Matches a byte that starts an incomplete multibyte character. Note that
there may be a sequence of more than one bytes that taken together form
the prefix of a multibyte character. To test for a potentially
incomplete byte sequence, use the pattern [[:INCOMPLETE:]]*. This
will never match a sequence starting with a valid multibyte character.</p>
<p>[:INVALID:]<br />
Matches a byte that does not start a valid multibyte character. Note
this may be a continuation byte of an incomplete multibyte character as
any part of a multibyte string consisting of invalid and incomplete
multibyte characters is treated as single bytes.</p>
<p>[:WORD:]<br />
The character is treated as part of a word; this test is sensitive to
the value of the WORDCHARS parameter</p>
2021-05-11 02:29:21 +02:00
<p>Note that the square brackets are additional to those enclosing the
2022-08-24 15:22:41 +02:00
whole set of characters, so to test for a single alphanumeric character
you need [[:alnum:]]. Named character sets can be used alongside
other types, e.g. [[:alpha:]0-9].</p>
<p>[^...]<br />
[!...]<br />
Like [...], except that it matches any character which is not in the
given set.</p>
<p>&lt;[<code>x</code>]-[<code>y</code>]&gt;<br />
2021-05-11 02:29:21 +02:00
Matches any number in the range <code>x</code> to <code>y</code>, inclusive. Either of the
2022-08-24 15:22:41 +02:00
numbers may be omitted to make the range open-ended; hence &lt;-&gt;
matches any number. To match individual digits, the [...] form is more
efficient.</p>
<p>Be careful when using other wildcards adjacent to patterns of this form;
for example, &lt;0-9&gt;* will actually match any number whatsoever at the
start of the string, since the &lt;0-9&gt; will match the first digit, and
the * will match any others. This is a trap for the unwary, but is
match always succeeds. Expressions such as &lt;0-9&gt;[^[:digit:]]*
can be used instead.</p>
<p>(...)<br />
Matches the enclosed pattern. This is used for grouping. If the KSH_GLOB
option is set, then a @, *, +, ? or ! immediately preceding
the ( is treated specially, as detailed below. The option SH_GLOB
prevents bare parentheses from being used in this way, though the
KSH_GLOB option is still available.</p>
2021-05-11 02:29:21 +02:00
<p>Note that grouping cannot extend over multiple directories: it is an
2022-08-24 15:22:41 +02:00
error to have a / within a group (this only applies for patterns used
in filename generation). There is one exception: a group of the form
(<code>pat</code>/)# appearing as a complete path segment can match a sequence of
directories. For example, foo/(a*/)#bar matches foo/bar, foo/any/bar,
foo/any/anyother/bar, and so on.</p>
<p><code>x</code>|<code>y</code><br />
Matches either <code>x</code> or <code>y</code>. This operator has lower precedence than any
other. The | character must be within parentheses, to avoid
interpretation as a pipeline. The alternatives are tried in order from
left to right.</p>
<p>^<code>x</code><br />
(Requires EXTENDED_GLOB to be set.) Matches anything except the pattern
<code>x</code>. This has a higher precedence than /, so ^foo/bar will search
directories in . except ./foo for a file named bar.</p>
<p><code>x</code>~<code>y</code><br />
(Requires EXTENDED_GLOB to be set.) Match anything that matches the
pattern <code>x</code> but does not match <code>y</code>. This has lower precedence than any
operator except |, so */*~foo/bar will search for all files in
all directories in . and then exclude foo/bar if there was such a
match. Multiple patterns can be excluded by <code>foo</code>~<code>bar</code>~<code>baz</code>. In
the exclusion pattern (<code>y</code>), / and . are not treated specially the
way they usually are in globbing.</p>
<p><code>x</code>#<br />
(Requires EXTENDED_GLOB to be set.) Matches zero or more occurrences of
the pattern <code>x</code>. This operator has high precedence; 12# is equivalent
to 1(2#), rather than (12)#. It is an error for an unquoted # to
follow something which cannot be repeated; this includes an empty
string, a pattern already followed by ##, or parentheses when part of
a KSH_GLOB pattern (for example, !(<code>foo</code>)# is invalid and must be
replaced by *(!(<code>foo</code>))).</p>
<p><code>x</code>##<br />
(Requires EXTENDED_GLOB to be set.) Matches one or more occurrences of
the pattern <code>x</code>. This operator has high precedence; 12## is equivalent
to 1(2##), rather than (12)##. No more than two active #
characters may appear together. (Note the potential clash with glob
qualifiers in the form 1(2##) which should therefore be avoided.)</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="ksh_002dlike-Glob-Operators"></span></p>
<h3 id="1482-ksh-like-glob-operators"><a class="header" href="#1482-ksh-like-glob-operators">14.8.2 ksh-like Glob Operators</a></h3>
<p><span id="index-KSH_005fGLOB_002c-use-of"></span></p>
2022-08-24 15:22:41 +02:00
<p>If the KSH_GLOB option is set, the effects of parentheses can be
modified by a preceding @, *, +, ? or !. This character need
not be unquoted to have special effects, but the ( must be.</p>
<p>@(...)<br />
Match the pattern in the parentheses. (Like (...).)</p>
<p>*(...)<br />
Match any number of occurrences. (Like (...)#, except that recursive
directory searching is not supported.)</p>
<p>+(...)<br />
Match at least one occurrence. (Like (...)##, except that recursive
directory searching is not supported.)</p>
<p>?(...)<br />
Match zero or one occurrence. (Like (|...).)</p>
<p>!(...)<br />
Match anything but the expression in parentheses. (Like (^(...)).)</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Precedence"></span></p>
<h3 id="1483-precedence"><a class="header" href="#1483-precedence">14.8.3 Precedence</a></h3>
<p><span id="index-precedence-of-glob-operators"></span></p>
2022-08-24 15:22:41 +02:00
<p>The precedence of the operators given above is (highest) ^, /, ~,
| (lowest); the remaining operators are simply treated from left to
right as part of a string, with # and ## applying to the shortest
possible preceding unit (i.e. a character, ?, [...], &lt;...&gt;, or
a parenthesised expression). As mentioned above, a / used as a
directory separator may not appear inside parentheses, while a | must
do so; in patterns used in other contexts than filename generation (for
example, in case statements and tests within [[...]]), a / is
not special; and / is also not special after a ~ appearing outside
parentheses in a filename pattern.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Globbing-Flags"></span></p>
<h3 id="1484-globbing-flags"><a class="header" href="#1484-globbing-flags">14.8.4 Globbing Flags</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-globbing-flags"></span> <span
id="index-glob-flags"></span></p>
2021-05-11 02:29:21 +02:00
<p>There are various flags which affect any text to their right up to the
end of the enclosing group or to the end of the pattern; they require
2022-08-24 15:22:41 +02:00
the EXTENDED_GLOB option. All take the form (#<code>X</code>) where <code>X</code> may have
one of the following forms:</p>
<p>i<br />
Case insensitive: upper or lower case characters in the pattern match
upper or lower case characters.</p>
<p>l<br />
2021-05-11 02:29:21 +02:00
Lower case characters in the pattern match upper or lower case
2022-08-24 15:22:41 +02:00
characters; upper case characters in the pattern still only match upper
case characters.</p>
<p>I<br />
Case sensitive: locally negates the effect of i or l from that point on.</p>
<p><span id="index-match"></span> <span id="index-mbegin"></span> <span
id="index-mend"></span></p>
<p>b<br />
Activate backreferences for parenthesised groups in the pattern; this
does not work in filename generation. When a pattern with a set of
active parentheses is matched, the strings matched by the groups are
stored in the array $match, the indices of the beginning of the matched
parentheses in the array $mbegin, and the indices of the end in the
array $mend, with the first element of each array corresponding to the
first parenthesised group, and so on. These arrays are not otherwise
special to the shell. The indices use the same convention as does
parameter substitution, so that elements of $mend and $mbegin may be
used in subscripts; the KSH_ARRAYS option is respected. Sets of globbing
flags are not considered parenthesised groups; only the first nine
active parentheses can be referenced.</p>
2021-05-11 02:29:21 +02:00
<p>For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">foo=&quot;a_string_with_a_message&quot;
2021-05-11 02:29:21 +02:00
if [[ $foo = (a|an)_(#b)(*) ]]; then
print ${foo[$mbegin[1],$mend[1]]}
fi
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>prints string_with_a_message. Note that the first set of parentheses
is before the (#b) and does not create a backreference.</p>
2021-05-11 02:29:21 +02:00
<p>Backreferences work with all forms of pattern matching other than
2022-08-24 15:22:41 +02:00
filename generation, but note that when performing matches on an entire
array, such as ${<code>array</code>#<code>pattern</code>}, or a global substitution, such as
${<code>param</code>//<code>pat</code>/<code>repl</code>}, only the data for the last match remains
available. In the case of global replacements this may still be useful.
See the example for the m flag below.</p>
2021-05-11 02:29:21 +02:00
<p>The numbering of backreferences strictly follows the order of the
2022-08-24 15:22:41 +02:00
opening parentheses from left to right in the pattern string, although
sets of parentheses may be nested. There are special rules for
parentheses followed by # or ##. Only the last match of the
parenthesis is remembered: for example, in [[ abab = (#b)([ab])#
]], only the final b is stored in match[1]. Thus extra
parentheses may be necessary to match the complete segment: for example,
use X((ab|cd)#)Y to match a whole string of either ab or cd
between X and Y, using the value of $match[1] rather than
$match[2].</p>
<p>If the match fails none of the parameters is altered, so in some cases
it may be necessary to initialise them beforehand. If some of the
backreferences fail to match — which happens if they are in an alternate
branch which fails to match, or if they are followed by # and matched
zero times — then the matched string is set to the empty string, and the
start and end indices are set to -1.</p>
<p>Pattern matching with backreferences is slightly slower than without.</p>
<p>B<br />
Deactivate backreferences, negating the effect of the b flag from that
point on.</p>
<p>c<code>N</code>,<code>M</code><br />
The flag (#c<code>N</code>,<code>M</code>) can be used anywhere that the # or ## operators can
be used except in the expressions (*/)# and (*/)## in filename
generation, where / has special meaning; it cannot be combined with
other globbing flags and a bad pattern error occurs if it is misplaced.
It is equivalent to the form {<code>N</code>,<code>M</code>} in regular expressions. The
previous character or group is required to match between <code>N</code> and <code>M</code>
times, inclusive. The form (#c<code>N</code>) requires exactly N matches; (#c,<code>M</code>)
is equivalent to specifying <code>N</code> as 0; (#c<code>N</code>,) specifies that there is
no maximum limit on the number of matches.</p>
<p><span id="index-MATCH"></span> <span id="index-MBEGIN"></span> <span
id="index-MEND"></span></p>
<p>m<br />
Set references to the match data for the entire string matched; this is
similar to backreferencing and does not work in filename generation. The
flag must be in effect at the end of the pattern, i.e. not local to a
group. The parameters $MATCH, $MBEGIN and $MEND will be set to the
string matched and to the indices of the beginning and end of the
string, respectively. This is most useful in parameter substitutions, as
otherwise the string matched is obvious.</p>
2021-05-11 02:29:21 +02:00
<p>For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">arr=(veldt jynx grimps waqf zho buck)
2021-05-11 02:29:21 +02:00
print ${arr//(#m)[aeiou]/${(U)MATCH}}
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>forces all the matches (i.e. all vowels) into uppercase, printing vEldt
jynx grImps wAqf zhO bUck.</p>
2021-05-11 02:29:21 +02:00
<p>Unlike backreferences, there is no speed penalty for using match
references, other than the extra substitutions required for the
replacement strings in cases such as the example shown.</p>
2022-08-24 15:22:41 +02:00
<p>M<br />
Deactivate the m flag, hence no references to match data will be
2021-05-11 02:29:21 +02:00
created.</p>
2022-08-24 15:22:41 +02:00
<p>a<code>num</code><br />
Approximate matching: <code>num</code> errors are allowed in the string matched by
the pattern. The rules for this are described in the next subsection.</p>
<p>s, e<br />
Unlike the other flags, these have only a local effect, and each must
appear on its own: (#s) and (#e) are the only valid forms. The
(#s) flag succeeds only at the start of the test string, and the
(#e) flag succeeds only at the end of the test string; they correspond
to ^ and $ in standard regular expressions. They are useful for
matching path segments in patterns other than those in filename
generation (where path segments are in any case treated separately). For
example, *((#s)|/)test((#e)|/)* matches a path segment test in
any of the following strings: test, test/at/start, at/end/test,
in/test/middle.</p>
2021-05-11 02:29:21 +02:00
<p>Another use is in parameter substitution; for example
2022-08-24 15:22:41 +02:00
${array/(#s)A*Z(#e)} will remove only elements of an array which
match the complete pattern A*Z. There are other ways of performing
many operations of this type, however the combination of the
substitution operations / and // with the (#s) and (#e) flags
provides a single simple and memorable method.</p>
<p>Note that assertions of the form (^(#s)) also work, i.e. match
anywhere except at the start of the string, although this actually means
anything except a zero-length portion at the start of the string; you
need to use (&quot;&quot;~(#s)) to match a zero-length portion of the string
not at the start.</p>
<p>q<br />
A q and everything up to the closing parenthesis of the globbing flags
are ignored by the pattern matching code. This is intended to support
the use of glob qualifiers, see below. The result is that the pattern
(#b)(*).c(#q.) can be used both for globbing and for matching against
a string. In the former case, the (#q.) will be treated as a glob
qualifier and the (#b) will not be useful, while in the latter case
the (#b) is useful for backreferences and the (#q.) will be ignored.
Note that colon modifiers in the glob qualifiers are also not applied in
ordinary pattern matching.</p>
<p>u<br />
2021-05-11 02:29:21 +02:00
Respect the current locale in determining the presence of multibyte
characters in a pattern, provided the shell was compiled with
2022-08-24 15:22:41 +02:00
MULTIBYTE_SUPPORT. This overrides the MULTIBYTE option; the default
behaviour is taken from the option. Compare U. (Mnemonic: typically
multibyte characters are from Unicode in the UTF-8 encoding, although
any extension of ASCII supported by the system library may be used.)</p>
<p>U<br />
2021-05-11 02:29:21 +02:00
All characters are considered to be a single byte long. The opposite
2022-08-24 15:22:41 +02:00
of u. This overrides the MULTIBYTE option.</p>
<p>For example, the test string fooxx can be matched by the pattern
(#i)FOOXX, but not by (#l)FOOXX, (#i)FOO(#I)XX or ((#i)FOOX)X. The
string (#ia2)readme specifies case-insensitive matching of readme with
up to two errors.</p>
<p>When using the ksh syntax for grouping both KSH_GLOB and EXTENDED_GLOB
must be set and the left parenthesis should be preceded by @. Note also
that the flags do not affect letters inside [...] groups, in other
words (#i)[a-z] still matches only lowercase letters. Finally, note
that when examining whole paths case-insensitively every directory must
be searched for all files which match, so that a pattern of the form
(#i)/foo/bar/... is potentially slow.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Approximate-Matching"></span></p>
<h3 id="1485-approximate-matching"><a class="header" href="#1485-approximate-matching">14.8.5 Approximate Matching</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-approximate-matching"></span> <span
id="index-matching_002c-approximate"></span></p>
2021-05-11 02:29:21 +02:00
<p>When matching approximately, the shell keeps a count of the errors
2022-08-24 15:22:41 +02:00
found, which cannot exceed the number specified in the (#a<code>num</code>) flags.
Four types of error are recognised:</p>
2021-05-11 02:29:21 +02:00
<p>1.<br />
2022-08-24 15:22:41 +02:00
Different characters, as in fooxbar and fooybar.</p>
2021-05-11 02:29:21 +02:00
<p>2.<br />
2022-08-24 15:22:41 +02:00
Transposition of characters, as in banana and abnana.</p>
2021-05-11 02:29:21 +02:00
<p>3.<br />
2022-08-24 15:22:41 +02:00
A character missing in the target string, as with the pattern road and
target string rod.</p>
2021-05-11 02:29:21 +02:00
<p>4.<br />
2022-08-24 15:22:41 +02:00
An extra character appearing in the target string, as with stove and
strove.</p>
<p>Thus, the pattern (#a3)abcd matches dcba, with the errors occurring by
using the first rule twice and the second once, grouping the string as
[d][cb][a] and [a][bc][d].</p>
2021-05-11 02:29:21 +02:00
<p>Non-literal parts of the pattern must match exactly, including
2022-08-24 15:22:41 +02:00
characters in character ranges: hence (#a1)??? matches strings of length
four, by applying rule 4 to an empty part of the pattern, but not
strings of length two, since all the ? must match. Other characters
2021-05-11 02:29:21 +02:00
which must match exactly are initial dots in filenames (unless the
2022-08-24 15:22:41 +02:00
GLOB_DOTS option is set), and all slashes in filenames, so that a/bc is
two errors from ab/c (the slash cannot be transposed with another
2021-05-11 02:29:21 +02:00
character). Similarly, errors are counted separately for non-contiguous
2022-08-24 15:22:41 +02:00
strings in the pattern, so that (ab|cd)ef is two errors from aebf.</p>
<p>When using exclusion via the ~ operator, approximate matching is
2021-05-11 02:29:21 +02:00
treated entirely separately for the excluded part and must be activated
2022-08-24 15:22:41 +02:00
separately. Thus, (#a1)README~READ_ME matches READ.ME but not READ_ME,
as the trailing READ_ME is matched without approximation. However,
(#a1)README~(#a1)READ_ME does not match any pattern of the form
READ<code>?</code>ME as all such forms are now excluded.</p>
2021-05-11 02:29:21 +02:00
<p>Apart from exclusions, there is only one overall error count; however,
the maximum errors allowed may be altered locally, and this can be
2022-08-24 15:22:41 +02:00
delimited by grouping. For example, (#a1)cat((#a0)dog)fox allows one
error in total, which may not occur in the dog section, and the pattern
(#a1)cat(#a0)dog(#a1)fox is equivalent. Note that the point at which an
error is first found is the crucial one for establishing whether to use
approximation; for example, (#a1)abc(#a0)xyz will not match abcdxyz,
because the error occurs at the x, where approximation is turned off.</p>
2021-05-11 02:29:21 +02:00
<p>Entire path segments may be matched approximately, so that
2022-08-24 15:22:41 +02:00
(#a1)/foo/d/is/available/at/the/bar allows one error in any path
segment. This is much less efficient than without the (#a1), however,
2021-05-11 02:29:21 +02:00
since every directory in the path must be scanned for a possible
2022-08-24 15:22:41 +02:00
approximate match. It is best to place the (#a1) after any path segments
which are known to be correct.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Recursive-Globbing"></span></p>
<h3 id="1486-recursive-globbing"><a class="header" href="#1486-recursive-globbing">14.8.6 Recursive Globbing</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-recursive-globbing"></span> <span
id="index-globbing_002c-recursive"></span></p>
<p>A pathname component of the form (<code>foo</code>/)# matches a path consisting
of zero or more directories matching the pattern <code>foo</code>.</p>
<p>As a shorthand, **/ is equivalent to (*/)#; note that this
2021-05-11 02:29:21 +02:00
therefore matches files in the current directory as well as
subdirectories. Thus:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">ls -ld -- (*/)#bar
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>or</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">ls -ld -- **/bar
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>does a recursive directory search for files named bar (potentially
including the file bar in the current directory). This form does not
follow symbolic links; the alternative form ***/ does, but is
2021-05-11 02:29:21 +02:00
otherwise identical. Neither of these can be combined with other forms
2022-08-24 15:22:41 +02:00
of globbing within the same path segment; in that case, the *
2021-05-11 02:29:21 +02:00
operators revert to their usual effect.</p>
2022-08-24 15:22:41 +02:00
<p>Even shorter forms are available when the option GLOB_STAR_SHORT is set.
In that case if no / immediately follows a ** or *** they are
treated as if both a / plus a further * are present. Hence:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">setopt GLOBSTARSHORT
2021-05-11 02:29:21 +02:00
ls -ld -- **.c
</code></pre>
</div>
<p>is equivalent to</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">ls -ld -- **/*.c
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<hr />
<p><span id="Glob-Qualifiers"></span></p>
<h3 id="1487-glob-qualifiers"><a class="header" href="#1487-glob-qualifiers">14.8.7 Glob Qualifiers</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-globbing_002c-qualifiers"></span> <span
id="index-qualifiers_002c-globbing"></span></p>
2021-05-11 02:29:21 +02:00
<p>Patterns used for filename generation may end in a list of qualifiers
enclosed in parentheses. The qualifiers specify which filenames that
otherwise match the given pattern will be inserted in the argument list.</p>
<p><span id="index-BARE_005fGLOB_005fQUAL_002c-use-of"></span></p>
2022-08-24 15:22:41 +02:00
<p>If the option BARE_GLOB_QUAL is set, then a trailing set of parentheses
containing no | or ( characters (or ~ if it is special) is taken
as a set of glob qualifiers. A glob subexpression that would normally be
taken as glob qualifiers, for example (^x), can be forced to be
treated as part of the glob pattern by doubling the parentheses, in this
case producing ((^x)).</p>
<p>If the option EXTENDED_GLOB is set, a different syntax for glob
qualifiers is available, namely (#q<code>x</code>) where <code>x</code> is any of the same
glob qualifiers used in the other format. The qualifiers must still
2021-05-11 02:29:21 +02:00
appear at the end of the pattern. However, with this syntax multiple
glob qualifiers may be chained together. They are treated as a logical
AND of the individual sets of flags. Also, as the syntax is unambiguous,
the expression will be treated as glob qualifiers just as long any
2022-08-24 15:22:41 +02:00
parentheses contained within it are balanced; appearance of |, ( or
~ does not negate the effect. Note that qualifiers will be recognised
in this form even if a bare glob qualifier exists at the end of files if
both options are set; however, mixed syntax should probably be avoided
for the sake of clarity. Note that within conditions using the [[
form the presence of a parenthesised expression (#q<code>...</code>) at the end of
a string indicates that globbing should be performed; the expression may
include glob qualifiers, but it is also valid if it is simply (#q). This
does not apply to the right hand side of pattern match operators as the
syntax already has special significance.</p>
2021-05-11 02:29:21 +02:00
<p>A qualifier may be any one of the following:</p>
2022-08-24 15:22:41 +02:00
<p>/<br />
2021-05-11 02:29:21 +02:00
directories</p>
2022-08-24 15:22:41 +02:00
<p>F<br />
full (i.e. non-empty) directories. Note that the opposite sense (^F)
expands to empty directories and all non-directories. Use (/^F) for
empty directories.</p>
<p>.<br />
2021-05-11 02:29:21 +02:00
plain files</p>
2022-08-24 15:22:41 +02:00
<p>@<br />
2021-05-11 02:29:21 +02:00
symbolic links</p>
2022-08-24 15:22:41 +02:00
<p>=<br />
2021-05-11 02:29:21 +02:00
sockets</p>
2022-08-24 15:22:41 +02:00
<p>p<br />
2021-05-11 02:29:21 +02:00
named pipes (FIFOs)</p>
2022-08-24 15:22:41 +02:00
<p>*<br />
%<br />
2021-05-11 02:29:21 +02:00
device files (character or block special)</p>
2022-08-24 15:22:41 +02:00
<p>%b<br />
2021-05-11 02:29:21 +02:00
block special files</p>
2022-08-24 15:22:41 +02:00
<p>%c<br />
2021-05-11 02:29:21 +02:00
character special files</p>
2022-08-24 15:22:41 +02:00
<p>r<br />
2021-05-11 02:29:21 +02:00
owner-readable files (0400)</p>
2022-08-24 15:22:41 +02:00
<p>w<br />
x<br />
A<br />
2021-05-11 02:29:21 +02:00
group-readable files (0040)</p>
2022-08-24 15:22:41 +02:00
<p>I<br />
E<br />
R<br />
2021-05-11 02:29:21 +02:00
world-readable files (0004)</p>
2022-08-24 15:22:41 +02:00
<p>W<br />
X<br />
s<br />
2021-05-11 02:29:21 +02:00
setuid files (04000)</p>
2022-08-24 15:22:41 +02:00
<p>S<br />
2021-05-11 02:29:21 +02:00
setgid files (02000)</p>
2022-08-24 15:22:41 +02:00
<p>t<br />
2021-05-11 02:29:21 +02:00
files with the sticky bit (01000)</p>
2022-08-24 15:22:41 +02:00
<p>f<code>spec</code><br />
2021-05-11 02:29:21 +02:00
files with access rights matching <code>spec</code>. This <code>spec</code> may be a octal
2022-08-24 15:22:41 +02:00
number optionally preceded by a =, a +, or a -. If none of these
characters is given, the behavior is the same as for =. The octal
number describes the mode bits to be expected, if combined with a =,
the value given must match the file-modes exactly, with a +, at least
the bits in the given number must be set in the file-modes, and with a
-, the bits in the number must not be set. Giving a ? instead of a
octal digit anywhere in the number ensures that the corresponding bits
in the file-modes are not checked, this is only useful in combination
with =.</p>
<p>If the qualifier f is followed by any other character anything up to
the next matching character ([, {, and &lt; match ], }, and
&gt; respectively, any other character matches itself) is taken as a list
of comma-separated <code>sub-spec</code>s. Each <code>sub-spec</code> may be either an octal
number as described above or a list of any of the characters u, g,
o, and a, followed by a =, a +, or a -, followed by a list of
any of the characters r, w, x, s, and t, or an octal digit.
The first list of characters specify which access rights are to be
checked. If a u is given, those for the owner of the file are used, if
a g is given, those of the group are checked, a o means to test
those of other users, and the a says to test all three groups. The
=, +, and - again says how the modes are to be checked and have
the same meaning as described for the first form above. The second list
of characters finally says which access rights are to be expected: r
for read access, w for write access, x for the right to execute the
file (or to search a directory), s for the setuid and setgid bits, and
t for the sticky bit.</p>
<p>Thus, *(f70?) gives the files for which the owner has read, write,
and execute permission, and for which other group members have no
rights, independent of the permissions for other users. The pattern
*(f-100) gives all files for which the owner does not have execute
permission, and *(f:gu+w,o-rx:) gives the files for which the owner
and the other members of the group have at least write permission, and
for which other users dont have read or execute permission.</p>
<p>e<code>string</code><br />
+<code>cmd</code><br />
2021-05-11 02:29:21 +02:00
The <code>string</code> will be executed as shell code. The filename will be
included in the list if and only if the code returns a zero status
(usually the status of the last command).</p>
2022-08-24 15:22:41 +02:00
<p>In the first form, the first character after the e will be used as a
separator and anything up to the next matching separator will be taken
as the <code>string</code>; [, {, and &lt; match ], }, and &gt;,
respectively, while any other character matches itself. Note that
expansions must be quoted in the <code>string</code> to prevent them from being
expanded before globbing is done. <code>string</code> is then executed as shell
code. The string globqual is appended to the array zsh_eval_context the
duration of execution.</p>
<p><span id="index-REPLY_002c-use-of-1"></span> <span
id="index-reply_002c-use-of"></span></p>
<p>During the execution of <code>string</code> the filename currently being tested is
available in the parameter REPLY; the parameter may be altered to a
string to be inserted into the list instead of the original filename. In
addition, the parameter reply may be set to an array or a string, which
overrides the value of REPLY. If set to an array, the latter is inserted
into the command line word by word.</p>
<p>For example, suppose a directory contains a single file lonely. Then
the expression *(e:reply=(${REPLY}{1,2}):) will cause the words
lonely1 and lonely2 to be inserted into the command line. Note the
quoting of <code>string</code>.</p>
<p>The form +<code>cmd</code> has the same effect, but no delimiters appear around
<code>cmd</code>. Instead, <code>cmd</code> is taken as the longest sequence of characters
following the + that are alphanumeric or underscore. Typically <code>cmd</code>
will be the name of a shell function that contains the appropriate test.
For example,</p>
<div class="example">
<pre><code class="language-zsh">nt() { [[ $REPLY -nt $NTREF ]] }
2021-05-11 02:29:21 +02:00
NTREF=reffile
ls -ld -- *(+nt)
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>lists all files in the directory that have been modified more recently
than reffile.</p>
<p>d<code>dev</code><br />
2021-05-11 02:29:21 +02:00
files on the device <code>dev</code></p>
2022-08-24 15:22:41 +02:00
<p>l[-|+]<code>ct</code><br />
files having a link count less than <code>ct</code> (-), greater than <code>ct</code> (+), or
equal to <code>ct</code></p>
<p>U<br />
2021-05-11 02:29:21 +02:00
files owned by the effective user ID</p>
2022-08-24 15:22:41 +02:00
<p>G<br />
2021-05-11 02:29:21 +02:00
files owned by the effective group ID</p>
2022-08-24 15:22:41 +02:00
<p>u<code>id</code><br />
2021-05-11 02:29:21 +02:00
files owned by user ID <code>id</code> if that is a number. Otherwise, <code>id</code>
2022-08-24 15:22:41 +02:00
specifies a user name: the character after the u will be taken as a
separator and the string between it and the next matching separator will
be taken as a user name. The starting separators [, {, and &lt;
match the final separators ], }, and &gt;, respectively; any other
character matches itself. The selected files are those owned by this
user. For example, u:foo: or u[foo] selects files owned by user
foo.</p>
<p>g<code>id</code><br />
like u<code>id</code> but with group IDs or names</p>
<p>a[Mwhms][-|+]<code>n</code><br />
files accessed exactly <code>n</code> days ago. Files accessed within the last <code>n</code>
days are selected using a negative value for <code>n</code> (-<code>n</code>). Files accessed
more than <code>n</code> days ago are selected by a positive <code>n</code> value (+<code>n</code>).
Optional unit specifiers M, w, h, m or s (e.g. ah5) cause
the check to be performed with months (of 30 days), weeks, hours,
minutes or seconds instead of days, respectively. An explicit d for
days is also allowed.</p>
<p>Any fractional part of the difference between the access time and the
current part in the appropriate units is ignored in the comparison. For
instance, echo *(ah-5) would echo files accessed within the last five
hours, while echo *(ah+5) would echo files accessed at least six
hours ago, as times strictly between five and six hours are treated as
five hours.</p>
<p>m[Mwhms][-|+]<code>n</code><br />
2021-05-11 02:29:21 +02:00
like the file access qualifier, except that it uses the file
modification time.</p>
2022-08-24 15:22:41 +02:00
<p>c[Mwhms][-|+]<code>n</code><br />
2021-05-11 02:29:21 +02:00
like the file access qualifier, except that it uses the file inode
change time.</p>
2022-08-24 15:22:41 +02:00
<p>L[+|-]<code>n</code><br />
files less than <code>n</code> bytes (-), more than <code>n</code> bytes (+), or exactly <code>n</code>
bytes in length.</p>
<p>If this flag is directly followed by a <em>size specifier</em> k (K), m
(M), or p (P) (e.g. Lk-50) the check is performed with
kilobytes, megabytes, or blocks (of 512 bytes) instead. (On some systems
additional specifiers are available for gigabytes, g or G, and
terabytes, t or T.) If a size specifier is used a file is regarded
as &quot;exactly&quot; the size if the file size rounded up to the next unit is
equal to the test size. Hence *(Lm1) matches files from 1 byte up to
1 Megabyte inclusive. Note also that the set of files &quot;less than&quot; the
test size only includes files that would not match the equality test;
hence *(Lm-1) only matches files of zero size.</p>
<p>^<br />
2021-05-11 02:29:21 +02:00
negates all qualifiers following it</p>
2022-08-24 15:22:41 +02:00
<p>-<br />
2021-05-11 02:29:21 +02:00
toggles between making the qualifiers work on symbolic links (the
2022-08-24 15:22:41 +02:00
default) and the files they point to, if any; any symbolic link for
whose target the stat system call fails (whatever the cause of the
failure) is treated as a file in its own right</p>
<p>M<br />
sets the MARK_DIRS option for the current pattern <span
id="index-MARK_005fDIRS_002c-setting-in-pattern"></span></p>
<p>T<br />
2021-05-11 02:29:21 +02:00
appends a trailing qualifier mark to the filenames, analogous to the
2022-08-24 15:22:41 +02:00
LIST_TYPES option, for the current pattern (overrides M)</p>
<p>N<br />
sets the NULL_GLOB option for the current pattern <span
id="index-NULL_005fGLOB_002c-setting-in-pattern"></span></p>
<p>D<br />
sets the GLOB_DOTS option for the current pattern <span
id="index-GLOB_005fDOTS_002c-setting-in-pattern"></span></p>
<p>n<br />
sets the NUMERIC_GLOB_SORT option for the current pattern <span
id="index-NUMERIC_005fGLOB_005fSORT_002c-setting-in-pattern"></span></p>
<p>Y<code>n</code><br />
2021-05-11 02:29:21 +02:00
enables short-circuit mode: the pattern will expand to at most <code>n</code>
2022-08-24 15:22:41 +02:00
filenames. If more than <code>n</code> matches exist, only the first <code>n</code> matches in
directory traversal order will be considered.</p>
<p>Implies oN when no o<code>c</code> qualifier is used.</p>
<p>o<code>c</code><br />
specifies how the names of the files should be sorted. The following
values of <code>c</code> sort in the following ways:</p>
<p>n<br />
By name.</p>
<p>L<br />
By the size (length) of the files.</p>
<p>l<br />
By number of links.</p>
<p>a<br />
By time of last access, youngest first.</p>
<p>m<br />
By time of last modification, youngest first.</p>
<p>c<br />
By time of last inode change, youngest first.</p>
<p>d<br />
By directories: files in subdirectories appear before those in the
current directory at each level of the search — this is best combined
with other criteria, for example odon to sort on names for files
within the same directory.</p>
<p>N<br />
No sorting is performed.</p>
<p>e<code>string</code><br />
+<code>cmd</code><br />
Sort by shell code (see below).</p>
<p>Note that the modifiers ^ and - are used, so *(^-oL) gives a list of
all files sorted by file size in descending order, following any
symbolic links. Unless oN is used, multiple order specifiers may occur
to resolve ties.</p>
<p>The default sorting is n (by name) unless the Y glob qualifier is used,
in which case it is N (unsorted).</p>
<p>oe and o+ are special cases; they are each followed by shell code,
delimited as for the e glob qualifier and the + glob qualifier
respectively (see above). The code is executed for each matched file
with the parameter REPLY set to the name of the file on entry and
globsort appended to zsh_eval_context. The code should modify the
parameter REPLY in some fashion. On return, the value of the parameter
is used instead of the file name as the string on which to sort. Unlike
other sort operators, oe and o+ may be repeated, but note that the
maximum number of sort operators of any kind that may appear in any glob
expression is 12.</p>
<p>O<code>c</code><br />
like o, but sorts in descending order; i.e. *(^o<code>c</code>) is the same as
*(O<code>c</code>) and *(^O<code>c</code>) is the same as *(o<code>c</code>); Od puts files in
the current directory before those in subdirectories at each level of
the search.</p>
<p>[<code>beg</code>[,<code>end</code>]]<br />
2021-05-11 02:29:21 +02:00
specifies which of the matched filenames should be included in the
2022-08-24 15:22:41 +02:00
returned list. The syntax is the same as for array subscripts. <code>beg</code> and
the optional <code>end</code> may be mathematical expressions. As in parameter
subscripting they may be negative to make them count from the last match
backward. E.g.: *(-OL[1,3]) gives a list of the names of the three
largest files.</p>
<p>P<code>string</code><br />
The <code>string</code> will be prepended to each glob match as a separate word.
<code>string</code> is delimited in the same way as arguments to the e glob
qualifier described above. The qualifier can be repeated; the words are
prepended separately so that the resulting command line contains the
words in the same order they were given in the list of glob qualifiers.</p>
<p>A typical use for this is to prepend an option before all occurrences of
a file name; for example, the pattern *(P:-f:) produces the command
line arguments -f <code>file1</code> -f <code>file2</code> ...</p>
<p>If the modifier ^ is active, then <code>string</code> will be appended instead of
prepended. Prepending and appending is done independently so both can be
used on the same glob expression; for example by writing
*(P:foo:^P:bar:^P:baz:) which produces the command line arguments
foo baz <code>file1</code> bar ...</p>
2021-05-11 02:29:21 +02:00
<p>More than one of these lists can be combined, separated by commas. The
whole list matches if at least one of the sublists matches (they are
2022-08-24 15:22:41 +02:00
ored, the qualifiers in the sublists are anded). Some qualifiers,
however, affect all matches generated, independent of the sublist in
which they are given. These are the qualifiers M, T, N, D, n,
o, O and the subscripts given in brackets ([<code>...</code>]).</p>
<p>If a : appears in a qualifier list, the remainder of the expression in
parenthesis is interpreted as a modifier (see <a href="Expansion.html#Modifiers">Modifiers</a> in
<a href="Expansion.html#History-Expansion">History Expansion</a>). Each modifier must be
introduced by a separate :. Note also that the result after
2021-05-11 02:29:21 +02:00
modification does not have to be an existing file. The name of any
2022-08-24 15:22:41 +02:00
existing file can be followed by a modifier of the form (:<code>...</code>) even
if no actual filename generation is performed, although note that the
presence of the parentheses causes the entire expression to be subjected
to any global pattern matching options such as NULL_GLOB. Thus:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">ls -ld -- *(-/)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>lists all directories and symbolic links that point to directories, and</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">ls -ld -- *(-@)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>lists all broken symbolic links, and</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">ls -ld -- *(%W)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">ls -ld -- *(W,X)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>lists all files in the current directory that are</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">print -rC1 /tmp/foo*(u0^@:t)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>outputs the basename of all root-owned files beginning with the string
2022-08-24 15:22:41 +02:00
foo in /tmp, ignoring symlinks, and</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">ls -ld -- *.*~(lex|parse).[ch](^D^l1)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>lists all files having a link count of one whose names contain a dot
2022-08-24 15:22:41 +02:00
(but not those starting with a dot, since GLOB_DOTS is explicitly
switched off) except for lex.c, lex.h, parse.c and parse.h.</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">print -rC1 b*.pro(#q:s/pro/shmo/)(#q.:s/builtin/shmiltin/)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>demonstrates how colon modifiers and other qualifiers may be chained
2022-08-24 15:22:41 +02:00
together. The ordinary qualifier . is applied first, then the colon
modifiers in order from left to right. So if EXTENDED_GLOB is set and
the base pattern matches the regular file builtin.pro, the shell will
print shmiltin.shmo.</p>
<hr />
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="Parameters.html#15-parameters">15 Parameters</a>
<ul>
<li><a href="Parameters.html#151-description">15.1 Description</a></li>
<li><a href="Parameters.html#152-array-parameters">15.2 Array Parameters</a>
<ul>
<li><a href="Parameters.html#1521-array-subscripts">15.2.1 Array Subscripts</a></li>
<li><a href="Parameters.html#1522-array-element-assignment">15.2.2 Array Element Assignment</a></li>
<li><a href="Parameters.html#1523-subscript-flags">15.2.3 Subscript Flags</a></li>
<li><a href="Parameters.html#1524-subscript-parsing">15.2.4 Subscript Parsing</a></li>
</ul>
</li>
<li><a href="Parameters.html#153-positional-parameters">15.3 Positional Parameters</a></li>
<li><a href="Parameters.html#154-local-parameters">15.4 Local Parameters</a></li>
<li><a href="Parameters.html#155-parameters-set-by-the-shell">15.5 Parameters Set By The Shell</a></li>
2022-08-24 15:22:41 +02:00
</ul>
</li>
<li><a href="Parameters.html#%5Cs">&lt;S&gt;</a>
<ul>
2021-05-11 02:29:21 +02:00
<li><a href="Parameters.html#156-parameters-used-by-the-shell">15.6 Parameters Used By The Shell</a></li>
</ul>
</li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2022-08-24 15:22:41 +02:00
<p><span id="Parameters"></span> <span id="Parameters-3"></span></p>
2021-05-11 02:29:21 +02:00
<h1 id="15-parameters"><a class="header" href="#15-parameters">15 Parameters</a></h1>
<p><span id="index-parameters"></span> <span id="index-variables"></span></p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Description-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="151-description"><a class="header" href="#151-description">15.1 Description</a></h2>
<p>A parameter has a name, a value, and a number of attributes. A name may
be any sequence of alphanumeric characters and underscores, or the
2022-08-24 15:22:41 +02:00
single characters *, @, #, ?, -, $, or !. A parameter
whose name begins with an alphanumeric or underscore is also referred to
as a <em>variable</em>.</p>
<p><span id="index-scalar"></span> <span
id="index-parameters_002c-scalar"></span> <span
id="index-parameters_002c-array"></span> <span
id="index-parameters_002c-associative-array"></span> <span
id="index-hash"></span></p>
2021-05-11 02:29:21 +02:00
<p>The attributes of a parameter determine the <em>type</em> of its value, often
referred to as the parameter type or variable type, and also control
other processing that may be applied to the value when it is referenced.
The value type may be a <em>scalar</em> (a string, an integer, or a floating
point number), an array (indexed numerically), or an <em>associative</em> array
(an unordered set of name-value pairs, indexed by name, also referred to
as a <em>hash</em>).</p>
<p><span id="index-export"></span> <span id="index-environment"></span>
2022-08-24 15:22:41 +02:00
<span id="index-environment-variables"></span> <span
id="index-variables_002c-environment"></span></p>
<p>Named scalar parameters may have the <em>exported</em>, -x, attribute, to copy
them into the process environment, which is then passed from the shell
to any new processes that it starts. Exported parameters are called
<em>environment variables</em>. The shell also <em>imports</em> environment variables
at startup time and automatically marks the corresponding parameters as
exported. Some environment variables are not imported for reasons of
security or because they would interfere with the correct operation of
other shell features.</p>
<p><span id="index-special-parameters"></span> <span
id="index-parameters_002c-special"></span></p>
2021-05-11 02:29:21 +02:00
<p>Parameters may also be <em>special</em>, that is, they have a predetermined
meaning to the shell. Special parameters cannot have their type changed
or their readonly attribute turned off, and if a special parameter is
unset, then later recreated, the special properties will be retained.</p>
<p>To declare the type of a parameter, or to assign a string or numeric
2022-08-24 15:22:41 +02:00
value to a scalar parameter, use the typeset builtin. <span
id="index-typeset_002c-use-of"></span></p>
<p>The value of a scalar parameter may also be assigned by writing: <span
id="index-assignment"></span></p>
2021-05-11 02:29:21 +02:00
<blockquote>
2022-08-24 15:22:41 +02:00
<p><code>name</code>=<code>value</code></p>
2021-05-11 02:29:21 +02:00
</blockquote>
<p>In scalar assignment, <code>value</code> is expanded as a single string, in which
the elements of arrays are joined together; filename expansion is not
2022-08-24 15:22:41 +02:00
performed unless the option GLOB_ASSIGN is set.</p>
<p>When the integer attribute, -i, or a floating point attribute, -E or -F,
is set for <code>name</code>, the <code>value</code> is subject to arithmetic evaluation.
Furthermore, by replacing = with +=, a parameter can be incremented
or appended to. See <a href="Parameters.html#Array-Parameters">Array Parameters</a> and
<a href="Arithmetic-Evaluation.html#Arithmetic-Evaluation">Arithmetic
2021-05-11 02:29:21 +02:00
Evaluation</a> for
additional forms of assignment.</p>
<p>Note that assignment may implicitly change the attributes of a
parameter. For example, assigning a number to a variable in arithmetic
2022-08-24 15:22:41 +02:00
evaluation may change its type to integer or float, and with GLOB_ASSIGN
assigning a pattern to a variable may change its type to an array.</p>
<p>To reference the value of a parameter, write $<code>name</code> or ${<code>name</code>}.
See <a href="Expansion.html#Parameter-Expansion">Parameter Expansion</a> for
complete details. That section also explains the effect of the
difference between scalar and array assignment on parameter expansion.</p>
<hr />
<p><span id="Array-Parameters"></span> <span
id="Array-Parameters-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="152-array-parameters"><a class="header" href="#152-array-parameters">15.2 Array Parameters</a></h2>
2022-08-24 15:22:41 +02:00
<p>To assign an array value, write one of: <span
id="index-set_002c-use-of"></span> <span
id="index-array-assignment"></span></p>
2021-05-11 02:29:21 +02:00
<blockquote>
2022-08-24 15:22:41 +02:00
<p>set -A <code>name</code> <code>value</code> ...</p>
2021-05-11 02:29:21 +02:00
</blockquote>
<blockquote>
2022-08-24 15:22:41 +02:00
<p><code>name</code>=(<code>value</code> ...)</p>
2021-05-11 02:29:21 +02:00
</blockquote>
<blockquote>
2022-08-24 15:22:41 +02:00
<p><code>name</code>=([<code>key</code>]=<code>value</code> ...)</p>
2021-05-11 02:29:21 +02:00
</blockquote>
<p>If no parameter <code>name</code> exists, an ordinary array parameter is created.
If the parameter <code>name</code> exists and is a scalar, it is replaced by a new
array.</p>
<p>In the third form, <code>key</code> is an expression that will be evaluated in
arithmetic context (in its simplest form, an integer) that gives the
index of the element to be assigned with <code>value</code>. In this form any
elements not explicitly mentioned that come before the largest index to
which a value is assigned are assigned an empty string. The indices may
2022-08-24 15:22:41 +02:00
be in any order. Note that this syntax is strict: [ and ]= must not be
quoted, and <code>key</code> may not consist of the unquoted string ]=, but is
2021-05-11 02:29:21 +02:00
otherwise treated as a simple string. The enhanced forms of subscript
expression that may be used when directly subscripting a variable name,
2022-08-24 15:22:41 +02:00
described in the section Array Subscripts below, are not available.</p>
2021-05-11 02:29:21 +02:00
<p>The syntaxes with and without the explicit key may be mixed. An implicit
<code>key</code> is deduced by incrementing the index from the previously assigned
element. Note that it is not treated as an error if latter assignments
in this form overwrite earlier assignments.</p>
2022-08-24 15:22:41 +02:00
<p>For example, assuming the option KSH_ARRAYS is not set, the following:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">array=(one [3]=three four)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>causes the array variable array to contain four elements one, an empty
string, three and four, in that order.</p>
2021-05-11 02:29:21 +02:00
<p>In the forms where only <code>value</code> is specified, full command line
expansion is performed.</p>
2022-08-24 15:22:41 +02:00
<p>In the [<code>key</code>]=<code>value</code> form, both <code>key</code> and <code>value</code> undergo all forms
of expansion allowed for single word shell expansions (this does not
include filename generation); these are as performed by the parameter
expansion flag (e) as described in <a href="Expansion.html#Parameter-Expansion">Parameter
2021-05-11 02:29:21 +02:00
Expansion</a>. Nested parentheses may
surround <code>value</code> and are included as part of the value, which is joined
into a plain string; this differs from ksh which allows the values
themselves to be arrays. A future version of zsh may support that. To
cause the brackets to be interpreted as a character class for filename
generation, and therefore to treat the resulting list of files as a set
of values, quote the equal sign using any form of quoting. Example:</p>
<blockquote>
2022-08-24 15:22:41 +02:00
<p><code>name</code>=([a-z]=*)</p>
2021-05-11 02:29:21 +02:00
</blockquote>
<p>To append to an array without changing the existing values, use one of
the following:</p>
<blockquote>
2022-08-24 15:22:41 +02:00
<p><code>name</code>+=(<code>value</code> ...)</p>
2021-05-11 02:29:21 +02:00
</blockquote>
<blockquote>
2022-08-24 15:22:41 +02:00
<p><code>name</code>+=([<code>key</code>]=<code>value</code> ...)</p>
2021-05-11 02:29:21 +02:00
</blockquote>
<p>In the second form <code>key</code> may specify an existing index as well as an
index off the end of the old array; any existing value is overwritten by
2022-08-24 15:22:41 +02:00
<code>value</code>. Also, it is possible to use [<code>key</code>]+=<code>value</code> to append to the
existing value at that index.</p>
2021-05-11 02:29:21 +02:00
<p>Within the parentheses on the right hand side of either form of the
assignment, newlines and semicolons are treated the same as white space,
separating individual <code>value</code>s. Any consecutive sequence of such
characters has the same effect.</p>
2022-08-24 15:22:41 +02:00
<p>Ordinary array parameters may also be explicitly declared with: <span
id="index-typeset_002c-use-of-1"></span></p>
2021-05-11 02:29:21 +02:00
<blockquote>
2022-08-24 15:22:41 +02:00
<p>typeset -a <code>name</code></p>
2021-05-11 02:29:21 +02:00
</blockquote>
<p>Associative arrays <em>must</em> be declared before assignment, by using:</p>
<blockquote>
2022-08-24 15:22:41 +02:00
<p>typeset -A <code>name</code></p>
2021-05-11 02:29:21 +02:00
</blockquote>
<p>When <code>name</code> refers to an associative array, the list in an assignment is
interpreted as alternating keys and values:</p>
<blockquote>
2022-08-24 15:22:41 +02:00
<p>set -A <code>name</code> <code>key</code> <code>value</code> ...</p>
2021-05-11 02:29:21 +02:00
</blockquote>
<blockquote>
2022-08-24 15:22:41 +02:00
<p><code>name</code>=(<code>key</code> <code>value</code> ...)</p>
2021-05-11 02:29:21 +02:00
</blockquote>
<blockquote>
2022-08-24 15:22:41 +02:00
<p><code>name</code>=([<code>key</code>]=<code>value</code> ...)</p>
2021-05-11 02:29:21 +02:00
</blockquote>
<p>Note that only one of the two syntaxes above may be used in any given
assignment; the forms may not be mixed. This is unlike the case of
numerically indexed arrays.</p>
<p>Every <code>key</code> must have a <code>value</code> in this case. Note that this assigns to
the entire array, deleting any elements that do not appear in the list.
The append syntax may also be used with an associative array:</p>
<blockquote>
2022-08-24 15:22:41 +02:00
<p><code>name</code>+=(<code>key</code> <code>value</code> ...)</p>
2021-05-11 02:29:21 +02:00
</blockquote>
<blockquote>
2022-08-24 15:22:41 +02:00
<p><code>name</code>+=([<code>key</code>]=<code>value</code> ...)</p>
2021-05-11 02:29:21 +02:00
</blockquote>
<p>This adds a new key/value pair if the key is not already present, and
replaces the value for the existing key if it is. In the second form it
2022-08-24 15:22:41 +02:00
is also possible to use [<code>key</code>]+=<code>value</code> to append to the existing
2021-05-11 02:29:21 +02:00
value at that key. Expansion is performed identically to the
corresponding forms for normal arrays, as described above.</p>
<p>To create an empty array (including associative arrays), use one of:</p>
<blockquote>
2022-08-24 15:22:41 +02:00
<p>set -A <code>name</code></p>
2021-05-11 02:29:21 +02:00
</blockquote>
<blockquote>
2022-08-24 15:22:41 +02:00
<p><code>name</code>=()</p>
2021-05-11 02:29:21 +02:00
</blockquote>
<hr />
<p><span id="Array-Subscripts"></span></p>
<h3 id="1521-array-subscripts"><a class="header" href="#1521-array-subscripts">15.2.1 Array Subscripts</a></h3>
<p><span id="index-subscripts"></span></p>
<p>Individual elements of an array may be selected using a subscript. A
2022-08-24 15:22:41 +02:00
subscript of the form [<code>exp</code>] selects the single element <code>exp</code>,
2021-05-11 02:29:21 +02:00
where <code>exp</code> is an arithmetic expression which will be subject to
2022-08-24 15:22:41 +02:00
arithmetic expansion as if it were surrounded by $((...)). The
elements are numbered beginning with 1, unless the KSH_ARRAYS option is
set in which case they are numbered from zero. <span
id="index-KSH_005fARRAYS_002c-use-of"></span></p>
2021-05-11 02:29:21 +02:00
<p>Subscripts may be used inside braces used to delimit a parameter name,
2022-08-24 15:22:41 +02:00
thus ${foo[2]} is equivalent to $foo[2]. If the KSH_ARRAYS
2021-05-11 02:29:21 +02:00
option is set, the braced form is the only one that works, as bracketed
expressions otherwise are not treated as subscripts.</p>
2022-08-24 15:22:41 +02:00
<p>If the KSH_ARRAYS option is not set, then by default accesses to an
2021-05-11 02:29:21 +02:00
array element with a subscript that evaluates to zero return an empty
string, while an attempt to write such an element is treated as an
2022-08-24 15:22:41 +02:00
error. For backward compatibility the KSH_ZERO_SUBSCRIPT option can be
2021-05-11 02:29:21 +02:00
set to cause subscript values 0 and 1 to be equivalent; see the
description of the option in <a href="Options.html#Description-of-Options">Description of
Options</a>.</p>
<p>The same subscripting syntax is used for associative arrays, except that
no arithmetic expansion is applied to <code>exp</code>. However, the parsing rules
for arithmetic expressions still apply, which affects the way that
certain special characters must be protected from interpretation. See
<em>Subscript Parsing</em> below for details.</p>
2022-08-24 15:22:41 +02:00
<p>A subscript of the form [*] or [@] evaluates to all elements of
2021-05-11 02:29:21 +02:00
an array; there is no difference between the two except when they appear
2022-08-24 15:22:41 +02:00
within double quotes. &quot;$foo[*]&quot; evaluates to &quot;$foo[1] $foo[2]
...&quot;, whereas &quot;$foo[@]&quot; evaluates to &quot;$foo[1]&quot; &quot;$foo[2]&quot; ....
For associative arrays, [*] or [@] evaluate to all the values,
in no particular order. Note that this does not substitute the keys; see
the documentation for the k flag under <a href="Expansion.html#Parameter-Expansion">Parameter
2021-05-11 02:29:21 +02:00
Expansion</a> for complete details.
2022-08-24 15:22:41 +02:00
When an array parameter is referenced as $<code>name</code> (with no subscript)
it evaluates to $<code>name</code>[*], unless the KSH_ARRAYS option is set in
which case it evaluates to ${<code>name</code>[0]} (for an associative array,
this means the value of the key 0, which may not exist even if there
are values for other keys).</p>
<p>A subscript of the form [<code>exp1</code>,<code>exp2</code>] selects all elements in the
range <code>exp1</code> to <code>exp2</code>, inclusive. (Associative arrays are unordered,
and so do not support ranges.) If one of the subscripts evaluates to a
negative number, say -<code>n</code>, then the <code>n</code>th element from the end of the
array is used. Thus $foo[-3] is the third element from the end of
the array foo, and $foo[1,-1] is the same as $foo[*].</p>
2021-05-11 02:29:21 +02:00
<p>Subscripting may also be performed on non-array values, in which case
2022-08-24 15:22:41 +02:00
the subscripts specify a substring to be extracted. For example, if FOO
is set to foobar, then echo $FOO[2,5] prints ooba. Note that
some forms of subscripting described below perform pattern matching, and
in that case the substring extends from the start of the match of the
first subscript to the end of the match of the second subscript. For
example,</p>
<div class="example">
<pre><code class="language-zsh">string=&quot;abcdefghijklm&quot;
2021-05-11 02:29:21 +02:00
print ${string[(r)d?,(r)h?]}
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>prints defghi. This is an obvious generalisation of the rule for
2021-05-11 02:29:21 +02:00
single-character matches. For a single subscript, only a single
character is referenced (not the range of characters covered by the
match).</p>
<p>Note that in substring operations the second subscript is handled
2022-08-24 15:22:41 +02:00
differently by the r and R subscript flags: the former takes the
2021-05-11 02:29:21 +02:00
shortest match as the length and the latter the longest match. Hence in
2022-08-24 15:22:41 +02:00
the former case a * at the end is redundant while in the latter case it
matches the whole remainder of the string. This does not affect the
2021-05-11 02:29:21 +02:00
result of the single subscript case as here the length of the match is
irrelevant.</p>
<hr />
<p><span id="Array-Element-Assignment"></span></p>
<h3 id="1522-array-element-assignment"><a class="header" href="#1522-array-element-assignment">15.2.2 Array Element Assignment</a></h3>
<p>A subscript may be used on the left side of an assignment like so:</p>
<blockquote>
2022-08-24 15:22:41 +02:00
<p><code>name</code>[<code>exp</code>]=<code>value</code></p>
2021-05-11 02:29:21 +02:00
</blockquote>
<p>In this form of assignment the element or range specified by <code>exp</code> is
replaced by the expression on the right side. An array (but not an
associative array) may be created by assignment to a range or element.
Arrays do not nest, so assigning a parenthesized list of values to an
element or range changes the number of elements in the array, shifting
the other elements to accommodate the new values. (This is not supported
for associative arrays.)</p>
2022-08-24 15:22:41 +02:00
<p>This syntax also works as an argument to the typeset command:</p>
2021-05-11 02:29:21 +02:00
<blockquote>
2022-08-24 15:22:41 +02:00
<p>typeset &quot;<code>name</code>[<code>exp</code>]&quot;=<code>value</code></p>
2021-05-11 02:29:21 +02:00
</blockquote>
<p>The <code>value</code> may <em>not</em> be a parenthesized list in this case; only
2022-08-24 15:22:41 +02:00
single-element assignments may be made with typeset. Note that quotes
2021-05-11 02:29:21 +02:00
are necessary in this case to prevent the brackets from being
2022-08-24 15:22:41 +02:00
interpreted as filename generation operators. The noglob precommand
2021-05-11 02:29:21 +02:00
modifier could be used instead.</p>
2022-08-24 15:22:41 +02:00
<p>To delete an element of an ordinary array, assign () to that element.
To delete an element of an associative array, use the unset command:</p>
2021-05-11 02:29:21 +02:00
<blockquote>
2022-08-24 15:22:41 +02:00
<p>unset &quot;<code>name</code>[<code>exp</code>]&quot;</p>
2021-05-11 02:29:21 +02:00
</blockquote>
<hr />
<p><span id="Subscript-Flags"></span></p>
<h3 id="1523-subscript-flags"><a class="header" href="#1523-subscript-flags">15.2.3 Subscript Flags</a></h3>
<p><span id="index-subscript-flags"></span></p>
<p>If the opening bracket, or the comma in a range, in any subscript
expression is directly followed by an opening parenthesis, the string up
to the matching closing one is considered to be a list of flags, as in
2022-08-24 15:22:41 +02:00
<code>name</code>[(<code>flags</code>)<code>exp</code>].</p>
<p>The flags s, n and b take an argument; the delimiter is shown below as
:, but any character, or the matching pairs (...), {...},
[...], or &lt;...&gt;, may be used, but note that &lt;...&gt; can only be
used if the subscript is inside a double quoted expression or a
parameter substitution enclosed in braces as otherwise the expression is
interpreted as a redirection.</p>
2021-05-11 02:29:21 +02:00
<p>The flags currently understood are:</p>
2022-08-24 15:22:41 +02:00
<p>w<br />
2021-05-11 02:29:21 +02:00
If the parameter subscripted is a scalar then this flag makes
subscripting work on words instead of characters. The default word
2022-08-24 15:22:41 +02:00
separator is whitespace. When combined with the i or I flag, the effect
is to produce the index of the first character of the first/last word
which matches the given pattern; note that a failed match in this case
always yields 0.</p>
<p>s:<code>string</code>:<br />
This gives the <code>string</code> that separates words (for use with the w flag).
The delimiter character : is arbitrary; see above.</p>
<p>p<br />
Recognize the same escape sequences as the print builtin in the string
argument of a subsequent s flag.</p>
<p>f<br />
2021-05-11 02:29:21 +02:00
If the parameter subscripted is a scalar then this flag makes
subscripting work on lines instead of characters, i.e. with elements
2022-08-24 15:22:41 +02:00
separated by newlines. This is a shorthand for pws:\n:.</p>
<p>r<br />
2021-05-11 02:29:21 +02:00
Reverse subscripting: if this flag is given, the <code>exp</code> is taken as a
2022-08-24 15:22:41 +02:00
pattern and the result is the first matching array element, substring or
word (if the parameter is an array, if it is a scalar, or if it is a
scalar and the w flag is given, respectively). The subscript used is
the number of the matching element, so that pairs of subscripts such as
$foo[(r)??,3] and $foo[(r)??,(r)f*] are possible if the
parameter is not an associative array. If the parameter is an
associative array, only the value part of each pair is compared to the
pattern, and the result is that value.</p>
2021-05-11 02:29:21 +02:00
<p>If a search through an ordinary array failed, the search sets the
subscript to one past the end of the array, and hence
2022-08-24 15:22:41 +02:00
${array[(r)<code>pattern</code>]} will substitute the empty string. Thus the
success of a search can be tested by using the (i) flag, for example
(assuming the option KSH_ARRAYS is not in effect):</p>
<div class="example">
<pre><code class="language-zsh">[[ ${array[(i)pattern]} -le ${#array} ]]
</code></pre>
</div>
<p>If KSH_ARRAYS is in effect, the -le should be replaced by -lt.</p>
<p>R<br />
Like r, but gives the last match. For associative arrays, gives all
possible matches. May be used for assigning to ordinary array elements,
but not for assigning to associative arrays. On failure, for normal
arrays this has the effect of returning the element corresponding to
subscript 0; this is empty unless one of the options KSH_ARRAYS or
KSH_ZERO_SUBSCRIPT is in effect.</p>
<p>Note that in subscripts with both r and R pattern characters are
active even if they were substituted for a parameter (regardless of the
setting of GLOB_SUBST which controls this feature in normal pattern
matching). The flag e can be added to inhibit pattern matching. As
this flag does not inhibit other forms of substitution, care is still
required; using a parameter to hold the key has the desired effect:</p>
<div class="example">
<pre><code class="language-zsh">key2='original key'
2021-05-11 02:29:21 +02:00
print ${array[(Re)$key2]}
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>i<br />
Like r, but gives the index of the match instead; this may not be
combined with a second argument. On the left side of an assignment,
behaves like r. For associative arrays, the key part of each pair is
compared to the pattern, and the first matching key found is the result.
On failure substitutes the length of the array plus one, as discussed
under the description of r, or the empty string for an associative
array.</p>
<p>Note: Although i may be applied to a scalar substitution to find the
offset of a substring, the results are likely to be misleading when
searching within substitutions that yield an empty string, or when
searching for the empty substring.</p>
<p>I<br />
Like i, but gives the index of the last match, or all possible
matching keys in an associative array. On failure substitutes 0, or the
empty string for an associative array. This flag is best when testing
for values or keys that do not exist.</p>
<p>Note: If the option KSH_ARRAYS is in effect and no match is found, the
result is indistinguishable from the case when the first element of the
array matches.</p>
<p>k<br />
2021-05-11 02:29:21 +02:00
If used in a subscript on an associative array, this flag causes the
2022-08-24 15:22:41 +02:00
keys to be interpreted as patterns, and returns the value for the first
key found where <code>exp</code> is matched by the key. Note this could be any such
key as no ordering of associative arrays is defined. This flag does not
work on the left side of an assignment to an associative array element.
If used on another type of parameter, this behaves like r.</p>
<p>K<br />
On an associative array this is like k but returns all values where
<code>exp</code> is matched by the keys. On other types of parameters this has the
same effect as R.</p>
<p>n:<code>expr</code>:<br />
If combined with r, R, i or I, makes them give the <code>n</code>th or
<code>n</code>th last match (if <code>expr</code> evaluates to <code>n</code>). This flag is ignored when
the array is associative. The delimiter character : is arbitrary; see
above.</p>
<p>b:<code>expr</code>:<br />
If combined with r, R, i or I, makes them begin at the <code>n</code>th or
<code>n</code>th last element, word, or character (if <code>expr</code> evaluates to <code>n</code>).
This flag is ignored when the array is associative. The delimiter
character : is arbitrary; see above.</p>
<p>e<br />
2021-05-11 02:29:21 +02:00
This flag causes any pattern matching that would be performed on the
subscript to use plain string matching instead. Hence
2022-08-24 15:22:41 +02:00
${array[(re)*]} matches only the array element whose value is *.
Note that other forms of substitution such as parameter substitution are
not inhibited.</p>
<p>This flag can also be used to force * or @ to be interpreted as a
single key rather than as a reference to all values. It may be used for
either purpose on the left side of an assignment.</p>
2021-05-11 02:29:21 +02:00
<p>See <em>Parameter Expansion Flags</em> (<a href="Expansion.html#Parameter-Expansion">Parameter
Expansion</a>) for additional ways to
manipulate the results of array subscripting.</p>
<hr />
<p><span id="Subscript-Parsing"></span></p>
<h3 id="1524-subscript-parsing"><a class="header" href="#1524-subscript-parsing">15.2.4 Subscript Parsing</a></h3>
<p>This discussion applies mainly to associative array key strings and to
2022-08-24 15:22:41 +02:00
patterns used for reverse subscripting (the r, R, i, etc. flags),
but it may also affect parameter substitutions that appear as part of an
arithmetic expression in an ordinary subscript.</p>
2021-05-11 02:29:21 +02:00
<p>To avoid subscript parsing limitations in assignments to associative
array elements, use the append syntax:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">aa+=('key with &quot;*strange*&quot; characters' 'value string')
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>The basic rule to remember when writing a subscript expression is that
2022-08-24 15:22:41 +02:00
all text between the opening [ and the closing ] is interpreted
2021-05-11 02:29:21 +02:00
<em>as if</em> it were in double quotes
(<a href="Shell-Grammar.html#Quoting">Quoting</a>). However, unlike double quotes
which normally cannot nest, subscript expressions may appear inside
double-quoted strings or inside other subscript expressions (or both!),
so the rules have two important differences.</p>
2022-08-24 15:22:41 +02:00
<p>The first difference is that brackets ([ and ]) must appear as
2021-05-11 02:29:21 +02:00
balanced pairs in a subscript expression unless they are preceded by a
2022-08-24 15:22:41 +02:00
backslash (\). Therefore, within a subscript expression (and unlike
true double-quoting) the sequence \[ becomes [, and similarly
\] becomes ]. This applies even in cases where a backslash is not
normally required; for example, the pattern [^[] (to match any
character other than an open bracket) should be written [^\[] in a
reverse-subscript pattern. However, note that \[^\[\] and even
\[^[] mean the <em>same</em> thing, because backslashes are always
2021-05-11 02:29:21 +02:00
stripped when they appear before brackets!</p>
2022-08-24 15:22:41 +02:00
<p>The same rule applies to parentheses (( and )) and braces ({ and
}): they must appear either in balanced pairs or preceded by a
2021-05-11 02:29:21 +02:00
backslash, and backslashes that protect parentheses or braces are
removed during parsing. This is because parameter expansions may be
surrounded by balanced braces, and subscript flags are introduced by
balanced parentheses.</p>
2022-08-24 15:22:41 +02:00
<p>The second difference is that a double-quote (&quot;) may appear as part of
a subscript expression without being preceded by a backslash, and
therefore that the two characters \&quot; remain as two characters in the
subscript (in true double-quoting, \&quot; becomes &quot;). However, because
of the standard shell quoting rules, any double-quotes that appear must
occur in balanced pairs unless preceded by a backslash. This makes it
more difficult to write a subscript expression that contains an odd
number of double-quote characters, but the reason for this difference is
so that when a subscript expression appears inside true double-quotes,
one can still write \&quot; (rather than \\\&quot;) for &quot;.</p>
2021-05-11 02:29:21 +02:00
<p>To use an odd number of double quotes as a key in an assignment, use the
2022-08-24 15:22:41 +02:00
typeset builtin and an enclosing pair of double quotes; to refer to the
value of that key, again use double quotes:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">typeset -A aa
2021-05-11 02:29:21 +02:00
typeset &quot;aa[one\&quot;two\&quot;three\&quot;quotes]&quot;=QQQ
print &quot;$aa[one\&quot;two\&quot;three\&quot;quotes]&quot;
</code></pre>
</div>
<p>It is important to note that the quoting rules do not change when a
parameter expansion with a subscript is nested inside another subscript
expression. That is, it is not necessary to use additional backslashes
within the inner subscript expression; they are removed only once, from
the innermost subscript outwards. Parameters are also expanded from the
innermost subscript first, as each expansion is encountered left to
right in the outer expression.</p>
<p>A further complication arises from a way in which subscript parsing is
<em>not</em> different from double quote parsing. As in true double-quoting,
2022-08-24 15:22:41 +02:00
the sequences \*, and \@ remain as two characters when they
appear in a subscript expression. To use a literal * or @ as an
associative array key, the e flag must be used:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">typeset -A aa
2021-05-11 02:29:21 +02:00
aa[(e)*]=star
print $aa[(e)*]
</code></pre>
</div>
<p>A last detail must be considered when reverse subscripting is performed.
Parameters appearing in the subscript expression are first expanded and
then the complete expression is interpreted as a pattern. This has two
2022-08-24 15:22:41 +02:00
effects: first, parameters behave as if GLOB_SUBST were on (and it
2021-05-11 02:29:21 +02:00
cannot be turned off); second, backslashes are interpreted twice, once
when parsing the array subscript and again when parsing the pattern. In
a reverse subscript, its necessary to use <em>four</em> backslashes to cause a
single backslash to match literally in the pattern. For complex
patterns, it is often easiest to assign the desired pattern to a
parameter and then refer to that parameter in the subscript, because
then the backslashes, brackets, parentheses, etc., are seen only when
the complete expression is converted to a pattern. To match the value of
a parameter literally in a reverse subscript, rather than as a pattern,
2022-08-24 15:22:41 +02:00
use ${(q)<code>name</code>} (<a href="Expansion.html#Parameter-Expansion">Parameter
2021-05-11 02:29:21 +02:00
Expansion</a>) to quote the expanded
value.</p>
2022-08-24 15:22:41 +02:00
<p>Note that the k and K flags are reverse subscripting for an ordinary
array, but are <em>not</em> reverse subscripting for an associative array! (For
an associative array, the keys in the array itself are interpreted as
patterns by those flags; the subscript is a plain string in that case.)</p>
2021-05-11 02:29:21 +02:00
<p>One final note, not directly related to subscripting: the numeric names
of positional parameters (<a href="Parameters.html#Positional-Parameters">Positional
Parameters</a>) are parsed specially, so for
2022-08-24 15:22:41 +02:00
example $2foo is equivalent to ${2}foo. Therefore, to use subscript
syntax to extract a substring from a positional parameter, the expansion
must be surrounded by braces; for example, ${2[3,5]} evaluates to
the third through fifth characters of the second positional parameter,
but $2[3,5] is the entire second parameter concatenated with the
filename generation pattern [3,5].</p>
<hr />
<p><span id="Positional-Parameters"></span> <span
id="Positional-Parameters-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="153-positional-parameters"><a class="header" href="#153-positional-parameters">15.3 Positional Parameters</a></h2>
<p>The positional parameters provide access to the command-line arguments
of a shell function, shell script, or the shell itself; see
<a href="Invocation.html#Invocation">Invocation</a>, and also
<a href="Functions.html#Functions">Functions</a>. The parameter <code>n</code>, where <code>n</code> is a
2022-08-24 15:22:41 +02:00
number, is the <code>n</code>th positional parameter. The parameter $0 is a
2021-05-11 02:29:21 +02:00
special case, see <a href="Parameters.html#Parameters-Set-By-The-Shell">Parameters Set By The
Shell</a>.</p>
2022-08-24 15:22:41 +02:00
<p>The parameters *, @ and argv are arrays containing all the positional
parameters; thus $argv[<code>n</code>], etc., is equivalent to simply $<code>n</code>.
Note that the options KSH_ARRAYS or KSH_ZERO_SUBSCRIPT apply to these
arrays as well, so with either of those options set, ${argv[0]} is
equivalent to $1 and so on.</p>
2021-05-11 02:29:21 +02:00
<p>Positional parameters may be changed after the shell or function starts
2022-08-24 15:22:41 +02:00
by using the set builtin, by assigning to the argv array, or by direct
assignment of the form <code>n</code>=<code>value</code> where <code>n</code> is the number of the
positional parameter to be changed. This also creates (with empty
2021-05-11 02:29:21 +02:00
values) any of the positions from 1 to <code>n</code> that do not already have
values. Note that, because the positional parameters form an array, an
2022-08-24 15:22:41 +02:00
array assignment of the form <code>n</code>=(<code>value</code> ...) is allowed, and has the
effect of shifting all the values at positions greater than <code>n</code> by as
many positions as necessary to accommodate the new values.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Local-Parameters"></span> <span
id="Local-Parameters-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="154-local-parameters"><a class="header" href="#154-local-parameters">15.4 Local Parameters</a></h2>
<p>Shell function executions delimit scopes for shell parameters.
2022-08-24 15:22:41 +02:00
(Parameters are dynamically scoped.) The typeset builtin, and its
alternative forms declare, integer, local and readonly (but not export),
can be used to declare a parameter as being local to the innermost
scope.</p>
2021-05-11 02:29:21 +02:00
<p>When a parameter is read or assigned to, the innermost existing
parameter of that name is used. (That is, the local parameter hides any
less-local parameter.) However, assigning to a non-existent parameter,
2022-08-24 15:22:41 +02:00
or declaring a new parameter with export, causes it to be created in the
<em>outer</em>most scope.</p>
<p>Local parameters disappear when their scope ends. unset can be used to
2021-05-11 02:29:21 +02:00
delete a parameter while it is still in scope; any outer parameter of
the same name remains hidden.</p>
<p>Special parameters may also be made local; they retain their special
attributes unless either the existing or the newly-created parameter has
2022-08-24 15:22:41 +02:00
the -h (hide) attribute. This may have unexpected effects: there is no
2021-05-11 02:29:21 +02:00
default value, so if there is no assignment at the point the variable is
made local, it will be set to an empty value (or zero in the case of
integers). The following:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">typeset PATH=/new/directory:$PATH
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>is valid for temporarily allowing the shell or programmes called from it
2022-08-24 15:22:41 +02:00
to find the programs in /new/directory inside a function.</p>
2021-05-11 02:29:21 +02:00
<p>Note that the restriction in older versions of zsh that local parameters
were never exported has been removed.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Parameters-Set-By-The-Shell"></span> <span
id="Parameters-Set-By-The-Shell-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="155-parameters-set-by-the-shell"><a class="header" href="#155-parameters-set-by-the-shell">15.5 Parameters Set By The Shell</a></h2>
<p>In the parameter lists that follow, the mark &lt;S&gt; indicates that the
2022-08-24 15:22:41 +02:00
parameter is special. &lt;Z&gt; indicates that the parameter does not exist
when the shell initializes in sh or ksh emulation mode.</p>
<p>The parameters !, #, *, -, ?, @, $, ARGC, HISTCMD,
LINENO, PPID, status, TTYIDLE, zsh_eval_context,
ZSH_EVAL_CONTEXT, and ZSH_SUBSHELL are read-only and thus cannot be
restored by the user, so they are not output by typeset -p. This also
applies to many read-only parameters loaded from modules.</p>
2021-05-11 02:29:21 +02:00
<p>The following parameters are automatically set by the shell:</p>
<p><span id="index-_0021"></span></p>
2022-08-24 15:22:41 +02:00
<p>! &lt;S&gt;</p>
<p>The process ID of the last command started in the background with &amp;, put
into the background with the bg builtin, or spawned with coproc.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_0023"></span></p>
2022-08-24 15:22:41 +02:00
<h1 id="s"><a class="header" href="#s">&lt;S&gt;</a></h1>
2021-05-11 02:29:21 +02:00
<p>The number of positional parameters in decimal. Note that some confusion
2022-08-24 15:22:41 +02:00
may occur with the syntax $#<code>param</code> which substitutes the length of
<code>param</code>. Use ${#} to resolve ambiguities. In particular, the sequence
$#-<code>...</code> in an arithmetic expression is interpreted as the length of
the parameter -, q.v.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-ARGC"></span></p>
2022-08-24 15:22:41 +02:00
<p>ARGC &lt;S&gt; &lt;Z&gt;</p>
<p>Same as #.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_0024"></span></p>
2022-08-24 15:22:41 +02:00
<p>$ &lt;S&gt;</p>
<p>The process ID of this shell, set when the shell initializes. Processes
forked from the shell without executing a new program, such as command
substitutions and commands grouped with (<code>...</code>), are subshells that
duplicate the current shell, and thus substitute the same value for $$
as their parent shell.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_002d-1"></span></p>
2022-08-24 15:22:41 +02:00
<p>- &lt;S&gt;</p>
<p>Flags supplied to the shell on invocation or by the set or setopt
2021-05-11 02:29:21 +02:00
commands.</p>
<p><span id="index-_002a"></span></p>
2022-08-24 15:22:41 +02:00
<p>* &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>An array containing the positional parameters.</p>
<p><span id="index-argv"></span></p>
2022-08-24 15:22:41 +02:00
<p>argv &lt;S&gt; &lt;Z&gt;</p>
<p>Same as *. Assigning to argv changes the local positional parameters,
but argv is <em>not</em> itself a local parameter. Deleting argv with unset in
any function deletes it everywhere, although only the innermost
positional parameter array is deleted (so * and @ in other scopes are
not affected).</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_0040"></span></p>
2022-08-24 15:22:41 +02:00
<p>@ &lt;S&gt;</p>
<p>Same as argv[@], even when argv is not set.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_003f"></span></p>
2022-08-24 15:22:41 +02:00
<p>? &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>The exit status returned by the last command.</p>
<p><span id="index-0"></span></p>
2022-08-24 15:22:41 +02:00
<p>0 &lt;S&gt;</p>
<p>The name used to invoke the current shell, or as set by the -c command
line option upon invocation. If the FUNCTION_ARGZERO option is set, $0
is set upon entry to a shell function to the name of the function, and
upon entry to a sourced script to the name of the script, and reset to
its previous value when the function or script returns.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-status"></span></p>
2022-08-24 15:22:41 +02:00
<p>status &lt;S&gt; &lt;Z&gt;</p>
<p>Same as ?.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-pipestatus"></span></p>
2022-08-24 15:22:41 +02:00
<p>pipestatus &lt;S&gt; &lt;Z&gt;</p>
2021-05-11 02:29:21 +02:00
<p>An array containing the exit statuses returned by all commands in the
last pipeline.</p>
<p><span id="index-_005f"></span></p>
2022-08-24 15:22:41 +02:00
<p>_ &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>The last argument of the previous command. Also, this parameter is set
in the environment of every command executed to the full pathname of the
command.</p>
<p><span id="index-CPUTYPE"></span></p>
2022-08-24 15:22:41 +02:00
<p>CPUTYPE</p>
2021-05-11 02:29:21 +02:00
<p>The machine type (microprocessor class or machine model), as determined
at run time.</p>
<p><span id="index-EGID"></span></p>
2022-08-24 15:22:41 +02:00
<p>EGID &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>The effective group ID of the shell process. If you have sufficient
privileges, you may change the effective group ID of the shell process
by assigning to this parameter. Also (assuming sufficient privileges),
you may start a single command with a different effective group ID by
2022-08-24 15:22:41 +02:00
(EGID=<code>gid</code>; command)</p>
2021-05-11 02:29:21 +02:00
<p>If this is made local, it is not implicitly set to 0, but may be
explicitly set locally.</p>
<p><span id="index-EUID"></span></p>
2022-08-24 15:22:41 +02:00
<p>EUID &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>The effective user ID of the shell process. If you have sufficient
privileges, you may change the effective user ID of the shell process by
assigning to this parameter. Also (assuming sufficient privileges), you
may start a single command with a different effective user ID by
2022-08-24 15:22:41 +02:00
(EUID=<code>uid</code>; command)</p>
2021-05-11 02:29:21 +02:00
<p>If this is made local, it is not implicitly set to 0, but may be
explicitly set locally.</p>
<p><span id="index-ERRNO"></span></p>
2022-08-24 15:22:41 +02:00
<p>ERRNO &lt;S&gt;</p>
<p>The value of errno (see errno(3)) as set by the most recently failed
system call. This value is system dependent and is intended for
debugging purposes. It is also useful with the zsh/system module which
2021-05-11 02:29:21 +02:00
allows the number to be turned into a name or message.</p>
2022-08-24 15:22:41 +02:00
<p>To use this parameter, it must first be assigned a value (typically 0
(zero)). It is initially unset for scripting compatibility.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-FUNCNEST"></span></p>
2022-08-24 15:22:41 +02:00
<p>FUNCNEST &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Integer. If greater than or equal to zero, the maximum nesting depth of
shell functions. When it is exceeded, an error is raised at the point
where a function is called. The default value is determined when the
shell is configured, but is typically 500. Increasing the value
increases the danger of a runaway function recursion causing the shell
to crash. Setting a negative value turns off the check.</p>
<p><span id="index-GID"></span></p>
2022-08-24 15:22:41 +02:00
<p>GID &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>The real group ID of the shell process. If you have sufficient
privileges, you may change the group ID of the shell process by
assigning to this parameter. Also (assuming sufficient privileges), you
2022-08-24 15:22:41 +02:00
may start a single command under a different group ID by (GID=<code>gid</code>;
command)</p>
2021-05-11 02:29:21 +02:00
<p>If this is made local, it is not implicitly set to 0, but may be
explicitly set locally.</p>
<p><span id="index-HISTCMD"></span></p>
2022-08-24 15:22:41 +02:00
<p>HISTCMD</p>
2021-05-11 02:29:21 +02:00
<p>The current history event number in an interactive shell, in other words
2022-08-24 15:22:41 +02:00
the event number for the command that caused $HISTCMD to be read. If the
current history event modifies the history, HISTCMD changes to the new
maximum history event number.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-HOST"></span></p>
2022-08-24 15:22:41 +02:00
<p>HOST</p>
2021-05-11 02:29:21 +02:00
<p>The current hostname.</p>
<p><span id="index-LINENO"></span></p>
2022-08-24 15:22:41 +02:00
<p>LINENO &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>The line number of the current line within the current script, sourced
file, or shell function being executed, whichever was started most
recently. Note that in the case of shell functions the line number
refers to the function as it appeared in the original definition, not
2022-08-24 15:22:41 +02:00
necessarily as displayed by the functions builtin.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-LOGNAME"></span></p>
2022-08-24 15:22:41 +02:00
<p>LOGNAME</p>
2021-05-11 02:29:21 +02:00
<p>If the corresponding variable is not set in the environment of the
shell, it is initialized to the login name corresponding to the current
login session. This parameter is exported by default but this can be
2022-08-24 15:22:41 +02:00
disabled using the typeset builtin. The value is set to the string
returned by the getlogin(3) system call if that is available.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-MACHTYPE"></span></p>
2022-08-24 15:22:41 +02:00
<p>MACHTYPE</p>
2021-05-11 02:29:21 +02:00
<p>The machine type (microprocessor class or machine model), as determined
at compile time.</p>
<p><span id="index-OLDPWD"></span></p>
2022-08-24 15:22:41 +02:00
<p>OLDPWD</p>
2021-05-11 02:29:21 +02:00
<p>The previous working directory. This is set when the shell initializes
and whenever the directory changes.</p>
<p><span id="index-OPTARG"></span></p>
2022-08-24 15:22:41 +02:00
<p>OPTARG &lt;S&gt;</p>
<p>The value of the last option argument processed by the getopts command.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-OPTIND"></span></p>
2022-08-24 15:22:41 +02:00
<p>OPTIND &lt;S&gt;</p>
<p>The index of the last option argument processed by the getopts command.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-OSTYPE"></span></p>
2022-08-24 15:22:41 +02:00
<p>OSTYPE</p>
2021-05-11 02:29:21 +02:00
<p>The operating system, as determined at compile time.</p>
<p><span id="index-PPID"></span></p>
2022-08-24 15:22:41 +02:00
<p>PPID &lt;S&gt;</p>
<p>The process ID of the parent of the shell, set when the shell
initializes. As with $$, the value does not change in subshells created
as a duplicate of the current shell.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-PWD"></span></p>
2022-08-24 15:22:41 +02:00
<p>PWD</p>
2021-05-11 02:29:21 +02:00
<p>The present working directory. This is set when the shell initializes
and whenever the directory changes.</p>
<p><span id="index-RANDOM"></span></p>
2022-08-24 15:22:41 +02:00
<p>RANDOM &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>A pseudo-random integer from 0 to 32767, newly generated each time this
parameter is referenced. The random number generator can be seeded by
2022-08-24 15:22:41 +02:00
assigning a numeric value to RANDOM.</p>
<p>sequence; subshells that reference RANDOM will result in identical
pseudo-random values unless the value of RANDOM is referenced or seeded
in the parent shell in between subshell invocations.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-SECONDS"></span></p>
2022-08-24 15:22:41 +02:00
<p>SECONDS &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>The number of seconds since shell invocation. If this parameter is
assigned a value, then the value returned upon reference will be the
value that was assigned plus the number of seconds since the assignment.</p>
2022-08-24 15:22:41 +02:00
<p>Unlike other special parameters, the type of the SECONDS parameter can
be changed using the typeset command. The type may be changed only to
one of the floating point types or back to integer. For example,
typeset -F SECONDS causes the value to be reported as a floating point
number. The value is available to microsecond accuracy, although the
shell may show more or fewer digits depending on the use of typeset. See
the documentation for the builtin typeset in <a href="Shell-Builtin-Commands.html#Shell-Builtin-Commands">Shell Builtin
2021-05-11 02:29:21 +02:00
Commands</a> for more
details.</p>
<p><span id="index-SHLVL"></span></p>
2022-08-24 15:22:41 +02:00
<p>SHLVL &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Incremented by one each time a new shell is started.</p>
<p><span id="index-signals"></span></p>
2022-08-24 15:22:41 +02:00
<p>signals</p>
2021-05-11 02:29:21 +02:00
<p>An array containing the names of the signals. Note that with the
standard zsh numbering of array indices, where the first element has
index 1, the signals are offset by 1 from the signal number used by the
2022-08-24 15:22:41 +02:00
operating system. For example, on typical Unix-like systems HUP is
signal number 1, but is referred to as $signals[2]. This is because of
EXIT at position 1 in the array, which is used internally by zsh but is
not known to the operating system.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-TRY_005fBLOCK_005fERROR"></span></p>
2022-08-24 15:22:41 +02:00
<p>TRY_BLOCK_ERROR &lt;S&gt;</p>
<p>In an always block, indicates whether the preceding list of code caused
an error. The value is 1 to indicate an error, 0 otherwise. It may be
reset, clearing the error condition. See <a href="Shell-Grammar.html#Complex-Commands">Complex
2021-05-11 02:29:21 +02:00
Commands</a></p>
<p><span id="index-TRY_005fBLOCK_005fINTERRUPT"></span></p>
2022-08-24 15:22:41 +02:00
<p>TRY_BLOCK_INTERRUPT &lt;S&gt;</p>
<p>This variable works in a similar way to TRY_BLOCK_ERROR, but represents
the status of an interrupt from the signal SIGINT, which typically comes
from the keyboard when the user types ^C. If set to 0, any such
interrupt will be reset; otherwise, the interrupt is propagated after
the always block.</p>
2021-05-11 02:29:21 +02:00
<p>Note that it is possible that an interrupt arrives during the execution
2022-08-24 15:22:41 +02:00
of the always block; this interrupt is also propagated.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-TTY"></span></p>
2022-08-24 15:22:41 +02:00
<p>TTY</p>
2021-05-11 02:29:21 +02:00
<p>The name of the tty associated with the shell, if any.</p>
<p><span id="index-TTYIDLE"></span></p>
2022-08-24 15:22:41 +02:00
<p>TTYIDLE &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>The idle time of the tty associated with the shell in seconds or -1 if
there is no such tty.</p>
<p><span id="index-UID"></span></p>
2022-08-24 15:22:41 +02:00
<p>UID &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>The real user ID of the shell process. If you have sufficient
privileges, you may change the user ID of the shell by assigning to this
parameter. Also (assuming sufficient privileges), you may start a single
2022-08-24 15:22:41 +02:00
command under a different user ID by (UID=<code>uid</code>; command)</p>
2021-05-11 02:29:21 +02:00
<p>If this is made local, it is not implicitly set to 0, but may be
explicitly set locally.</p>
<p><span id="index-USERNAME"></span></p>
2022-08-24 15:22:41 +02:00
<p>USERNAME &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>The username corresponding to the real user ID of the shell process. If
you have sufficient privileges, you may change the username (and also
the user ID and group ID) of the shell by assigning to this parameter.
Also (assuming sufficient privileges), you may start a single command
under a different username (and user ID and group ID) by
2022-08-24 15:22:41 +02:00
(USERNAME=<code>username</code>; command)</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-VENDOR"></span></p>
2022-08-24 15:22:41 +02:00
<p>VENDOR</p>
2021-05-11 02:29:21 +02:00
<p>The vendor, as determined at compile time.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-zsh_005feval_005fcontext"></span> <span
id="index-ZSH_005fEVAL_005fCONTEXT"></span></p>
<p>zsh_eval_context &lt;S&gt; &lt;Z&gt; (ZSH_EVAL_CONTEXT &lt;S&gt;)</p>
2021-05-11 02:29:21 +02:00
<p>An array (colon-separated list) indicating the context of shell code
that is being run. Each time a piece of shell code that is stored within
the shell is executed a string is temporarily appended to the array to
indicate the type of operation that is being performed. Read in order
the array gives an indication of the stack of operations being performed
with the most immediate context last.</p>
<p>Note that the variable does not give information on syntactic context
2022-08-24 15:22:41 +02:00
such as pipelines or subshells. Use $ZSH_SUBSHELL to detect subshells.</p>
2021-05-11 02:29:21 +02:00
<p>The context is one of the following:</p>
2022-08-24 15:22:41 +02:00
<p>cmdarg<br />
Code specified by the -c option to the command line that invoked the
shell.</p>
<p>cmdsubst<br />
Command substitution using the <code>...</code> or $(<code>...</code>) construct.</p>
<p>equalsubst<br />
File substitution using the =(<code>...</code>) construct.</p>
<p>eval<br />
Code executed by the eval builtin.</p>
<p>evalautofunc<br />
Code executed with the KSH_AUTOLOAD mechanism in order to define an
autoloaded function.</p>
<p>fc<br />
Code from the shell history executed by the -e option to the fc builtin.</p>
<p>file<br />
Lines of code being read directly from a file, for example by the source
2021-05-11 02:29:21 +02:00
builtin.</p>
2022-08-24 15:22:41 +02:00
<p>filecode<br />
Lines of code being read from a .zwc file instead of directly from the
source file.</p>
<p>globqual<br />
Code executed by the e or + glob qualifier.</p>
<p>globsort<br />
Code executed to order files by the o glob qualifier.</p>
<p>insubst<br />
File substitution using the &lt;(<code>...</code>) construct.</p>
<p>loadautofunc<br />
2021-05-11 02:29:21 +02:00
Code read directly from a file to define an autoloaded function.</p>
2022-08-24 15:22:41 +02:00
<p>outsubst<br />
File substitution using the &gt;(<code>...</code>) construct.</p>
<p>sched<br />
Code executed by the sched builtin.</p>
<p>shfunc<br />
2021-05-11 02:29:21 +02:00
A shell function.</p>
2022-08-24 15:22:41 +02:00
<p>stty<br />
Code passed to stty by the STTY environment variable. Normally this is
passed directly to the systems stty command, so this value is unlikely
to be seen in practice.</p>
<p>style<br />
Code executed as part of a style retrieved by the zstyle builtin from
the zsh/zutil module.</p>
<p>toplevel<br />
2021-05-11 02:29:21 +02:00
The highest execution level of a script or interactive shell.</p>
2022-08-24 15:22:41 +02:00
<p>trap<br />
Code executed as a trap defined by the trap builtin. Traps defined as
functions have the context shfunc. As traps are asynchronous they may
have a different hierarchy from other code.</p>
<p>zpty<br />
Code executed by the zpty builtin from the zsh/zpty module.</p>
<p>zregexparse-guard<br />
Code executed as a guard by the zregexparse command from the zsh/zutil
module.</p>
<p>zregexparse-action<br />
Code executed as an action by the zregexparse command from the zsh/zutil
module.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-ZSH_005fARGZERO"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZSH_ARGZERO</p>
2021-05-11 02:29:21 +02:00
<p>If zsh was invoked to run a script, this is the name of the script.
Otherwise, it is the name used to invoke the current shell. This is the
2022-08-24 15:22:41 +02:00
same as the value of $0 when the POSIX_ARGZERO option is set, but is
2021-05-11 02:29:21 +02:00
always available.</p>
<p><span id="index-ZSH_005fEXECUTION_005fSTRING"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZSH_EXECUTION_STRING</p>
<p>If the shell was started with the option -c, this contains the argument
passed to the option. Otherwise it is not set.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-ZSH_005fNAME"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZSH_NAME</p>
2021-05-11 02:29:21 +02:00
<p>Expands to the basename of the command used to invoke this instance of
zsh.</p>
<p><span id="index-ZSH_005fPATCHLEVEL"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZSH_PATCHLEVEL</p>
<p>The output of git describe tags long for the zsh repository used to
build the shell. This is most useful in order to keep track of versions
of the shell during development between releases; hence most users
should not use it and should instead rely on $ZSH_VERSION.</p>
<p>zsh_scheduled_events</p>
2021-05-11 02:29:21 +02:00
<p>See <a href="Zsh-Modules.html#The-zsh_002fsched-Module">The zsh/sched Module</a>.</p>
<p><span id="index-ZSH_005fSCRIPT"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZSH_SCRIPT</p>
2021-05-11 02:29:21 +02:00
<p>If zsh was invoked to run a script, this is the name of the script,
otherwise it is unset.</p>
<p><span id="index-ZSH_005fSUBSHELL-_003cS_003e"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZSH_SUBSHELL</p>
2021-05-11 02:29:21 +02:00
<p>Readonly integer. Initially zero, incremented each time the shell forks
2022-08-24 15:22:41 +02:00
to create a subshell for executing code. Hence (print $ZSH_SUBSHELL)
and print $(print $ZSH_SUBSHELL) output 1, while ( (print
$ZSH_SUBSHELL) ) outputs 2.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-ZSH_005fVERSION"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZSH_VERSION</p>
2021-05-11 02:29:21 +02:00
<p>The version number of the release of zsh.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Parameters-Used-By-The-Shell"></span> <span
id="Parameters-Used-By-The-Shell-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="156-parameters-used-by-the-shell"><a class="header" href="#156-parameters-used-by-the-shell">15.6 Parameters Used By The Shell</a></h2>
<p>The following parameters are used by the shell. Again, &lt;S&gt; indicates
that the parameter is special and &lt;Z&gt; indicates that the parameter
2022-08-24 15:22:41 +02:00
does not exist when the shell initializes in sh or ksh emulation mode.</p>
2021-05-11 02:29:21 +02:00
<p>In cases where there are two parameters with an upper- and lowercase
2022-08-24 15:22:41 +02:00
form of the same name, such as path and PATH, the lowercase form is an
array and the uppercase form is a scalar with the elements of the array
joined together by colons. These are similar to tied parameters created
via typeset -T. The normal use for the colon-separated form is for
exporting to the environment, while the array form is easier to
2021-05-11 02:29:21 +02:00
manipulate within the shell. Note that unsetting either of the pair will
unset the other; they retain their special properties when recreated,
and recreating one of the pair will recreate the other.</p>
<p><span id="index-ARGV0"></span></p>
2022-08-24 15:22:41 +02:00
<p>ARGV0</p>
<p>If exported, its value is used as the argv[0] of external commands.
Usually used in constructs like ARGV0=emacs nethack.</p>
<p><span id="index-editing-over-slow-connection"></span> <span
id="index-slow-connection_002c-editing-over"></span> <span
id="index-BAUD"></span></p>
<p>BAUD</p>
2021-05-11 02:29:21 +02:00
<p>The rate in bits per second at which data reaches the terminal. The line
editor will use this value in order to compensate for a slow terminal by
delaying updates to the display until necessary. If the parameter is
unset or the value is zero the compensation mechanism is turned off. The
parameter is not set by default.</p>
<p>This parameter may be profitably set in some circumstances, e.g. for
slow modems dialing into a communications server, or on a slow wide area
network. It should be set to the baud rate of the slowest part of the
link for best performance.</p>
<p><span id="index-cdpath"></span> <span id="index-CDPATH"></span></p>
2022-08-24 15:22:41 +02:00
<p>cdpath &lt;S&gt; &lt;Z&gt; (CDPATH &lt;S&gt;)</p>
2021-05-11 02:29:21 +02:00
<p>An array (colon-separated list) of directories specifying the search
2022-08-24 15:22:41 +02:00
path for the cd command.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-COLUMNS"></span></p>
2022-08-24 15:22:41 +02:00
<p>COLUMNS &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>The number of columns for this terminal session. Used for printing
select lists and for the line editor.</p>
<p><span id="index-CORRECT_005fIGNORE"></span></p>
2022-08-24 15:22:41 +02:00
<p>CORRECT_IGNORE</p>
2021-05-11 02:29:21 +02:00
<p>If set, is treated as a pattern during spelling correction. Any
potential correction that matches the pattern is ignored. For example,
2022-08-24 15:22:41 +02:00
if the value is _* then completion functions (which, by convention,
have names beginning with _) will never be offered as spelling
2021-05-11 02:29:21 +02:00
corrections. The pattern does not apply to the correction of file names,
2022-08-24 15:22:41 +02:00
as applied by the CORRECT_ALL option (so with the example just given
files beginning with _ in the current directory would still be
2021-05-11 02:29:21 +02:00
completed).</p>
<p><span id="index-CORRECT_005fIGNORE_005fFILE"></span></p>
2022-08-24 15:22:41 +02:00
<p>CORRECT_IGNORE_FILE</p>
2021-05-11 02:29:21 +02:00
<p>If set, is treated as a pattern during spelling correction of file
names. Any file name that matches the pattern is never offered as a
2022-08-24 15:22:41 +02:00
correction. For example, if the value is .* then dot file names will
2021-05-11 02:29:21 +02:00
never be offered as spelling corrections. This is useful with the
2022-08-24 15:22:41 +02:00
CORRECT_ALL option.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-DIRSTACKSIZE"></span></p>
2022-08-24 15:22:41 +02:00
<p>DIRSTACKSIZE</p>
2021-05-11 02:29:21 +02:00
<p>The maximum size of the directory stack, by default there is no limit.
If the stack gets larger than this, it will be truncated automatically.
2022-08-24 15:22:41 +02:00
This is useful with the AUTO_PUSHD option. <span
id="index-AUTO_005fPUSHD_002c-use-of"></span></p>
2021-05-11 02:29:21 +02:00
<p><span id="index-ENV"></span></p>
2022-08-24 15:22:41 +02:00
<p>ENV</p>
<p>If the ENV environment variable is set when zsh is invoked as sh or ksh,
$ENV is sourced after the profile scripts. The value of ENV is subjected
to parameter expansion, command substitution, and arithmetic expansion
before being interpreted as a pathname. Note that ENV is <em>not</em> used
unless the shell is interactive and zsh is emulating sh or ksh.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-FCEDIT"></span></p>
2022-08-24 15:22:41 +02:00
<p>FCEDIT</p>
<p>The default editor for the fc builtin. If FCEDIT is not set, the
parameter EDITOR is used; if that is not set either, a builtin default,
usually vi, is used.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-fignore"></span> <span id="index-FIGNORE"></span></p>
2022-08-24 15:22:41 +02:00
<p>fignore &lt;S&gt; &lt;Z&gt; (FIGNORE &lt;S&gt;)</p>
2021-05-11 02:29:21 +02:00
<p>An array (colon separated list) containing the suffixes of files to be
ignored during filename completion. However, if completion only
generates files with suffixes in this list, then these files are
completed anyway.</p>
<p><span id="index-fpath"></span> <span id="index-FPATH"></span></p>
2022-08-24 15:22:41 +02:00
<p>fpath &lt;S&gt; &lt;Z&gt; (FPATH &lt;S&gt;)</p>
2021-05-11 02:29:21 +02:00
<p>An array (colon separated list) of directories specifying the search
path for function definitions. This path is searched when a function
file is found, then it is read and executed in the current environment.</p>
<p><span id="index-histchars"></span></p>
2022-08-24 15:22:41 +02:00
<p>histchars &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Three characters used by the shells history and lexical analysis
mechanism. The first character signals the start of a history expansion
2022-08-24 15:22:41 +02:00
(default !). The second character signals the start of a quick history
substitution (default ^). The third character is the comment character
(default #).</p>
2021-05-11 02:29:21 +02:00
<p>The characters must be in the ASCII character set; any attempt to set
2022-08-24 15:22:41 +02:00
histchars to characters with a locale-dependent meaning will be rejected
with an error message.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-HISTCHARS"></span></p>
2022-08-24 15:22:41 +02:00
<p>HISTCHARS &lt;S&gt; &lt;Z&gt;</p>
<p>Same as histchars. (Deprecated.)</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-HISTFILE"></span></p>
2022-08-24 15:22:41 +02:00
<p>HISTFILE</p>
2021-05-11 02:29:21 +02:00
<p>The file to save the history in when an interactive shell exits. If
unset, the history is not saved.</p>
<p><span id="index-HISTORY_005fIGNORE"></span></p>
2022-08-24 15:22:41 +02:00
<p>HISTORY_IGNORE</p>
2021-05-11 02:29:21 +02:00
<p>If set, is treated as a pattern at the time history files are written.
Any potential history entry that matches the pattern is skipped. For
2022-08-24 15:22:41 +02:00
example, if the value is fc * then commands that invoke the
2021-05-11 02:29:21 +02:00
interactive history editor are never written to the history file.</p>
2022-08-24 15:22:41 +02:00
<p>Note that HISTORY_IGNORE defines a single pattern: to specify
alternatives use the (<code>first</code>|<code>second</code>|<code>...</code>) syntax.</p>
<p>Compare the HIST_NO_STORE option or the zshaddhistory hook, either of
which would prevent such commands from being added to the interactive
history at all. If you wish to use HISTORY_IGNORE to stop history being
added in the first place, you can define the following hook:</p>
<div class="example">
<pre><code class="language-zsh">zshaddhistory() {
2021-05-11 02:29:21 +02:00
emulate -L zsh
## uncomment if HISTORY_IGNORE
## should use EXTENDED_GLOB syntax
# setopt extendedglob
[[ $1 != ${~HISTORY_IGNORE} ]]
}
</code></pre>
</div>
<p><span id="index-HISTSIZE"></span></p>
2022-08-24 15:22:41 +02:00
<p>HISTSIZE &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>The maximum number of events stored in the internal history list. If you
2022-08-24 15:22:41 +02:00
use the HIST_EXPIRE_DUPS_FIRST option, setting this value larger than
the SAVEHIST size will give you the difference as a cushion for saving
2021-05-11 02:29:21 +02:00
duplicated history events.</p>
<p>If this is made local, it is not implicitly set to 0, but may be
explicitly set locally.</p>
<p><span id="index-HOME"></span></p>
2022-08-24 15:22:41 +02:00
<p>HOME &lt;S&gt;</p>
<p>The default argument for the cd command. This is not set automatically
by the shell in sh, ksh or csh emulation, but it is typically present in
the environment anyway, and if it becomes set it has its usual special
behaviour.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-IFS"></span></p>
2022-08-24 15:22:41 +02:00
<p>IFS &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Internal field separators (by default space, tab, newline and NUL), that
are used to separate words which result from command or parameter
2022-08-24 15:22:41 +02:00
expansion and words read by the read builtin. Any characters from the
2021-05-11 02:29:21 +02:00
set space, tab and newline that appear in the IFS are called <em>IFS white
space</em>. One or more IFS white space characters or one non-IFS white
space character together with any adjacent IFS white space character
delimit a field. If an IFS white space character appears twice
consecutively in the IFS, this character is treated as if it were not an
IFS white space character.</p>
<p>If the parameter is unset, the default is used. Note this has a
different effect from setting the parameter to an empty string.</p>
<p><span id="index-KEYBOARD_005fHACK"></span></p>
2022-08-24 15:22:41 +02:00
<p>KEYBOARD_HACK</p>
2021-05-11 02:29:21 +02:00
<p>This variable defines a character to be removed from the end of the
command line before interpreting it (interactive shells only). It is
intended to fix the problem with keys placed annoyingly close to return
2022-08-24 15:22:41 +02:00
and replaces the SUNKEYBOARDHACK option which did this for backquotes
2021-05-11 02:29:21 +02:00
only. Should the chosen character be one of singlequote, doublequote or
backquote, there must also be an odd number of them on the command line
for the last one to be removed.</p>
2022-08-24 15:22:41 +02:00
<p>For backward compatibility, if the SUNKEYBOARDHACK option is explicitly
set, the value of KEYBOARD_HACK reverts to backquote. If the option is
explicitly unset, this variable is set to empty.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-KEYTIMEOUT"></span></p>
2022-08-24 15:22:41 +02:00
<p>KEYTIMEOUT</p>
2021-05-11 02:29:21 +02:00
<p>The time the shell waits, in hundredths of seconds, for another key to
be pressed when reading bound multi-character sequences.</p>
<p><span id="index-LANG"></span></p>
2022-08-24 15:22:41 +02:00
<p>LANG &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>This variable determines the locale category for any category not
2022-08-24 15:22:41 +02:00
specifically selected via a variable starting with LC_.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-LC_005fALL"></span></p>
2022-08-24 15:22:41 +02:00
<p>LC_ALL &lt;S&gt;</p>
<p>This variable overrides the value of the LANG variable and the value
of any of the other variables starting with LC_.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-LC_005fCOLLATE"></span></p>
2022-08-24 15:22:41 +02:00
<p>LC_COLLATE &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>This variable determines the locale category for character collation
information within ranges in glob brackets and for sorting.</p>
<p><span id="index-LC_005fCTYPE"></span></p>
2022-08-24 15:22:41 +02:00
<p>LC_CTYPE &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>This variable determines the locale category for character handling
2022-08-24 15:22:41 +02:00
functions. If the MULTIBYTE option is in effect this variable or LANG
should contain a value that reflects the character set in use, even if
it is a single-byte character set, unless only the 7-bit subset (ASCII)
is used. For example, if the character set Linux distributions) or
en_US.ISO8859-1 (MacOS).</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-LC_005fMESSAGES"></span></p>
2022-08-24 15:22:41 +02:00
<p>LC_MESSAGES &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>This variable determines the language in which messages should be
written. Note that zsh does not use message catalogs.</p>
<p><span id="index-LC_005fNUMERIC"></span></p>
2022-08-24 15:22:41 +02:00
<p>LC_NUMERIC &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>This variable affects the decimal point character and thousands
separator character for the formatted input/output functions and string
conversion functions. Note that zsh ignores this setting when parsing
floating point mathematical expressions.</p>
<p><span id="index-LC_005fTIME"></span></p>
2022-08-24 15:22:41 +02:00
<p>LC_TIME &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>This variable determines the locale category for date and time
formatting in prompt escape sequences.</p>
<p><span id="index-LINES"></span></p>
2022-08-24 15:22:41 +02:00
<p>LINES &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>The number of lines for this terminal session. Used for printing select
lists and for the line editor.</p>
<p><span id="index-LISTMAX"></span></p>
2022-08-24 15:22:41 +02:00
<p>LISTMAX</p>
<p>In the line editor, the number of matches to list without asking first.
If the value is negative, the list will be shown if it spans at most as
2021-05-11 02:29:21 +02:00
many lines as given by the absolute value. If set to zero, the shell
asks only if the top of the listing would scroll off the screen.</p>
<p><span id="index-MAIL"></span></p>
2022-08-24 15:22:41 +02:00
<p>MAIL</p>
<p>If this parameter is set and mailpath is not set, the shell looks for
2021-05-11 02:29:21 +02:00
mail in the specified file.</p>
<p><span id="index-MAILCHECK"></span></p>
2022-08-24 15:22:41 +02:00
<p>MAILCHECK</p>
2021-05-11 02:29:21 +02:00
<p>The interval in seconds between checks for new mail.</p>
<p><span id="index-mailpath"></span> <span id="index-MAILPATH"></span></p>
2022-08-24 15:22:41 +02:00
<p>mailpath &lt;S&gt; &lt;Z&gt; (MAILPATH &lt;S&gt;)</p>
2021-05-11 02:29:21 +02:00
<p>An array (colon-separated list) of filenames to check for new mail. Each
2022-08-24 15:22:41 +02:00
filename can be followed by a ? and a message that will be printed.
2021-05-11 02:29:21 +02:00
The message will undergo parameter expansion, command substitution and
2022-08-24 15:22:41 +02:00
arithmetic expansion with the variable $_ defined as the name of the
file that has changed. The default message is You have new mail. If an
element is a directory instead of a file the shell will recursively
2021-05-11 02:29:21 +02:00
check every file in every subdirectory of the element.</p>
<p><span id="index-manpath"></span> <span id="index-MANPATH"></span></p>
2022-08-24 15:22:41 +02:00
<p>manpath &lt;S&gt; &lt;Z&gt; (MANPATH &lt;S&gt; &lt;Z&gt;)</p>
2021-05-11 02:29:21 +02:00
<p>An array (colon-separated list) whose value is not used by the shell.
2022-08-24 15:22:41 +02:00
The manpath array can be useful, however, since setting it also sets
MANPATH, and vice versa.</p>
<p>match</p>
<p>mbegin</p>
<p>mend</p>
<p>Arrays set by the shell when the b globbing flag is used in pattern
2021-05-11 02:29:21 +02:00
matches. See the subsection <em>Globbing flags</em> in <a href="Expansion.html#Filename-Generation">Filename
Generation</a>.</p>
2022-08-24 15:22:41 +02:00
<p>MATCH</p>
<p>MBEGIN</p>
<p>MEND</p>
<p>Set by the shell when the m globbing flag is used in pattern matches.
2021-05-11 02:29:21 +02:00
See the subsection <em>Globbing flags</em> in <a href="Expansion.html#Filename-Generation">Filename
Generation</a>.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-module_005fpath"></span> <span
id="index-MODULE_005fPATH"></span></p>
<p>module_path &lt;S&gt; &lt;Z&gt; (MODULE_PATH &lt;S&gt;)</p>
<p>An array (colon-separated list) of directories that zmodload searches
2021-05-11 02:29:21 +02:00
for dynamically loadable modules. This is initialized to a standard
2022-08-24 15:22:41 +02:00
pathname, usually /usr/local/lib/zsh/$ZSH_VERSION. (The
/usr/local/lib part varies from installation to installation.) For
2021-05-11 02:29:21 +02:00
security reasons, any value set in the environment when the shell is
started will be ignored.</p>
<p>These parameters only exist if the installation supports dynamic module
loading.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-NULLCMD"></span> <span
id="index-null-command-style"></span> <span
id="index-csh_002c-null-command-style"></span> <span
id="index-ksh_002c-null-command-style"></span></p>
<p>NULLCMD &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>The command name to assume if a redirection is specified with no
2022-08-24 15:22:41 +02:00
command. Defaults to cat. For sh/ksh behavior, change this to :. For
2021-05-11 02:29:21 +02:00
csh-like behavior, unset this parameter; the shell will print an error
message if null commands are entered.</p>
<p><span id="index-path"></span> <span id="index-PATH"></span></p>
2022-08-24 15:22:41 +02:00
<p>path &lt;S&gt; &lt;Z&gt; (PATH &lt;S&gt;)</p>
2021-05-11 02:29:21 +02:00
<p>An array (colon-separated list) of directories to search for commands.
When this parameter is set, each directory is scanned</p>
<p><span id="index-POSTEDIT"></span></p>
2022-08-24 15:22:41 +02:00
<p>POSTEDIT &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>This string is output whenever the line editor exits. It usually
contains termcap strings to reset the terminal.</p>
<p><span id="index-PROMPT"></span></p>
2022-08-24 15:22:41 +02:00
<p>PROMPT &lt;S&gt; &lt;Z&gt;</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-PROMPT2"></span></p>
2022-08-24 15:22:41 +02:00
<p>PROMPT2 &lt;S&gt; &lt;Z&gt;</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-PROMPT3"></span></p>
2022-08-24 15:22:41 +02:00
<p>PROMPT3 &lt;S&gt; &lt;Z&gt;</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-PROMPT4"></span></p>
2022-08-24 15:22:41 +02:00
<p>PROMPT4 &lt;S&gt; &lt;Z&gt;</p>
<p>Same as PS1, PS2, PS3 and PS4, respectively.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-prompt"></span></p>
2022-08-24 15:22:41 +02:00
<p>prompt &lt;S&gt; &lt;Z&gt;</p>
<p>Same as PS1.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-PROMPT_005fEOL_005fMARK"></span></p>
2022-08-24 15:22:41 +02:00
<p>PROMPT_EOL_MARK</p>
<p>When the PROMPT_CR and PROMPT_SP options are set, the PROMPT_EOL_MARK
parameter can be used to customize how the end of partial lines are
shown. This parameter undergoes prompt expansion, with the
PROMPT_PERCENT option set. If not set, the default behavior is
equivalent to the value %B%S%#%s%b.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-PS1"></span></p>
2022-08-24 15:22:41 +02:00
<p>PS1 &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>The primary prompt string, printed before a command is read. It
undergoes a special form of expansion before being displayed; see
<a href="Prompt-Expansion.html#Prompt-Expansion">Prompt Expansion</a>. The default
2022-08-24 15:22:41 +02:00
is %m%# .</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-PS2"></span></p>
2022-08-24 15:22:41 +02:00
<p>PS2 &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>The secondary prompt, printed when the shell needs more information to
2022-08-24 15:22:41 +02:00
complete a command. It is expanded in the same way as PS1. The default
is %_&gt; , which displays any shell constructs or quotation marks
2021-05-11 02:29:21 +02:00
which are currently being processed.</p>
<p><span id="index-PS3"></span></p>
2022-08-24 15:22:41 +02:00
<p>PS3 &lt;S&gt;</p>
<p>Selection prompt used within a select loop. It is expanded in the same
way as PS1. The default is ?# .</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-PS4"></span></p>
2022-08-24 15:22:41 +02:00
<p>PS4 &lt;S&gt;</p>
<p>The execution trace prompt. Default is +%N:%i&gt; , which displays the
name of the current shell structure and the line number within it. In sh
or ksh emulation, the default is + .</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-psvar"></span> <span id="index-PSVAR"></span></p>
2022-08-24 15:22:41 +02:00
<p>psvar &lt;S&gt; &lt;Z&gt; (PSVAR &lt;S&gt;)</p>
<p>An array (colon-separated list) whose elements can be used in PROMPT
strings. Setting psvar also sets PSVAR, and vice versa.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-READNULLCMD"></span></p>
2022-08-24 15:22:41 +02:00
<p>READNULLCMD &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>The command name to assume if a single input redirection is specified
2022-08-24 15:22:41 +02:00
with no command. Defaults to more.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-REPORTMEMORY"></span></p>
2022-08-24 15:22:41 +02:00
<p>REPORTMEMORY</p>
2021-05-11 02:29:21 +02:00
<p>If nonnegative, commands whose maximum resident set size (roughly
speaking, main memory usage) in kilobytes is greater than this value
have timing statistics reported. The format used to output statistics is
2022-08-24 15:22:41 +02:00
the value of the TIMEFMT parameter, which is the same as for the
REPORTTIME variable and the time builtin; note that by default this does
not output memory usage. Appending &quot; max RSS %M&quot; to the value of TIMEFMT
causes it to output the value that triggered the report. If REPORTTIME
is also in use, at most a single report is printed for both triggers.
This feature requires the getrusage() system call, commonly supported by
modern Unix-like systems.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-REPORTTIME"></span></p>
2022-08-24 15:22:41 +02:00
<p>REPORTTIME</p>
2021-05-11 02:29:21 +02:00
<p>If nonnegative, commands whose combined user and system execution times
(measured in seconds) are greater than this value have timing statistics
printed for them. Output is suppressed for commands executed within the
line editor, including completion; commands explicitly marked with the
2022-08-24 15:22:41 +02:00
time keyword still cause the summary to be printed in this case.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-REPLY"></span></p>
2022-08-24 15:22:41 +02:00
<p>REPLY</p>
2021-05-11 02:29:21 +02:00
<p>This parameter is reserved by convention to pass string values between
shell scripts and shell builtins in situations where a function call or
2022-08-24 15:22:41 +02:00
redirection are impossible or undesirable. The read builtin and the
select complex command may set REPLY, and filename generation both sets
and examines its value when evaluating certain expressions. Some modules
also employ REPLY for similar purposes.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-reply"></span></p>
2022-08-24 15:22:41 +02:00
<p>reply</p>
<p>As REPLY, but for array values rather than strings.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-RPROMPT"></span></p>
2022-08-24 15:22:41 +02:00
<p>RPROMPT &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-RPS1"></span></p>
2022-08-24 15:22:41 +02:00
<p>RPS1 &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>This prompt is displayed on the right-hand side of the screen when the
primary prompt is being displayed on the left. This does not work if the
2022-08-24 15:22:41 +02:00
SINGLE_LINE_ZLE option is set. It is expanded in the same way as PS1.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-RPROMPT2"></span></p>
2022-08-24 15:22:41 +02:00
<p>RPROMPT2 &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-RPS2"></span></p>
2022-08-24 15:22:41 +02:00
<p>RPS2 &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>This prompt is displayed on the right-hand side of the screen when the
secondary prompt is being displayed on the left. This does not work if
2022-08-24 15:22:41 +02:00
the SINGLE_LINE_ZLE option is set. It is expanded in the same way as
PS2.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-SAVEHIST"></span></p>
2022-08-24 15:22:41 +02:00
<p>SAVEHIST</p>
2021-05-11 02:29:21 +02:00
<p>The maximum number of history events to save in the history file.</p>
<p>If this is made local, it is not implicitly set to 0, but may be
explicitly set locally.</p>
<p><span id="index-SPROMPT"></span></p>
2022-08-24 15:22:41 +02:00
<p>SPROMPT &lt;S&gt;</p>
<p>The prompt used for spelling correction. The sequence %R expands to
the string which presumably needs spelling correction, and %r expands
to the proposed correction. All other prompt escapes are also allowed.</p>
<p>The actions available at the prompt are [nyae]:</p>
<p>n (no) (default)<br />
2021-05-11 02:29:21 +02:00
Discard the correction and run the command.</p>
2022-08-24 15:22:41 +02:00
<p>y (yes)<br />
2021-05-11 02:29:21 +02:00
Make the correction and run the command.</p>
2022-08-24 15:22:41 +02:00
<p>a (abort)<br />
2021-05-11 02:29:21 +02:00
Discard the entire command line without running it.</p>
2022-08-24 15:22:41 +02:00
<p>e (edit)<br />
2021-05-11 02:29:21 +02:00
Resume editing the command line.</p>
<p><span id="index-STTY"></span></p>
2022-08-24 15:22:41 +02:00
<p>STTY</p>
2021-05-11 02:29:21 +02:00
<p>If this parameter is set in a commands environment, the shell runs the
2022-08-24 15:22:41 +02:00
stty command with the value of this parameter as arguments in order to
2021-05-11 02:29:21 +02:00
set up the terminal before executing the command. The modes apply only
to the command, and are reset when it finishes or is suspended. If the
2022-08-24 15:22:41 +02:00
command is suspended and continued later with the fg or wait builtins it
will see the modes specified by STTY, as if it were not suspended. This
(intentionally) does not apply if the command is continued via kill
-CONT. STTY is ignored if the command is run in the background, or if
it is in the environment of the shell but not explicitly assigned to in
the input line. This avoids running stty at every external command by
accidentally exporting it. Also note that STTY should not be used for
window size specifications; these will not be local to the command.</p>
<p>If the parameter is set and empty, all of the above applies except that
stty is not run. This can be useful as a way to freeze the tty around a
single command, blocking its changes to tty settings, similar to the
ttyctl builtin.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-TERM"></span></p>
2022-08-24 15:22:41 +02:00
<p>TERM &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>The type of terminal in use. This is used when looking up termcap
2022-08-24 15:22:41 +02:00
sequences. An assignment to TERM causes zsh to re-initialize the
terminal, even if the value does not change (e.g., TERM=$TERM). It is
necessary to make such an assignment upon any change to the terminal
2021-05-11 02:29:21 +02:00
definition database or terminal type in order for the new settings to
take effect.</p>
<p><span id="index-TERMINFO"></span></p>
2022-08-24 15:22:41 +02:00
<p>TERMINFO &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>A reference to your terminfo database, used by the terminfo library
2022-08-24 15:22:41 +02:00
when the system has it; see terminfo(5). If set, this causes the shell
to reinitialise the terminal, making the workaround TERM=$TERM
unnecessary.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-TERMINFO_005fDIRS"></span></p>
2022-08-24 15:22:41 +02:00
<p>TERMINFO_DIRS &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>A colon-seprarated list of terminfo databases, used by the terminfo
2022-08-24 15:22:41 +02:00
library when the system has it; see terminfo(5). This variable is only
used by certain terminal libraries, in particular ncurses; see
terminfo(5) to check support on your system. If set, this causes the
shell to reinitialise the terminal, making the workaround TERM=$TERM
unnecessary. Note that unlike other colon-separated arrays this is not
tied to a zsh array.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-TIMEFMT"></span></p>
2022-08-24 15:22:41 +02:00
<p>TIMEFMT</p>
<p>The format of process time reports with the time keyword. The default is
%J %U user %S system %P cpu %*E total. Recognizes the following
2021-05-11 02:29:21 +02:00
escape sequences, although not all may be available on all systems, and
some that are available may not be useful:</p>
2022-08-24 15:22:41 +02:00
<p>%%<br />
A %.</p>
<p>%U<br />
2021-05-11 02:29:21 +02:00
CPU seconds spent in user mode.</p>
2022-08-24 15:22:41 +02:00
<p>%S<br />
2021-05-11 02:29:21 +02:00
CPU seconds spent in kernel mode.</p>
2022-08-24 15:22:41 +02:00
<p>%E<br />
2021-05-11 02:29:21 +02:00
Elapsed time in seconds.</p>
2022-08-24 15:22:41 +02:00
<p>%P<br />
The CPU percentage, computed as 100*(%U+%S)/%E.</p>
<p>%W<br />
2021-05-11 02:29:21 +02:00
Number of times the process was swapped.</p>
2022-08-24 15:22:41 +02:00
<p>%X<br />
2021-05-11 02:29:21 +02:00
The average amount in (shared) text space used in kilobytes.</p>
2022-08-24 15:22:41 +02:00
<p>%D<br />
2021-05-11 02:29:21 +02:00
The average amount in (unshared) data/stack space used in kilobytes.</p>
2022-08-24 15:22:41 +02:00
<p>%K<br />
The total space used (%X+%D) in kilobytes.</p>
<p>%M<br />
2021-05-11 02:29:21 +02:00
The maximum memory the process had in use at any time in kilobytes.</p>
2022-08-24 15:22:41 +02:00
<p>%F<br />
The number of major page faults (page needed to be brought from disk).</p>
<p>%R<br />
2021-05-11 02:29:21 +02:00
The number of minor page faults.</p>
2022-08-24 15:22:41 +02:00
<p>%I<br />
2021-05-11 02:29:21 +02:00
The number of input operations.</p>
2022-08-24 15:22:41 +02:00
<p>%O<br />
2021-05-11 02:29:21 +02:00
The number of output operations.</p>
2022-08-24 15:22:41 +02:00
<p>%r<br />
2021-05-11 02:29:21 +02:00
The number of socket messages received.</p>
2022-08-24 15:22:41 +02:00
<p>%s<br />
2021-05-11 02:29:21 +02:00
The number of socket messages sent.</p>
2022-08-24 15:22:41 +02:00
<p>%k<br />
2021-05-11 02:29:21 +02:00
The number of signals received.</p>
2022-08-24 15:22:41 +02:00
<p>%w<br />
2021-05-11 02:29:21 +02:00
Number of voluntary context switches (waits).</p>
2022-08-24 15:22:41 +02:00
<p>%c<br />
2021-05-11 02:29:21 +02:00
Number of involuntary context switches.</p>
2022-08-24 15:22:41 +02:00
<p>%J<br />
2021-05-11 02:29:21 +02:00
The name of this job.</p>
<p>A star may be inserted between the percent sign and flags printing time
2022-08-24 15:22:41 +02:00
(e.g., %*E); this causes the time to be printed in
<code>hh</code>:<code>mm</code>:<code>ss</code>.<code>ttt</code> format (hours and minutes are only printed if
they are not zero). Alternatively, m or u may be used (e.g., %mE)
to produce time output in milliseconds or microseconds, respectively.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-TMOUT"></span></p>
2022-08-24 15:22:41 +02:00
<p>TMOUT</p>
<p>If this parameter is nonzero, the shell will receive an ALRM signal if a
command is not entered within the specified number of seconds after
issuing a prompt. If there is a trap on SIGALRM, it will be executed and
a new alarm is scheduled using the value of the TMOUT parameter after
executing the trap. If no trap is set, and the idle time of the terminal
is not less than the value of the TMOUT parameter, zsh terminates.
Otherwise a new alarm is scheduled to TMOUT seconds after the last
keypress.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-TMPPREFIX"></span></p>
2022-08-24 15:22:41 +02:00
<p>TMPPREFIX</p>
2021-05-11 02:29:21 +02:00
<p>A pathname prefix which the shell will use for all temporary files. Note
that this should include an initial part for the file name as well as
2022-08-24 15:22:41 +02:00
any directory names. The default is /tmp/zsh.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-TMPSUFFIX"></span></p>
2022-08-24 15:22:41 +02:00
<p>TMPSUFFIX</p>
2021-05-11 02:29:21 +02:00
<p>A filename suffix which the shell will use for temporary files created
2022-08-24 15:22:41 +02:00
by process substitutions (e.g., =(<code>list</code>)). Note that the value should
include a leading dot . if intended to be interpreted as a file
2021-05-11 02:29:21 +02:00
extension. The default is not to append any suffix, thus this parameter
should be assigned only when needed and then unset again.</p>
<p><span id="index-WORDCHARS"></span></p>
2022-08-24 15:22:41 +02:00
<p>WORDCHARS &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>A list of non-alphanumeric characters considered part of a word by the
line editor.</p>
<p><span id="index-ZBEEP"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZBEEP</p>
2021-05-11 02:29:21 +02:00
<p>If set, this gives a string of characters, which can use all the same
2022-08-24 15:22:41 +02:00
codes as the bindkey command as described in <a href="Zsh-Modules.html#The-zsh_002fzle-Module">The zsh/zle
2021-05-11 02:29:21 +02:00
Module</a>, that will be output to
the terminal instead of beeping. This may have a visible instead of an
2022-08-24 15:22:41 +02:00
audible effect; for example, the string \e[?5h\e[?5l on a vt100 or
2021-05-11 02:29:21 +02:00
xterm will have the effect of flashing reverse video on and off (if you
2022-08-24 15:22:41 +02:00
usually use reverse video, you should use the string \e[?5l\e[?5h
instead). This takes precedence over the NOBEEP option.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-ZDOTDIR"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZDOTDIR</p>
2021-05-11 02:29:21 +02:00
<p>The directory to search for shell startup files (.zshrc, etc), if not
2022-08-24 15:22:41 +02:00
$HOME.</p>
<p><span id="index-zle_005fbracketed_005fpaste"></span> <span
id="index-bracketed-paste"></span> <span
id="index-enabling-bracketed-paste"></span></p>
<p>zle_bracketed_paste</p>
2021-05-11 02:29:21 +02:00
<p>Many terminal emulators have a feature that allows applications to
identify when text is pasted into the terminal rather than being typed
normally. For ZLE, this means that special characters such as tabs and
newlines can be inserted instead of invoking editor commands.
Furthermore, pasted text forms a single undo event and if the region is
active, pasted text will replace the region.</p>
<p>This two-element array contains the terminal escape sequences for
enabling and disabling the feature. These escape sequences are used to
enable bracketed paste when ZLE is active and disable it at other times.
Unsetting the parameter has the effect of ensuring that bracketed paste
remains disabled.</p>
<p><span id="index-zle_005fhighlight"></span></p>
2022-08-24 15:22:41 +02:00
<p>zle_highlight</p>
2021-05-11 02:29:21 +02:00
<p>An array describing contexts in which ZLE should highlight the input
text. See <a href="Zsh-Line-Editor.html#Character-Highlighting">Character
Highlighting</a>.</p>
<p><span id="index-ZLE_005fLINE_005fABORTED"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZLE_LINE_ABORTED</p>
2021-05-11 02:29:21 +02:00
<p>This parameter is set by the line editor when an error occurs. It
contains the line that was being edited at the point of the error.
2022-08-24 15:22:41 +02:00
print -zr $ZLE_LINE_ABORTED can be used to recover the line. Only
the most recent line of this kind is remembered.</p>
<p><span id="index-ZLE_005fREMOVE_005fSUFFIX_005fCHARS"></span> <span
id="index-ZLE_005fSPACE_005fSUFFIX_005fCHARS"></span></p>
<p>ZLE_REMOVE_SUFFIX_CHARS</p>
<p>ZLE_SPACE_SUFFIX_CHARS</p>
2021-05-11 02:29:21 +02:00
<p>These parameters are used by the line editor. In certain circumstances
suffixes (typically space or slash) added by the completion system will
be removed automatically, either because the next editing command as
requiring the suffix to be removed.</p>
<p>These variables can contain the sets of characters that will cause the
2022-08-24 15:22:41 +02:00
suffix to be removed. If ZLE_REMOVE_SUFFIX_CHARS is set, those
2021-05-11 02:29:21 +02:00
characters will cause the suffix to be removed; if
2022-08-24 15:22:41 +02:00
ZLE_SPACE_SUFFIX_CHARS is set, those characters will cause the suffix to
be removed and replaced by a space.</p>
<p>If ZLE_REMOVE_SUFFIX_CHARS is not set, the default behaviour is
2021-05-11 02:29:21 +02:00
equivalent to:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">ZLE_REMOVE_SUFFIX_CHARS=$' \t\n;&amp;|'
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>If ZLE_REMOVE_SUFFIX_CHARS is set but is empty, no characters have this
behaviour. ZLE_SPACE_SUFFIX_CHARS takes precedence, so that the
2021-05-11 02:29:21 +02:00
following:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">ZLE_SPACE_SUFFIX_CHARS=$'&amp;|'
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>causes the characters &amp; and | to remove the suffix but to replace
it with a space.</p>
<p>To illustrate the difference, suppose that the option AUTO_REMOVE_SLASH
is in effect and the directory DIR has just been completed, with an
appended /, following which the user types &amp;. The default result is
DIR&amp;. With ZLE_REMOVE_SUFFIX_CHARS set but without including &amp; the
result is DIR/&amp;. With ZLE_SPACE_SUFFIX_CHARS set to include &amp; the
result is DIR &amp;.</p>
2021-05-11 02:29:21 +02:00
<p>Note that certain completions may provide their own suffix removal or
replacement behaviour which overrides the values described here. See the
completion system documentation in <a href="Completion-System.html#Completion-System">Completion
System</a>.</p>
<p><span id="index-ZLE_005fRPROMPT_005fINDENT"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZLE_RPROMPT_INDENT &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>If set, used to give the indentation between the right hand side of the
2022-08-24 15:22:41 +02:00
right prompt in the line editor as given by RPS1 or RPROMPT and the
2021-05-11 02:29:21 +02:00
right hand side of the screen. If not set, the value 1 is used.</p>
<p>Typically this will be used to set the value to 0 so that the prompt
appears flush with the right hand side of the screen. This is not the
default as many terminals do not handle this correctly, in particular
when the prompt appears at the extreme bottom right of the screen.
Recent virtual terminals are more likely to handle this case correctly.
Some experimentation is necessary.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="Options.html#16-options">16 Options</a>
<ul>
<li><a href="Options.html#161-specifying-options">16.1 Specifying Options</a></li>
<li><a href="Options.html#162-description-of-options">16.2 Description of Options</a>
<ul>
<li><a href="Options.html#1621-changing-directories">16.2.1 Changing Directories</a></li>
<li><a href="Options.html#1622-completion">16.2.2 Completion</a></li>
<li><a href="Options.html#1623-expansion-and-globbing">16.2.3 Expansion and Globbing</a></li>
<li><a href="Options.html#1624-history">16.2.4 History</a></li>
<li><a href="Options.html#1625-initialisation">16.2.5 Initialisation</a></li>
<li><a href="Options.html#1626-inputoutput">16.2.6 Input/Output</a></li>
<li><a href="Options.html#1627-job-control">16.2.7 Job Control</a></li>
<li><a href="Options.html#1628-prompting">16.2.8 Prompting</a></li>
<li><a href="Options.html#1629-scripts-and-functions">16.2.9 Scripts and Functions</a></li>
<li><a href="Options.html#16210-shell-emulation">16.2.10 Shell Emulation</a></li>
<li><a href="Options.html#16211-shell-state">16.2.11 Shell State</a></li>
<li><a href="Options.html#16212-zle">16.2.12 Zle</a></li>
</ul>
</li>
<li><a href="Options.html#163-option-aliases">16.3 Option Aliases</a></li>
<li><a href="Options.html#164-single-letter-options">16.4 Single Letter Options</a>
<ul>
<li><a href="Options.html#1641-default-set">16.4.1 Default set</a></li>
<li><a href="Options.html#1642-shksh-emulation-set">16.4.2 sh/ksh emulation set</a></li>
<li><a href="Options.html#1643-also-note">16.4.3 Also note</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2022-08-24 15:22:41 +02:00
<p><span id="Options"></span> <span id="Options-3"></span></p>
2021-05-11 02:29:21 +02:00
<h1 id="16-options"><a class="header" href="#16-options">16 Options</a></h1>
<p><span id="index-options"></span></p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Specifying-Options"></span> <span
id="Specifying-Options-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="161-specifying-options"><a class="header" href="#161-specifying-options">16.1 Specifying Options</a></h2>
<p><span id="index-options_002c-specifying"></span></p>
<p>Options are primarily referred to by name. These names are case
2022-08-24 15:22:41 +02:00
insensitive and underscores are ignored. For example, allexport is
equivalent to A__lleXP_ort.</p>
<p>The sense of an option name may be inverted by preceding it with no,
so setopt No_Beep is equivalent to unsetopt beep. This inversion can
only be done once, so nonobeep is <em>not</em> a synonym for beep.
Similarly, tify is not a synonym for nonotify (the inversion of
notify).</p>
2021-05-11 02:29:21 +02:00
<p>Some options also have one or more single letter names. There are two
sets of single letter options: one used by default, and another used to
2022-08-24 15:22:41 +02:00
emulate sh/ksh (used when the SH_OPTION_LETTERS option is set). The
2021-05-11 02:29:21 +02:00
single letter options can be used on the shell command line, or with the
2022-08-24 15:22:41 +02:00
set, setopt and unsetopt builtins, as normal Unix options preceded by
-.</p>
<p>The sense of the single letter options may be inverted by using +
instead of -. Some of the single letter option names refer to an
2021-05-11 02:29:21 +02:00
option being off, in which case the inversion of that name refers to the
2022-08-24 15:22:41 +02:00
option being on. For example, +n is the short name of exec, and -n
is the short name of its inversion, noexec.</p>
2021-05-11 02:29:21 +02:00
<p>In strings of single letter options supplied to the shell at startup,
2022-08-24 15:22:41 +02:00
trailing whitespace will be ignored; for example the string -f will
be treated just as -f, but the string -f i is an error. This is
because many systems which implement the #! mechanism for calling
scripts do not strip trailing whitespace.</p>
<p>It is possible for options to be set within a function scope. See the
description of the option LOCAL_OPTIONS below.</p>
<hr />
<p><span id="Description-of-Options"></span> <span
id="Description-of-Options-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="162-description-of-options"><a class="header" href="#162-description-of-options">16.2 Description of Options</a></h2>
<p><span id="index-options_002c-description"></span></p>
<p>In the following list, options set by default in all emulations are
marked &lt;D&gt;; those set by default only in csh, ksh, sh, or zsh
emulations are marked &lt;C&gt;, &lt;K&gt;, &lt;S&gt;, &lt;Z&gt; as appropriate. When
2022-08-24 15:22:41 +02:00
listing options (by setopt, unsetopt, set -o or set +o), those
turned on by default appear in the list prefixed with no. Hence
(unless KSH_OPTION_PRINT is set), setopt shows all options whose
settings are changed from the default.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Changing-Directories"></span></p>
<h3 id="1621-changing-directories"><a class="header" href="#1621-changing-directories">16.2.1 Changing Directories</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-AUTO_005fCD"></span> <span
id="index-NO_005fAUTO_005fCD"></span> <span id="index-AUTOCD"></span>
<span id="index-NOAUTOCD"></span> <span
id="index-cd_002c-automatic"></span></p>
<p>AUTO_CD (-J)</p>
2021-05-11 02:29:21 +02:00
<p>If a command is issued that cant be executed as a normal command, and
2022-08-24 15:22:41 +02:00
the command is the name of a directory, perform the cd command to that
directory. This option is only applicable if the option SHIN_STDIN is
2021-05-11 02:29:21 +02:00
set, i.e. if commands are being read from standard input. The option is
2022-08-24 15:22:41 +02:00
designed for interactive use; it is recommended that cd be used
2021-05-11 02:29:21 +02:00
explicitly in scripts to avoid ambiguity.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-AUTO_005fPUSHD"></span> <span
id="index-NO_005fAUTO_005fPUSHD"></span> <span
id="index-AUTOPUSHD"></span> <span id="index-NOAUTOPUSHD"></span> <span
id="index-cd_002c-behaving-like-pushd"></span> <span
id="index-pushd_002c-making-cd-behave-like"></span></p>
<p>AUTO_PUSHD (-N)</p>
<p>Make cd push the old directory onto the directory stack.</p>
<p><span id="index-CDABLE_005fVARS"></span> <span
id="index-NO_005fCDABLE_005fVARS"></span> <span
id="index-CDABLEVARS"></span> <span id="index-NOCDABLEVARS"></span>
2021-05-11 02:29:21 +02:00
<span id="index-cd_002c-to-parameter"></span></p>
2022-08-24 15:22:41 +02:00
<p>CDABLE_VARS (-T)</p>
<p>If the argument to a cd command (or an implied cd with the AUTO_CD
2021-05-11 02:29:21 +02:00
option set) is not a directory, and does not begin with a slash, try to
2022-08-24 15:22:41 +02:00
expand the expression as if it were preceded by a ~ (see <a href="Expansion.html#Filename-Expansion">Filename
2021-05-11 02:29:21 +02:00
Expansion</a>).</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-CD_005fSILENT"></span> <span
id="index-NO_005fCD_005fSILENT"></span> <span
id="index-CDSILENT"></span> <span id="index-NOCDSILENT"></span> <span
id="index-cd_002c-silencing"></span> <span
id="index-autocd_002c-silencing"></span></p>
<p>CD_SILENT</p>
<p>Never print the working directory after a cd (whether explicit or
implied with the AUTO_CD option set). cd normally prints the working
directory when the argument given to it was -, a stack entry, or the
name of a directory found under CDPATH. Note that this is distinct from
pushds stack-printing behaviour, which is controlled by PUSHD_SILENT.
This option overrides the printing-related effects of POSIX_CD.</p>
<p><span id="index-CHASE_005fDOTS"></span> <span
id="index-NO_005fCHASE_005fDOTS"></span> <span
id="index-CHASEDOTS"></span> <span id="index-NOCHASEDOTS"></span> <span
id="index-cd_002c-with-_002e_002e-in-argument"></span></p>
<p>CHASE_DOTS</p>
<p>When changing to a directory containing a path segment .. which would
otherwise be treated as canceling the previous segment in the path (in
other words, foo/.. would be removed from the path, or if .. is the
first part of the path, the last part of the current working directory
would be removed), instead resolve the path to the physical directory.
This option is overridden by CHASE_LINKS.</p>
<p>For example, suppose /foo/bar is a link to the directory /alt/rod.
Without this option set, cd /foo/bar/.. changes to /foo; with it set,
it changes to /alt. The same applies if the current directory is
/foo/bar and cd .. is used. Note that all other symbolic links in the
path will also be resolved.</p>
<p><span id="index-CHASE_005fLINKS"></span> <span
id="index-NO_005fCHASE_005fLINKS"></span> <span
id="index-CHASELINKS"></span> <span id="index-NOCHASELINKS"></span>
<span id="index-links_002c-symbolic"></span> <span
id="index-symbolic-links"></span></p>
<p>CHASE_LINKS (-w)</p>
2021-05-11 02:29:21 +02:00
<p>Resolve symbolic links to their true values when changing directory.
2022-08-24 15:22:41 +02:00
This also has the effect of CHASE_DOTS, i.e. a .. path segment will be
treated as referring to the physical parent, even if the preceding path
segment is a symbolic link.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-POSIX_005fCD"></span> <span id="index-POSIXCD"></span>
2022-08-24 15:22:41 +02:00
<span id="index-NO_005fPOSIX_005fCD"></span> <span
id="index-NOPOSIXCD"></span> <span
id="index-CDPATH_002c-order-of-checking"></span></p>
<p>POSIX_CD &lt;K&gt; &lt;S&gt;</p>
<p>Modifies the behaviour of cd, chdir and pushd commands to make them more
compatible with the POSIX standard. The behaviour with the option unset
is described in the documentation for the cd builtin in <a href="Shell-Builtin-Commands.html#Shell-Builtin-Commands">Shell Builtin
2021-05-11 02:29:21 +02:00
Commands</a>. If the
option is set, the shell does not test for directories beneath the local
2022-08-24 15:22:41 +02:00
directory (.) until after all directories in cdpath have been tested,
and the cd and chdir commands do not recognise arguments of the form
{+|-}<code>n</code> as directory stack entries.</p>
2021-05-11 02:29:21 +02:00
<p>Also, if the option is set, the conditions under which the shell prints
the new directory after changing to it are modified. It is no longer
restricted to interactive shells (although printing of the directory
2022-08-24 15:22:41 +02:00
stack with pushd is still limited to interactive shells); and any use of
a component of CDPATH, including a . but excluding an empty component
that is otherwise treated as ., causes the directory to be printed.</p>
<p><span id="index-PUSHD_005fIGNORE_005fDUPS"></span> <span
id="index-NO_005fPUSHD_005fIGNORE_005fDUPS"></span> <span
id="index-PUSHDIGNOREDUPS"></span> <span
id="index-NOPUSHDIGNOREDUPS"></span> <span
id="index-directory-stack_002c-ignoring-duplicates"></span></p>
<p>PUSHD_IGNORE_DUPS</p>
2021-05-11 02:29:21 +02:00
<p>Dont push multiple copies of the same directory onto the directory
stack.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-PUSHD_005fMINUS"></span> <span
id="index-NO_005fPUSHD_005fMINUS"></span> <span
id="index-PUSHDMINUS"></span> <span id="index-NOPUSHDMINUS"></span>
2021-05-11 02:29:21 +02:00
<span id="index-directory-stack_002c-controlling-syntax"></span></p>
2022-08-24 15:22:41 +02:00
<p>PUSHD_MINUS</p>
<p>Exchanges the meanings of + and - when used with a number to specify
a directory in the stack.</p>
<p><span id="index-PUSHD_005fSILENT"></span> <span
id="index-NO_005fPUSHD_005fSILENT"></span> <span
id="index-PUSHDSILENT"></span> <span id="index-NOPUSHDSILENT"></span>
2021-05-11 02:29:21 +02:00
<span id="index-directory-stack_002c-silencing"></span></p>
2022-08-24 15:22:41 +02:00
<p>PUSHD_SILENT (-E)</p>
<p>Do not print the directory stack after pushd or popd.</p>
<p><span id="index-PUSHD_005fTO_005fHOME"></span> <span
id="index-NO_005fPUSHD_005fTO_005fHOME"></span> <span
id="index-PUSHDTOHOME"></span> <span id="index-NOPUSHDTOHOME"></span>
2021-05-11 02:29:21 +02:00
<span id="index-pushd_002c-to-home"></span></p>
2022-08-24 15:22:41 +02:00
<p>PUSHD_TO_HOME (-D)</p>
<p>Have pushd with no arguments act like pushd $HOME.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Completion-4"></span></p>
<h3 id="1622-completion"><a class="header" href="#1622-completion">16.2.2 Completion</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-ALWAYS_005fLAST_005fPROMPT"></span> <span
id="index-NO_005fALWAYS_005fLAST_005fPROMPT"></span> <span
id="index-ALWAYSLASTPROMPT"></span> <span
id="index-NOALWAYSLASTPROMPT"></span></p>
<p>ALWAYS_LAST_PROMPT &lt;D&gt;</p>
2021-05-11 02:29:21 +02:00
<p>If unset, key functions that list completions try to return to the last
prompt if given a numeric argument. If set these functions try to return
to the last prompt if given <em>no</em> numeric argument.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-ALWAYS_005fTO_005fEND"></span> <span
id="index-NO_005fALWAYS_005fTO_005fEND"></span> <span
id="index-ALWAYSTOEND"></span> <span id="index-NOALWAYSTOEND"></span></p>
<p>ALWAYS_TO_END</p>
2021-05-11 02:29:21 +02:00
<p>If a completion is performed with the cursor within a word, and a full
completion is inserted, the cursor is moved to the end of the word. That
is, the cursor is moved to the end of the word if either a single match
is inserted or menu completion is performed.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-AUTO_005fLIST"></span> <span
id="index-NO_005fAUTO_005fLIST"></span> <span
id="index-AUTOLIST"></span> <span id="index-NOAUTOLIST"></span> <span
id="index-completion_002c-listing-choices"></span></p>
<p>AUTO_LIST (-9) &lt;D&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Automatically list choices on an ambiguous completion.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-AUTO_005fMENU"></span> <span
id="index-NO_005fAUTO_005fMENU"></span> <span
id="index-AUTOMENU"></span> <span id="index-NOAUTOMENU"></span> <span
id="index-completion_002c-menu"></span></p>
<p>AUTO_MENU &lt;D&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Automatically use menu completion after the second consecutive request
for completion, for example by pressing the tab key repeatedly. This
2022-08-24 15:22:41 +02:00
option is overridden by MENU_COMPLETE.</p>
<p><span id="index-AUTO_005fNAME_005fDIRS"></span> <span
id="index-NO_005fAUTO_005fNAME_005fDIRS"></span> <span
id="index-AUTONAMEDIRS"></span> <span id="index-NOAUTONAMEDIRS"></span>
2021-05-11 02:29:21 +02:00
<span id="index-directories_002c-named"></span></p>
2022-08-24 15:22:41 +02:00
<p>AUTO_NAME_DIRS</p>
2021-05-11 02:29:21 +02:00
<p>Any parameter that is set to the absolute name of a directory
immediately becomes a name for that directory, that will be used by the
2022-08-24 15:22:41 +02:00
%~ and related prompt sequences, and will be available when
completion is performed on a word starting with ~. (Otherwise, the
parameter must be used in the form ~<code>param</code> first.)</p>
<p><span id="index-AUTO_005fPARAM_005fKEYS"></span> <span
id="index-NO_005fAUTO_005fPARAM_005fKEYS"></span> <span
id="index-AUTOPARAMKEYS"></span> <span
id="index-NOAUTOPARAMKEYS"></span></p>
<p>AUTO_PARAM_KEYS &lt;D&gt;</p>
2021-05-11 02:29:21 +02:00
<p>If a parameter name was completed and a following character (normally a
space) automatically inserted, and the next character typed is one of
2022-08-24 15:22:41 +02:00
those that have to come directly after the name (like }, :, etc.),
the automatically added character is deleted, so that the character
typed comes immediately after the parameter name. Completion in a brace
expansion is affected similarly: the added character is a ,, which
will be removed if } is typed next.</p>
<p><span id="index-AUTO_005fPARAM_005fSLASH"></span> <span
id="index-NO_005fAUTO_005fPARAM_005fSLASH"></span> <span
id="index-AUTOPARAMSLASH"></span> <span
id="index-NOAUTOPARAMSLASH"></span></p>
<p>AUTO_PARAM_SLASH &lt;D&gt;</p>
2021-05-11 02:29:21 +02:00
<p>If a parameter is completed whose content is the name of a directory,
then add a trailing slash instead of a space.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-AUTO_005fREMOVE_005fSLASH"></span> <span
id="index-NO_005fAUTO_005fREMOVE_005fSLASH"></span> <span
id="index-AUTOREMOVESLASH"></span> <span
id="index-NOAUTOREMOVESLASH"></span> <span
id="index-slash_002c-removing-trailing"></span></p>
<p>AUTO_REMOVE_SLASH &lt;D&gt;</p>
2021-05-11 02:29:21 +02:00
<p>When the last character resulting from a completion is a slash and the
next character typed is a word delimiter, a slash, or a character that
ends a command (such as a semicolon or an ampersand), remove the slash.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-BASH_005fAUTO_005fLIST"></span> <span
id="index-NO_005fBASH_005fAUTO_005fLIST"></span> <span
id="index-BASHAUTOLIST"></span> <span id="index-NOBASHAUTOLIST"></span>
2021-05-11 02:29:21 +02:00
<span id="index-completion_002c-listing-choices_002c-bash-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>BASH_AUTO_LIST</p>
2021-05-11 02:29:21 +02:00
<p>On an ambiguous completion, automatically list choices when the
completion function is called twice in succession. This takes precedence
2022-08-24 15:22:41 +02:00
over AUTO_LIST. The setting of LIST_AMBIGUOUS is respected. If AUTO_MENU
is set, the menu behaviour will then start with the third press. Note
that this will not work with MENU_COMPLETE, since repeated completion
calls immediately cycle through the list in that case.</p>
<p><span id="index-COMPLETE_005fALIASES"></span> <span
id="index-NO_005fCOMPLETE_005fALIASES"></span> <span
id="index-COMPLETEALIASES"></span> <span
id="index-NOCOMPLETEALIASES"></span> <span
id="index-aliases_002c-completion-of"></span></p>
<p>COMPLETE_ALIASES</p>
2021-05-11 02:29:21 +02:00
<p>Prevents aliases on the command line from being internally substituted
before completion is attempted. The effect is to make the alias a
distinct command for completion purposes.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-COMPLETE_005fIN_005fWORD"></span> <span
id="index-NO_005fCOMPLETE_005fIN_005fWORD"></span> <span
id="index-COMPLETEINWORD"></span> <span
id="index-NOCOMPLETEINWORD"></span></p>
<p>COMPLETE_IN_WORD</p>
2021-05-11 02:29:21 +02:00
<p>If unset, the cursor is set to the end of the word if completion is
started. Otherwise it stays there and completion is done from both ends.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-GLOB_005fCOMPLETE"></span> <span
id="index-NO_005fGLOB_005fCOMPLETE"></span> <span
id="index-GLOBCOMPLETE"></span> <span id="index-NOGLOBCOMPLETE"></span></p>
<p>GLOB_COMPLETE</p>
2021-05-11 02:29:21 +02:00
<p>When the current word has a glob pattern, do not insert all the words
resulting from the expansion but generate matches as for completion and
2022-08-24 15:22:41 +02:00
cycle through them like MENU_COMPLETE. The matches are generated as if a
* was added to the end of the word, or inserted at the cursor when
COMPLETE_IN_WORD is set. This actually uses pattern matching, not
2021-05-11 02:29:21 +02:00
globbing, so it works not only for files but for any completion, such as
options, user names, etc.</p>
<p>Note that when the pattern matcher is used, matching control (for
example, case-insensitive or anchored matching) cannot be used. This
limitation only applies when the current word contains a pattern; simply
2022-08-24 15:22:41 +02:00
turning on the GLOB_COMPLETE option does not have this effect.</p>
<p><span id="index-HASH_005fLIST_005fALL"></span> <span
id="index-NO_005fHASH_005fLIST_005fALL"></span> <span
id="index-HASHLISTALL"></span> <span id="index-NOHASHLISTALL"></span></p>
<p>HASH_LIST_ALL &lt;D&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Whenever a command completion or spelling correction is attempted, make
sure the entire command path is hashed first. This makes the first
completion slower but avoids false reports of spelling errors.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-LIST_005fAMBIGUOUS"></span> <span
id="index-NO_005fLIST_005fAMBIGUOUS"></span> <span
id="index-LISTAMBIGUOUS"></span> <span
id="index-NOLISTAMBIGUOUS"></span> <span
id="index-ambiguous-completion"></span> <span
id="index-completion_002c-ambiguous"></span></p>
<p>LIST_AMBIGUOUS &lt;D&gt;</p>
<p>This option works when AUTO_LIST or BASH_AUTO_LIST is also set. If there
is an unambiguous prefix to insert on the command line, that is done
without a completion list being displayed; in other words, auto-listing
behaviour only takes place when nothing would be inserted. In the case
of BASH_AUTO_LIST, this means that the list will be delayed to the third
call of the function.</p>
<p><span id="index-LIST_005fBEEP"></span> <span
id="index-NO_005fLIST_005fBEEP"></span> <span
id="index-LISTBEEP"></span> <span id="index-NOLISTBEEP"></span> <span
id="index-beep_002c-ambiguous-completion"></span> <span
id="index-completion_002c-beep-on-ambiguous"></span></p>
<p>LIST_BEEP &lt;D&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Beep on an ambiguous completion. More accurately, this forces the
completion widgets to return status 1 on an ambiguous completion, which
2022-08-24 15:22:41 +02:00
causes the shell to beep if the option BEEP is also set; this may be
2021-05-11 02:29:21 +02:00
modified if completion is called from a user-defined widget.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-LIST_005fPACKED"></span> <span
id="index-NO_005fLIST_005fPACKED"></span> <span
id="index-LISTPACKED"></span> <span id="index-NOLISTPACKED"></span>
2021-05-11 02:29:21 +02:00
<span id="index-completion_002c-listing"></span></p>
2022-08-24 15:22:41 +02:00
<p>LIST_PACKED</p>
2021-05-11 02:29:21 +02:00
<p>Try to make the completion list smaller (occupying less lines) by
printing the matches in columns with different widths.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-LIST_005fROWS_005fFIRST"></span> <span
id="index-NO_005fLIST_005fROWS_005fFIRST"></span> <span
id="index-LISTROWSFIRST"></span> <span
id="index-NOLISTROWSFIRST"></span> <span
id="index-completion_002c-listing-order"></span></p>
<p>LIST_ROWS_FIRST</p>
2021-05-11 02:29:21 +02:00
<p>Lay out the matches in completion lists sorted horizontally, that is,
the second match is to the right of the first one, not under it as
usual.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-LIST_005fTYPES"></span> <span
id="index-NO_005fLIST_005fTYPES"></span> <span
id="index-LISTTYPES"></span> <span id="index-NOLISTTYPES"></span> <span
id="index-marking-file-types"></span> <span
id="index-files_002c-marking-type-of"></span></p>
<p>LIST_TYPES (-X) &lt;D&gt;</p>
2021-05-11 02:29:21 +02:00
<p>When listing files that are possible completions, show the type of each
file with a trailing identifying mark.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-MENU_005fCOMPLETE"></span> <span
id="index-NO_005fMENU_005fCOMPLETE"></span> <span
id="index-MENUCOMPLETE"></span> <span id="index-NOMENUCOMPLETE"></span>
2021-05-11 02:29:21 +02:00
<span id="index-completion_002c-menu-1"></span></p>
2022-08-24 15:22:41 +02:00
<p>MENU_COMPLETE (-Y)</p>
2021-05-11 02:29:21 +02:00
<p>On an ambiguous completion, instead of listing possibilities or beeping,
insert the first match immediately. Then when completion is requested
again, remove the first match and insert the second match, etc. When
there are no more matches, go back to the first one again.
2022-08-24 15:22:41 +02:00
reverse-menu-complete may be used to loop through the list in the other
direction. This option overrides AUTO_MENU.</p>
<p><span id="index-REC_005fEXACT"></span> <span
id="index-NO_005fREC_005fEXACT"></span> <span
id="index-RECEXACT"></span> <span id="index-NORECEXACT"></span> <span
id="index-completion_002c-exact-matches"></span></p>
<p>REC_EXACT (-S)</p>
2021-05-11 02:29:21 +02:00
<p>If the string on the command line exactly matches one of the possible
completions, it is accepted, even if there is another completion (i.e.
that string with something else added) that also matches.</p>
<hr />
<p><span id="Expansion-and-Globbing"></span></p>
<h3 id="1623-expansion-and-globbing"><a class="header" href="#1623-expansion-and-globbing">16.2.3 Expansion and Globbing</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-BAD_005fPATTERN"></span> <span
id="index-NO_005fBAD_005fPATTERN"></span> <span
id="index-BADPATTERN"></span> <span id="index-NOBADPATTERN"></span>
<span id="index-globbing_002c-bad-pattern"></span> <span
id="index-filename-generation_002c-bad-pattern"></span></p>
<p>BAD_PATTERN (+2) &lt;C&gt; &lt;Z&gt;</p>
2021-05-11 02:29:21 +02:00
<p>If a pattern for filename generation is badly formed, print an error
message. (If this option is unset, the pattern will be left unchanged.)</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-BARE_005fGLOB_005fQUAL"></span> <span
id="index-NO_005fBARE_005fGLOB_005fQUAL"></span> <span
id="index-BAREGLOBQUAL"></span> <span id="index-NOBAREGLOBQUAL"></span>
<span id="index-globbing-qualifiers_002c-enable"></span> <span
id="index-enable-globbing-qualifiers"></span></p>
<p>BARE_GLOB_QUAL &lt;Z&gt;</p>
2021-05-11 02:29:21 +02:00
<p>In a glob pattern, treat a trailing set of parentheses as a qualifier
2022-08-24 15:22:41 +02:00
list, if it contains no |, ( or (if special) ~ characters. See
<a href="Expansion.html#Filename-Generation">Filename Generation</a>.</p>
<p><span id="index-BRACE_005fCCL"></span> <span
id="index-NO_005fBRACE_005fCCL"></span> <span
id="index-BRACECCL"></span> <span id="index-NOBRACECCL"></span> <span
id="index-brace-expansion_002c-extending"></span> <span
id="index-expansion_002c-brace_002c-extending"></span></p>
<p>BRACE_CCL</p>
2021-05-11 02:29:21 +02:00
<p>Expand expressions in braces which would not otherwise undergo brace
expansion to a lexically ordered list of all the characters. See <a href="Expansion.html#Brace-Expansion">Brace
Expansion</a>.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-CASE_005fGLOB"></span> <span
id="index-NO_005fCASE_005fGLOB"></span> <span
id="index-CASEGLOB"></span> <span id="index-NOCASEGLOB"></span> <span
id="index-case_002dinsensitive-globbing_002c-option"></span></p>
<p>CASE_GLOB &lt;D&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Make globbing (filename generation) sensitive to case. Note that other
uses of patterns are always sensitive to case. If the option is unset,
the presence of any character which is special to filename generation
2022-08-24 15:22:41 +02:00
will cause case-insensitive matching. For example, cvs(/) can match the
directory CVS owing to the presence of the globbing flag (unless the
option BARE_GLOB_QUAL is unset).</p>
<p><span id="index-CASE_005fMATCH"></span> <span
id="index-NO_005fCASE_005fMATCH"></span> <span
id="index-CASEMATCH"></span> <span id="index-NOCASEMATCH"></span> <span
id="index-case_002dinsensitive-regular-expression-matches_002c-option"></span>
<span
id="index-regular-expressions_002c-case_002dinsensitive-matching_002c-option"></span></p>
<p>CASE_MATCH &lt;D&gt;</p>
<p>Make regular expressions using the zsh/regex module (including matches
with =~) sensitive to case.</p>
<p><span id="index-CASE_005fPATHS"></span> <span
id="index-NO_005fCASE_005fPATHS"></span> <span
id="index-CASEPATHS"></span> <span id="index-NOCASEPATHS"></span> <span
id="index-case_002dsensitive-globbing_002c-option"></span></p>
<p>CASE_PATHS</p>
<p>If CASE_PATHS is not set (the default), CASE_GLOB affects the
interpretation of <em>every</em> path component, whenever a special character
appears in <em>any</em> component. When CASE_PATHS is set, file path components
that do <em>not</em> contain special filename generation characters are always
sensitive to case, thus restricting NO_CASE_GLOB to components that
contain globbing characters.</p>
<p>Note that if the filesystem itself is not sensitive to case, then
CASE_PATHS has no effect.</p>
<p><span id="index-CSH_005fNULL_005fGLOB"></span> <span
id="index-NO_005fCSH_005fNULL_005fGLOB"></span> <span
id="index-CSHNULLGLOB"></span> <span id="index-NOCSHNULLGLOB"></span>
<span id="index-csh_002c-null-globbing-style"></span> <span
id="index-null-globbing-style_002c-csh"></span> <span
id="index-globbing_002c-null_002c-style_002c-csh"></span></p>
<p>CSH_NULL_GLOB &lt;C&gt;</p>
2021-05-11 02:29:21 +02:00
<p>If a pattern for filename generation has no matches, delete the pattern
from the argument list; do not report an error unless all the patterns
2022-08-24 15:22:41 +02:00
in a command have no matches. Overrides NOMATCH.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-EQUALS"></span> <span id="index-NO_005fEQUALS"></span>
2022-08-24 15:22:41 +02:00
<span id="index-NOEQUALS"></span> <span
id="index-filename-expansion_002c-_003d"></span></p>
<p>EQUALS &lt;Z&gt;</p>
<p>Perform = filename expansion. (See <a href="Expansion.html#Filename-Expansion">Filename
2021-05-11 02:29:21 +02:00
Expansion</a>.)</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-EXTENDED_005fGLOB"></span> <span
id="index-NO_005fEXTENDED_005fGLOB"></span> <span
id="index-EXTENDEDGLOB"></span> <span id="index-NOEXTENDEDGLOB"></span>
2021-05-11 02:29:21 +02:00
<span id="index-globbing_002c-extended"></span></p>
2022-08-24 15:22:41 +02:00
<p>EXTENDED_GLOB</p>
<p>Treat the #, ~ and ^ characters as part of patterns for filename
generation, etc. (An initial unquoted ~ always produces named
directory expansion.)</p>
<p><span id="index-FORCE_005fFLOAT"></span> <span
id="index-NO_005fFORCE_005fFLOAT"></span> <span
id="index-FORCEFLOAT"></span> <span id="index-NOFORCEFLOAT"></span>
<span id="index-floating-point_002c-forcing-use-of"></span> <span
id="index-forcing-use-of-floating-point"></span></p>
<p>FORCE_FLOAT</p>
2021-05-11 02:29:21 +02:00
<p>Constants in arithmetic evaluation will be treated as floating point
even without the use of a decimal point; the values of integer variables
will be converted to floating point when used in arithmetic expressions.
Integers in any base will be converted.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-GLOB"></span> <span id="index-NO_005fGLOB"></span> <span
id="index-NOGLOB"></span> <span
id="index-globbing_002c-enabling"></span> <span
id="index-enabling-globbing"></span></p>
<p>GLOB (+F, ksh: +f) &lt;D&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Perform filename generation (globbing). (See <a href="Expansion.html#Filename-Generation">Filename
Generation</a>.)</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-GLOB_005fASSIGN"></span> <span
id="index-NO_005fGLOB_005fASSIGN"></span> <span
id="index-GLOBASSIGN"></span> <span id="index-NOGLOBASSIGN"></span></p>
<p>GLOB_ASSIGN &lt;C&gt;</p>
2021-05-11 02:29:21 +02:00
<p>If this option is set, filename generation (globbing) is performed on
the right hand side of scalar parameter assignments of the form
2022-08-24 15:22:41 +02:00
<code>name</code>=<code>pattern</code> (e.g. foo=*). If the result has more than one word
the parameter will become an array with those words as arguments. This
option is provided for backwards compatibility only: globbing is always
performed on the right hand side of array assignments of the form
<code>name</code>=(<code>value</code>) (e.g. foo=(*)) and this form is recommended for
clarity; with this option set, it is not possible to predict whether the
result will be an array or a scalar.</p>
<p><span id="index-GLOB_005fDOTS"></span> <span
id="index-NO_005fGLOB_005fDOTS"></span> <span
id="index-GLOBDOTS"></span> <span id="index-NOGLOBDOTS"></span> <span
id="index-globbing_002c-of-_002e-files"></span></p>
<p>GLOB_DOTS (-4)</p>
<p>Do not require a leading . in a filename to be matched explicitly.</p>
<p><span id="index-GLOB_005fSTAR_005fSHORT"></span> <span
id="index-NO_005fGLOB_005fSTAR_005fSHORT"></span> <span
id="index-GLOBSTARSHORT"></span> <span
id="index-NOGLOBSTARSHORT"></span> <span
id="index-globbing_002c-short-forms"></span> <span
id="index-globbing_002c-_002a_002a-special"></span></p>
<p>GLOB_STAR_SHORT</p>
2021-05-11 02:29:21 +02:00
<p>When this option is set and the default zsh-style globbing is in effect,
2022-08-24 15:22:41 +02:00
the pattern **/* can be abbreviated to ** and the pattern
***/* can be abbreviated to ***. Hence **.c finds a file
ending in .c in any subdirectory, and ***.c does the same while
also following symbolic links. A / immediately after the ** or
*** forces the pattern to be treated as the unabbreviated form.</p>
<p><span id="index-GLOB_005fSUBST"></span> <span
id="index-NO_005fGLOB_005fSUBST"></span> <span
id="index-GLOBSUBST"></span> <span id="index-NOGLOBSUBST"></span></p>
<p>GLOB_SUBST &lt;C&gt; &lt;K&gt; &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Treat any characters resulting from parameter expansion as being
eligible for filename expansion and filename generation, and any
characters resulting from command substitution as being eligible for
filename generation. Braces (and commas in between) do not become
eligible for expansion.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-HIST_005fSUBST_005fPATTERN"></span> <span
id="index-NO_005fHIST_005fSUBST_005fPATTERN"></span> <span
id="index-HISTSUBSTPATTERN"></span> <span
id="index-NOHISTSUBSTPATTERN"></span></p>
<p>HIST_SUBST_PATTERN</p>
<p>Substitutions using the :s and :&amp; history modifiers are performed with
pattern matching instead of string matching. This occurs wherever
2021-05-11 02:29:21 +02:00
history modifiers are valid, including glob qualifiers and parameters.
See <a href="Expansion.html#Modifiers">Modifiers</a>.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-IGNORE_005fBRACES"></span> <span
id="index-NO_005fIGNORE_005fBRACES"></span> <span
id="index-IGNOREBRACES"></span> <span id="index-NOIGNOREBRACES"></span>
<span id="index-disabling-brace-expansion"></span> <span
id="index-brace-expansion_002c-disabling"></span> <span
id="index-expansion_002c-brace_002c-disabling"></span></p>
<p>IGNORE_BRACES (-I) &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Do not perform brace expansion. For historical reasons this also
2022-08-24 15:22:41 +02:00
includes the effect of the IGNORE_CLOSE_BRACES option.</p>
<p><span id="index-IGNORE_005fCLOSE_005fBRACES"></span> <span
id="index-NO_005fIGNORE_005fCLOSE_005fBRACES"></span> <span
id="index-IGNORECLOSEBRACES"></span> <span
id="index-NOIGNORECLOSEBRACES"></span></p>
<p>IGNORE_CLOSE_BRACES</p>
<p>When neither this option nor IGNORE_BRACES is set, a sole close brace
character } is syntactically significant at any point on a command
2021-05-11 02:29:21 +02:00
line. This has the effect that no semicolon or newline is necessary
before the brace terminating a function or current shell construct. When
either option is set, a closing brace is syntactically significant only
2022-08-24 15:22:41 +02:00
in command position. Unlike IGNORE_BRACES, this option does not disable
brace expansion.</p>
2021-05-11 02:29:21 +02:00
<p>For example, with both options unset a function may be defined in the
following fashion:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">args() { echo $# }
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>while if either option is set, this does not work and something
equivalent to the following is required:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">args() { echo $#; }
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p><span id="index-KSH_005fGLOB"></span> <span
id="index-NO_005fKSH_005fGLOB"></span> <span id="index-KSHGLOB"></span>
<span id="index-NOKSHGLOB"></span></p>
<p>KSH_GLOB &lt;K&gt;</p>
2021-05-11 02:29:21 +02:00
<p>In pattern matching, the interpretation of parentheses is affected by a
2022-08-24 15:22:41 +02:00
preceding @, *, +, ? or !. See <a href="Expansion.html#Filename-Generation">Filename
2021-05-11 02:29:21 +02:00
Generation</a>.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-MAGIC_005fEQUAL_005fSUBST"></span> <span
id="index-NO_005fMAGIC_005fEQUAL_005fSUBST"></span> <span
id="index-MAGICEQUALSUBST"></span> <span
id="index-NOMAGICEQUALSUBST"></span></p>
<p>MAGIC_EQUAL_SUBST</p>
<p>All unquoted arguments of the form <code>anything</code>=<code>expression</code> appearing
2021-05-11 02:29:21 +02:00
after the command name have filename expansion (that is, where
2022-08-24 15:22:41 +02:00
<code>expression</code> has a leading ~ or =) performed on <code>expression</code> as if
it were a parameter assignment. The argument is not otherwise treated
2021-05-11 02:29:21 +02:00
specially; it is passed to the command as a single argument, and not
2022-08-24 15:22:41 +02:00
used as an actual parameter assignment. For example, in echo
foo=~/bar:~/rod, both occurrences of ~ would be replaced. Note that
this happens anyway with typeset and similar statements.</p>
<p>This option respects the setting of the KSH_TYPESET option. In other
2021-05-11 02:29:21 +02:00
words, if both options are in effect, arguments looking like assignments
will not undergo word splitting.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-MARK_005fDIRS"></span> <span
id="index-NO_005fMARK_005fDIRS"></span> <span
id="index-MARKDIRS"></span> <span id="index-NOMARKDIRS"></span> <span
id="index-directories_002c-marking"></span> <span
id="index-marking-directories"></span></p>
<p>MARK_DIRS (-8, ksh: -X)</p>
<p>Append a trailing / to all directory names resulting from filename
2021-05-11 02:29:21 +02:00
generation (globbing).</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-MULTIBYTE"></span> <span
id="index-NO_005fMULTIBYTE"></span> <span id="index-NOMULTIBYTE"></span>
<span
id="index-characters_002c-multibyte_002c-in-expansion-and-globbing"></span>
<span
id="index-multibyte-characters_002c-in-expansion-and-globbing"></span></p>
<p>MULTIBYTE &lt;D&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Respect multibyte characters when found in strings. When this option is
set, strings are examined using the system library to determine how many
bytes form a character, depending on the current locale. This affects
the way characters are counted in pattern matching, parameter values and
various delimiters.</p>
<p>The option is on by default if the shell was compiled with
2022-08-24 15:22:41 +02:00
MULTIBYTE_SUPPORT; otherwise it is off by default and has no effect if
2021-05-11 02:29:21 +02:00
turned on.</p>
<p>If the option is off a single byte is always treated as a single
character. This setting is designed purely for examining strings known
to contain raw bytes or other values that may not be characters in the
current locale. It is not necessary to unset the option merely because
the character set for the current locale does not contain multibyte
characters.</p>
<p>The option does not affect the shells editor, which always uses the
locale to determine multibyte characters. This is because the character
set displayed by the terminal emulator is independent of shell settings.</p>
<p><span id="index-NOMATCH"></span> <span id="index-NO_005fNOMATCH"></span>
2022-08-24 15:22:41 +02:00
<span id="index-NONOMATCH"></span> <span
id="index-globbing_002c-no-matches"></span></p>
<p>NOMATCH (+3) &lt;C&gt; &lt;Z&gt;</p>
2021-05-11 02:29:21 +02:00
<p>If a pattern for filename generation has no matches, print an error,
instead of leaving it unchanged in the argument list. This also applies
2022-08-24 15:22:41 +02:00
to file expansion of an initial ~ or =.</p>
<p><span id="index-NULL_005fGLOB"></span> <span
id="index-NO_005fNULL_005fGLOB"></span> <span
id="index-NULLGLOB"></span> <span id="index-NONULLGLOB"></span> <span
id="index-globbing_002c-no-matches-1"></span></p>
<p>NULL_GLOB (-G)</p>
2021-05-11 02:29:21 +02:00
<p>If a pattern for filename generation has no matches, delete the pattern
2022-08-24 15:22:41 +02:00
from the argument list instead of reporting an error. Overrides NOMATCH.</p>
<p><span id="index-NUMERIC_005fGLOB_005fSORT"></span> <span
id="index-NO_005fNUMERIC_005fGLOB_005fSORT"></span> <span
id="index-NUMERICGLOBSORT"></span> <span
id="index-NONUMERICGLOBSORT"></span> <span
id="index-globbing_002c-sorting-numerically"></span></p>
<p>NUMERIC_GLOB_SORT</p>
2021-05-11 02:29:21 +02:00
<p>If numeric filenames are matched by a filename generation pattern, sort
the filenames numerically rather than lexicographically.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-RC_005fEXPAND_005fPARAM"></span> <span
id="index-NO_005fRC_005fEXPAND_005fPARAM"></span> <span
id="index-RCEXPANDPARAM"></span> <span
id="index-NORCEXPANDPARAM"></span> <span
id="index-rc_002c-parameter-expansion-style"></span> <span
id="index-parameter-expansion-style_002c-rc"></span></p>
<p>RC_EXPAND_PARAM (-P)</p>
<p>Array expansions of the form <code>foo</code>${<code>xx</code>}<code>bar</code>, where the parameter
<code>xx</code> is set to (<code>a b c</code>), are substituted with
<code>fooabar foobbar foocbar</code> instead of the default <code>fooa b cbar</code>. Note
that an empty array will therefore cause all arguments to be removed.</p>
<p><span id="index-REMATCH_005fPCRE"></span> <span
id="index-NO_005fREMATCH_005fPCRE"></span> <span
id="index-REMATCHPCRE"></span> <span id="index-NOREMATCHPCRE"></span>
<span id="index-regexp_002c-PCRE"></span> <span
id="index-PCRE_002c-regexp"></span></p>
<p>REMATCH_PCRE</p>
<p>If set, regular expression matching with the =~ operator will use
Perl-Compatible Regular Expressions from the PCRE library. (The zsh/pcre
module must be available.) If not set, regular expressions will use the
extended regexp syntax provided by the system libraries.</p>
<p><span id="index-SH_005fGLOB"></span> <span
id="index-NO_005fSH_005fGLOB"></span> <span id="index-SHGLOB"></span>
<span id="index-NOSHGLOB"></span> <span
id="index-sh_002c-globbing-style"></span> <span
id="index-globbing-style_002c-sh"></span></p>
<p>SH_GLOB &lt;K&gt; &lt;S&gt;</p>
<p>Disables the special meaning of (, |, ) and &lt; for globbing the
result of parameter and command substitutions, and in some other places
where the shell accepts patterns. If SH_GLOB is set but KSH_GLOB is not,
the shell allows the interpretation of subshell expressions enclosed in
parentheses in some cases where there is no space before the opening
parenthesis, e.g. !(true) is interpreted as if there were a space after
the !. This option is set by default if zsh is invoked as sh or ksh.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-UNSET"></span> <span id="index-NO_005fUNSET"></span>
2022-08-24 15:22:41 +02:00
<span id="index-NOUNSET"></span> <span
id="index-parameters_002c-substituting-unset"></span> <span
id="index-unset-parameters_002c-substituting"></span></p>
<p>UNSET (+u, ksh: +u) &lt;K&gt; &lt;S&gt; &lt;Z&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Treat unset parameters as if they were empty when substituting, and as
if they were zero when reading their values in arithmetic expansion and
arithmetic commands. Otherwise they are treated as an error.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-WARN_005fCREATE_005fGLOBAL"></span> <span
id="index-NO_005fWARN_005fCREATE_005fGLOBAL"></span> <span
id="index-WARNCREATEGLOBAL"></span> <span
id="index-NOWARNCREATEGLOBAL"></span> <span
id="index-parameters_002c-warning-when-created-globally"></span></p>
<p>WARN_CREATE_GLOBAL</p>
2021-05-11 02:29:21 +02:00
<p>Print a warning message when a global parameter is created in a function
by an assignment or in math context. This often indicates that a
parameter has not been declared local when it should have been.
Parameters explicitly declared global from within a function using
2022-08-24 15:22:41 +02:00
typeset -g do not cause a warning. Note that there is no warning when a
local parameter is assigned to in a nested function, which may also
2021-05-11 02:29:21 +02:00
indicate an error.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-WARN_005fNESTED_005fVAR"></span> <span
id="index-NO_005fWARN_005fNESTED_005fVAR"></span> <span
id="index-WARNNESTEDVAR"></span> <span
id="index-NO_005fWARNNESTEDVAR"></span> <span
id="index-parameters_002c-warning-when-setting-in-enclosing-scope"></span></p>
<p>WARN_NESTED_VAR</p>
2021-05-11 02:29:21 +02:00
<p>Print a warning message when an existing parameter from an enclosing
function scope, or global, is set in a function by an assignment or in
math context. Assignment to shell special parameters does not cause a
2022-08-24 15:22:41 +02:00
warning. This is the companion to WARN_CREATE_GLOBAL as in this case the
warning is only printed when a parameter is <em>not</em> created. Where
possible, use of typeset -g to set the parameter suppresses the error,
2021-05-11 02:29:21 +02:00
but note that this needs to be used every time the parameter is set. To
restrict the effect of this option to a single function scope, use
2022-08-24 15:22:41 +02:00
functions -W.</p>
2021-05-11 02:29:21 +02:00
<p>For example, the following code produces a warning for the assignment
2022-08-24 15:22:41 +02:00
inside the function nested as that overrides the value within toplevel</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">toplevel() {
2021-05-11 02:29:21 +02:00
local foo=&quot;in fn&quot;
nested
}
nested() {
foo=&quot;in nested&quot;
}
setopt warn_nested_var
toplevel
</code></pre>
</div>
<hr />
<p><span id="History"></span></p>
<h3 id="1624-history"><a class="header" href="#1624-history">16.2.4 History</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-APPEND_005fHISTORY"></span> <span
id="index-NO_005fAPPEND_005fHISTORY"></span> <span
id="index-APPENDHISTORY"></span> <span
id="index-NOAPPENDHISTORY"></span> <span
id="index-history_002c-appending-to-a-file"></span></p>
<p>APPEND_HISTORY &lt;D&gt;</p>
2021-05-11 02:29:21 +02:00
<p>If this is set, zsh sessions will append their history list to the
history file, rather than replace it. Thus, multiple parallel zsh
sessions will all have the new entries from their history lists added to
the history file, in the order that they exit. The file will still be
periodically re-written to trim it when the number of lines grows 20%
2022-08-24 15:22:41 +02:00
beyond the value specified by $SAVEHIST (see also the HIST_SAVE_BY_COPY
option).</p>
<p><span id="index-BANG_005fHIST"></span> <span
id="index-NO_005fBANG_005fHIST"></span> <span
id="index-BANGHIST"></span> <span id="index-NOBANGHIST"></span> <span
id="index-history_002c-enable-substitution"></span> <span
id="index-enable-history-substitution"></span></p>
<p>BANG_HIST (+K) &lt;C&gt; &lt;Z&gt;</p>
<p>Perform textual history expansion, csh-style, treating the character !
specially.</p>
<p><span id="index-EXTENDED_005fHISTORY"></span> <span
id="index-NO_005fEXTENDED_005fHISTORY"></span> <span
id="index-EXTENDEDHISTORY"></span> <span
id="index-NOEXTENDEDHISTORY"></span> <span
id="index-history_002c-timestamping"></span></p>
<p>EXTENDED_HISTORY &lt;C&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Save each commands beginning timestamp (in seconds since the epoch) and
the duration (in seconds) to the history file. The format of this
prefixed data is:</p>
2022-08-24 15:22:41 +02:00
<p>: <code>&lt;beginning time&gt;</code>:<code>&lt;elapsed seconds&gt;</code>;<code>&lt;command&gt;</code>.</p>
<p><span id="index-HIST_005fALLOW_005fCLOBBER"></span> <span
id="index-NO_005fHIST_005fALLOW_005fCLOBBER"></span> <span
id="index-HISTALLOWCLOBBER"></span> <span
id="index-NOHISTALLOWCLOBBER"></span></p>
<p>HIST_ALLOW_CLOBBER</p>
<p>Add | to output redirections in the history. This allows history
references to clobber files even when CLOBBER is unset.</p>
<p><span id="index-HIST_005fBEEP"></span> <span
id="index-NO_005fHIST_005fBEEP"></span> <span
id="index-HISTBEEP"></span> <span id="index-NOHISTBEEP"></span> <span
id="index-history-beeping"></span> <span
id="index-beep_002c-history"></span></p>
<p>HIST_BEEP &lt;D&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Beep in ZLE when a widget attempts to access a history entry which isnt
there.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-HIST_005fEXPIRE_005fDUPS_005fFIRST"></span> <span
id="index-NO_005fHIST_005fEXPIRE_005fDUPS_005fFIRST"></span> <span
id="index-HISTEXPIREDUPSFIRST"></span> <span
id="index-NOHISTEXPIREDUPSFIRST"></span> <span
id="index-history_002c-expiring-duplicates"></span></p>
<p>HIST_EXPIRE_DUPS_FIRST</p>
2021-05-11 02:29:21 +02:00
<p>If the internal history needs to be trimmed to add the current command
line, setting this option will cause the oldest history event that has a
duplicate to be lost before losing a unique event from the list. You
2022-08-24 15:22:41 +02:00
should be sure to set the value of HISTSIZE to a larger number than
SAVEHIST in order to give you some room for the duplicated events,
otherwise this option will behave just like HIST_IGNORE_ALL_DUPS once
2021-05-11 02:29:21 +02:00
the history fills up with unique events.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-HIST_005fFCNTL_005fLOCK"></span> <span
id="index-NO_005fHIST_005fFCNTL_005fLOCK"></span> <span
id="index-HISTFCNTLLOCK"></span> <span
id="index-NOHISTFCNTLLOCK"></span></p>
<p>HIST_FCNTL_LOCK</p>
2021-05-11 02:29:21 +02:00
<p>When writing out the history file, by default zsh uses ad-hoc file
locking to avoid known problems with locking on some operating systems.
2022-08-24 15:22:41 +02:00
With this option locking is done by means of the systems fcntl call,
2021-05-11 02:29:21 +02:00
where this method is available. On recent operating systems this may
provide better performance, in particular avoiding history corruption
when files are stored on NFS.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-HIST_005fFIND_005fNO_005fDUPS"></span> <span
id="index-NO_005fHIST_005fFIND_005fNO_005fDUPS"></span> <span
id="index-HISTFINDNODUPS"></span> <span
id="index-NOHISTFINDNODUPS"></span> <span
id="index-history_002c-ignoring-duplicates-in-search"></span></p>
<p>HIST_FIND_NO_DUPS</p>
2021-05-11 02:29:21 +02:00
<p>When searching for history entries in the line editor, do not display
duplicates of a line previously found, even if the duplicates are not
contiguous.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-HIST_005fIGNORE_005fALL_005fDUPS"></span> <span
id="index-NO_005fHIST_005fIGNORE_005fALL_005fDUPS"></span> <span
id="index-HISTIGNOREALLDUPS"></span> <span
id="index-NOHISTIGNOREALLDUPS"></span> <span
id="index-history_002c-ignoring-all-duplicates"></span></p>
<p>HIST_IGNORE_ALL_DUPS</p>
2021-05-11 02:29:21 +02:00
<p>If a new command line being added to the history list duplicates an
older one, the older command is removed from the list (even if it is not
the previous event).</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-HIST_005fIGNORE_005fDUPS"></span> <span
id="index-NO_005fHIST_005fIGNORE_005fDUPS"></span> <span
id="index-HISTIGNOREDUPS"></span> <span
id="index-NOHISTIGNOREDUPS"></span> <span
id="index-history_002c-ignoring-duplicates"></span></p>
<p>HIST_IGNORE_DUPS (-h)</p>
2021-05-11 02:29:21 +02:00
<p>Do not enter command lines into the history list if they are duplicates
of the previous event.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-HIST_005fIGNORE_005fSPACE"></span> <span
id="index-NO_005fHIST_005fIGNORE_005fSPACE"></span> <span
id="index-HISTIGNORESPACE"></span> <span
id="index-NOHISTIGNORESPACE"></span> <span
id="index-history_002c-ignoring-spaces"></span></p>
<p>HIST_IGNORE_SPACE (-g)</p>
2021-05-11 02:29:21 +02:00
<p>Remove command lines from the history list when the first character on
the line is a space, or when one of the expanded aliases contains a
leading space. Only normal aliases (not global or suffix aliases) have
this behaviour. Note that the command lingers in the internal history
until the next command is entered before it vanishes, allowing you to
briefly reuse or edit the line. If you want to make it vanish right away
without entering another command, type a space and press return.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-HIST_005fLEX_005fWORDS"></span> <span
id="index-NO_005fHIST_005fLEX_005fWORDS"></span> <span
id="index-HISTLEXWORDS"></span> <span id="index-NOHISTLEXWORDS"></span></p>
<p>HIST_LEX_WORDS</p>
2021-05-11 02:29:21 +02:00
<p>By default, shell history that is read in from files is split into words
on all white space. This means that arguments with quoted whitespace are
not correctly handled, with the consequence that references to words in
history lines that have been read from a file may be inaccurate. When
this option is set, words read in from a history file are divided up in
a similar fashion to normal shell command line handling. Although this
produces more accurately delimited words, if the size of the history
file is large this can be slow. Trial and error is necessary to decide.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-HIST_005fNO_005fFUNCTIONS"></span> <span
id="index-NO_005fHIST_005fNO_005fFUNCTIONS"></span> <span
id="index-HISTNOFUNCTIONS"></span> <span
id="index-NOHISTNOFUNCTIONS"></span></p>
<p>HIST_NO_FUNCTIONS</p>
2021-05-11 02:29:21 +02:00
<p>Remove function definitions from the history list. Note that the
function lingers in the internal history until the next command is
entered before it vanishes, allowing you to briefly reuse or edit the
definition.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-HIST_005fNO_005fSTORE"></span> <span
id="index-NO_005fHIST_005fNO_005fSTORE"></span> <span
id="index-HISTNOSTORE"></span> <span id="index-NOHISTNOSTORE"></span></p>
<p>HIST_NO_STORE</p>
<p>Remove the history (fc -l) command from the history list when invoked.
Note that the command lingers in the internal history until the next
command is entered before it vanishes, allowing you to briefly reuse or
edit the line.</p>
<p><span id="index-HIST_005fREDUCE_005fBLANKS"></span> <span
id="index-NO_005fHIST_005fREDUCE_005fBLANKS"></span> <span
id="index-HISTREDUCEBLANKS"></span> <span
id="index-NOHISTREDUCEBLANKS"></span></p>
<p>HIST_REDUCE_BLANKS</p>
2021-05-11 02:29:21 +02:00
<p>Remove superfluous blanks from each command line being added to the
history list.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-HIST_005fSAVE_005fBY_005fCOPY"></span> <span
id="index-NO_005fHIST_005fSAVE_005fBY_005fCOPY"></span> <span
id="index-HISTSAVEBYCOPY"></span> <span
id="index-NOHISTSAVEBYCOPY"></span></p>
<p>HIST_SAVE_BY_COPY &lt;D&gt;</p>
2021-05-11 02:29:21 +02:00
<p>When the history file is re-written, we normally write out a copy of the
2022-08-24 15:22:41 +02:00
file named $HISTFILE.new and then rename it over the old one. However,
2021-05-11 02:29:21 +02:00
if this option is unset, we instead truncate the old history file and
write out the new version in-place. If one of the history-appending
options is enabled, this option only has an effect when the enlarged
history file needs to be re-written to trim it down to size. Disable
this only if you have special needs, as doing so makes it possible to
lose history entries if zsh gets interrupted during the save.</p>
<p>When writing out a copy of the history file, zsh preserves the old
2022-08-24 15:22:41 +02:00
files permissions and group information, but will refuse to write out a
new file if it would change the history files owner.</p>
<p><span id="index-HIST_005fSAVE_005fNO_005fDUPS"></span> <span
id="index-NO_005fHIST_005fSAVE_005fNO_005fDUPS"></span> <span
id="index-HISTSAVENODUPS"></span> <span
id="index-NOHISTSAVENODUPS"></span></p>
<p>HIST_SAVE_NO_DUPS</p>
2021-05-11 02:29:21 +02:00
<p>When writing out the history file, older commands that duplicate newer
ones are omitted.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-HIST_005fVERIFY"></span> <span
id="index-NO_005fHIST_005fVERIFY"></span> <span
id="index-HISTVERIFY"></span> <span id="index-NOHISTVERIFY"></span>
2021-05-11 02:29:21 +02:00
<span id="index-history_002c-verifying-substitution"></span></p>
2022-08-24 15:22:41 +02:00
<p>HIST_VERIFY</p>
2021-05-11 02:29:21 +02:00
<p>Whenever the user enters a line with history expansion, dont execute
the line directly; instead, perform history expansion and reload the
line into the editing buffer.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-INC_005fAPPEND_005fHISTORY"></span> <span
id="index-NO_005fINC_005fAPPEND_005fHISTORY"></span> <span
id="index-INCAPPENDHISTORY"></span> <span
id="index-NOINCAPPENDHISTORY"></span> <span
id="index-history_002c-incremental-appending-to-a-file"></span></p>
<p>INC_APPEND_HISTORY</p>
<p>This option works like APPEND_HISTORY except that new history lines are
added to the $HISTFILE incrementally (as soon as they are entered),
rather than waiting until the shell exits. The file will still be
periodically re-written to trim it when the number of lines grows 20%
beyond the value specified by $SAVEHIST (see also the HIST_SAVE_BY_COPY
option).</p>
<p><span id="index-INC_005fAPPEND_005fHISTORY_005fTIME"></span> <span
id="index-NO_005fINC_005fAPPEND_005fHISTORY_005fTIME"></span> <span
id="index-INCAPPENDHISTORYTIME"></span> <span
id="index-NOINCAPPENDHISTORYTIME"></span> <span
id="index-history_002c-incremental-appending-to-a-file-with-time"></span></p>
<p>INC_APPEND_HISTORY_TIME</p>
<p>This option is a variant of INC_APPEND_HISTORY in which, where possible,
the history entry is written out to the file after the command is
finished, so that the time taken by the command is recorded correctly in
the history file in EXTENDED_HISTORY format. This means that the history
entry will not be available immediately from other instances of the
shell that are using the same history file.</p>
<p>This option is only useful if INC_APPEND_HISTORY and SHARE_HISTORY are
turned off. The three options should be considered mutually exclusive.</p>
<p><span id="index-SHARE_005fHISTORY"></span> <span
id="index-NO_005fSHARE_005fHISTORY"></span> <span
id="index-SHAREHISTORY"></span> <span id="index-NOSHAREHISTORY"></span>
<span id="index-share-history"></span> <span
id="index-history_002c-sharing"></span></p>
<p>SHARE_HISTORY &lt;K&gt;</p>
2021-05-11 02:29:21 +02:00
<p>This option both imports new commands from the history file, and also
causes your typed commands to be appended to the history file (the
2022-08-24 15:22:41 +02:00
latter is like specifying INC_APPEND_HISTORY, which should be turned off
if this option is in effect). The history lines are also output with
timestamps ala EXTENDED_HISTORY (which makes it easier to find the spot
where we left off reading the file after it gets re-written).</p>
2021-05-11 02:29:21 +02:00
<p>By default, history movement commands visit the imported lines as well
as the local lines, but you can toggle this on and off with the
set-local-history zle binding. It is also possible to create a zle
widget that will make some commands ignore imported commands, and some
include them.</p>
<p>If you find that you want more control over when commands get imported,
2022-08-24 15:22:41 +02:00
you may wish to turn SHARE_HISTORY off, INC_APPEND_HISTORY or
INC_APPEND_HISTORY_TIME (see above) on, and then manually import
commands whenever you need them using fc -RI.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Initialisation"></span></p>
<h3 id="1625-initialisation"><a class="header" href="#1625-initialisation">16.2.5 Initialisation</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-ALL_005fEXPORT"></span> <span
id="index-NO_005fALL_005fEXPORT"></span> <span
id="index-ALLEXPORT"></span> <span id="index-NOALLEXPORT"></span> <span
id="index-export_002c-automatic"></span></p>
<p>ALL_EXPORT (-a, ksh: -a)</p>
2021-05-11 02:29:21 +02:00
<p>All parameters subsequently defined are automatically exported.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-GLOBAL_005fEXPORT"></span> <span
id="index-NO_005fGLOBAL_005fEXPORT"></span> <span
id="index-GLOBALEXPORT"></span> <span id="index-NOGLOBALEXPORT"></span>
2021-05-11 02:29:21 +02:00
<span id="index-environment_002c-and-local-parameters"></span></p>
2022-08-24 15:22:41 +02:00
<p>GLOBAL_EXPORT &lt;Z&gt;</p>
<p>If this option is set, passing the -x flag to the builtins declare,
float, integer, readonly and typeset (but not local) will also set the
-g flag; hence parameters exported to the environment will not be made
local to the enclosing function, unless they were already or the flag +g
is given explicitly. If the option is unset, exported parameters will be
made local in just the same way as any other parameter.</p>
2021-05-11 02:29:21 +02:00
<p>This option is set by default for backward compatibility; it is not
recommended that its behaviour be relied upon. Note that the builtin
2022-08-24 15:22:41 +02:00
export always sets both the -x and -g flags, and hence its effect
2021-05-11 02:29:21 +02:00
extends beyond the scope of the enclosing function; this is the</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-exporting_002c-and-local-parameters"></span> <span
id="index-GLOBAL_005fRCS"></span> <span
id="index-NO_005fGLOBAL_005fRCS"></span> <span
id="index-GLOBALRCS"></span> <span id="index-NOGLOBALRCS"></span> <span
id="index-startup-files_002c-global_002c-inhibiting"></span> <span
id="index-files_002c-global-startup_002c-inhibiting"></span></p>
<p>GLOBAL_RCS (+d) &lt;D&gt;</p>
<p>If this option is unset, the startup files /etc/zprofile, /etc/zshrc,
/etc/zlogin and /etc/zlogout will not be run. It can be disabled and
re-enabled at any time, including inside local startup files (.zshrc,
etc.).</p>
<p><span id="index-RCS"></span> <span id="index-NO_005fRCS"></span> <span
id="index-NORCS"></span> <span
id="index-startup-files_002c-sourcing"></span></p>
<p>RCS (+f) &lt;D&gt;</p>
<p>After /etc/zshenv is sourced on startup, source the .zshenv,
/etc/zprofile, .zprofile, /etc/zshrc, .zshrc, /etc/zlogin, .zlogin, and
.zlogout files, as described in <a href="Files.html#Files">Files</a>. If this
option is unset, the /etc/zshenv file is still sourced, but any of the
others will not be; it can be set at any time to prevent the remaining
startup files after the currently executing one from being sourced.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Input_002fOutput"></span></p>
<h3 id="1626-inputoutput"><a class="header" href="#1626-inputoutput">16.2.6 Input/Output</a></h3>
<p><span id="index-ALIASES"></span> <span id="index-NO_005fALIASES"></span>
2022-08-24 15:22:41 +02:00
<span id="index-NOALIASES"></span> <span
id="index-aliases_002c-expansion"></span></p>
<p>ALIASES &lt;D&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Expand aliases.</p>
<p><span id="index-CLOBBER"></span> <span id="index-NO_005fCLOBBER"></span>
2022-08-24 15:22:41 +02:00
<span id="index-NOCLOBBER"></span> <span
id="index-clobbering_002c-of-files"></span> <span
id="index-file-clobbering_002c-allowing"></span></p>
<p>CLOBBER (+C, ksh: +C) &lt;D&gt;</p>
<p>Allows &gt; redirection to truncate existing files. Otherwise &gt;! or
&gt;| must be used to truncate a file.</p>
<p>If the option is not set, and the option APPEND_CREATE is also not set,
&gt;&gt;! or &gt;&gt;| must be used to create a file. If either option is
set, &gt;&gt; may be used.</p>
<p><span id="index-CLOBBER_005fEMPTY"></span> <span
id="index-NO_005fCLOBBER_005fEMPTY"></span> <span
id="index-CLOBBEREMPTY"></span> <span id="index-NOCLOBBEREMPTY"></span>
<span id="index-clobbering_002c-of-empty-files"></span> <span
id="index-file-clobbering_002c-of-empty-files"></span></p>
<p>CLOBBER_EMPTY</p>
<p>This option is only used if the option CLOBBER is not set: note that it
is set by default.</p>
<p>If this option is set, then regular files of zero length may be
ovewritten (clobbered). Note that it is possible another process has
written to the file between this test and use of the file by the current
process. This option should therefore not be used in cases where files
to be clobbered may be written to asynchronously.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-CORRECT"></span> <span id="index-NO_005fCORRECT"></span>
2022-08-24 15:22:41 +02:00
<span id="index-NOCORRECT"></span> <span
id="index-correction_002c-spelling"></span> <span
id="index-spelling-correction"></span></p>
<p>CORRECT (-0)</p>
2021-05-11 02:29:21 +02:00
<p>Try to correct the spelling of commands. Note that, when the
2022-08-24 15:22:41 +02:00
HASH_LIST_ALL option is not set or when some directories in the path are
not readable, this may falsely report spelling errors the first time
2021-05-11 02:29:21 +02:00
some commands are used.</p>
2022-08-24 15:22:41 +02:00
<p>The shell variable CORRECT_IGNORE may be set to a pattern to match words
that will never be offered as corrections.</p>
<p><span id="index-CORRECT_005fALL"></span> <span
id="index-NO_005fCORRECT_005fALL"></span> <span
id="index-CORRECTALL"></span> <span id="index-NOCORRECTALL"></span></p>
<p>CORRECT_ALL (-O)</p>
2021-05-11 02:29:21 +02:00
<p>Try to correct the spelling of all arguments in a line.</p>
2022-08-24 15:22:41 +02:00
<p>The shell variable CORRECT_IGNORE_FILE may be set to a pattern to match
file names that will never be offered as corrections.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-DVORAK"></span> <span id="index-NO_005fDVORAK"></span>
<span id="index-NODVORAK"></span></p>
2022-08-24 15:22:41 +02:00
<p>DVORAK</p>
2021-05-11 02:29:21 +02:00
<p>Use the Dvorak keyboard instead of the standard qwerty keyboard as a
2022-08-24 15:22:41 +02:00
basis for examining spelling mistakes for the CORRECT and CORRECT_ALL
options and the spell-word editor command.</p>
<p><span id="index-FLOW_005fCONTROL"></span> <span
id="index-NO_005fFLOW_005fCONTROL"></span> <span
id="index-FLOWCONTROL"></span> <span id="index-NOFLOWCONTROL"></span>
2021-05-11 02:29:21 +02:00
<span id="index-flow-control"></span></p>
2022-08-24 15:22:41 +02:00
<p>FLOW_CONTROL &lt;D&gt;</p>
2021-05-11 02:29:21 +02:00
<p>If this option is unset, output flow control via start/stop characters
(usually assigned to ^S/^Q) is disabled in the shells editor.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-IGNORE_005fEOF"></span> <span
id="index-NO_005fIGNORE_005fEOF"></span> <span
id="index-IGNOREEOF"></span> <span id="index-NOIGNOREEOF"></span> <span
id="index-EOF_002c-ignoring"></span></p>
<p>IGNORE_EOF (-7)</p>
<p>Do not exit on end-of-file. Require the use of exit or logout instead.
However, ten consecutive EOFs will cause the shell to exit anyway, to
avoid the shell hanging if its tty goes away.</p>
2021-05-11 02:29:21 +02:00
<p>Also, if this option is set and the Zsh Line Editor is used, widgets
implemented by shell functions can be bound to EOF (normally Control-D)
without printing the normal warning message. This works only for normal
widgets, not for completion widgets.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-INTERACTIVE_005fCOMMENTS"></span> <span
id="index-NO_005fINTERACTIVE_005fCOMMENTS"></span> <span
id="index-INTERACTIVECOMMENTS"></span> <span
id="index-NOINTERACTIVECOMMENTS"></span> <span
id="index-comments_002c-in-interactive-shells"></span></p>
<p>INTERACTIVE_COMMENTS (-k) &lt;K&gt; &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Allow comments even in interactive shells.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-HASH_005fCMDS"></span> <span
id="index-NO_005fHASH_005fCMDS"></span> <span
id="index-HASHCMDS"></span> <span id="index-NOHASHCMDS"></span> <span
id="index-hashing_002c-of-commands"></span> <span
id="index-command-hashing"></span></p>
<p>HASH_CMDS &lt;D&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Note the location of each command the first time it is executed.
Subsequent invocations of the same command will use the saved location,
avoiding a path search. If this option is unset, no path hashing is done
2022-08-24 15:22:41 +02:00
at all. However, when CORRECT is set, commands whose names do not appear
in reporting them as spelling errors.</p>
<p><span id="index-HASH_005fDIRS"></span> <span
id="index-NO_005fHASH_005fDIRS"></span> <span
id="index-HASHDIRS"></span> <span id="index-NOHASHDIRS"></span> <span
id="index-hashing_002c-of-directories"></span> <span
id="index-directories_002c-hashing"></span></p>
<p>HASH_DIRS &lt;D&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Whenever a command name is hashed, hash the directory containing it, as
well as all directories that occur earlier in the path. Has no effect if
2022-08-24 15:22:41 +02:00
neither HASH_CMDS nor CORRECT is set.</p>
<p><span id="index-HASH_005fEXECUTABLES_005fONLY"></span> <span
id="index-NO_005fHASH_005fEXECUTABLES_005fONLY"></span> <span
id="index-HASHEXECUTABLESONLY"></span> <span
id="index-NOHASHEXECUTABLESONLY"></span></p>
<p>HASH_EXECUTABLES_ONLY</p>
<p>When hashing commands because of HASH_CMDS, check that the is unset by
2021-05-11 02:29:21 +02:00
default as if the path contains a large number of commands, or consists
of many remote files, the additional tests can take a long time. Trial
and error is needed to show if this option is beneficial.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-MAIL_005fWARNING"></span> <span
id="index-NO_005fMAIL_005fWARNING"></span> <span
id="index-MAILWARNING"></span> <span id="index-NOMAILWARNING"></span>
2021-05-11 02:29:21 +02:00
<span id="index-mail_002c-warning-of-reading"></span></p>
2022-08-24 15:22:41 +02:00
<p>MAIL_WARNING (-U)</p>
2021-05-11 02:29:21 +02:00
<p>Print a warning message if a mail file has been accessed since the shell
last checked.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-PATH_005fDIRS"></span> <span
id="index-NO_005fPATH_005fDIRS"></span> <span
id="index-PATHDIRS"></span> <span id="index-NOPATHDIRS"></span> <span
id="index-path-search_002c-extended"></span></p>
<p>PATH_DIRS (-Q)</p>
2021-05-11 02:29:21 +02:00
<p>Perform a path search even on command names with slashes in them. Thus
2022-08-24 15:22:41 +02:00
if /usr/local/bin is in the users path, and he or she types
X11/xinit, the command /usr/local/bin/X11/xinit will be executed
(assuming it exists). Commands explicitly beginning with /, ./ or
../ are not subject to the path search. This also applies to the .
and source builtins.</p>
2021-05-11 02:29:21 +02:00
<p>Note that subdirectories of the current directory are always searched
2022-08-24 15:22:41 +02:00
for indicated by this option, and regardless of whether . or the
2021-05-11 02:29:21 +02:00
current directory appear in the command search path.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-PATH_005fSCRIPT"></span> <span
id="index-NO_005fPATH_005fSCRIPT"></span> <span
id="index-PATHSCRIPT"></span> <span id="index-NOPATHSCRIPT"></span>
2021-05-11 02:29:21 +02:00
<span id="index-path-search_002c-for-script-argument-to-shell"></span></p>
2022-08-24 15:22:41 +02:00
<p>PATH_SCRIPT &lt;K&gt; &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>If this option is not set, a script passed as the first non-option
argument to the shell must contain the name of the file to open. If this
option is set, and the script does not specify a directory path, the
script is looked for first in the current directory, then in the command
path. See <a href="Invocation.html#Invocation">Invocation</a>.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-PRINT_005fEIGHT_005fBIT"></span> <span
id="index-NO_005fPRINT_005fEIGHT_005fBIT"></span> <span
id="index-PRINTEIGHTBIT"></span> <span
id="index-NOPRINTEIGHTBIT"></span> <span
id="index-eight-bit-characters_002c-printing"></span></p>
<p>PRINT_EIGHT_BIT</p>
2021-05-11 02:29:21 +02:00
<p>Print eight bit characters literally in completion lists, etc. This
option is not necessary if your system correctly returns the
2022-08-24 15:22:41 +02:00
printability of eight bit characters (see ctype(3)).</p>
<p><span id="index-PRINT_005fEXIT_005fVALUE"></span> <span
id="index-NO_005fPRINT_005fEXIT_005fVALUE"></span> <span
id="index-PRINTEXITVALUE"></span> <span
id="index-NOPRINTEXITVALUE"></span> <span
id="index-exit-status_002c-printing"></span></p>
<p>PRINT_EXIT_VALUE (-1)</p>
2021-05-11 02:29:21 +02:00
<p>Print the exit value of programs with non-zero exit status. This is only
available at the command line in interactive shells.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-RC_005fQUOTES"></span> <span
id="index-NO_005fRC_005fQUOTES"></span> <span
id="index-RCQUOTES"></span> <span id="index-NORCQUOTES"></span> <span
id="index-rc_002c-quoting-style"></span> <span
id="index-quoting-style_002c-rc"></span></p>
<p>RC_QUOTES</p>
<p>Allow the character sequence to signify a single quote within
2021-05-11 02:29:21 +02:00
singly quoted strings. Note this does not apply in quoted strings using
2022-08-24 15:22:41 +02:00
the format $<code>...</code>, where a backslashed single quote can be used.</p>
<p><span id="index-RM_005fSTAR_005fSILENT"></span> <span
id="index-NO_005fRM_005fSTAR_005fSILENT"></span> <span
id="index-RMSTARSILENT"></span> <span id="index-NORMSTARSILENT"></span>
<span id="index-rm-_002a_002c-querying-before"></span> <span
id="index-querying-before-rm-_002a"></span></p>
<p>RM_STAR_SILENT (-H) &lt;K&gt; &lt;S&gt;</p>
<p>Do not query the user before executing rm * or rm path/*.</p>
<p><span id="index-RM_005fSTAR_005fWAIT"></span> <span
id="index-NO_005fRM_005fSTAR_005fWAIT"></span> <span
id="index-RMSTARWAIT"></span> <span id="index-NORMSTARWAIT"></span>
<span id="index-rm-_002a_002c-waiting-before"></span> <span
id="index-waiting-before-rm-_002a"></span></p>
<p>RM_STAR_WAIT</p>
<p>If querying the user before executing rm * or rm path/*, first
2021-05-11 02:29:21 +02:00
wait ten seconds and ignore anything typed in that time. This avoids the
problem of reflexively answering yes to the query when one didnt
really mean it. The wait and query can always be avoided by expanding
2022-08-24 15:22:41 +02:00
the * in ZLE (with tab).</p>
<p><span id="index-SHORT_005fLOOPS"></span> <span
id="index-NO_005fSHORT_005fLOOPS"></span> <span
id="index-SHORTLOOPS"></span> <span id="index-NOSHORTLOOPS"></span></p>
<p>SHORT_LOOPS &lt;C&gt; &lt;Z&gt;</p>
<p>Allow the short forms of for, repeat, select, if, and function
2021-05-11 02:29:21 +02:00
constructs.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-SHORT_005fREPEAT"></span> <span
id="index-NO_005fSHORT_005fREPEAT"></span> <span
id="index-SHORTREPEAT"></span> <span id="index-NOSHORTREPEAT"></span></p>
<p>SHORT_REPEAT</p>
<p>Allow the short form repeat as SHORT_LOOPS but without enabling it for
the other constructs.</p>
<p><span id="index-SUN_005fKEYBOARD_005fHACK"></span> <span
id="index-NO_005fSUN_005fKEYBOARD_005fHACK"></span> <span
id="index-SUNKEYBOARDHACK"></span> <span
id="index-NOSUNKEYBOARDHACK"></span> <span
id="index-sun-keyboard_002c-annoying"></span> <span
id="index-annoying-keyboard_002c-sun"></span></p>
<p>SUN_KEYBOARD_HACK (-L)</p>
2021-05-11 02:29:21 +02:00
<p>If a line ends with a backquote, and there are an odd number of
backquotes on the line, ignore the trailing backquote. This is useful on
some keyboards where the return key is too small, and the backquote key
lies annoyingly close to it. As an alternative the variable
2022-08-24 15:22:41 +02:00
KEYBOARD_HACK lets you choose the character to be removed.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Job-Control"></span></p>
<h3 id="1627-job-control"><a class="header" href="#1627-job-control">16.2.7 Job Control</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-AUTO_005fCONTINUE"></span> <span
id="index-NO_005fAUTO_005fCONTINUE"></span> <span
id="index-AUTOCONTINUE"></span> <span id="index-NOAUTOCONTINUE"></span>
<span id="index-jobs_002c-continuing-automatically"></span> <span
id="index-continuing-jobs-automatically"></span></p>
<p>AUTO_CONTINUE</p>
<p>with the disown builtin command are automatically sent a CONT signal to
make them running.</p>
<p><span id="index-AUTO_005fRESUME"></span> <span
id="index-NO_005fAUTO_005fRESUME"></span> <span
id="index-AUTORESUME"></span> <span id="index-NOAUTORESUME"></span>
<span id="index-jobs_002c-resuming-automatically"></span> <span
id="index-resuming-jobs-automatically"></span></p>
<p>AUTO_RESUME (-W)</p>
2021-05-11 02:29:21 +02:00
<p>Treat single word simple commands without redirection as candidates for
resumption of an existing job.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-BG_005fNICE"></span> <span
id="index-NO_005fBG_005fNICE"></span> <span id="index-BGNICE"></span>
<span id="index-NOBGNICE"></span> <span
id="index-jobs_002c-background-priority"></span> <span
id="index-background-jobs_002c-priority-of"></span> <span
id="index-priority-of-background-jobs"></span></p>
<p>BG_NICE (-6) &lt;C&gt; &lt;Z&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Run all background jobs at a lower priority. This option is set by
default.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-CHECK_005fJOBS"></span> <span
id="index-NO_005fCHECK_005fJOBS"></span> <span
id="index-CHECKJOBS"></span> <span id="index-NOCHECKJOBS"></span> <span
id="index-exiting_002c-checking-jobs-when"></span> <span
id="index-logging-out_002c-checking-jobs-when"></span></p>
<p>CHECK_JOBS &lt;Z&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Report the status of background and suspended jobs before exiting a
shell with job control; a second attempt to exit the shell will succeed.
2022-08-24 15:22:41 +02:00
NO_CHECK_JOBS is best used only in combination with NO_HUP, else such
jobs will be killed automatically.</p>
2021-05-11 02:29:21 +02:00
<p>The check is omitted if the commands run from the previous command line
2022-08-24 15:22:41 +02:00
included a jobs command, since it is assumed the user is aware that
there are background or suspended jobs. A jobs command run from one of
the hook functions defined in the section Special Functions in
2021-05-11 02:29:21 +02:00
<a href="Functions.html#Functions">Functions</a> is not counted for this purpose.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-CHECK_005fRUNNING_005fJOBS"></span> <span
id="index-NO_005fCHECK_005fRUNNING_005fJOBS"></span> <span
id="index-CHECKRUNNINGJOBS"></span> <span
id="index-NOCHECKRUNNINGJOBS"></span> <span
id="index-exiting_002c-checking-running-jobs-when"></span> <span
id="index-logging-out_002c-checking-running-jobs-when"></span></p>
<p>CHECK_RUNNING_JOBS &lt;Z&gt;</p>
<p>Check for both running and suspended jobs when CHECK_JOBS is enabled.
2021-05-11 02:29:21 +02:00
When this option is disabled, zsh checks only for suspended jobs, which
matches the default behavior of bash.</p>
2022-08-24 15:22:41 +02:00
<p>This option has no effect unless CHECK_JOBS is set.</p>
<p><span id="index-HUP"></span> <span id="index-NO_005fHUP"></span> <span
id="index-NOHUP"></span> <span id="index-jobs_002c-HUP"></span></p>
<p>HUP &lt;Z&gt;</p>
<p>Send the HUP signal to running jobs when the shell exits.</p>
<p><span id="index-LONG_005fLIST_005fJOBS"></span> <span
id="index-NO_005fLONG_005fLIST_005fJOBS"></span> <span
id="index-LONGLISTJOBS"></span> <span id="index-NOLONGLISTJOBS"></span>
2021-05-11 02:29:21 +02:00
<span id="index-jobs_002c-list-format"></span></p>
2022-08-24 15:22:41 +02:00
<p>LONG_LIST_JOBS (-R)</p>
2021-05-11 02:29:21 +02:00
<p>Print job notifications in the long format by default.</p>
<p><span id="index-MONITOR"></span> <span id="index-NO_005fMONITOR"></span>
2022-08-24 15:22:41 +02:00
<span id="index-NOMONITOR"></span> <span
id="index-job-control_002c-allowing"></span></p>
<p>MONITOR (-m, ksh: -m)</p>
2021-05-11 02:29:21 +02:00
<p>Allow job control. Set by default in interactive shells.</p>
<p><span id="index-NOTIFY"></span> <span id="index-NO_005fNOTIFY"></span>
2022-08-24 15:22:41 +02:00
<span id="index-NONOTIFY"></span> <span
id="index-background-jobs_002c-notification"></span> <span
id="index-notification-of-background-jobs"></span></p>
<p>NOTIFY (-5, ksh: -b) &lt;Z&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Report the status of background jobs immediately, rather than waiting
until just before printing a prompt.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-POSIX_005fJOBS"></span> <span
id="index-POSIXJOBS"></span> <span
id="index-NO_005fPOSIX_005fJOBS"></span> <span
id="index-NOPOSIXJOBS"></span> <span
id="index-bg_002c-output-in-POSIX-format"></span> <span
id="index-fg_002c-output-in-POSIX-format"></span> <span
id="index-job-control_002c-in-subshell"></span> <span
id="index-jobs_002c-output-in-subshell"></span></p>
<p>POSIX_JOBS &lt;K&gt; &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>This option makes job control more compliant with the POSIX standard.</p>
2022-08-24 15:22:41 +02:00
<p>When the option is not set, the MONITOR option is unset on entry to
2021-05-11 02:29:21 +02:00
subshells, so that job control is no longer active. When the option is
2022-08-24 15:22:41 +02:00
set, the MONITOR option and job control remain active in the subshell,
2021-05-11 02:29:21 +02:00
but note that the subshell has no access to jobs in the parent shell.</p>
<p>When the option is not set, jobs put in the background or foreground
2022-08-24 15:22:41 +02:00
with bg or fg are displayed with the same information that would be
reported by jobs. When the option is set, only the text is printed. The
output from jobs itself is not affected by the option.</p>
2021-05-11 02:29:21 +02:00
<p>When the option is not set, job information from the parent shell is
saved for output within a subshell (for example, within a pipeline).
2022-08-24 15:22:41 +02:00
When the option is set, the output of jobs is empty until a job is
2021-05-11 02:29:21 +02:00
started within the subshell.</p>
2022-08-24 15:22:41 +02:00
<p>In previous versions of the shell, it was necessary to enable POSIX_JOBS
in order for the builtin command wait to return the status of background
jobs that had already exited. This is no longer the case.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Prompting"></span></p>
<h3 id="1628-prompting"><a class="header" href="#1628-prompting">16.2.8 Prompting</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-PROMPT_005fBANG"></span> <span
id="index-NO_005fPROMPT_005fBANG"></span> <span
id="index-PROMPTBANG"></span> <span id="index-NOPROMPTBANG"></span>
2021-05-11 02:29:21 +02:00
<span id="index-prompt_002c-_0021-expansion"></span></p>
2022-08-24 15:22:41 +02:00
<p>PROMPT_BANG &lt;K&gt;</p>
<p>If set, ! is treated specially in prompt expansion. See <a href="Prompt-Expansion.html#Prompt-Expansion">Prompt
2021-05-11 02:29:21 +02:00
Expansion</a>.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-PROMPT_005fCR"></span> <span
id="index-NO_005fPROMPT_005fCR"></span> <span
id="index-PROMPTCR"></span> <span id="index-NOPROMPTCR"></span> <span
id="index-prompt_002c-with-CR"></span></p>
<p>PROMPT_CR (+V) &lt;D&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Print a carriage return just before printing a prompt in the line
editor. This is on by default as multi-line editing is only possible if
the editor knows where the start of the line appears.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-PROMPT_005fSP"></span> <span
id="index-NO_005fPROMPT_005fSP"></span> <span
id="index-PROMPTSP"></span> <span id="index-NOPROMPTSP"></span> <span
id="index-prompt_002c-save-partial-lines"></span></p>
<p>PROMPT_SP &lt;D&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Attempt to preserve a partial line (i.e. a line that did not end with a
newline) that would otherwise be covered up by the command prompt due to
2022-08-24 15:22:41 +02:00
the PROMPT_CR option. This works by outputting some cursor-control
2021-05-11 02:29:21 +02:00
characters, including a series of spaces, that should make the terminal
wrap to the next line when a partial line is present (note that this is
only successful if your terminal has automatic margins, which is
typical).</p>
<p>When a partial line is preserved, by default you will see an
2022-08-24 15:22:41 +02:00
inverse+bold character at the end of the partial line: a % for a
normal user or a # for root. If set, the shell parameter
PROMPT_EOL_MARK can be used to customize how the end of partial lines
2021-05-11 02:29:21 +02:00
are shown.</p>
2022-08-24 15:22:41 +02:00
<p>NOTE: if the PROMPT_CR option is not set, enabling this option will have
no effect. This option is on by default.</p>
<p><span id="index-PROMPT_005fPERCENT"></span> <span
id="index-NO_005fPROMPT_005fPERCENT"></span> <span
id="index-PROMPTPERCENT"></span> <span
id="index-NOPROMPTPERCENT"></span> <span
id="index-prompt_002c-_0025-expansion"></span></p>
<p>PROMPT_PERCENT &lt;C&gt; &lt;Z&gt;</p>
<p>If set, % is treated specially in prompt expansion. See <a href="Prompt-Expansion.html#Prompt-Expansion">Prompt
2021-05-11 02:29:21 +02:00
Expansion</a>.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-PROMPT_005fSUBST"></span> <span
id="index-NO_005fPROMPT_005fSUBST"></span> <span
id="index-PROMPTSUBST"></span> <span id="index-NOPROMPTSUBST"></span>
2021-05-11 02:29:21 +02:00
<span id="index-prompt_002c-parameter-expansion"></span></p>
2022-08-24 15:22:41 +02:00
<p>PROMPT_SUBST &lt;K&gt; &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>If set, <em>parameter expansion</em>, <em>command substitution</em> and <em>arithmetic
expansion</em> are performed in prompts. Substitutions within prompts do not
affect the command status.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-TRANSIENT_005fRPROMPT"></span> <span
id="index-NO_005fTRANSIENT_005fRPROMPT"></span> <span
id="index-TRANSIENTRPROMPT"></span> <span
id="index-NOTRANSIENTRPROMPT"></span></p>
<p>TRANSIENT_RPROMPT</p>
2021-05-11 02:29:21 +02:00
<p>Remove any right prompt from display when accepting a command line. This
may be useful with terminals with other cut/paste methods.</p>
<hr />
<p><span id="Scripts-and-Functions"></span></p>
<h3 id="1629-scripts-and-functions"><a class="header" href="#1629-scripts-and-functions">16.2.9 Scripts and Functions</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-ALIAS_005fFUNC_005fDEF"></span> <span
id="index-NO_005fALIAS_005fFUNC_005fDEF"></span> <span
id="index-ALIASFUNCDEF"></span> <span id="index-NOALIASFUNCDEF"></span>
2021-05-11 02:29:21 +02:00
<span id="index-functions_002c-defining-with-expanded-aliases"></span>
<span id="index-aliases_002c-expanding-in-function-definition"></span></p>
2022-08-24 15:22:41 +02:00
<p>ALIAS_FUNC_DEF &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>By default, zsh does not allow the definition of functions using the
2022-08-24 15:22:41 +02:00
<code>name</code> () syntax if <code>name</code> was expanded as an alias: this causes an
error. This is usually the desired behaviour, as otherwise the
2021-05-11 02:29:21 +02:00
combination of an alias and a function based on the same definition can
easily cause problems.</p>
<p>When this option is set, aliases can be used for defining functions.</p>
<p>For example, consider the following definitions as they might occur in a
startup file.</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">alias foo=bar
2021-05-11 02:29:21 +02:00
foo() {
print This probably does not do what you expect.
}
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Here, foo is expanded as an alias to bar before the () is encountered,
so the function defined would be named bar. By default this is instead
an error in native mode. Note that quoting any part of the function
name, or using the keyword function, avoids the problem, so is
recommended when the function name can also be an alias.</p>
<p><span id="index-C_005fBASES"></span> <span
id="index-NO_005fC_005fBASES"></span> <span id="index-CBASES"></span>
<span id="index-NOCBASES"></span> <span
id="index-bases_002c-output-in-C-format"></span> <span
id="index-hexadecimal_002c-output-in-C-format"></span> <span
id="index-octal_002c-output-in-C-format"></span></p>
<p>C_BASES</p>
<p>Output hexadecimal numbers in the standard C format, for example 0xFF
instead of the usual 16#FF. If the option OCTAL_ZEROES is also set (it
is not by default), octal numbers will be treated similarly and hence
appear as 077 instead of 8#77. This option has no effect on the
choice of the output base, nor on the output of bases other than
hexadecimal and octal. Note that these formats will be understood on
input irrespective of the setting of C_BASES.</p>
<p><span id="index-C_005fPRECEDENCES"></span> <span
id="index-NO_005fC_005fPRECEDENCES"></span> <span
id="index-CPRECEDENCES"></span> <span id="index-NOCPRECEDENCES"></span>
<span id="index-precedence_002c-operator"></span> <span
id="index-operator-precedence"></span></p>
<p>C_PRECEDENCES</p>
2021-05-11 02:29:21 +02:00
<p>This alters the precedence of arithmetic operators to be more like C and
other programming languages; <a href="Arithmetic-Evaluation.html#Arithmetic-Evaluation">Arithmetic
Evaluation</a> has an
explicit list.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-DEBUG_005fBEFORE_005fCMD"></span> <span
id="index-NO_005fDEBUG_005fBEFORE_005fCMD"></span> <span
id="index-DEBUGBEFORECMD"></span> <span
id="index-NODEBUGBEFORECMD"></span> <span
id="index-traps_002c-DEBUG_002c-before-or-after-command"></span> <span
id="index-DEBUG-trap_002c-before-or-after-command"></span></p>
<p>DEBUG_BEFORE_CMD &lt;D&gt;</p>
<p>Run the DEBUG trap before each command; otherwise it is run after each
2021-05-11 02:29:21 +02:00
command. Setting this option mimics the behaviour of ksh 93; with the
option unset the behaviour is that of ksh 88.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-ERR_005fEXIT"></span> <span
id="index-NO_005fERR_005fEXIT"></span> <span id="index-ERREXIT"></span>
<span id="index-NOERREXIT"></span> <span
id="index-exit-status_002c-trapping"></span></p>
<p>ERR_EXIT (-e, ksh: -e)</p>
<p>If a command has a non-zero exit status, execute the ZERR trap, if set,
and exit. This is disabled while running initialization scripts.</p>
<p>The behaviour is also disabled inside DEBUG traps. In this case the
2021-05-11 02:29:21 +02:00
option is handled specially: it is unset on entry to the trap. If the
2022-08-24 15:22:41 +02:00
option DEBUG_BEFORE_CMD is set, as it is by default, and the option
ERR_EXIT is found to have been set on exit, then the command for which
the DEBUG trap is being executed is skipped. The option is restored
2021-05-11 02:29:21 +02:00
after the trap exits.</p>
2022-08-24 15:22:41 +02:00
<p>Non-zero status in a command list containing &amp;&amp; or || is ignored for
2021-05-11 02:29:21 +02:00
commands not at the end of the list. Hence</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">false &amp;&amp; true
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>does not trigger exit.</p>
2022-08-24 15:22:41 +02:00
<p>Exiting due to ERR_EXIT has certain interactions with asynchronous jobs
noted in <a href="Jobs-_0026-Signals.html#Jobs-_0026-Signals">Jobs &amp; Signals</a>.</p>
<p><span id="index-ERR_005fRETURN"></span> <span
id="index-NO_005fERR_005fRETURN"></span> <span
id="index-ERRRETURN"></span> <span id="index-NOERRRETURN"></span> <span
id="index-function-return_002c-on-error"></span> <span
id="index-return-from-function_002c-on-error"></span></p>
<p>ERR_RETURN</p>
2021-05-11 02:29:21 +02:00
<p>If a command has a non-zero exit status, return immediately from the
2022-08-24 15:22:41 +02:00
enclosing function. The logic is similar to that for ERR_EXIT, except
that an implicit return statement is executed instead of an exit. This
will trigger an exit at the outermost level of a non-interactive script.</p>
<p>Normally this option inherits the behaviour of ERR_EXIT that code
followed by &amp;&amp; || does not trigger a return. Hence in the
2021-05-11 02:29:21 +02:00
following:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">summit || true
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>no return is forced as the combined effect always has a zero return
status.</p>
2022-08-24 15:22:41 +02:00
<p>Note. however, that if summit in the above example is itself a function,
code inside it is considered separately: it may force a return from
summit (assuming the option remains set within summit), but not from the
enclosing context. This behaviour is different from ERR_EXIT which is
unaffected by function scope.</p>
<p><span id="index-EVAL_005fLINENO"></span> <span
id="index-NO_005fEVAL_005fLINENO"></span> <span
id="index-EVALLINENO"></span> <span id="index-NOEVALLINENO"></span>
2021-05-11 02:29:21 +02:00
<span id="index-line-number_002c-in-evaluated-expression"></span></p>
2022-08-24 15:22:41 +02:00
<p>EVAL_LINENO &lt;Z&gt;</p>
<p>If set, line numbers of expressions evaluated using the builtin eval are
tracked separately of the enclosing environment. This applies both to
the parameter LINENO and the line number output by the prompt escape %i.
If the option is set, the prompt escape %N will output the string
(eval) instead of the script or function name as an indication. (The
two prompt escapes are typically used in the parameter PS4 to be output
when the option XTRACE is set.) If EVAL_LINENO is unset, the line number
of the surrounding script or function is retained during the evaluation.</p>
<p><span id="index-EXEC"></span> <span id="index-NO_005fEXEC"></span> <span
id="index-NOEXEC"></span> <span
id="index-command-execution_002c-enabling"></span></p>
<p>EXEC (+n, ksh: +n) &lt;D&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Do execute commands. Without this option, commands are read and checked
for syntax errors, but not executed. This option cannot be turned off in
2022-08-24 15:22:41 +02:00
an interactive shell, except when -n is supplied to the shell at
2021-05-11 02:29:21 +02:00
startup.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-FUNCTION_005fARGZERO"></span> <span
id="index-NO_005fFUNCTION_005fARGZERO"></span> <span
id="index-FUNCTIONARGZERO"></span> <span
id="index-NOFUNCTIONARGZERO"></span> <span
id="index-_00240_002c-setting"></span></p>
<p>FUNCTION_ARGZERO &lt;C&gt; &lt;Z&gt;</p>
<p>When executing a shell function or sourcing a script, set $0 temporarily
to the name of the function/script. Note that toggling FUNCTION_ARGZERO
from on to off (or off to on) does not change the current value of $0.
Only the state upon entry to the function or script has an effect.
Compare POSIX_ARGZERO.</p>
<p><span id="index-LOCAL_005fLOOPS"></span> <span
id="index-NO_005fLOCAL_005fLOOPS"></span> <span
id="index-LOCALLOOPS"></span> <span id="index-NOLOCALLOOPS"></span>
<span id="index-break_002c-inside-function"></span> <span
id="index-continue_002c-inside-function"></span> <span
id="index-function_002c-scope-of-break-and-continue"></span></p>
<p>LOCAL_LOOPS</p>
<p>When this option is not set, the effect of break and continue commands
may propagate outside function scope, affecting loops in calling
functions. When the option is set in a calling function, a break or a
continue that is not caught within a called function (regardless of the
setting of the option within that function) produces a warning and the
effect is cancelled.</p>
<p><span id="index-LOCAL_005fOPTIONS"></span> <span
id="index-NO_005fLOCAL_005fOPTIONS"></span> <span
id="index-LOCALOPTIONS"></span> <span id="index-NOLOCALOPTIONS"></span></p>
<p>LOCAL_OPTIONS &lt;K&gt;</p>
2021-05-11 02:29:21 +02:00
<p>If this option is set at the point of return from a shell function, most
options (including this one) which were in force upon entry to the
2022-08-24 15:22:41 +02:00
function are restored; options that are not restored are PRIVILEGED and
RESTRICTED. Otherwise, only this option, and the LOCAL_LOOPS, XTRACE and
PRINT_EXIT_VALUE options are restored. Hence if this is explicitly unset
by a shell function the other options in force at the point of return
will remain so. A shell function can also guarantee itself a known shell
configuration with a formulation like emulate -L zsh; the -L activates
LOCAL_OPTIONS.</p>
<p><span id="index-LOCAL_005fPATTERNS"></span> <span
id="index-NO_005fLOCAL_005fPATTERNS"></span> <span
id="index-LOCALPATTERNS"></span> <span
id="index-NOLOCALPATTERNS"></span></p>
<p>LOCAL_PATTERNS</p>
2021-05-11 02:29:21 +02:00
<p>If this option is set at the point of return from a shell function, the
2022-08-24 15:22:41 +02:00
state of pattern disables, as set with the builtin command disable -p,
is restored to what it was when the function was entered. The behaviour
of this option is similar to the effect of LOCAL_OPTIONS on options;
hence emulate -L sh (or indeed any other emulation with the -L option)
activates LOCAL_PATTERNS.</p>
<p><span id="index-LOCAL_005fTRAPS"></span> <span
id="index-NO_005fLOCAL_005fTRAPS"></span> <span
id="index-LOCALTRAPS"></span> <span id="index-NOLOCALTRAPS"></span></p>
<p>LOCAL_TRAPS &lt;K&gt;</p>
2021-05-11 02:29:21 +02:00
<p>If this option is set when a signal trap is set inside a function, then
the previous status of the trap for that signal will be restored when
the function exits. Note that this option must be set <em>prior</em> to
2022-08-24 15:22:41 +02:00
altering the trap behaviour in a function; unlike LOCAL_OPTIONS, the
2021-05-11 02:29:21 +02:00
value on exit from the function is irrelevant. However, it does not need
to be set before any global trap for that to be correctly restored by a
function. For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">unsetopt localtraps
2021-05-11 02:29:21 +02:00
trap - INT
fn() { setopt localtraps; trap '' INT; sleep 3; }
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>will restore normal handling of SIGINT after the function exits.</p>
<p><span id="index-MULTI_005fFUNC_005fDEF"></span> <span
id="index-NO_005fMULTI_005fFUNC_005fDEF"></span> <span
id="index-MULTIFUNCDEF"></span> <span id="index-NOMULTIFUNCDEF"></span></p>
<p>MULTI_FUNC_DEF &lt;Z&gt;</p>
<p>Allow definitions of multiple functions at once in the form fn1
fn2<code>...</code>(); if the option is not set, this causes a parse error.
Definition of multiple functions with the function keyword is always
2021-05-11 02:29:21 +02:00
allowed. Multiple function definitions are not often used and can cause
obscure errors.</p>
<p><span id="index-MULTIOS"></span> <span id="index-NO_005fMULTIOS"></span>
<span id="index-NOMULTIOS"></span></p>
2022-08-24 15:22:41 +02:00
<p>MULTIOS &lt;Z&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Perform implicit tees or cats when multiple redirections are attempted
(see <a href="Redirection.html#Redirection">Redirection</a>).</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-OCTAL_005fZEROES"></span> <span
id="index-NO_005fOCTAL_005fZEROES"></span> <span
id="index-OCTALZEROES"></span> <span id="index-NOOCTALZEROES"></span>
2021-05-11 02:29:21 +02:00
<span id="index-octal_002c-arithmetic-expressions"></span></p>
2022-08-24 15:22:41 +02:00
<p>OCTAL_ZEROES &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Interpret any integer constant beginning with a 0 as octal, per IEEE Std
1003.2-1992 (ISO 9945-2:1993). This is not enabled by default as it
causes problems with parsing of, for example, date and time strings with
leading zeroes.</p>
2022-08-24 15:22:41 +02:00
<p>Sequences of digits indicating a numeric base such as the 08 component
in 08#77 are always interpreted as decimal, regardless of leading
zeroes.</p>
<p><span id="index-PIPE_005fFAIL"></span> <span
id="index-NO_005fPIPE_005fFAIL"></span> <span
id="index-PIPEFAIL"></span> <span id="index-NOPIPEFAIL"></span> <span
id="index-exit-status-from-pipeline"></span> <span
id="index-status_002c-on-exit-from-pipeline"></span> <span
id="index-pipeline_002c-exit-status-from"></span></p>
<p>PIPE_FAIL</p>
2021-05-11 02:29:21 +02:00
<p>By default, when a pipeline exits the exit status recorded by the shell
2022-08-24 15:22:41 +02:00
and returned by the shell variable $? reflects that of the rightmost
2021-05-11 02:29:21 +02:00
element of a pipeline. If this option is set, the exit status instead
reflects the status of the rightmost element of the pipeline that was
non-zero, or zero if all elements exited with zero status.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-SOURCE_005fTRACE"></span> <span
id="index-NO_005fSOURCE_005fTRACE"></span> <span
id="index-SOURCETRACE"></span> <span id="index-NOSOURCETRACE"></span></p>
<p>SOURCE_TRACE</p>
2021-05-11 02:29:21 +02:00
<p>If set, zsh will print an informational message announcing the name of
each file it loads. The format of the output is similar to that for the
2022-08-24 15:22:41 +02:00
XTRACE option, with the message &lt;sourcetrace&gt;. A file may be loaded by
the shell itself when it starts up and shuts down (Startup/Shutdown
Files) or by the use of the source and dot builtin commands.</p>
<p><span id="index-TYPESET_005fSILENT"></span> <span
id="index-NO_005fTYPESET_005fSILENT"></span> <span
id="index-TYPESETSILENT"></span> <span
id="index-NOTYPESETSILENT"></span></p>
<p>TYPESET_SILENT</p>
<p>If this is unset, executing any of the typeset family of commands with
no options and a list of parameters that have no values to be assigned
but already exist will display the value of the parameter. If the option
is set, they will only be shown when parameters are selected with the
-m option. The option -p is available whether or not the option is
set.</p>
<p><span id="index-TYPESET_005fTO_005fUNSET"></span> <span
id="index-NO_005fTYPESET_005fTO_005fUNSET"></span> <span
id="index-TYPESETTOUNSET"></span> <span
id="index-NOTYPESETTOUNSET"></span></p>
<p>TYPESET_TO_UNSET &lt;K&gt; &lt;S&gt;</p>
<p>When declaring a new parameter with any of the typeset family of
related commands, the parameter remains unset unless and until a value
is explicity assigned to it, either in the typeset command itself or
as a later assignment statement.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-VERBOSE"></span> <span id="index-NO_005fVERBOSE"></span>
2022-08-24 15:22:41 +02:00
<span id="index-NOVERBOSE"></span> <span
id="index-tracing_002c-of-input-lines"></span> <span
id="index-input_002c-tracing"></span></p>
<p>VERBOSE (-v, ksh: -v)</p>
2021-05-11 02:29:21 +02:00
<p>Print shell input lines as they are read.</p>
<p><span id="index-XTRACE"></span> <span id="index-NO_005fXTRACE"></span>
2022-08-24 15:22:41 +02:00
<span id="index-NOXTRACE"></span> <span
id="index-tracing_002c-of-commands"></span> <span
id="index-commands_002c-tracing"></span></p>
<p>XTRACE (-x, ksh: -x)</p>
2021-05-11 02:29:21 +02:00
<p>Print commands and their arguments as they are executed. The output is
2022-08-24 15:22:41 +02:00
preceded by the value of $PS4, formatted as described in <a href="Prompt-Expansion.html#Prompt-Expansion">Prompt
2021-05-11 02:29:21 +02:00
Expansion</a>.</p>
<hr />
<p><span id="Shell-Emulation"></span></p>
<h3 id="16210-shell-emulation"><a class="header" href="#16210-shell-emulation">16.2.10 Shell Emulation</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-APPEND_005fCREATE"></span> <span
id="index-NO_005fAPPEND_005fCREATE"></span> <span
id="index-APPENDCREATE"></span> <span id="index-NOAPPENDCREATE"></span>
<span id="index-clobbering_002c-POSIX-compatibility"></span> <span
id="index-file-clobbering_002c-POSIX-compatibility"></span> <span
id="index-no-clobber_002c-POSIX-compatible"></span></p>
<p>APPEND_CREATE &lt;K&gt; &lt;S&gt;</p>
<p>This option only applies when NO_CLOBBER (-C) is in effect.</p>
2021-05-11 02:29:21 +02:00
<p>If this option is not set, the shell will report an error when a append
2022-08-24 15:22:41 +02:00
redirection (&gt;&gt;) is used on a file that does not already exists (the
traditional zsh behaviour of NO_CLOBBER). If the option is set, no error
is reported (POSIX behaviour).</p>
<p><span id="index-BASH_005fREMATCH"></span> <span
id="index-NO_005fBASH_005fREMATCH"></span> <span
id="index-BASHREMATCH"></span> <span id="index-NOBASHREMATCH"></span>
<span id="index-bash_002c-BASH_005fREMATCH-variable"></span> <span
id="index-regexp_002c-bash-BASH_005fREMATCH-variable"></span></p>
<p>BASH_REMATCH</p>
<p>When set, matches performed with the =~ operator will set the
BASH_REMATCH array variable, instead of the default MATCH and match
variables. The first element of the BASH_REMATCH array will contain the
entire matched text and subsequent elements will contain extracted
substrings. This option makes more sense when KSH_ARRAYS is also set, so
that the entire matched portion is stored at index 0 and the first
substring is at index 1. Without this option, the MATCH variable
contains the entire matched text and the match array variable contains
substrings.</p>
<p><span id="index-BSD_005fECHO"></span> <span
id="index-NO_005fBSD_005fECHO"></span> <span id="index-BSDECHO"></span>
<span id="index-NOBSDECHO"></span> <span
id="index-echo_002c-BSD-compatible"></span></p>
<p>BSD_ECHO &lt;S&gt;</p>
<p>Make the echo builtin compatible with the BSD echo(1) command. This
disables backslashed escape sequences in echo strings unless the -e
option is specified.</p>
<p><span id="index-CONTINUE_005fON_005fERROR"></span> <span
id="index-NO_005fCONTINUE_005fON_005fERROR"></span> <span
id="index-CONTINUEONERROR"></span> <span
id="index-NOCONTINUEONERROR"></span> <span
id="index-error_002c-option-to-continue-script-on"></span></p>
<p>CONTINUE_ON_ERROR</p>
2021-05-11 02:29:21 +02:00
<p>If a fatal error is encountered (see
<a href="Shell-Grammar.html#Errors">Errors</a>), and the code is running in a
script, the shell will resume execution at the next statement in the
script at the top level, in other words outside all functions or shell
constructs such as loops and conditions. This mimics the behaviour of
interactive shells, where the shell returns to the line editor to read a
new command; it was the normal behaviour in versions of zsh before
5.0.1.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-CSH_005fJUNKIE_005fHISTORY"></span> <span
id="index-NO_005fCSH_005fJUNKIE_005fHISTORY"></span> <span
id="index-CSHJUNKIEHISTORY"></span> <span
id="index-NOCSHJUNKIEHISTORY"></span> <span
id="index-csh_002c-history-style"></span> <span
id="index-history-style_002c-csh"></span></p>
<p>CSH_JUNKIE_HISTORY &lt;C&gt;</p>
2021-05-11 02:29:21 +02:00
<p>A history reference without an event specifier will always refer to the
previous command. Without this option, such a history reference refers
to the same event as the previous history reference on the current
command line, defaulting to the previous command.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-CSH_005fJUNKIE_005fLOOPS"></span> <span
id="index-NO_005fCSH_005fJUNKIE_005fLOOPS"></span> <span
id="index-CSHJUNKIELOOPS"></span> <span
id="index-NOCSHJUNKIELOOPS"></span> <span
id="index-csh_002c-loop-style"></span> <span
id="index-loop-style_002c-csh"></span></p>
<p>CSH_JUNKIE_LOOPS &lt;C&gt;</p>
<p>Allow loop bodies to take the form <code>list</code>; end instead of do <code>list</code>;
done.</p>
<p><span id="index-CSH_005fJUNKIE_005fQUOTES"></span> <span
id="index-NO_005fCSH_005fJUNKIE_005fQUOTES"></span> <span
id="index-CSHJUNKIEQUOTES"></span> <span
id="index-NOCSHJUNKIEQUOTES"></span> <span
id="index-csh_002c-quoting-style"></span> <span
id="index-quoting-style_002c-csh"></span></p>
<p>CSH_JUNKIE_QUOTES &lt;C&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Changes the rules for single- and double-quoted text to match that of
csh. These require that embedded newlines be preceded by a backslash;
unescaped newlines will cause an error message. In double-quoted
2022-08-24 15:22:41 +02:00
strings, it is made impossible to escape $, or &quot; (and \
itself no longer needs escaping). Command substitutions are only
expanded once, and cannot be nested.</p>
<p><span id="index-CSH_005fNULLCMD"></span> <span
id="index-NO_005fCSH_005fNULLCMD"></span> <span
id="index-CSHNULLCMD"></span> <span id="index-NOCSHNULLCMD"></span>
<span id="index-NULLCMD_002c-ignoring"></span> <span
id="index-READNULLCMD_002c-ignoring"></span> <span
id="index-redirections-with-no-command_002c-csh"></span> <span
id="index-csh_002c-redirections-with-no-command"></span></p>
<p>CSH_NULLCMD &lt;C&gt;</p>
<p>Do not use the values of NULLCMD and READNULLCMD when running
2021-05-11 02:29:21 +02:00
redirections with no command. This make such redirections fail (see
<a href="Redirection.html#Redirection">Redirection</a>).</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-KSH_005fARRAYS"></span> <span
id="index-NO_005fKSH_005fARRAYS"></span> <span
id="index-KSHARRAYS"></span> <span id="index-NOKSHARRAYS"></span> <span
id="index-arrays_002c-ksh-style"></span> <span
id="index-array-style_002c-ksh"></span> <span
id="index-ksh_002c-array-style"></span></p>
<p>KSH_ARRAYS &lt;K&gt; &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Emulate ksh array handling as closely as possible. If this option is
set, array elements are numbered from zero, an array parameter without
subscript refers to the first element instead of the whole array, and
2022-08-24 15:22:41 +02:00
braces are required to delimit a subscript (${path[2]} rather than
just $path[2]) or to apply modifiers to any parameter (${PWD:h}
rather than $PWD:h).</p>
<p><span id="index-KSH_005fAUTOLOAD"></span> <span
id="index-NO_005fKSH_005fAUTOLOAD"></span> <span
id="index-KSHAUTOLOAD"></span> <span id="index-NOKSHAUTOLOAD"></span></p>
<p>KSH_AUTOLOAD &lt;K&gt; &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Emulate ksh function autoloading. This means that when a function is
autoloaded, the corresponding file is merely executed, and must define
the function itself. (By default, the function is defined to the
contents of the file. However, the most common ksh-style case - of the
file containing only a simple definition of the function - is always
handled in the ksh-compatible manner.)</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-KSH_005fOPTION_005fPRINT"></span> <span
id="index-NO_005fKSH_005fOPTION_005fPRINT"></span> <span
id="index-KSHOPTIONPRINT"></span> <span
id="index-NOKSHOPTIONPRINT"></span> <span
id="index-option-printing_002c-ksh-style"></span> <span
id="index-option-printing-style_002c-ksh"></span> <span
id="index-ksh_002c-option-printing-style"></span></p>
<p>KSH_OPTION_PRINT &lt;K&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Alters the way options settings are printed: instead of separate lists
of set and unset options, all options are shown, marked on if they are
in the non-default state, off otherwise.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-KSH_005fTYPESET"></span> <span
id="index-NO_005fKSH_005fTYPESET"></span> <span
id="index-KSHTYPESET"></span> <span id="index-NOKSHTYPESET"></span>
2021-05-11 02:29:21 +02:00
<span id="index-argument-splitting_002c-in-typeset-etc_002e"></span>
<span id="index-ksh_002c-argument-splitting-in-typeset"></span></p>
2022-08-24 15:22:41 +02:00
<p>KSH_TYPESET</p>
2021-05-11 02:29:21 +02:00
<p>This option is now obsolete: a better appropximation to the behaviour of
2022-08-24 15:22:41 +02:00
other shells is obtained with the reserved word interface to declare,
export, float, integer, local, readonly and typeset. Note that the
option is only applied when the reserved word interface is <em>not</em> in use.</p>
<p>Alters the way arguments to the typeset family of commands, including
declare, export, float, integer, local and readonly, are processed.
Without this option, zsh will perform normal word splitting after
command and parameter expansion in arguments of an assignment; with it,
word splitting does not take place in those cases.</p>
<p><span id="index-KSH_005fZERO_005fSUBSCRIPT"></span> <span
id="index-NO_005fKSH_005fZERO_005fSUBSCRIPT"></span> <span
id="index-KSHZEROSUBSCRIPT"></span> <span
id="index-NOKSHZEROSUBSCRIPT"></span> <span
id="index-arrays_002c-behaviour-of-index-zero"></span></p>
<p>KSH_ZERO_SUBSCRIPT</p>
2021-05-11 02:29:21 +02:00
<p>Treat use of a subscript of value zero in array or string expressions as
a reference to the first element, i.e. the element that usually has the
2022-08-24 15:22:41 +02:00
subscript 1. Ignored if KSH_ARRAYS is also set.</p>
<p>If neither this option nor KSH_ARRAYS is set, accesses to an element of
an array or string with subscript zero return an empty element or
2021-05-11 02:29:21 +02:00
string, while attempts to set element zero of an array or string are
treated as an error. However, attempts to set an otherwise valid
subscript range that includes zero will succeed. For example, if
2022-08-24 15:22:41 +02:00
KSH_ZERO_SUBSCRIPT is not set,</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">array[0]=(element)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>is an error, while</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">array[0,1]=(element)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>is not and will replace the first element of the array.</p>
<p>This option is for compatibility with older versions of the shell and is
not recommended in new code.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-POSIX_005fALIASES"></span> <span
id="index-NO_005fPOSIX_005fALIASES"></span> <span
id="index-POSIXALIASES"></span> <span id="index-NOPOSIXALIASES"></span></p>
<p>POSIX_ALIASES &lt;K&gt; &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>When this option is set, reserved words are not candidates for alias
expansion: it is still possible to declare any of them as an alias, but
the alias will never be expanded. Reserved words are described in
<a href="Shell-Grammar.html#Reserved-Words">Reserved Words</a>.</p>
<p>Alias expansion takes place while text is being read; hence when this
option is set it does not take effect until the end of any function or
other piece of shell code parsed as one unit. Note this may cause
differences from other shells even when the option is in effect. For
2022-08-24 15:22:41 +02:00
example, when running a command with zsh -c, or even zsh -o
posixaliases -c, the entire command argument is parsed as one unit, so
2021-05-11 02:29:21 +02:00
aliases defined within the argument are not available even in later
lines. If in doubt, avoid use of aliases in non-interactive code.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-POSIX_005fARGZERO"></span> <span
id="index-NO_005fPOSIX_005fARGZERO"></span> <span
id="index-POSIXARGZERO"></span> <span id="index-NOPOSIXARGZERO"></span>
2021-05-11 02:29:21 +02:00
<span id="index-_00240_002c-using"></span></p>
2022-08-24 15:22:41 +02:00
<p>POSIX_ARGZERO</p>
<p>This option may be used to temporarily disable FUNCTION_ARGZERO and
thereby restore the value of $0 to the name used to invoke the shell (or
as set by the -c command line option). For compatibility with previous
versions of the shell, emulations use NO_FUNCTION_ARGZERO instead of
POSIX_ARGZERO, which may result in unexpected scoping of $0 if the
emulation mode is changed inside a function or script. To avoid this,
explicitly enable POSIX_ARGZERO in the emulate command:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">emulate sh -o POSIX_ARGZERO
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Note that NO_POSIX_ARGZERO has no effect unless FUNCTION_ARGZERO was
2021-05-11 02:29:21 +02:00
already enabled upon entry to the function or script.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-POSIX_005fBUILTINS"></span> <span
id="index-NO_005fPOSIX_005fBUILTINS"></span> <span
id="index-POSIXBUILTINS"></span> <span
id="index-NOPOSIXBUILTINS"></span></p>
<p>POSIX_BUILTINS &lt;K&gt; &lt;S&gt;</p>
<p>When this option is set the command builtin can be used to execute shell
builtin commands. Parameter assignments specified before shell functions
and special builtins are kept after the command completes unless the
special builtin is prefixed with the command builtin. Special builtins
are ., :, break, continue, declare, eval, exit, export, integer, local,
readonly, return, set, shift, source, times, trap and unset.</p>
2021-05-11 02:29:21 +02:00
<p>In addition, various error conditions associated with the above builtins
2022-08-24 15:22:41 +02:00
or exec cause a non-interactive shell to exit and an interactive shell
2021-05-11 02:29:21 +02:00
to return to its top-level processing.</p>
2022-08-24 15:22:41 +02:00
<p>Furthermore, functions and shell builtins are not executed after an exec
prefix; the command to be executed must be an external command found in
the path.</p>
<p>Furthermore, the getopts builtin behaves in a POSIX-compatible fashion
in that the associated variable OPTIND is not made local to functions,
and its value is calculated differently to match other shells.</p>
<p>Moreover, the warning and special exit code from [[ -o
<code>non_existent_option</code> ]] are suppressed.</p>
<p><span id="index-POSIX_005fIDENTIFIERS"></span> <span
id="index-NO_005fPOSIX_005fIDENTIFIERS"></span> <span
id="index-POSIXIDENTIFIERS"></span> <span
id="index-NOPOSIXIDENTIFIERS"></span></p>
<p>POSIX_IDENTIFIERS &lt;K&gt; &lt;S&gt;</p>
<p>When this option is set, only the ASCII characters a to z, A to Z, 0 to
9 and _ may be used in identifiers (names of shell parameters and
modules).</p>
2021-05-11 02:29:21 +02:00
<p>In addition, setting this option limits the effect of parameter
2022-08-24 15:22:41 +02:00
substitution with no braces, so that the expression $# is treated as the
parameter $# even if followed by a valid parameter name. When it is
unset, zsh allows expressions of the form $#<code>name</code> to refer to the
length of $<code>name</code>, even for special variables, for example in
expressions such as $#- and $#*.</p>
2021-05-11 02:29:21 +02:00
<p>Another difference is that with the option set assignment to an unset
variable in arithmetic context causes the variable to be created as a
2022-08-24 15:22:41 +02:00
scalar rather than a numeric type. So after unset t; (( t = 3 )).
without POSIX_IDENTIFIERS set t has integer type, while with it set it
has scalar type.</p>
2021-05-11 02:29:21 +02:00
<p>When the option is unset and multibyte character support is enabled
2022-08-24 15:22:41 +02:00
(i.e. it is compiled in and the option MULTIBYTE is set), then
2021-05-11 02:29:21 +02:00
additionally any alphanumeric characters in the local character set may
be used in identifiers. Note that scripts and functions written with
this feature are or function is parsed; setting them during execution is
2022-08-24 15:22:41 +02:00
not sufficient as the syntax <code>variable</code>=<code>value</code> has already been parsed
as a command rather than an assignment.</p>
2021-05-11 02:29:21 +02:00
<p>If multibyte character support is not compiled into the shell this
option is ignored; all octets with the top bit set may be used in
identifiers. This is non-standard but is the traditional zsh behaviour.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-POSIX_005fSTRINGS"></span> <span
id="index-NO_005fPOSIX_005fSTRINGS"></span> <span
id="index-POSIXSTRINGS"></span> <span id="index-NOPOSIXSTRINGS"></span>
<span
id="index-discarding-embedded-nulls-in-_0024_0027_002e_002e_002e_0027"></span>
<span
id="index-embedded-nulls_002c-in-_0024_0027_002e_002e_002e_0027"></span>
<span
id="index-nulls_002c-embedded-in-_0024_0027_002e_002e_002e_0027"></span></p>
<p>POSIX_STRINGS &lt;K&gt; &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>This option affects processing of quoted strings. Currently it only
affects the behaviour of null characters, i.e. character 0 in the</p>
<p>When this option is not set, null characters embedded within strings of
2022-08-24 15:22:41 +02:00
the form $<code>...</code> are treated as ordinary characters. The entire string
is maintained within the shell and output to files where necessary,
although owing to restrictions of the library interface the string is
truncated at the null character in file names, environment variables, or
in arguments to external programs.</p>
<p>When this option is set, the $<code>...</code> expression is truncated at the
2021-05-11 02:29:21 +02:00
null character. Note that remaining parts of the same string beyond the
termination of the quotes are not truncated.</p>
2022-08-24 15:22:41 +02:00
<p>For example, the command line argument a$b\0cd is treated with the
option off as the characters a, b, null, c, d, and with the option on as
the characters a, b, d.</p>
<p><span id="index-POSIX_005fTRAPS"></span> <span
id="index-NO_005fPOSIX_005fTRAPS"></span> <span
id="index-POSIXTRAPS"></span> <span id="index-NOPOSIXTRAPS"></span>
<span id="index-traps_002c-on-function-exit"></span> <span
id="index-traps_002c-POSIX-compatibility"></span></p>
<p>POSIX_TRAPS &lt;K&gt; &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>When this option is set, the usual zsh behaviour of executing traps for
2022-08-24 15:22:41 +02:00
EXIT on exit from shell functions is suppressed. In that case,
manipulating EXIT traps always alters the global trap for exiting the
shell; the LOCAL_TRAPS option is ignored for the EXIT trap.</p>
<p>Also, a return statement executed in a trap with no argument passes back
from the function the value from the surrounding context, not from code
executed within the trap.</p>
<p>Furthermore, if a trap is set to be ignored, this state persists when a
subshell is entered. Without the option, the trap would be reset to its
default state at this point.</p>
<p><span id="index-SH_005fFILE_005fEXPANSION"></span> <span
id="index-NO_005fSH_005fFILE_005fEXPANSION"></span> <span
id="index-SHFILEEXPANSION"></span> <span
id="index-NOSHFILEEXPANSION"></span> <span
id="index-sh_002c-expansion-style"></span> <span
id="index-expansion-style_002c-sh"></span></p>
<p>SH_FILE_EXPANSION &lt;K&gt; &lt;S&gt;</p>
<p>Perform filename expansion (e.g., ~ expansion) <em>before</em> parameter
2021-05-11 02:29:21 +02:00
expansion, command substitution, arithmetic expansion and brace
expansion. If this option is unset, it is performed <em>after</em> brace
2022-08-24 15:22:41 +02:00
expansion, so things like ~$USERNAME and ~{pfalstad,rc} will work.</p>
<p><span id="index-SH_005fNULLCMD"></span> <span
id="index-NO_005fSH_005fNULLCMD"></span> <span
id="index-SHNULLCMD"></span> <span id="index-NOSHNULLCMD"></span> <span
id="index-NULLCMD_002c-ignoring-1"></span> <span
id="index-READNULLCMD_002c-ignoring-1"></span> <span
id="index-sh_002c-redirections-with-no-command"></span> <span
id="index-ksh_002c-redirections-with-no-command"></span> <span
id="index-redirections-with-no-command_002c-sh"></span> <span
id="index-redirections-with-no-command_002c-ksh"></span></p>
<p>SH_NULLCMD &lt;K&gt; &lt;S&gt;</p>
<p>Do not use the values of NULLCMD and READNULLCMD when doing
redirections, use : instead (see
2021-05-11 02:29:21 +02:00
<a href="Redirection.html#Redirection">Redirection</a>).</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-SH_005fOPTION_005fLETTERS"></span> <span
id="index-NO_005fSH_005fOPTION_005fLETTERS"></span> <span
id="index-SHOPTIONLETTERS"></span> <span
id="index-NOSHOPTIONLETTERS"></span> <span
id="index-sh_002c-single-letter-options-style"></span> <span
id="index-ksh_002c-single-letter-options-style"></span> <span
id="index-single-letter-options_002c-ksh-style"></span> <span
id="index-options_002c-single-letter_002c-ksh-style"></span></p>
<p>SH_OPTION_LETTERS &lt;K&gt; &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>If this option is set the shell tries to interpret single letter options
2022-08-24 15:22:41 +02:00
(which are used with set and setopt) like ksh does. This also affects
the value of the - special parameter.</p>
<p><span id="index-SH_005fWORD_005fSPLIT"></span> <span
id="index-NO_005fSH_005fWORD_005fSPLIT"></span> <span
id="index-SHWORDSPLIT"></span> <span id="index-NOSHWORDSPLIT"></span>
<span id="index-field-splitting_002c-sh-style"></span> <span
id="index-sh_002c-field-splitting-style"></span></p>
<p>SH_WORD_SPLIT (-y) &lt;K&gt; &lt;S&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Causes field splitting to be performed on unquoted parameter expansions.
Note that this option has nothing to do with word splitting. (See
<a href="Expansion.html#Parameter-Expansion">Parameter Expansion</a>.)</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-TRAPS_005fASYNC"></span> <span
id="index-NO_005fTRAPS_005fASYNC"></span> <span
id="index-TRAPSASYNC"></span> <span id="index-NOTRAPSASYNC"></span>
2021-05-11 02:29:21 +02:00
<span id="index-traps_002c-asynchronous"></span></p>
2022-08-24 15:22:41 +02:00
<p>TRAPS_ASYNC</p>
2021-05-11 02:29:21 +02:00
<p>While waiting for a program to exit, handle signals and run traps
immediately. Otherwise the trap is run after a child process has exited.
Note this does not affect the point at which traps are run for any case
other than when the shell is waiting for a child process.</p>
<hr />
<p><span id="Shell-State"></span></p>
<h3 id="16211-shell-state"><a class="header" href="#16211-shell-state">16.2.11 Shell State</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-INTERACTIVE"></span> <span
id="index-NO_005fINTERACTIVE"></span> <span
id="index-NOINTERACTIVE"></span></p>
<p>INTERACTIVE (-i, ksh: -i)</p>
2021-05-11 02:29:21 +02:00
<p>This is an interactive shell. This option is set upon initialisation if
the standard input is a tty and commands are being read from standard
2022-08-24 15:22:41 +02:00
input. (See the discussion of SHIN_STDIN.) This heuristic may be
2021-05-11 02:29:21 +02:00
overridden by specifying a state for this option on the command line.
The value of this option can only be changed via flags supplied at
invocation of the shell. It cannot be changed once zsh is running.</p>
<p><span id="index-LOGIN"></span> <span id="index-NO_005fLOGIN"></span>
<span id="index-NOLOGIN"></span></p>
2022-08-24 15:22:41 +02:00
<p>LOGIN (-l, ksh: -l)</p>
2021-05-11 02:29:21 +02:00
<p>This is a login shell. If this option is not explicitly set, the shell
2022-08-24 15:22:41 +02:00
becomes a login shell if the first character of the argv[0] passed to
the shell is a -.</p>
<p><span id="index-PRIVILEGED"></span> <span
id="index-NO_005fPRIVILEGED"></span> <span
id="index-NOPRIVILEGED"></span> <span id="index-privileged-mode"></span>
2021-05-11 02:29:21 +02:00
<span id="index-mode_002c-privileged"></span></p>
2022-08-24 15:22:41 +02:00
<p>PRIVILEGED (-p, ksh: -p)</p>
2021-05-11 02:29:21 +02:00
<p>Turn on privileged mode. Typically this is used when script is to be run
with elevated privileges. This should be done as follows directly with
2022-08-24 15:22:41 +02:00
the -p option to zsh so that it takes effect during startup.</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">#!/bin/zsh -p
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>The option is enabled automatically on startup if the effective user
(group) ID is not equal to the real user (group) ID. In this case,
turning the option off causes the effective user and group IDs to be set
to the real user and group IDs. Be aware that if that fails the shell
may be running with different IDs than was intended so a script should
check for failure and act accordingly, for example:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">unsetopt privileged || exit
</code></pre>
</div>
<p>The PRIVILEGED option disables sourcing user startup files. If zsh is
invoked as sh or ksh with this option set, /etc/suid_profile is
sourced (after /etc/profile on interactive shells). Sourcing ~/.profile
is disabled and the contents of the ENV variable is ignored. This option
cannot be changed using the -m option of setopt and unsetopt, and
changing it inside a function always changes it globally regardless of
the LOCAL_OPTIONS option.</p>
<p><span id="index-RESTRICTED-1"></span> <span
id="index-NO_005fRESTRICTED"></span> <span
id="index-NORESTRICTED"></span> <span
id="index-restricted-shell-1"></span></p>
<p>RESTRICTED (-r)</p>
<p>Enables restricted mode. This option cannot be changed using unsetopt,
2021-05-11 02:29:21 +02:00
and setting it inside a function always changes it globally regardless
2022-08-24 15:22:41 +02:00
of the LOCAL_OPTIONS option. See <a href="Invocation.html#Restricted-Shell">Restricted
2021-05-11 02:29:21 +02:00
Shell</a>.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-SHIN_005fSTDIN"></span> <span
id="index-NO_005fSHIN_005fSTDIN"></span> <span
id="index-SHINSTDIN"></span> <span id="index-NOSHINSTDIN"></span></p>
<p>SHIN_STDIN (-s, ksh: -s)</p>
2021-05-11 02:29:21 +02:00
<p>Commands are being read from the standard input. Commands are read from
2022-08-24 15:22:41 +02:00
standard input if no command is specified with -c and no file of
commands is specified. If SHIN_STDIN is set explicitly on the command
2021-05-11 02:29:21 +02:00
line, any argument that would otherwise have been taken as a file to run
will instead be treated as a normal positional parameter. Note that
setting or unsetting this option on the command line does not
necessarily affect the state the option will have while the shell is
running - that is purely an indicator of whether or not commands are
<em>actually</em> being read from standard input. The value of this option can
only be changed via flags supplied at invocation of the shell. It cannot
be changed once zsh is running.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-SINGLE_005fCOMMAND"></span> <span
id="index-NO_005fSINGLE_005fCOMMAND"></span> <span
id="index-SINGLECOMMAND"></span> <span
id="index-NOSINGLECOMMAND"></span> <span
id="index-single-command"></span> <span
id="index-INTERACTIVE_002c-use-of"></span></p>
<p>SINGLE_COMMAND (-t, ksh: -t)</p>
2021-05-11 02:29:21 +02:00
<p>If the shell is reading from standard input, it exits after a single
command has been executed. This also makes the shell non-interactive,
2022-08-24 15:22:41 +02:00
unless the INTERACTIVE option is explicitly set on the command line. The
value of this option can only be changed via flags supplied at
2021-05-11 02:29:21 +02:00
invocation of the shell. It cannot be changed once zsh is running.</p>
<hr />
<p><span id="Zle"></span></p>
<h3 id="16212-zle"><a class="header" href="#16212-zle">16.2.12 Zle</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-BEEP"></span> <span id="index-NO_005fBEEP"></span> <span
id="index-NOBEEP"></span> <span id="index-beep_002c-enabling"></span>
2021-05-11 02:29:21 +02:00
<span id="index-enabling-the-beep"></span></p>
2022-08-24 15:22:41 +02:00
<p>BEEP (+B) &lt;D&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Beep on error in ZLE.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-COMBINING_005fCHARS"></span> <span
id="index-NO_005fCOMBINING_005fCHARS"></span> <span
id="index-COMBININGCHARS"></span> <span
id="index-NOCOMBININGCHARS"></span> <span
id="index-characters_002c-_0028Unicode_0029-combining"></span> <span
id="index-combining-characters-_0028Unicode_0029"></span> <span
id="index-Unicode-combining-characters"></span></p>
<p>COMBINING_CHARS</p>
2021-05-11 02:29:21 +02:00
<p>Assume that the terminal displays combining characters correctly.
Specifically, if a base alphanumeric character is followed by one or
more zero-width punctuation characters, assume that the zero-width
characters will be displayed as modifications to the base character
within the same width. Not all terminals handle this. If this option is
not set, zero-width characters are displayed separately with special
mark-up.</p>
2022-08-24 15:22:41 +02:00
<p>If this option is set, the pattern test [[:WORD:]] matches a
2021-05-11 02:29:21 +02:00
zero-width punctuation character on the assumption that it will be used
as part of a word in combination with a word character. Otherwise the
base shell does not handle combining characters specially.</p>
<p><span id="index-EMACS"></span> <span id="index-NO_005fEMACS"></span>
<span id="index-NOEMACS"></span></p>
2022-08-24 15:22:41 +02:00
<p>EMACS</p>
2021-05-11 02:29:21 +02:00
<p>If ZLE is loaded, turning on this option has the equivalent effect of
2022-08-24 15:22:41 +02:00
bindkey -e. In addition, the VI option is unset. Turning it off has no
effect. The option setting is not guaranteed to reflect the current
keymap. This option is provided for compatibility; bindkey is the
recommended interface.</p>
<p><span id="index-OVERSTRIKE"></span> <span
id="index-NO_005fOVERSTRIKE"></span> <span
id="index-NOOVERSTRIKE"></span> <span
id="index-editor_002c-overstrike-mode"></span> <span
id="index-overstrike-mode_002c-of-editor"></span></p>
<p>OVERSTRIKE</p>
2021-05-11 02:29:21 +02:00
<p>Start up the line editor in overstrike mode.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-SINGLE_005fLINE_005fZLE"></span> <span
id="index-NO_005fSINGLE_005fLINE_005fZLE"></span> <span
id="index-SINGLELINEZLE"></span> <span
id="index-NOSINGLELINEZLE"></span> <span
id="index-editor_002c-single-line-mode"></span></p>
<p>SINGLE_LINE_ZLE (-M) &lt;K&gt;</p>
2021-05-11 02:29:21 +02:00
<p>Use single-line command line editing instead of multi-line.</p>
<p>Note that although this is on by default in ksh emulation it only
provides superficial compatibility with the ksh line editor and reduces
the effectiveness of the zsh line editor. As it has no effect on shell
syntax, many users may wish to disable this option when using ksh
emulation interactively.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-VI"></span> <span id="index-NO_005fVI"></span> <span
id="index-NOVI"></span></p>
<p>VI</p>
2021-05-11 02:29:21 +02:00
<p>If ZLE is loaded, turning on this option has the equivalent effect of
2022-08-24 15:22:41 +02:00
bindkey -v. In addition, the EMACS option is unset. Turning it off has
no effect. The option setting is not guaranteed to reflect the current
keymap. This option is provided for compatibility; bindkey is the
recommended interface.</p>
<p><span id="index-ZLE"></span> <span id="index-NO_005fZLE"></span> <span
id="index-NOZLE"></span> <span id="index-editor_002c-enabling"></span>
2021-05-11 02:29:21 +02:00
<span id="index-enabling-the-editor"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZLE (-Z)</p>
2021-05-11 02:29:21 +02:00
<p>Use the zsh line editor. Set by default in interactive shells connected
to a terminal.</p>
<hr />
<p><span id="Option-Aliases"></span> <span id="Option-Aliases-1"></span></p>
<h2 id="163-option-aliases"><a class="header" href="#163-option-aliases">16.3 Option Aliases</a></h2>
<p><span id="index-options_002c-aliases"></span></p>
<p>Some options have alternative names. These aliases are never used for
output, but can be used just like normal option names when specifying
options to the shell.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-BRACE_005fEXPAND"></span> <span
id="index-NO_005fBRACE_005fEXPAND"></span> <span
id="index-BRACEEXPAND"></span> <span id="index-NOBRACEEXPAND"></span></p>
<p>BRACE_EXPAND</p>
<p>*NO_*IGNORE_BRACES (ksh and bash compatibility)</p>
<p><span id="index-DOT_005fGLOB"></span> <span
id="index-NO_005fDOT_005fGLOB"></span> <span id="index-DOTGLOB"></span>
<span id="index-NODOTGLOB"></span></p>
<p>DOT_GLOB</p>
<p>GLOB_DOTS (bash compatibility)</p>
<p><span id="index-HASH_005fALL"></span> <span
id="index-NO_005fHASH_005fALL"></span> <span id="index-HASHALL"></span>
<span id="index-NOHASHALL"></span></p>
<p>HASH_ALL</p>
<p>HASH_CMDS (bash compatibility)</p>
<p><span id="index-HIST_005fAPPEND"></span> <span
id="index-NO_005fHIST_005fAPPEND"></span> <span
id="index-HISTAPPEND"></span> <span id="index-NOHISTAPPEND"></span></p>
<p>HIST_APPEND</p>
<p>APPEND_HISTORY (bash compatibility)</p>
<p><span id="index-HIST_005fEXPAND"></span> <span
id="index-NO_005fHIST_005fEXPAND"></span> <span
id="index-HISTEXPAND"></span> <span id="index-NOHISTEXPAND"></span></p>
<p>HIST_EXPAND</p>
<p>BANG_HIST (bash compatibility)</p>
<p><span id="index-LOG"></span> <span id="index-NO_005fLOG"></span> <span
id="index-NOLOG"></span></p>
<p>LOG</p>
<p>*NO_*HIST_NO_FUNCTIONS (ksh compatibility)</p>
<p><span id="index-MAIL_005fWARN"></span> <span
id="index-NO_005fMAIL_005fWARN"></span> <span
id="index-MAILWARN"></span> <span id="index-NOMAILWARN"></span></p>
<p>MAIL_WARN</p>
<p>MAIL_WARNING (bash compatibility)</p>
<p><span id="index-ONE_005fCMD"></span> <span
id="index-NO_005fONE_005fCMD"></span> <span id="index-ONECMD"></span>
<span id="index-NOONECMD"></span></p>
<p>ONE_CMD</p>
<p>SINGLE_COMMAND (bash compatibility)</p>
<p><span id="index-PHYSICAL"></span> <span
id="index-NO_005fPHYSICAL"></span> <span id="index-NOPHYSICAL"></span></p>
<p>PHYSICAL</p>
<p>CHASE_LINKS (ksh and bash compatibility)</p>
<p><span id="index-PROMPT_005fVARS"></span> <span
id="index-NO_005fPROMPT_005fVARS"></span> <span
id="index-PROMPTVARS"></span> <span id="index-NOPROMPTVARS"></span></p>
<p>PROMPT_VARS</p>
<p>PROMPT_SUBST (bash compatibility)</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-STDIN"></span> <span id="index-NO_005fSTDIN"></span>
<span id="index-NOSTDIN"></span></p>
2022-08-24 15:22:41 +02:00
<p>STDIN</p>
<p>SHIN_STDIN (ksh compatibility)</p>
<p><span id="index-TRACK_005fALL"></span> <span
id="index-NO_005fTRACK_005fALL"></span> <span
id="index-TRACKALL"></span> <span id="index-NOTRACKALL"></span></p>
<p>TRACK_ALL</p>
<p>HASH_CMDS (ksh compatibility)</p>
<hr />
<p><span id="Single-Letter-Options"></span> <span
id="Single-Letter-Options-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="164-single-letter-options"><a class="header" href="#164-single-letter-options">16.4 Single Letter Options</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-options_002c-single-letter"></span> <span
id="index-single-letter-options"></span></p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Default-set"></span></p>
<h3 id="1641-default-set"><a class="header" href="#1641-default-set">16.4.1 Default set</a></h3>
2022-08-24 15:22:41 +02:00
<p>-0<br />
2021-05-11 02:29:21 +02:00
CORRECT</p>
2022-08-24 15:22:41 +02:00
<p>-1<br />
2021-05-11 02:29:21 +02:00
PRINT_EXIT_VALUE</p>
2022-08-24 15:22:41 +02:00
<p>-2<br />
2021-05-11 02:29:21 +02:00
*NO_*BAD_PATTERN</p>
2022-08-24 15:22:41 +02:00
<p>-3<br />
2021-05-11 02:29:21 +02:00
*NO_*NOMATCH</p>
2022-08-24 15:22:41 +02:00
<p>-4<br />
2021-05-11 02:29:21 +02:00
GLOB_DOTS</p>
2022-08-24 15:22:41 +02:00
<p>-5<br />
2021-05-11 02:29:21 +02:00
NOTIFY</p>
2022-08-24 15:22:41 +02:00
<p>-6<br />
2021-05-11 02:29:21 +02:00
BG_NICE</p>
2022-08-24 15:22:41 +02:00
<p>-7<br />
2021-05-11 02:29:21 +02:00
IGNORE_EOF</p>
2022-08-24 15:22:41 +02:00
<p>-8<br />
2021-05-11 02:29:21 +02:00
MARK_DIRS</p>
2022-08-24 15:22:41 +02:00
<p>-9<br />
2021-05-11 02:29:21 +02:00
AUTO_LIST</p>
2022-08-24 15:22:41 +02:00
<p>-B<br />
2021-05-11 02:29:21 +02:00
*NO_*BEEP</p>
2022-08-24 15:22:41 +02:00
<p>-C<br />
2021-05-11 02:29:21 +02:00
*NO_*CLOBBER</p>
2022-08-24 15:22:41 +02:00
<p>-D<br />
2021-05-11 02:29:21 +02:00
PUSHD_TO_HOME</p>
2022-08-24 15:22:41 +02:00
<p>-E<br />
2021-05-11 02:29:21 +02:00
PUSHD_SILENT</p>
2022-08-24 15:22:41 +02:00
<p>-F<br />
2021-05-11 02:29:21 +02:00
*NO_*GLOB</p>
2022-08-24 15:22:41 +02:00
<p>-G<br />
2021-05-11 02:29:21 +02:00
NULL_GLOB</p>
2022-08-24 15:22:41 +02:00
<p>-H<br />
2021-05-11 02:29:21 +02:00
RM_STAR_SILENT</p>
2022-08-24 15:22:41 +02:00
<p>-I<br />
2021-05-11 02:29:21 +02:00
IGNORE_BRACES</p>
2022-08-24 15:22:41 +02:00
<p>-J<br />
2021-05-11 02:29:21 +02:00
AUTO_CD</p>
2022-08-24 15:22:41 +02:00
<p>-K<br />
2021-05-11 02:29:21 +02:00
*NO_*BANG_HIST</p>
2022-08-24 15:22:41 +02:00
<p>-L<br />
2021-05-11 02:29:21 +02:00
SUN_KEYBOARD_HACK</p>
2022-08-24 15:22:41 +02:00
<p>-M<br />
2021-05-11 02:29:21 +02:00
SINGLE_LINE_ZLE</p>
2022-08-24 15:22:41 +02:00
<p>-N<br />
2021-05-11 02:29:21 +02:00
AUTO_PUSHD</p>
2022-08-24 15:22:41 +02:00
<p>-O<br />
2021-05-11 02:29:21 +02:00
CORRECT_ALL</p>
2022-08-24 15:22:41 +02:00
<p>-P<br />
2021-05-11 02:29:21 +02:00
RC_EXPAND_PARAM</p>
2022-08-24 15:22:41 +02:00
<p>-Q<br />
2021-05-11 02:29:21 +02:00
PATH_DIRS</p>
2022-08-24 15:22:41 +02:00
<p>-R<br />
2021-05-11 02:29:21 +02:00
LONG_LIST_JOBS</p>
2022-08-24 15:22:41 +02:00
<p>-S<br />
2021-05-11 02:29:21 +02:00
REC_EXACT</p>
2022-08-24 15:22:41 +02:00
<p>-T<br />
2021-05-11 02:29:21 +02:00
CDABLE_VARS</p>
2022-08-24 15:22:41 +02:00
<p>-U<br />
2021-05-11 02:29:21 +02:00
MAIL_WARNING</p>
2022-08-24 15:22:41 +02:00
<p>-V<br />
2021-05-11 02:29:21 +02:00
*NO_*PROMPT_CR</p>
2022-08-24 15:22:41 +02:00
<p>-W<br />
2021-05-11 02:29:21 +02:00
AUTO_RESUME</p>
2022-08-24 15:22:41 +02:00
<p>-X<br />
2021-05-11 02:29:21 +02:00
LIST_TYPES</p>
2022-08-24 15:22:41 +02:00
<p>-Y<br />
2021-05-11 02:29:21 +02:00
MENU_COMPLETE</p>
2022-08-24 15:22:41 +02:00
<p>-Z<br />
2021-05-11 02:29:21 +02:00
ZLE</p>
2022-08-24 15:22:41 +02:00
<p>-a<br />
2021-05-11 02:29:21 +02:00
ALL_EXPORT</p>
2022-08-24 15:22:41 +02:00
<p>-e<br />
2021-05-11 02:29:21 +02:00
ERR_EXIT</p>
2022-08-24 15:22:41 +02:00
<p>-f<br />
2021-05-11 02:29:21 +02:00
*NO_*RCS</p>
2022-08-24 15:22:41 +02:00
<p>-g<br />
2021-05-11 02:29:21 +02:00
HIST_IGNORE_SPACE</p>
2022-08-24 15:22:41 +02:00
<p>-h<br />
2021-05-11 02:29:21 +02:00
HIST_IGNORE_DUPS</p>
2022-08-24 15:22:41 +02:00
<p>-i<br />
2021-05-11 02:29:21 +02:00
INTERACTIVE</p>
2022-08-24 15:22:41 +02:00
<p>-k<br />
2021-05-11 02:29:21 +02:00
INTERACTIVE_COMMENTS</p>
2022-08-24 15:22:41 +02:00
<p>-l<br />
2021-05-11 02:29:21 +02:00
LOGIN</p>
2022-08-24 15:22:41 +02:00
<p>-m<br />
2021-05-11 02:29:21 +02:00
MONITOR</p>
2022-08-24 15:22:41 +02:00
<p>-n<br />
2021-05-11 02:29:21 +02:00
*NO_*EXEC</p>
2022-08-24 15:22:41 +02:00
<p>-p<br />
2021-05-11 02:29:21 +02:00
PRIVILEGED</p>
2022-08-24 15:22:41 +02:00
<p>-r<br />
2021-05-11 02:29:21 +02:00
RESTRICTED</p>
2022-08-24 15:22:41 +02:00
<p>-s<br />
2021-05-11 02:29:21 +02:00
SHIN_STDIN</p>
2022-08-24 15:22:41 +02:00
<p>-t<br />
2021-05-11 02:29:21 +02:00
SINGLE_COMMAND</p>
2022-08-24 15:22:41 +02:00
<p>-u<br />
2021-05-11 02:29:21 +02:00
*NO_*UNSET</p>
2022-08-24 15:22:41 +02:00
<p>-v<br />
2021-05-11 02:29:21 +02:00
VERBOSE</p>
2022-08-24 15:22:41 +02:00
<p>-w<br />
2021-05-11 02:29:21 +02:00
CHASE_LINKS</p>
2022-08-24 15:22:41 +02:00
<p>-x<br />
2021-05-11 02:29:21 +02:00
XTRACE</p>
2022-08-24 15:22:41 +02:00
<p>-y<br />
2021-05-11 02:29:21 +02:00
SH_WORD_SPLIT</p>
<hr />
<p><span id="sh_002fksh-emulation-set"></span></p>
<h3 id="1642-shksh-emulation-set"><a class="header" href="#1642-shksh-emulation-set">16.4.2 sh/ksh emulation set</a></h3>
2022-08-24 15:22:41 +02:00
<p>-C<br />
2021-05-11 02:29:21 +02:00
*NO_*CLOBBER</p>
2022-08-24 15:22:41 +02:00
<p>-T<br />
2021-05-11 02:29:21 +02:00
TRAPS_ASYNC</p>
2022-08-24 15:22:41 +02:00
<p>-X<br />
2021-05-11 02:29:21 +02:00
MARK_DIRS</p>
2022-08-24 15:22:41 +02:00
<p>-a<br />
2021-05-11 02:29:21 +02:00
ALL_EXPORT</p>
2022-08-24 15:22:41 +02:00
<p>-b<br />
2021-05-11 02:29:21 +02:00
NOTIFY</p>
2022-08-24 15:22:41 +02:00
<p>-e<br />
2021-05-11 02:29:21 +02:00
ERR_EXIT</p>
2022-08-24 15:22:41 +02:00
<p>-f<br />
2021-05-11 02:29:21 +02:00
*NO_*GLOB</p>
2022-08-24 15:22:41 +02:00
<p>-i<br />
2021-05-11 02:29:21 +02:00
INTERACTIVE</p>
2022-08-24 15:22:41 +02:00
<p>-l<br />
2021-05-11 02:29:21 +02:00
LOGIN</p>
2022-08-24 15:22:41 +02:00
<p>-m<br />
2021-05-11 02:29:21 +02:00
MONITOR</p>
2022-08-24 15:22:41 +02:00
<p>-n<br />
2021-05-11 02:29:21 +02:00
*NO_*EXEC</p>
2022-08-24 15:22:41 +02:00
<p>-p<br />
2021-05-11 02:29:21 +02:00
PRIVILEGED</p>
2022-08-24 15:22:41 +02:00
<p>-r<br />
2021-05-11 02:29:21 +02:00
RESTRICTED</p>
2022-08-24 15:22:41 +02:00
<p>-s<br />
2021-05-11 02:29:21 +02:00
SHIN_STDIN</p>
2022-08-24 15:22:41 +02:00
<p>-t<br />
2021-05-11 02:29:21 +02:00
SINGLE_COMMAND</p>
2022-08-24 15:22:41 +02:00
<p>-u<br />
2021-05-11 02:29:21 +02:00
*NO_*UNSET</p>
2022-08-24 15:22:41 +02:00
<p>-v<br />
2021-05-11 02:29:21 +02:00
VERBOSE</p>
2022-08-24 15:22:41 +02:00
<p>-x<br />
2021-05-11 02:29:21 +02:00
XTRACE</p>
<hr />
<p><span id="Also-note"></span></p>
<h3 id="1643-also-note"><a class="header" href="#1643-also-note">16.4.3 Also note</a></h3>
2022-08-24 15:22:41 +02:00
<p>-A<br />
Used by set for setting arrays</p>
<p>-b<br />
2021-05-11 02:29:21 +02:00
Used on the command line to specify end of option processing</p>
2022-08-24 15:22:41 +02:00
<p>-c<br />
2021-05-11 02:29:21 +02:00
Used on the command line to specify a single command</p>
2022-08-24 15:22:41 +02:00
<p>-m<br />
Used by setopt for pattern-matching option setting</p>
<p>-o<br />
2021-05-11 02:29:21 +02:00
Used in all places to allow use of long option names</p>
2022-08-24 15:22:41 +02:00
<p>-s<br />
Used by set to sort positional parameters</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="Shell-Builtin-Commands.html#17-shell-builtin-commands">17 Shell Builtin Commands</a></li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2022-08-24 15:22:41 +02:00
<p><span id="Shell-Builtin-Commands"></span> <span
id="Shell-Builtin-Commands-1"></span></p>
2021-05-11 02:29:21 +02:00
<h1 id="17-shell-builtin-commands"><a class="header" href="#17-shell-builtin-commands">17 Shell Builtin Commands</a></h1>
2022-08-24 15:22:41 +02:00
<p><span id="index-builtin-commands"></span> <span
id="index-commands_002c-builtin"></span></p>
2021-05-11 02:29:21 +02:00
<p>Some shell builtin commands take options as described in individual
2022-08-24 15:22:41 +02:00
entries; these are often referred to in the list below as flags to
2021-05-11 02:29:21 +02:00
avoid confusion with shell options, which may also have an effect on the
2022-08-24 15:22:41 +02:00
behaviour of builtin commands. In this introductory section, option
2021-05-11 02:29:21 +02:00
always has the meaning of an option to a command that should be familiar
to most command line users.</p>
2022-08-24 15:22:41 +02:00
<p>Typically, options are single letters preceded by a hyphen (-). Options
that take an argument accept it either immediately following the option
letter or after white space, for example print -C3 {1..9} or print -C
3 {1..9} are equivalent. Arguments to options are not the same as
arguments to the command; the documentation indicates which is which.
Options that do not take an argument may be combined in a single word,
for example print -rca * and print -r -c -a * are equivalent.</p>
<p>Some shell builtin commands also take options that begin with +
instead of -. The list below makes clear which commands these are.</p>
2021-05-11 02:29:21 +02:00
<p>Options (together with their individual arguments, if any) must appear
in a group before any non-option arguments; once the first non-option
argument has been found, option processing is terminated.</p>
2022-08-24 15:22:41 +02:00
<p>All builtin commands other than echo and precommand modifiers, even
those that have no options, can be given the argument -- to terminate
option processing. This indicates that the following words are
2021-05-11 02:29:21 +02:00
non-option arguments, but is otherwise ignored. This is useful in cases
2022-08-24 15:22:41 +02:00
where arguments to the command may begin with -. For historical
reasons, most builtin commands (including echo) also recognize a
single - in a separate word for this purpose; note that this is less
standard and use of -- is recommended.</p>
<p>- <code>simple command</code><br />
2021-05-11 02:29:21 +02:00
See <a href="Shell-Grammar.html#Precommand-Modifiers">Precommand Modifiers</a>.</p>
<p><span id="index-_002e"></span></p>
2022-08-24 15:22:41 +02:00
<p>. <code>file</code> [ <code>arg</code> ... ]<br />
2021-05-11 02:29:21 +02:00
Read commands from <code>file</code> and execute them in the current shell
environment.</p>
2022-08-24 15:22:41 +02:00
<p>If <code>file</code> does not contain a slash, or if PATH_DIRS is set, the shell
looks in the components of $path to find the directory containing
<code>file</code>. Files in the current directory are not read unless . appears
somewhere in $path. If a file named <code>file</code>.zwc is found, is newer than
<code>file</code>, and is the compiled form (created with the zcompile builtin) of
<code>file</code>, then commands are read from that file instead of <code>file</code>.</p>
<p>If any arguments <code>arg</code> are given, they become the positional parameters;
the old positional parameters are restored when the <code>file</code> is done
executing. However, if no arguments are given, the positional parameters
remain those of the calling context, and no restoring is done.</p>
<p>If <code>file</code> was not found the return status is 127; if <code>file</code> was found
but contained a syntax error the return status is 126; else the return
status is the exit status of the last command executed.</p>
<p><span id="index-_003a"></span> <span
id="index-expanding-parameters"></span> <span
id="index-parameters_002c-expanding"></span> <span
id="index-doing-nothing"></span></p>
<p>: [ <code>arg</code> ... ]<br />
2021-05-11 02:29:21 +02:00
This command does nothing, although normal argument expansions is
2022-08-24 15:22:41 +02:00
performed which may have effects on shell parameters. A zero exit status
is returned.</p>
<p><span id="index-alias"></span> <span
id="index-aliases_002c-defining"></span> <span
id="index-aliases_002c-listing"></span></p>
<p>alias [ {+|-}gmrsL ] [ <code>name</code>[=<code>value</code>] ... ]<br />
For each <code>name</code> with a corresponding <code>value</code>, define an alias with that
value. A trailing space in <code>value</code> causes the next word to be checked
for alias expansion. If the -g flag is present, define a global alias;
global aliases are expanded even if they do not occur in command
position:</p>
<div class="example">
<pre><code class="language-zsh">% perldoc --help 2&gt;&amp;1 | grep 'built-in functions'
-f Search Perl built-in functions
% alias -g HG='--help 2&gt;&amp;1 | grep'
% perldoc HG 'built-in functions'
-f Search Perl built-in functions
</code></pre>
</div>
<p>If the -s flag is present, define a suffix alias: if the command word on
a command line is in the form <code>text</code>.<code>name</code>, where <code>text</code> is any
non-empty string, it is replaced by the text <code>value</code> <code>text</code>.<code>name</code>.
Note that <code>name</code> is treated as a literal string, not a pattern. A
trailing space in <code>value</code> is not special in this case. For example,</p>
<div class="example">
<pre><code class="language-zsh">alias -s ps='gv --'
</code></pre>
</div>
<p>will cause the command *.ps to be expanded to gv *.ps. As alias
expansion is carried out earlier than globbing, the *.ps will then be
expanded. Suffix aliases constitute a different name space from other
aliases (so in the above example it is still possible to create an alias
for the command ps) and the two sets are never listed together.</p>
<p>For each <code>name</code> with no <code>value</code>, print the value of <code>name</code>, if any. With
no arguments, print all currently defined aliases other than suffix
aliases. If the -m flag is given the arguments are taken as patterns
(they should be quoted to preserve them from being interpreted as glob
patterns), and the aliases matching these patterns are printed. When
printing aliases and one of the -g, -r or -s flags is present, restrict
the printing to global, regular or suffix aliases, respectively; a
regular alias is one which is neither a global nor a suffix alias. Using
+ instead of -, or ending the option list with a single +,
prevents the values of the aliases from being printed.</p>
<p>If the -L flag is present, then print each status is nonzero if a <code>name</code>
(with no <code>value</code>) is given for which no alias has been defined.</p>
2021-05-11 02:29:21 +02:00
<p>For more on aliases, include common problems, see
<a href="Shell-Grammar.html#Aliasing">Aliasing</a>.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-autoload"></span> <span
id="index-functions_002c-autoloading-1"></span> <span
id="index-autoloading-functions-1"></span></p>
<p>autoload [ {+|-}RTUXdkmrtWz ] [ -w ] [ <code>name</code> ... ]<br />
2021-05-11 02:29:21 +02:00
<span id="index-fpath_002c-searching"></span></p>
<p>See the section Autoloading Functions in
2022-08-24 15:22:41 +02:00
<a href="Functions.html#Functions">Functions</a> for full details. The fpath
2021-05-11 02:29:21 +02:00
parameter will be searched to find the function definition when the
function is first referenced.</p>
2022-08-24 15:22:41 +02:00
<p>If <code>name</code> consists of an absolute path, the function is defined to load
from the file given (searching as usual for dump files in the given
location). The name of the function is the basename (non-directory part)
of the file. It is normally an error if the function is not found in the
given location; however, if the option -d is given, searching for the
function defaults to $fpath. If a function is loaded by absolute path,
any functions loaded from it that are marked for autoload without an
absolute path have the load path of the parent function temporarily
prepended to $fpath.</p>
<p>If the option -r or -R is given, the function is searched for
2021-05-11 02:29:21 +02:00
immediately and the location is recorded internally for use when the
function is executed; a relative path is expanded using the value of
2022-08-24 15:22:41 +02:00
$PWD. This protects against a change to $fpath after the call to
autoload. With -r, if the function is not found, it is silently left
unresolved until execution; with -R, an error message is printed and
command processing aborted immediately the search fails, i.e. at the
autoload command rather than at function execution..</p>
<p>The flag -X may be used only inside a shell function. It causes the
calling function to be marked for autoloading and then immediately
loaded and executed, with the current array of positional parameters as
arguments. This replaces the previous definition of the function. If no
function definition is found, an error is printed and the function
remains undefined and marked for autoloading. If an argument is given,
it is used as a directory (i.e. it does not include the name of the
function) in which the function is to be found; this may be combined
with the -d option to allow the function search to default to $fpath if
it is not in the given location.</p>
<p>The flag +X attempts to load each <code>name</code> as an autoloaded function, but
does <em>not</em> execute it. The exit status is zero (success) if the function
was not previously defined <em>and</em> a definition for it was found. This
does <em>not</em> replace any existing definition of the function. The exit
status is nonzero (failure) if the function was already defined or when
no definition was found. In the latter case the function remains
undefined and marked for autoloading. If ksh-style autoloading is
enabled, the function created will contain the contents of the file plus
a call to the function itself appended to it, thus giving normal ksh
autoloading behaviour on the first call to the function. If the -m flag
is also given each <code>name</code> is treated as a pattern and all functions
2021-05-11 02:29:21 +02:00
already marked for autoload that match the pattern are loaded.</p>
2022-08-24 15:22:41 +02:00
<p>With the -t flag, turn on execution tracing; with -T, turn on execution
tracing only for the current function, turning it off on entry to any
called functions that do not also have tracing enabled.</p>
<p>With the -U flag, alias expansion is suppressed when the function is
loaded.</p>
<p>With the -w flag, the <code>name</code>s are taken as names of files compiled with
the zcompile builtin, and all functions defined in them are marked for
autoloading.</p>
<p>The flags -z and -k mark the function to be autoloaded using the zsh or
ksh style, as if the option KSH_AUTOLOAD were unset or were set,
respectively. The flags override the setting of the option at the time
the function is loaded.</p>
<p>Note that the autoload command makes no attempt to ensure the shell
options set during the loading or execution of the file have any
particular value. For this, the emulate command can be used:</p>
<div class="example">
<pre><code class="language-zsh">emulate zsh -c 'autoload -Uz func'
</code></pre>
</div>
<p>arranges that when <code>func</code> is loaded the shell is in native zsh
2021-05-11 02:29:21 +02:00
emulation, and this emulation is also applied when <code>func</code> is run.</p>
2022-08-24 15:22:41 +02:00
<p>Some of the functions of autoload are also provided by functions -u or
functions -U, but autoload is a more comprehensive interface.</p>
<p><span id="index-bg"></span> <span
id="index-jobs_002c-backgrounding"></span></p>
<p>bg [ <code>job</code> ... ]<br />
<code>job</code> ... &amp;<br />
Put each specified <code>job</code> in the background, or the current job if none
is specified.</p>
<p>bindkey<br />
2021-05-11 02:29:21 +02:00
See <a href="Zsh-Line-Editor.html#Zle-Builtins">Zle Builtins</a>.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-break"></span> <span id="index-exiting-loops"></span>
2021-05-11 02:29:21 +02:00
<span id="index-loops_002c-exiting"></span></p>
2022-08-24 15:22:41 +02:00
<p>break [ <code>n</code> ]<br />
Exit from an enclosing for, while, until, select or repeat loop. If an
arithmetic expression <code>n</code> is specified, then break <code>n</code> levels instead of
just one.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-builtin-1"></span></p>
2022-08-24 15:22:41 +02:00
<p>builtin <code>name</code> [ <code>args</code> ... ]<br />
2021-05-11 02:29:21 +02:00
Executes the builtin <code>name</code>, with the given <code>args</code>.</p>
<p><span id="index-bye"></span></p>
2022-08-24 15:22:41 +02:00
<p>bye<br />
Same as exit.</p>
<p>cap<br />
2021-05-11 02:29:21 +02:00
See <a href="Zsh-Modules.html#The-zsh_002fcap-Module">The zsh/cap Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-cd"></span> <span
id="index-directories_002c-changing"></span></p>
<p>cd [ -qsLP ] [ <code>arg</code> ]<br />
cd [ -qsLP ] <code>old</code> <code>new</code><br />
cd [ -qsLP ] {+|-}<code>n</code><br />
2021-05-11 02:29:21 +02:00
Change the current directory. In the first form, change the current
2022-08-24 15:22:41 +02:00
directory to <code>arg</code>, or to the value of $HOME if <code>arg</code> is not specified.
If <code>arg</code> is -, change to the previous directory.</p>
2021-05-11 02:29:21 +02:00
<p>Otherwise, if <code>arg</code> begins with a slash, attempt to change to the
directory given by <code>arg</code>.</p>
2022-08-24 15:22:41 +02:00
<p>If <code>arg</code> does not begin with a slash, the behaviour depends on whether
the current directory . occurs in the list of directories contained in
the shell parameter cdpath. If it does not, first attempt to change to
the directory <code>arg</code> under the current directory, and if that fails but
cdpath is set and contains at least one element attempt to change to the
directory <code>arg</code> under each component of cdpath in turn until successful.
If . occurs in cdpath, then cdpath is searched strictly in order so
that . is only tried at the appropriate point.</p>
<p>The order of testing cdpath is modified if the option POSIX_CD is set,
as described in the documentation for the option.</p>
<p>If no directory is found, the option CDABLE_VARS is set, and a parameter
named <code>arg</code> exists whose value begins with a slash, treat its value as
the directory. In that case, the parameter is added to the named</p>
<p>The second form of cd substitutes the string <code>new</code> for the string <code>old</code>
in the name of the current directory, and tries to change to this new
directory.</p>
<p>The third form of cd extracts an entry from the directory stack, and
changes to that directory. An argument of the form +<code>n</code> identifies a
stack entry by counting from the left of the list shown by the dirs
command, starting with zero. An argument of the form -<code>n</code> counts from
the right. If the PUSHD_MINUS option is set, the meanings of + and -
in this context are swapped. If the POSIX_CD option is set, this form of
cd is not recognised and will be interpreted as the first form.</p>
<p>If the -q (quiet) option is specified, the hook function chpwd and the
functions in the array chpwd_functions are not called. This is useful
for calls to cd that do not change the environment seen by an
interactive user.</p>
<p>If the -s option is specified, cd refuses to change the current
directory if the given pathname contains symlinks. If the -P option is
given or the CHASE_LINKS option is set, symbolic links are resolved to
their true values. If the -L option is given symbolic links are retained
in the directory (and not resolved) regardless of the state of the
CHASE_LINKS option.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-chdir"></span></p>
2022-08-24 15:22:41 +02:00
<p>chdir<br />
Same as cd.</p>
<p>clone<br />
See <a href="Zsh-Modules.html#The-zsh_002fclone-Module">The zsh/clone Module</a>.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-command-1"></span></p>
2022-08-24 15:22:41 +02:00
<p>command [ -pvV ] <code>simple command</code><br />
The simple command argument is taken as an external command instead of a
function or builtin and is executed. If the POSIX_BUILTINS option is
set, builtins will also be executed but certain special properties of
them are suppressed. The -p flag causes a default path to be searched
instead of that in $path. With the -v flag, command is similar to whence
and with -V, it is equivalent to whence -v.</p>
2021-05-11 02:29:21 +02:00
<p>See also <a href="Shell-Grammar.html#Precommand-Modifiers">Precommand
Modifiers</a>.</p>
2022-08-24 15:22:41 +02:00
<p>comparguments<br />
2021-05-11 02:29:21 +02:00
See <a href="Zsh-Modules.html#The-zsh_002fcomputil-Module">The zsh/computil
Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p>compcall<br />
2021-05-11 02:29:21 +02:00
See <a href="Zsh-Modules.html#The-zsh_002fcompctl-Module">The zsh/compctl
Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p>compctl<br />
2021-05-11 02:29:21 +02:00
See <a href="Zsh-Modules.html#The-zsh_002fcompctl-Module">The zsh/compctl
Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p>compdescribe<br />
2021-05-11 02:29:21 +02:00
See <a href="Zsh-Modules.html#The-zsh_002fcomputil-Module">The zsh/computil
Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p>compfiles<br />
2021-05-11 02:29:21 +02:00
See <a href="Zsh-Modules.html#The-zsh_002fcomputil-Module">The zsh/computil
Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p>compgroups<br />
2021-05-11 02:29:21 +02:00
See <a href="Zsh-Modules.html#The-zsh_002fcomputil-Module">The zsh/computil
Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p>compquote<br />
2021-05-11 02:29:21 +02:00
See <a href="Zsh-Modules.html#The-zsh_002fcomputil-Module">The zsh/computil
Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p>comptags<br />
2021-05-11 02:29:21 +02:00
See <a href="Zsh-Modules.html#The-zsh_002fcomputil-Module">The zsh/computil
Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p>comptry<br />
2021-05-11 02:29:21 +02:00
See <a href="Zsh-Modules.html#The-zsh_002fcomputil-Module">The zsh/computil
Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p>compvalues<br />
2021-05-11 02:29:21 +02:00
See <a href="Zsh-Modules.html#The-zsh_002fcomputil-Module">The zsh/computil
Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-continue"></span> <span
id="index-loops_002c-continuing"></span> <span
id="index-continuing-loops"></span></p>
<p>continue [ <code>n</code> ]<br />
Resume the next iteration of the enclosing for, while, until, select or
repeat loop. If an arithmetic expression <code>n</code> is specified, break out of
<code>n</code>-1 loops and resume at the <code>n</code>th enclosing loop.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-declare"></span></p>
2022-08-24 15:22:41 +02:00
<p>declare<br />
Same as typeset.</p>
<p><span id="index-dirs"></span> <span
id="index-directory-stack_002c-printing"></span></p>
<p>dirs [ -c ] [ <code>arg</code> ... ]<br />
dirs [ -lpv ]<br />
2021-05-11 02:29:21 +02:00
With no arguments, print the contents of the directory stack.
2022-08-24 15:22:41 +02:00
Directories are added to this stack with the pushd command, and removed
with the cd or popd commands. If arguments are specified, load them onto
the directory stack, replacing anything that was there, and push the
current directory onto the stack.</p>
<p>-c<br />
2021-05-11 02:29:21 +02:00
clear the directory stack.</p>
2022-08-24 15:22:41 +02:00
<p>-l<br />
print directory names in full instead of using of using ~ expressions
(<a href="Expansion.html#Filename-Expansion">Filename Expansion</a>).</p>
<p>-p<br />
2021-05-11 02:29:21 +02:00
print directory entries one per line.</p>
2022-08-24 15:22:41 +02:00
<p>-v<br />
2021-05-11 02:29:21 +02:00
number the directories in the stack when printing.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-disable"></span> <span
id="index-disabling-commands"></span> <span
id="index-commands_002c-disabling"></span></p>
<p>disable [ -afmprs ] <code>name</code> ...<br />
?<br />
The pattern character ? wherever it occurs, including when preceding a
parenthesis with KSH_GLOB.</p>
<p>*<br />
The pattern character * wherever it occurs, including recursive
globbing and when preceding a parenthesis with KSH_GLOB.</p>
<p>[<br />
2021-05-11 02:29:21 +02:00
Character classes.</p>
2022-08-24 15:22:41 +02:00
<p>&lt; (NO_SH_GLOB)<br />
2021-05-11 02:29:21 +02:00
Numeric ranges.</p>
2022-08-24 15:22:41 +02:00
<p>| (NO_SH_GLOB)<br />
2021-05-11 02:29:21 +02:00
Alternation in grouped patterns, case statements, or KSH_GLOB
parenthesised expressions.</p>
2022-08-24 15:22:41 +02:00
<p>( (NO_SH_GLOB)<br />
Grouping using single parentheses. Disabling this does not disable the
use of parentheses for KSH_GLOB where they are introduced by a special
character, nor for glob qualifiers (use setopt NO_BARE_GLOB_QUAL to
disable glob qualifiers that use parentheses only).</p>
<p>~ (EXTENDED_GLOB)<br />
Exclusion in the form <code>A</code>~<code>B</code>.</p>
<p>^ (EXTENDED_GLOB)<br />
Exclusion in the form <code>A</code>^<code>B</code>.</p>
<p># (EXTENDED_GLOB)<br />
The pattern character # wherever it occurs, both for repetition of a
previous pattern and for indicating globbing flags.</p>
<p>?( (KSH_GLOB)<br />
The grouping form ?(<code>...</code>). Note this is also disabled if ? is
disabled.</p>
<p>*( (KSH_GLOB)<br />
The grouping form *(<code>...</code>). Note this is also disabled if * is
disabled.</p>
<p>+( (KSH_GLOB)<br />
The grouping form +(<code>...</code>).</p>
<p>!( (KSH_GLOB)<br />
The grouping form !(<code>...</code>).</p>
<p>@( (KSH_GLOB)<br />
The grouping form @(<code>...</code>).</p>
<p><span id="index-disown"></span> <span
id="index-jobs_002c-disowning-1"></span></p>
<p>disown [ <code>job</code> ... ]</p>
<p><code>job</code> ... &amp;|</p>
<p><code>job</code> ... &amp;!</p>
2021-05-11 02:29:21 +02:00
<p>no longer report their status, and will not complain if you try to exit
an interactive shell with them running or stopped. If no <code>job</code> is
specified, disown the current job.</p>
2022-08-24 15:22:41 +02:00
<p>If the <code>job</code>s are currently stopped and the AUTO_CONTINUE option is not
set, a warning is printed containing information about how to make them
running after they have been disowned. If one of the latter two forms is
used, the <code>job</code>s will automatically be made running, independent of the
setting of the AUTO_CONTINUE option.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-echo"></span></p>
2022-08-24 15:22:41 +02:00
<p>echo [ -neE ] [ <code>arg</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>Write each <code>arg</code> on the standard output, with a space separating each
2022-08-24 15:22:41 +02:00
one. If the -n flag is not present, print a newline at the end. echo
2021-05-11 02:29:21 +02:00
recognizes the following escape sequences:</p>
2022-08-24 15:22:41 +02:00
<p>\a<br />
2021-05-11 02:29:21 +02:00
bell character</p>
2022-08-24 15:22:41 +02:00
<p>\b<br />
2021-05-11 02:29:21 +02:00
backspace</p>
2022-08-24 15:22:41 +02:00
<p>\c<br />
2021-05-11 02:29:21 +02:00
suppress subsequent characters and final newline</p>
2022-08-24 15:22:41 +02:00
<p>\e<br />
2021-05-11 02:29:21 +02:00
escape</p>
2022-08-24 15:22:41 +02:00
<p>\f<br />
2021-05-11 02:29:21 +02:00
form feed</p>
2022-08-24 15:22:41 +02:00
<p>\n<br />
2021-05-11 02:29:21 +02:00
linefeed (newline)</p>
2022-08-24 15:22:41 +02:00
<p>\r<br />
2021-05-11 02:29:21 +02:00
carriage return</p>
2022-08-24 15:22:41 +02:00
<p>\t<br />
2021-05-11 02:29:21 +02:00
horizontal tab</p>
2022-08-24 15:22:41 +02:00
<p>\v<br />
2021-05-11 02:29:21 +02:00
vertical tab</p>
2022-08-24 15:22:41 +02:00
<p>\\<br />
2021-05-11 02:29:21 +02:00
backslash</p>
2022-08-24 15:22:41 +02:00
<p>\0<code>NNN</code><br />
2021-05-11 02:29:21 +02:00
character code in octal</p>
2022-08-24 15:22:41 +02:00
<p>\x<code>NN</code><br />
2021-05-11 02:29:21 +02:00
character code in hexadecimal</p>
2022-08-24 15:22:41 +02:00
<p>\u<code>NNNN</code><br />
2021-05-11 02:29:21 +02:00
unicode character code in hexadecimal</p>
2022-08-24 15:22:41 +02:00
<p>\U<code>NNNNNNNN</code><br />
2021-05-11 02:29:21 +02:00
unicode character code in hexadecimal</p>
<p><span id="index-BSD_005fECHO_002c-use-of"></span></p>
2022-08-24 15:22:41 +02:00
<p>The -E flag, or the BSD_ECHO option, can be used to disable these escape
sequences. In the latter case, -e flag can be used to enable them.</p>
2021-05-11 02:29:21 +02:00
<p>Note that for standards compliance a double dash does not terminate
option processing; instead, it is printed directly. However, a single
dash does terminate option processing, so the first dash, possibly
following options, is not printed, but everything following it is
2022-08-24 15:22:41 +02:00
printed as an argument. The single dash behaviour is different printf,
and for a more controllable way of printing text within zsh, see print.</p>
<p>echotc</p>
2021-05-11 02:29:21 +02:00
<p>See <a href="Zsh-Modules.html#The-zsh_002ftermcap-Module">The zsh/termcap
Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p>echoti</p>
2021-05-11 02:29:21 +02:00
<p>See <a href="Zsh-Modules.html#The-zsh_002fterminfo-Module">The zsh/terminfo
Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-emulate"></span> <span
id="index-compatibility_002c-sh"></span> <span
id="index-compatibility_002c-ksh"></span> <span
id="index-compatibility_002c-csh"></span> <span
id="index-sh_002c-compatibility"></span> <span
id="index-ksh_002c-compatibility"></span> <span
id="index-csh_002c-compatibility"></span></p>
<p>emulate [ -lLR ] [ {zsh|sh|ksh|csh} [ <code>flags</code> ... ] ]</p>
2021-05-11 02:29:21 +02:00
<p>Without any argument print current emulation mode.</p>
<p>With single argument set up zsh options to emulate the specified shell
as much as possible. csh will never be fully emulated. If the argument
2022-08-24 15:22:41 +02:00
is not one of the shells listed above, zsh will be used as a default;
2021-05-11 02:29:21 +02:00
more precisely, the tests performed on the argument are the same as
those used to determine the emulation at startup based on the shell
name, see <a href="Invocation.html#Compatibility">Compatibility</a> . In addition
to setting shell options, the command also restores the pristine state
2022-08-24 15:22:41 +02:00
of pattern enables, as if all patterns had been enabled using enable -p.</p>
<p>If the emulate command occurs inside a function that has been marked for
execution tracing with functions -t then the xtrace option will be
turned on regardless of emulation mode or other options. Note that code
executed inside the function by the ., source, or eval commands is not
considered to be running directly from the function, hence does not
provoke this behaviour.</p>
2021-05-11 02:29:21 +02:00
<p>are reset to their default value corresponding to the specified
emulation mode, except for certain options describing the interactive
environment; otherwise, only those options likely to cause portability
2022-08-24 15:22:41 +02:00
problems in scripts and functions are altered. If the -L switch is
given, the options LOCAL_OPTIONS, LOCAL_PATTERNS and LOCAL_TRAPS will be
set as well, causing the effects of the emulate command and any setopt,
disable -p or enable -p, and trap commands to be local to the
immediately surrounding shell function, if any; normally these options
are turned off in all emulation modes except ksh. The -L switch is
mutually exclusive with the use of -c in <code>flags</code>.</p>
<p>If there is a single argument and the -l switch is given, the options
that would be set or unset (the latter indicated with the prefix no)
are listed. -l can be combined with -L or -R and the list will be
2021-05-11 02:29:21 +02:00
modified in the appropriate way. Note the list does not depend on the
current setting of options, i.e. it includes all options that may in
principle change, not just those that would actually change.</p>
<p>The <code>flags</code> may be any of the invocation-time flags described in
2022-08-24 15:22:41 +02:00
<a href="Invocation.html#Invocation">Invocation</a>, except that -o EMACS and -o
VI may not be used. Flags such as +r/+o RESTRICTED may be
prohibited in some circumstances.</p>
<p>If -c <code>arg</code> appears in <code>flags</code>, <code>arg</code> is evaluated while the requested
2021-05-11 02:29:21 +02:00
emulation is temporarily in effect. In this case the emulation mode and
2022-08-24 15:22:41 +02:00
all options are restored to their previous values before emulate
returns. The -R switch may precede the name of the shell to emulate;
note this has a meaning distinct from including -R in <code>flags</code>.</p>
<p>Use of -c enables sticky emulation mode for functions defined within
2021-05-11 02:29:21 +02:00
the evaluated expression: the emulation mode is associated thereafter
with the function so that whenever the function is executed the
2022-08-24 15:22:41 +02:00
emulation (respecting the -R switch, if present) and all options are set
(and pattern disables cleared) before entry to the function, and the
2021-05-11 02:29:21 +02:00
state is restored after exit. If the function is called when the sticky
2022-08-24 15:22:41 +02:00
emulation is already in effect, either within an emulate <code>shell</code> -c
expression or within another function with the same sticky emulation,
entry and exit from the function do not cause options to be altered
(except due to standard processing such as the LOCAL_OPTIONS option).
This also applies to functions marked for autoload within the sticky
emulation; the appropriate set of options will be applied at the point
the function is loaded as well as when it is run.</p>
2021-05-11 02:29:21 +02:00
<p>For example:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">emulate sh -c 'fni() { setopt cshnullglob; }
2021-05-11 02:29:21 +02:00
fno() { fni; }'
fno
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The two functions fni and fno are defined with sticky sh emulation. fno
is then executed, causing options associated with emulations to be set
to their values in sh. fno then calls fni; because fni is also marked
for sticky sh emulation, no option changes take place on entry to or
exit from it. Hence the option cshnullglob, turned off by sh emulation,
will be turned on within fni and remain on return to fno. On exit from
fno, the emulation mode and all options will be restored to the state
they were in before entry to the temporary emulation.</p>
2021-05-11 02:29:21 +02:00
<p>The documentation above is typically sufficient for the intended
environment. More detailed rules follow.</p>
<p>1.<br />
2022-08-24 15:22:41 +02:00
The sticky emulation environment provided by emulate <code>shell</code> -c is
identical to that provided by entry to a function marked for sticky
emulation as a consequence of being defined in such an environment.
Hence, for example, the sticky emulation is inherited by subfunctions
defined within functions with sticky emulation.</p>
2021-05-11 02:29:21 +02:00
<p>2.<br />
2022-08-24 15:22:41 +02:00
No change of options takes place on entry to or exit from functions that
are not marked for sticky emulation, other than those that would
normally take place, even if those functions are called within sticky
emulation.</p>
2021-05-11 02:29:21 +02:00
<p>3.<br />
2022-08-24 15:22:41 +02:00
No special handling is provided for functions marked for autoload nor
for functions present in wordcode created by the zcompile command.</p>
2021-05-11 02:29:21 +02:00
<p>4.<br />
2022-08-24 15:22:41 +02:00
The presence or absence of the -R switch to emulate corresponds to
different sticky emulation modes, so for example emulate sh -c,
emulate -R sh -c and emulate csh -c are treated as three distinct
sticky emulations.</p>
2021-05-11 02:29:21 +02:00
<p>5.<br />
2022-08-24 15:22:41 +02:00
Difference in shell options supplied in addition to the basic emulation
also mean the sticky emulations are different, so for example emulate
zsh -c and emulate zsh -o cbases -c are treated as distinct sticky
emulations.</p>
<p><span id="index-enable"></span> <span
id="index-enabling-commands"></span> <span
id="index-commands_002c-enabling"></span></p>
<p>enable [ -afmprs ] <code>name</code> ...</p>
<p>earlier with disable. The default is to enable builtin commands. The -a
option causes enable to act on regular or global aliases. The -s option
causes enable to act on suffix aliases. The -f option causes enable to
act on shell functions. The -r option causes enable to act on reserved
words. Without arguments printed. With the -m flag the arguments are
taken as patterns disabled with the disable builtin command.</p>
<p>enable -p reenables patterns disabled with disable -p. Note that it does
not override globbing options; for example, enable -p &quot;~&quot; does not
cause the pattern character ~ to be active unless the EXTENDED_GLOB
option is also set. To enable all possible patterns (so that they may be
individually disabled with disable -p), use setopt EXTENDED_GLOB
KSH_GLOB NO_SH_GLOB.</p>
<p><span id="index-eval"></span> <span
id="index-evaluating-arguments-as-commands"></span></p>
<p>eval [ <code>arg</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>Read the arguments as input to the shell and execute the resulting
command(s) in the current shell process. The return status is the same
as if the commands had been executed directly by the shell; if there are
no <code>args</code> or they contain no commands (i.e. are an empty string or
whitespace) the return status is zero.</p>
2022-08-24 15:22:41 +02:00
<p>exec [ -cl ] [ -a <code>argv0</code> ] [ <code>command</code> [ <code>arg</code> ... ] ]</p>
2021-05-11 02:29:21 +02:00
<p>Replace the current shell with <code>command</code> rather than forking. If
<code>command</code> is a shell builtin command or a shell function, the shell
executes it, and exits when the command is complete.</p>
2022-08-24 15:22:41 +02:00
<p>With -c clear the environment; with -l prepend - to the argv[0] string
of the command executed (to simulate a login shell); with -a <code>argv0</code> set
the argv[0] string of the command executed. See <a href="Shell-Grammar.html#Precommand-Modifiers">Precommand
Modifiers</a>.</p>
<p>If the option POSIX_BUILTINS is set, <code>command</code> is never interpreted as a
shell builtin command or shell function. This means further precommand
modifiers such as builtin and noglob are also not interpreted within the
shell. Hence <code>command</code> is always found by searching the command path.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-redirection_002c-current-shell_0027s-I_002fO"></span></p>
<p>If <code>command</code> is omitted but any redirections are specified, then the
redirections will take effect in the current shell.</p>
<p><span id="index-exit"></span></p>
2022-08-24 15:22:41 +02:00
<p>exit [ <code>n</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>Exit the shell with the exit status specified by an arithmetic
expression <code>n</code>; if none is specified, use the exit status from the last
command executed. <span id="index-IGNORE_005fEOF_002c-use-of"></span> An
2022-08-24 15:22:41 +02:00
EOF condition will also cause the shell to exit, unless the IGNORE_EOF
2021-05-11 02:29:21 +02:00
option is set.</p>
<p>See notes at the end of <a href="Jobs-_0026-Signals.html#Jobs-_0026-Signals">Jobs &amp;
Signals</a> for some possibly
2022-08-24 15:22:41 +02:00
unexpected interactions of the exit command with jobs.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-export-1"></span></p>
2022-08-24 15:22:41 +02:00
<p>export [ <code>name</code>[=<code>value</code>] ... ]</p>
2021-05-11 02:29:21 +02:00
<p>The specified <code>name</code>s are marked for automatic export to the environment
2022-08-24 15:22:41 +02:00
of subsequently executed commands. Equivalent to typeset -gx. If a
2021-05-11 02:29:21 +02:00
parameter specified does not already exist, it is created in the global
scope.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-false"></span> <span
id="index-doing-nothing_002c-unsuccessfully"></span></p>
<p>false [ <code>arg</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>Do nothing and return an exit status of 1.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-fc"></span> <span
id="index-history_002c-editing"></span> <span
id="index-editing-history"></span></p>
<p>fc [ -e <code>ename</code> ] [ -s ] [ -LI ] [ -m <code>match</code> ] [ <code>old</code>=<code>new</code>
2021-05-11 02:29:21 +02:00
... ] [ <code>first</code> [ <code>last</code> ] ]</p>
2022-08-24 15:22:41 +02:00
<p>fc -l [ -LI ] [ -nrdfEiD ] [ -t <code>timefmt</code> ] [ -m <code>match</code> ]</p>
<p>      [ <code>old</code>=<code>new</code> ... ] [ <code>first</code> [ <code>last</code> ] ]</p>
<p>fc -p [ -a ] [ <code>filename</code> [ <code>histsize</code> [ <code>savehistsize</code> ] ] ]</p>
<p>fc -P</p>
<p>fc -ARWI [ <code>filename</code> ]</p>
<p>The fc command controls the interactive history mechanism. Note that
2021-05-11 02:29:21 +02:00
reading and writing of history options is only performed if the shell is
interactive. Usually this is detected automatically, but it can be
2022-08-24 15:22:41 +02:00
forced by setting the interactive option when starting the shell.</p>
2021-05-11 02:29:21 +02:00
<p>The first two forms of this command select a range of events from
<code>first</code> to <code>last</code> from the history list. The arguments <code>first</code> and
<code>last</code> may be specified as a number or as a string. A negative number is
used as an offset to the current history event number. A string
specifies the most recent event beginning with the given string. All
2022-08-24 15:22:41 +02:00
substitutions <code>old</code>=<code>new</code>, if any, are then performed on the text of the
events.</p>
<p>The range of events selected by numbers can be narrowed further by the
following flags.</p>
<p>-I<br />
restricts to only internal events (not from $HISTFILE)</p>
<p>-L<br />
restricts to only local events (not from other shells, see SHARE_HISTORY
in <a href="Options.html#Description-of-Options">Description of Options</a> note
that $HISTFILE is considered local when read at startup)</p>
<p>-m<br />
takes the first argument as a pattern (which should be quoted) and only
2021-05-11 02:29:21 +02:00
the history events matching this pattern are considered</p>
<p>If <code>first</code> is not specified, it will be set to -1 (the most recent
2022-08-24 15:22:41 +02:00
event), or to -16 if the -l flag is given. If <code>last</code> is not specified,
it will be set to <code>first</code>, or to -1 if the -l flag is given. However, if
the current event has added entries to the history with print -s or
fc -R, then the default <code>last</code> for -l includes all new history entries
since the current event began.</p>
<p>When the -l flag is given, the resulting events are listed on standard
output. Otherwise the editor program specified by -e <code>ename</code> is invoked
on a file containing these history events. If -e is not given, the value
of the parameter FCEDIT is used; if that is not set the value of the
parameter EDITOR is used; if that is not set a builtin default, usually
vi is used. If <code>ename</code> is -, no editor is invoked. When editing is
complete, the edited command is executed.</p>
<p>The flag -s is equivalent to -e -. The flag -r reverses the order of
the events and the flag -n suppresses event numbers when listing.</p>
2021-05-11 02:29:21 +02:00
<p>Also when listing,</p>
2022-08-24 15:22:41 +02:00
<p>-d<br />
2021-05-11 02:29:21 +02:00
prints timestamps for each event</p>
2022-08-24 15:22:41 +02:00
<p>-f<br />
prints full time-date stamps in the US <code>MM</code>/<code>DD</code>/<code>YY</code> <code>hh</code>:<code>mm</code> format</p>
<p>-E<br />
prints full time-date stamps in the European <code>dd</code>.<code>mm</code>.<code>yyyy</code>
<code>hh</code>:<code>mm</code> format</p>
<p>-i<br />
prints full time-date stamps in ISO8601 <code>yyyy</code>-<code>mm</code>-<code>dd</code> <code>hh</code>:<code>mm</code>
format</p>
<p>-t <code>fmt</code><br />
prints time and date stamps in the given format; <code>fmt</code> is formatted with
the strftime function with the zsh extensions described for the
%D{<code>string</code>} prompt format in <a href="Prompt-Expansion.html#Prompt-Expansion">Prompt
2021-05-11 02:29:21 +02:00
Expansion</a>. The resulting
formatted string must be no more than 256 characters or will not be
printed</p>
2022-08-24 15:22:41 +02:00
<p>-D<br />
2021-05-11 02:29:21 +02:00
prints elapsed times; may be combined with one of the options above</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-history_002c-stack"></span> <span
id="index-stack_002c-history"></span></p>
<p>fc -p pushes the current history list onto a stack and switches to a
new history list. If the -a option is also specified, this history list
will be automatically popped when the current function scope is exited,
which is a much better solution than creating a trap function to call
fc -P manually. If no arguments are specified, the history list is
left empty, $HISTFILE is unset, and $HISTSIZE &amp; $SAVEHIST are set to
their default values. If one argument is given, $HISTFILE is set to that
filename, $HISTSIZE &amp; $SAVEHIST are left unchanged, and the history file
is read in (if it exists) to initialize the new list. If a second
argument is specified, $HISTSIZE &amp; $SAVEHIST are instead set to the
single specified numeric value. Finally, if a third argument is
specified, $SAVEHIST is set to a separate value from $HISTSIZE. You are
free to change these environment values for the new history list however
you desire in order to manipulate the new history list.</p>
<p>fc -P pops the history list back to an older list saved by fc -p.
The current list is saved to its $HISTFILE before it is destroyed
(assuming that $HISTFILE and $SAVEHIST are set appropriately, of
course). The values of $HISTFILE, $HISTSIZE, and $SAVEHIST are restored
to the values they had when fc -p was called. Note that this
restoration can conflict with making these variables &quot;local&quot;, so your
best bet is to avoid local declarations for these variables in functions
that use fc -p. The one other guaranteed-safe combination is declaring
these variables to be local at the top of your function and using the
automatic option (-a) with fc -p. Finally, note that it is legal to
manually pop a push marked for automatic popping if you need to do so
before the function exits.</p>
<p><span id="index-history_002c-file"></span> <span
id="index-file_002c-history"></span></p>
<p>fc -R reads the history from the given file, fc -W writes the
history out to the given file, and fc -A appends the history out to
the given file. If no filename is specified, the $HISTFILE is assumed.
If the -I option is added to -R, only those events that are not already
contained within the internal history list are added. If the -I option
is added to -A or -W, only those events that are new since last
incremental append/write to the history file are appended/written. In
any case, the created file will have no more than $SAVEHIST entries.</p>
<p><span id="index-fg"></span> <span
id="index-jobs_002c-foregrounding"></span> <span
id="index-jobs_002c-resuming"></span></p>
<p>fg [ <code>job</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p><code>job</code> ...</p>
<p>Bring each specified <code>job</code> in turn to the foreground. If no <code>job</code> is
specified, resume the current job.</p>
<p><span id="index-float"></span></p>
2022-08-24 15:22:41 +02:00
<p>float [ {+|-}Hghlprtux ] [ {+|-}EFLRZ [ <code>n</code> ] ] [
<code>name</code>[=<code>value</code>] ... ]</p>
<p>Equivalent to typeset -E, except that options irrelevant to floating
2021-05-11 02:29:21 +02:00
point numbers are not permitted.</p>
<p><span id="index-functions-1"></span></p>
2022-08-24 15:22:41 +02:00
<p>functions [ {+|-}UkmtTuWz ] [ -x <code>num</code> ] [ <code>name</code> ... ]</p>
<p>functions -c <code>oldfn</code> <code>newfn</code></p>
<p>functions -M [-s] <code>mathfn</code> [ <code>min</code> [ <code>max</code> [ <code>shellfn</code> ] ] ]</p>
<p>functions -M [ -m <code>pattern</code> ... ]</p>
<p>functions +M [ -m ] <code>mathfn</code> ...</p>
<p>Equivalent to typeset -f, with the exception of the -c, -x, -M and -W
options. For functions -u and functions -U, see autoload, which provides
additional options. For functions -t and functions -T, see typeset -f.</p>
<p>The -x option indicates that any functions output will have each leading
tab for indentation, added by the shell to show syntactic structure,
expanded to the given number <code>num</code> of spaces. <code>num</code> can also be 0 to
suppress all indentation.</p>
<p>The -W option turns on the option WARN_NESTED_VAR for the named function
or functions only. The option is turned off at the start of nested
functions (apart from anonoymous functions) unless the called function
also has the -W attribute.</p>
<p>The -c option causes <code>oldfn</code> to be copied to <code>newfn</code>. The copy is
2021-05-11 02:29:21 +02:00
efficiently handled internally by reference counting. If <code>oldfn</code> was
marked for autoload it is first loaded and if this fails the copy fails.
Either function may subsequently be redefined without affecting the
other. A typical idiom is that <code>oldfn</code> is the name of a library shell
2022-08-24 15:22:41 +02:00
function which is then redefined to call newfn, thereby installing a
2021-05-11 02:29:21 +02:00
modified version of the function.</p>
2022-08-24 15:22:41 +02:00
<p><em>The</em> -M <em>and</em> +M <em>flags</em> <span
id="index-defining-mathematical-functions"></span> <span
id="index-functions_002c-defining-mathematical"></span></p>
<p>Use of the -M option may not be combined with any of the options handled
by typeset -f.</p>
<p>functions -M <code>mathfn</code> defines <code>mathfn</code> as the name of a mathematical
2021-05-11 02:29:21 +02:00
function recognised in all forms of arithmetical expressions; see
<a href="Arithmetic-Evaluation.html#Arithmetic-Evaluation">Arithmetic
Evaluation</a>. By
default <code>mathfn</code> may take any number of comma-separated arguments. If
<code>min</code> is given, it must have exactly <code>min</code> args; if <code>min</code> and <code>max</code> are
both given, it must have at least <code>min</code> and at most <code>max</code> args. <code>max</code>
may be -1 to indicate that there is no upper limit.</p>
<p>By default the function is implemented by a shell function of the same
name; if <code>shellfn</code> is specified it gives the name of the corresponding
shell function while <code>mathfn</code> remains the name used in arithmetical
2022-08-24 15:22:41 +02:00
expressions. The name of the function in $0 is <code>mathfn</code> (not <code>shellfn</code>
as would usually be the case), provided the option FUNCTION_ARGZERO is
2021-05-11 02:29:21 +02:00
in effect. The positional parameters in the shell function correspond to
2022-08-24 15:22:41 +02:00
the arguments of the mathematical function call.</p>
<p>The result of the last arithmetical expression evaluated inside the
shell function gives the result of the mathematical function. This is
not limited to arithmetic substitutions of the form $((<code>...</code>)), but also
includes arithmetical expressions evaluated in any other way, including
by the let builtin, by ((<code>...</code>)) statements, and even by the return
builtin and by array subscripts. Therefore, care must be taken not to
use syntactical constructs that perform arithmetic evaluation after
evaluating what is to be the result of the function. For example:</p>
<p><span id="index-zmath_005fcube"></span> <span id="index-cube"></span></p>
<div class="example">
<pre><code class="language-zsh"># WRONG
zmath_cube() {
(( $1 * $1 * $1 ))
return 0
}
functions -M cube 1 1 zmath_cube
print $(( cube(3) ))
</code></pre>
</div>
<p>This will print 0 because of the return.</p>
<p>Commenting the return out would lead to a different problem: the
((<code>...</code>)) statement would become the last statement in the function, so
the <em>return status</em> ($?) of the function would be non-zero (indicating
failure) whenever the <em>arithmetic result</em> of the function would happen
to be zero (numerically):</p>
<div class="example">
<pre><code class="language-zsh"># WRONG
zmath_cube() {
(( $1 * $1 * $1 ))
}
functions -M cube 1 1 zmath_cube
print $(( cube(0) ))
</code></pre>
</div>
<p>Instead, the true builtin can be used:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh"># RIGHT
zmath_cube() {
(( $1 * $1 * $1 ))
true
}
2021-05-11 02:29:21 +02:00
functions -M cube 1 1 zmath_cube
print $(( cube(3) ))
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>If the additional option -s is given to functions -M, the argument to
the function is a single string: anything between the opening and
matching closing parenthesis is passed to the function as a single
argument, even if it includes commas or white space. The minimum and
maximum argument specifiers must therefore be 1 if given. An empty
argument list is passed as a zero-length string. Thus, the following
string function takes a single argument, including the commas, and
prints 11:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">stringfn() { (( $#1 )); true }
2021-05-11 02:29:21 +02:00
functions -Ms stringfn
print $(( stringfn(foo,bar,rod) ))
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>functions -M with no arguments lists all such user-defined functions in
the same form as a definition. With the additional option -m and a list
of arguments, all functions whose <code>mathfn</code> matches one of the pattern
arguments are listed.</p>
<p>function +M removes the list of mathematical functions; with the
additional option -m the arguments are treated as patterns and all
functions whose <code>mathfn</code> matches the pattern are removed. Note that the
shell function implementing the behaviour is not removed (regardless of
whether its name coincides with <code>mathfn</code>).</p>
<p>getcap</p>
2021-05-11 02:29:21 +02:00
<p>See <a href="Zsh-Modules.html#The-zsh_002fcap-Module">The zsh/cap Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-getln"></span> <span
id="index-line_002c-reading"></span> <span
id="index-reading-a-line"></span></p>
<p>getln [ -AclneE ] <code>name</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>Read the top value from the buffer stack and put it in the shell
2022-08-24 15:22:41 +02:00
parameter <code>name</code>. Equivalent to read -zr.</p>
<p><span id="index-getopts"></span> <span
id="index-options_002c-processing"></span></p>
<p>getopts <code>optstring</code> <code>name</code> [ <code>arg</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>Checks the <code>arg</code>s for legal options. If the <code>arg</code>s are omitted, use the
2022-08-24 15:22:41 +02:00
positional parameters. A valid option argument begins with a + or a
-. An argument not beginning with a + or a -, or the argument
--, ends the options. Note that a single - is not considered a valid
option argument. <code>optstring</code> contains the letters that getopts
recognizes. If a letter is followed by a :, that option requires an
argument. The options can be separated from the argument by blanks.</p>
<p>Each time it is invoked, getopts places the option letter it finds in
the shell parameter <code>name</code>, prepended with a + when <code>arg</code> begins with
a +. The index of the next <code>arg</code> is stored in OPTIND. The option
argument, if any, is stored in OPTARG. <span
id="index-OPTIND_002c-use-of"></span> <span
id="index-OPTARG_002c-use-of"></span></p>
2021-05-11 02:29:21 +02:00
<p>The first option to be examined may be changed by explicitly assigning
2022-08-24 15:22:41 +02:00
to OPTIND. OPTIND has an initial value of 1, and is normally set to 1
upon entry to a shell function and restored upon exit. (The
POSIX_BUILTINS option disables this, and also changes the way the value
is calculated to match other shells.) OPTARG is not reset and retains
its value from the most recent call to getopts. If either of OPTIND or
OPTARG is explicitly unset, it remains unset, and the index or option
argument is not stored. The option itself is still stored in <code>name</code> in
this case.</p>
<p>A leading : in <code>optstring</code> causes getopts to store the letter of any
invalid option in OPTARG, and to set <code>name</code> to ? for an unknown option
and to : when a required argument is missing. Otherwise, getopts sets
<code>name</code> to ? and prints an error message when an option is invalid. The
exit status is nonzero when there are no more options.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-hash-1"></span></p>
2022-08-24 15:22:41 +02:00
<p>hash [ -Ldfmrv ] [ <code>name</code>[=<code>value</code>] ] ...</p>
<p>hash can be used to directly modify the contents of the command</p>
<p>A command <code>name</code> starting with a / is never hashed, whether by explicit
use of the hash command or otherwise. Such a command is always found by
direct look up in the file system.</p>
<p>Given no arguments, and neither the -r or -f options,</p>
2021-05-11 02:29:21 +02:00
<p>It will be subsequently rebuilt in the normal fashion. all the absolute
2022-08-24 15:22:41 +02:00
directories in the PATH, These two options cannot be used with any
2021-05-11 02:29:21 +02:00
arguments.</p>
2022-08-24 15:22:41 +02:00
<p>The -m option causes the arguments to be taken as patterns matching
2021-05-11 02:29:21 +02:00
those patterns are printed. This is the only way to display</p>
<p>For each <code>name</code> with a corresponding <code>value</code>, put <code>name</code> in whenever
<code>name</code> is used as a command argument, the shell will try to execute
the file given by <code>value</code>. that <code>value</code> may be referred to as
2022-08-24 15:22:41 +02:00
~<code>name</code>.</p>
<p>For each <code>name</code> with no checking what the appropriate value is in the
2021-05-11 02:29:21 +02:00
normal manner for</p>
2022-08-24 15:22:41 +02:00
<p>added by explicit specification. If has no effect if used with -f.</p>
2021-05-11 02:29:21 +02:00
<p>the form of a call to hash.</p>
<p><span id="index-history-1"></span></p>
2022-08-24 15:22:41 +02:00
<p>history</p>
<p>Same as fc -l.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-integer"></span></p>
2022-08-24 15:22:41 +02:00
<p>integer [ {+|-}Hghlprtux ] [ {+|-}LRZi [ <code>n</code> ] ] [
<code>name</code>[=<code>value</code>] ... ]</p>
<p>Equivalent to typeset -i, except that options irrelevant to integers are
not permitted.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-jobs-1"></span></p>
2022-08-24 15:22:41 +02:00
<p>jobs [ -dlprs ] [ <code>job</code> ... ]</p>
<p>jobs -Z <code>string</code></p>
2021-05-11 02:29:21 +02:00
<p>Lists information about each given job, or all jobs if <code>job</code> is omitted.
2022-08-24 15:22:41 +02:00
The -l flag lists process IDs, and the -p flag lists process groups. If
the -r flag is specified only running jobs will be listed and if the -s
flag is given only stopped jobs are shown. If the -d flag is given, the
directory from which the job was started (which may not be the current
directory of the job) will also be shown.</p>
<p>The -Z option replaces the shells argument and environment space with
2021-05-11 02:29:21 +02:00
the given string, truncated if necessary to fit. This will normally be
2022-08-24 15:22:41 +02:00
visible in ps (ps(1)) listings. This feature is typically used by
daemons, to indicate their state.</p>
<p>Full job control is only available in the top-level interactive shell,
not in commands run in the left hand side of pipelines or within the
(<code>...</code>) construct. However, a snapshot of the job state at that point is
taken, so it is still possible to use the jobs builtin, or any parameter
providing job information. This gives information about the state of
jobs at the point the subshell was created. If background processes are
created within the subshell, then instead information about those
processes is provided.</p>
<p>For example,</p>
<div class="example">
<pre><code class="language-zsh">sleep 10 &amp; # Job in background
( # Shell forks
jobs # Shows information about &quot;sleep 10 &amp;&quot;
sleep 5 &amp; # Process in background (no job control)
jobs # Shows information about &quot;sleep 5 &amp;&quot;
)
</code></pre>
</div>
2021-05-11 02:29:21 +02:00
<p><span id="index-kill"></span> <span id="index-killing-jobs"></span>
<span id="index-jobs_002c-killing"></span></p>
2022-08-24 15:22:41 +02:00
<p>kill [ -s <code>signal_name</code> | -n <code>signal_number</code> | -<code>sig</code> ] <code>job</code> ...</p>
<p>kill -l [ <code>sig</code> ... ]</p>
<p>Sends either SIGTERM or the specified signal to the given jobs or
2021-05-11 02:29:21 +02:00
processes. Signals are given by number or by names, with or without the
2022-08-24 15:22:41 +02:00
SIG prefix. If the signal being sent is not KILL or CONT, then the
job will be sent a CONT signal if it is stopped. The argument <code>job</code>
can be the process ID of a job not in the job list. In the second form,
kill -l, if <code>sig</code> is not specified the signal names are listed.
Otherwise, for each <code>sig</code> that is a name, the corresponding signal
number is listed. For each <code>sig</code> that is a signal number or a number
representing the exit status of a process which was terminated or
2021-05-11 02:29:21 +02:00
stopped by a signal the name of the signal is printed.</p>
<p>On some systems, alternative signal names are allowed for a few signals.
2022-08-24 15:22:41 +02:00
Typical examples are SIGCHLD and SIGCLD or SIGPOLL and SIGIO, assuming
they correspond to the same signal number. kill -l will only list the
preferred form, however kill -l <code>alt</code> will show if the alternative form
corresponds to a signal number. For example, under Linux kill -l IO and
kill -l POLL both output 29, hence kill -IO and kill -POLL have the same
effect.</p>
2021-05-11 02:29:21 +02:00
<p>Many systems will allow process IDs to be negative to kill a process
group or zero to kill the current process group.</p>
<p><span id="index-let"></span></p>
2022-08-24 15:22:41 +02:00
<p>let <code>arg</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>Evaluate each <code>arg</code> as an arithmetic expression. See <a href="Arithmetic-Evaluation.html#Arithmetic-Evaluation">Arithmetic
Evaluation</a> for a
description of arithmetic expressions. The exit status is 0 if the value
of the last expression is nonzero, 1 if it is zero, and 2 if an error
occurred.</p>
<p><span id="index-limit"></span> <span id="index-resource-limits"></span>
<span id="index-limits_002c-resource"></span></p>
2022-08-24 15:22:41 +02:00
<p>limit [ -hs ] [ <code>resource</code> [ <code>limit</code> ] ] ...</p>
<p>Set or display resource limits. Unless the -s flag is given, the limit
applies only the children of the shell. If -s is given without other
2021-05-11 02:29:21 +02:00
arguments, the resource limits of the current shell is set to the
previously set resource limits of the children.</p>
<p>If <code>limit</code> is not specified, print the current limit placed on
2022-08-24 15:22:41 +02:00
<code>resource</code>, otherwise set the limit to the specified value. If the -h
2021-05-11 02:29:21 +02:00
flag is given, use hard limits instead of soft limits. If no <code>resource</code>
is given, print all limits.</p>
<p>When looping over multiple resources, the shell will abort immediately
if it detects a badly formed argument. However, if it fails to set a
limit for some other reason it will continue trying to set the remaining
limits.</p>
<p><code>resource</code> can be one of:</p>
2022-08-24 15:22:41 +02:00
<p>addressspace<br />
2021-05-11 02:29:21 +02:00
Maximum amount of address space used.</p>
2022-08-24 15:22:41 +02:00
<p>aiomemorylocked<br />
2021-05-11 02:29:21 +02:00
Maximum amount of memory locked in RAM for AIO operations.</p>
2022-08-24 15:22:41 +02:00
<p>aiooperations<br />
2021-05-11 02:29:21 +02:00
Maximum number of AIO operations.</p>
2022-08-24 15:22:41 +02:00
<p>cachedthreads<br />
2021-05-11 02:29:21 +02:00
Maximum number of cached threads.</p>
2022-08-24 15:22:41 +02:00
<p>coredumpsize<br />
2021-05-11 02:29:21 +02:00
Maximum size of a core dump.</p>
2022-08-24 15:22:41 +02:00
<p>cputime<br />
2021-05-11 02:29:21 +02:00
Maximum CPU seconds per process.</p>
2022-08-24 15:22:41 +02:00
<p>datasize<br />
2021-05-11 02:29:21 +02:00
Maximum data size (including stack) for each process.</p>
2022-08-24 15:22:41 +02:00
<p>descriptors<br />
2021-05-11 02:29:21 +02:00
Maximum value for a file descriptor.</p>
2022-08-24 15:22:41 +02:00
<p>filesize<br />
2021-05-11 02:29:21 +02:00
Largest single file allowed.</p>
2022-08-24 15:22:41 +02:00
<p>kqueues<br />
2021-05-11 02:29:21 +02:00
Maximum number of kqueues allocated.</p>
2022-08-24 15:22:41 +02:00
<p>maxproc<br />
2021-05-11 02:29:21 +02:00
Maximum number of processes.</p>
2022-08-24 15:22:41 +02:00
<p>maxpthreads<br />
2021-05-11 02:29:21 +02:00
Maximum number of threads per process.</p>
2022-08-24 15:22:41 +02:00
<p>memorylocked<br />
2021-05-11 02:29:21 +02:00
Maximum amount of memory locked in RAM.</p>
2022-08-24 15:22:41 +02:00
<p>memoryuse<br />
2021-05-11 02:29:21 +02:00
Maximum resident set size.</p>
2022-08-24 15:22:41 +02:00
<p>msgqueue<br />
2021-05-11 02:29:21 +02:00
Maximum number of bytes in POSIX message queues.</p>
2022-08-24 15:22:41 +02:00
<p>posixlocks<br />
2021-05-11 02:29:21 +02:00
Maximum number of POSIX locks per user.</p>
2022-08-24 15:22:41 +02:00
<p>pseudoterminals<br />
2021-05-11 02:29:21 +02:00
Maximum number of pseudo-terminals.</p>
2022-08-24 15:22:41 +02:00
<p>resident<br />
2021-05-11 02:29:21 +02:00
Maximum resident set size.</p>
2022-08-24 15:22:41 +02:00
<p>sigpending<br />
2021-05-11 02:29:21 +02:00
Maximum number of pending signals.</p>
2022-08-24 15:22:41 +02:00
<p>sockbufsize<br />
2021-05-11 02:29:21 +02:00
Maximum size of all socket buffers.</p>
2022-08-24 15:22:41 +02:00
<p>stacksize<br />
2021-05-11 02:29:21 +02:00
Maximum stack size for each process.</p>
2022-08-24 15:22:41 +02:00
<p>swapsize<br />
2021-05-11 02:29:21 +02:00
Maximum amount of swap used.</p>
2022-08-24 15:22:41 +02:00
<p>vmemorysize<br />
2021-05-11 02:29:21 +02:00
Maximum amount of virtual memory.</p>
<p>Which of these resource limits are available depends on the system.
<code>resource</code> can be abbreviated to any unambiguous prefix. It can also be
an integer, which corresponds to the integer defined for the resource by
the operating system.</p>
<p>If argument corresponds to a number which is out of the range of the
resources configured into the shell, the shell will try to read or write
the limit anyway, and will report an error if this fails. As the shell
does not store such resources internally, an attempt to set the limit
2022-08-24 15:22:41 +02:00
will fail unless the -s option is present.</p>
2021-05-11 02:29:21 +02:00
<p><code>limit</code> is a number, with an optional scaling factor, as follows:</p>
2022-08-24 15:22:41 +02:00
<p><code>n</code>h<br />
2021-05-11 02:29:21 +02:00
hours</p>
2022-08-24 15:22:41 +02:00
<p><code>n</code>k<br />
2021-05-11 02:29:21 +02:00
kilobytes (default)</p>
2022-08-24 15:22:41 +02:00
<p><code>n</code>m<br />
2021-05-11 02:29:21 +02:00
megabytes or minutes</p>
2022-08-24 15:22:41 +02:00
<p><code>n</code>g<br />
2021-05-11 02:29:21 +02:00
gigabytes</p>
2022-08-24 15:22:41 +02:00
<p>[<code>mm</code>:]<code>ss</code><br />
2021-05-11 02:29:21 +02:00
minutes and seconds</p>
2022-08-24 15:22:41 +02:00
<p>The limit command is not made available by default when the shell starts
in a mode emulating another shell. It can be made available with the
command zmodload -F zsh/rlimits b:limit.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-local"></span></p>
2022-08-24 15:22:41 +02:00
<p>local [ {+|-}AHUahlprtux ] [ {+|-}EFLRZi [ <code>n</code> ] ] [
<code>name</code>[=<code>value</code>] ... ]</p>
<p>Same as typeset, except that the options -g, and -f are not permitted.
In this case the -x option does not force the use of -g, i.e. exported
variables will be local to functions.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-logout"></span></p>
2022-08-24 15:22:41 +02:00
<p>logout [ <code>n</code> ]</p>
<p>Same as exit, except that it only works in a login shell.</p>
<p>noglob <code>simple command</code></p>
2021-05-11 02:29:21 +02:00
<p>See <a href="Shell-Grammar.html#Precommand-Modifiers">Precommand Modifiers</a>.</p>
<p><span id="index-popd"></span></p>
2022-08-24 15:22:41 +02:00
<p>popd [ -q ] [ {+|-}<code>n</code> ]</p>
<p>Remove an entry from the directory stack, and perform a cd to the new
2021-05-11 02:29:21 +02:00
top directory. With no argument, the current top entry is removed. An
2022-08-24 15:22:41 +02:00
argument of the form +<code>n</code> identifies a stack entry by counting from
the left of the list shown by the dirs command, starting with zero. An
argument of the form -<code>n</code> counts from the right. <span
id="index-PUSHD_005fMINUS_002c-use-of-1"></span> If the PUSHD_MINUS
option is set, the meanings of + and - in this context are swapped.</p>
<p>If the -q (quiet) option is specified, the hook function chpwd and the
functions in the array $chpwd_functions are not called, and the new
directory stack is not printed. This is useful for calls to popd that do
not change the environment seen by an interactive user.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-print"></span></p>
2022-08-24 15:22:41 +02:00
<p>print [ -abcDilmnNoOpPrsSz ] [ -u <code>n</code> ] [ -f <code>format</code> ] [ -C
<code>cols</code> ]</p>
<p>      [ -v <code>name</code> ] [ -xX <code>tabstop</code> ] [ -R [ -en ]] [ <code>arg</code> ...
]</p>
<p>With the -f option the arguments are printed as described by printf.
With no flags or with the flag -, the arguments are printed on the
standard output as described by echo, with the following differences:
the escape sequence \M-<code>x</code> (or \M<code>x</code>) metafies the character <code>x</code>
(sets the highest bit), \C-<code>x</code> (or \C<code>x</code>) produces a control
character (\C-@ and \C-? give the characters NULL and delete), a
character code in octal is represented by \<code>NNN</code> (instead of
\0<code>NNN</code>), and \E is a synonym for \e. Finally, if not in an
escape sequence, \ escapes the following character and is not
printed.</p>
<p>-a<br />
Print arguments with the column incrementing first. Only useful with the
-c and -C options.</p>
<p>-b<br />
Recognize all the escape sequences defined for the bindkey command, see
<a href="Zsh-Line-Editor.html#Zle-Builtins">Zle Builtins</a>.</p>
<p>-c<br />
Print the arguments in columns. Unless -a is also given, arguments are
printed with the row incrementing first.</p>
<p>-C <code>cols</code><br />
Print the arguments in <code>cols</code> columns. Unless -a is also given,
2021-05-11 02:29:21 +02:00
arguments are printed with the row incrementing first.</p>
2022-08-24 15:22:41 +02:00
<p>-D<br />
Treat the arguments as paths, replacing directory prefixes with ~
2021-05-11 02:29:21 +02:00
expressions corresponding to directory names, as appropriate.</p>
2022-08-24 15:22:41 +02:00
<p>-i<br />
If given together with -o or -O, sorting is performed
2021-05-11 02:29:21 +02:00
case-independently.</p>
2022-08-24 15:22:41 +02:00
<p>-l<br />
Print the arguments separated by newlines instead of spaces. Note: if
the list of arguments is empty, print -l will still output one empty
line. To print a possibly-empty list of arguments one per line, use
print -C1, as in print -rC1 &quot;$list[@]&quot;.</p>
<p>-m<br />
Take the first argument as a pattern (should be quoted), and remove it
from the argument list together with subsequent arguments that do not
match this pattern.</p>
<p>-n<br />
2021-05-11 02:29:21 +02:00
Do not add a newline to the output.</p>
2022-08-24 15:22:41 +02:00
<p>-N<br />
Print the arguments separated and terminated by nulls. Again, print
-rNC1 &quot;$list[@]&quot; is a canonical way to print an arbitrary list as
2021-05-11 02:29:21 +02:00
null-delimited records.</p>
2022-08-24 15:22:41 +02:00
<p>-o<br />
2021-05-11 02:29:21 +02:00
Print the arguments sorted in ascending order.</p>
2022-08-24 15:22:41 +02:00
<p>-O<br />
2021-05-11 02:29:21 +02:00
Print the arguments sorted in descending order.</p>
2022-08-24 15:22:41 +02:00
<p>-p<br />
2021-05-11 02:29:21 +02:00
Print the arguments to the input of the coprocess.</p>
2022-08-24 15:22:41 +02:00
<p>-P<br />
2021-05-11 02:29:21 +02:00
Perform prompt expansion (see <a href="Prompt-Expansion.html#Prompt-Expansion">Prompt
2022-08-24 15:22:41 +02:00
Expansion</a>). In combination with
-f, prompt escape sequences are parsed only within interpolated
arguments, not within the format string.</p>
<p>-r<br />
Ignore the escape conventions of echo.</p>
<p>-R<br />
Emulate the BSD echo command, which does not process escape sequences
unless the -e flag is given. The -n flag suppresses the trailing
newline. Only the -e and -n flags are recognized after -R; all other
arguments and options are printed.</p>
<p>-s<br />
Place the results in the history list instead of on the standard output.
Each argument to the print command is treated as a single word in the
history, regardless of its content.</p>
<p>-S<br />
Place the results in the history list instead of on the standard output.
In this case only a single argument is allowed; it will be split into
words as if it were a full shell command line. The effect is similar to
reading the line from a history file with the HIST_LEX_WORDS option
active.</p>
<p>-u <code>n</code><br />
2021-05-11 02:29:21 +02:00
Print the arguments to file descriptor <code>n</code>.</p>
2022-08-24 15:22:41 +02:00
<p>-v <code>name</code><br />
2021-05-11 02:29:21 +02:00
Store the printed arguments as the value of the parameter <code>name</code>.</p>
2022-08-24 15:22:41 +02:00
<p>-x <code>tab-stop</code><br />
2021-05-11 02:29:21 +02:00
Expand leading tabs on each line of output in the printed string
2022-08-24 15:22:41 +02:00
assuming a tab stop every <code>tab-stop</code> characters. This is appropriate for
formatting code that may be indented with tabs. Note that leading tabs
of any argument to print, not just the first, are expanded, even if
print is using spaces to separate arguments (the column count is
maintained across arguments but may be incorrect on output owing to
previous unexpanded tabs).</p>
<p>The start of the output of each print command is assumed to be aligned
with a tab stop. Widths of multibyte characters are handled if the
option MULTIBYTE is in effect. This option is ignored if other
formatting options are in effect, namely column alignment or printf
style, or if output is to a special location such as shell history or
the command line editor.</p>
<p>-X <code>tab-stop</code><br />
This is similar to -x, except that all tabs in the printed string are
expanded. This is appropriate if tabs in the arguments are</p>
<p>-z<br />
Push the arguments onto the editing buffer stack, separated by spaces.</p>
<p>If any of -m, -o or -O are used in combination with -f and there
are no arguments (after the removal process in the case of -m) then
nothing is printed.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-printf"></span></p>
2022-08-24 15:22:41 +02:00
<p>printf [ -v <code>name</code> ] <code>format</code> [ <code>arg</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>Print the arguments according to the format specification. Formatting
2022-08-24 15:22:41 +02:00
rules are the same as used in C. The same escape sequences as for echo
2021-05-11 02:29:21 +02:00
are recognised in the format. All C conversion specifications ending in
2022-08-24 15:22:41 +02:00
one of csdiouxXeEfgGn are handled. In addition to this, %b can be used
instead of %s to cause escape sequences in the argument to be
recognised and %q can be used to quote the argument in such a way that
allows it to be reused as shell input. With the numeric format
2021-05-11 02:29:21 +02:00
specifiers, if the corresponding argument starts with a quote character,
the numeric value of the following character is used as the number to
print; otherwise the argument is evaluated as an arithmetic expression.
See <a href="Arithmetic-Evaluation.html#Arithmetic-Evaluation">Arithmetic
Evaluation</a> for a
2022-08-24 15:22:41 +02:00
description of arithmetic expressions. With %n, the corresponding
2021-05-11 02:29:21 +02:00
argument is taken as an identifier which is created as an integer
parameter.</p>
<p>Normally, conversion specifications are applied to each argument in
order but they can explicitly specify the <code>n</code>th argument is to be used
2022-08-24 15:22:41 +02:00
by replacing % by %<code>n</code>$ and * by *<code>n</code>$. It is recommended that
you do not mix references of this explicit style with the normal style
and the handling of such mixed styles may be subject to future change.</p>
2021-05-11 02:29:21 +02:00
<p>If arguments remain unused after formatting, the format string is reused
2022-08-24 15:22:41 +02:00
until all arguments have been consumed. With the print builtin, this can
be suppressed by using the -r option. If more arguments are required by
the format than have been specified, the behaviour is as if zero or an
empty string had been specified as the argument.</p>
<p>The -v option causes the output to be stored as the value of the
2021-05-11 02:29:21 +02:00
parameter <code>name</code>, instead of printed. If <code>name</code> is an array and the
format string is reused when consuming arguments then one array element
will be used for each use of the format string.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-pushd"></span> <span
id="index-PUSHD_005fTO_005fHOME_002c-use-of"></span> <span
id="index-PUSHD_005fMINUS_002c-use-of-2"></span> <span
id="index-CDABLE_005fVARS_002c-use-of"></span> <span
id="index-PUSHD_005fSILENT_002c-use-of"></span></p>
<p>pushd [ -qsLP ] [ <code>arg</code> ]</p>
<p>pushd [ -qsLP ] <code>old</code> <code>new</code></p>
<p>pushd [ -qsLP ] {+|-}<code>n</code></p>
2021-05-11 02:29:21 +02:00
<p>Change the current directory, and push the old current directory onto
the directory stack. In the first form, change the current directory to
<code>arg</code>. If <code>arg</code> is not specified, change to the second directory on the
2022-08-24 15:22:41 +02:00
stack (that is, exchange the top two entries), or change to $HOME if the
PUSHD_TO_HOME option is set or if there is only one entry on the stack.
Otherwise, <code>arg</code> is interpreted as it would be by cd. The meaning of
<code>old</code> and <code>new</code> in the second form is also the same as for cd.</p>
<p>The third form of pushd changes directory by rotating the directory
list. An argument of the form +<code>n</code> identifies a stack entry by
counting from the left of the list shown by the dirs command, starting
with zero. An argument of the form -<code>n</code> counts from the right. If the
PUSHD_MINUS option is set, the meanings of + and - in this context
are swapped.</p>
<p>If the -q (quiet) option is specified, the hook function chpwd and the
functions in the array $chpwd_functions are not called, and the new
directory stack is not printed. This is useful for calls to pushd that
do not change the environment seen by an interactive user.</p>
<p>If the option -q is not specified and the shell option PUSHD_SILENT is
not set, the directory stack will be printed after a pushd is performed.</p>
<p>The options -s, -L and -P have the same meanings as for the cd builtin.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-pushln"></span></p>
2022-08-24 15:22:41 +02:00
<p>pushln [ <code>arg</code> ... ]</p>
<p>Equivalent to print -nz.</p>
<p><span id="index-pwd"></span> <span
id="index-CHASE_005fLINKS_002c-use-of"></span></p>
<p>pwd [ -rLP ]</p>
<p>Print the absolute pathname of the current working directory. If the -r
or the -P flag is specified, or the CHASE_LINKS option is set and the -L
flag is not given, the printed path will not contain symbolic links.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-r"></span></p>
2022-08-24 15:22:41 +02:00
<p>r</p>
<p>Same as fc -e -.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-read"></span> <span id="index-IFS_002c-use-of-2"></span></p>
2022-08-24 15:22:41 +02:00
<p>read [ -rszpqAclneE ] [ -t [ <code>num</code> ] ] [ -k [ <code>num</code> ] ] [ -d
<code>delim</code> ]</p>
<p>     [ -u <code>n</code> ] [ [<code>name</code>][?<code>prompt</code>] ] [ <code>name</code> ... ]</p>
<p><span id="index-REPLY_002c-use-of-2"></span> <span
id="index-reply_002c-use-of-1"></span></p>
<p>Read one line and break it into fields using the characters in $IFS as
2021-05-11 02:29:21 +02:00
separators, except as noted below. The first field is assigned to the
first <code>name</code>, the second field to the second <code>name</code>, etc., with leftover
2022-08-24 15:22:41 +02:00
fields assigned to the last <code>name</code>. If <code>name</code> is omitted then REPLY is
used for scalars and reply for arrays.</p>
<p>-r<br />
Raw mode: a \ at the end of a line does not signify line continuation
and backslashes in the line dont quote the following character and are
not removed.</p>
<p>-s<br />
2021-05-11 02:29:21 +02:00
Dont echo back characters if reading from the terminal.</p>
2022-08-24 15:22:41 +02:00
<p>-q<br />
Read only one character from the terminal and set <code>name</code> to y if this
character was y or Y and to n otherwise. With this flag set the
return status is zero only if the character was y or Y. This option
may be used with a timeout (see -t); if the read times out, or
encounters end of file, status 2 is returned. Input is read from the
terminal unless one of -u or -p is present. This option may also be used
within zle widgets.</p>
<p>-k [ <code>num</code> ]<br />
2021-05-11 02:29:21 +02:00
Read only one (or <code>num</code>) characters. All are assigned to the first
2022-08-24 15:22:41 +02:00
<code>name</code>, without word splitting. This flag is ignored when -q is present.
Input is read from the terminal unless one of -u or -p is present. This
option may also be used within zle widgets.</p>
2021-05-11 02:29:21 +02:00
<p>Note that despite the mnemonic key this option does read full
2022-08-24 15:22:41 +02:00
characters, which may consist of multiple bytes if the option MULTIBYTE
is set.</p>
<p>-z<br />
Read one entry from the editor buffer stack and assign it to the first
<code>name</code>, without word splitting. Text is pushed onto the stack with
print -z or with push-line from the line editor (see <a href="Zsh-Line-Editor.html#Zsh-Line-Editor">Zsh Line
Editor</a>). This flag is ignored
when the -k or -q flags are present.</p>
<p>-e<br />
-E<br />
The input read is printed (echoed) to the standard output. If the -e
flag is used, no input is assigned to the parameters.</p>
<p>-A<br />
2021-05-11 02:29:21 +02:00
The first <code>name</code> is taken as the name of an array and all words are
assigned to it.</p>
2022-08-24 15:22:41 +02:00
<p>-c<br />
-l<br />
2021-05-11 02:29:21 +02:00
These flags are allowed only if called inside a function used for
2022-08-24 15:22:41 +02:00
completion (specified with the -K flag to compctl). If the -c flag is
given, the words of the current command are read. If the -l flag is
given, the whole line is assigned as a scalar. If both flags are
present, -l is used and -c is ignored.</p>
<p>-n<br />
Together with -c, the number of the word the cursor is on is read. With
-l, the index of the character the cursor is on is read. Note that the
command name is word number 1, not word 0, and that when the cursor is
at the end of the line, its character index is the length of the line
plus one.</p>
<p>-u <code>n</code><br />
2021-05-11 02:29:21 +02:00
Input is read from file descriptor <code>n</code>.</p>
2022-08-24 15:22:41 +02:00
<p>-p<br />
2021-05-11 02:29:21 +02:00
Input is read from the coprocess.</p>
2022-08-24 15:22:41 +02:00
<p>-d <code>delim</code><br />
2021-05-11 02:29:21 +02:00
Input is terminated by the first character of <code>delim</code> instead of by
newline.</p>
2022-08-24 15:22:41 +02:00
<p>-t [ <code>num</code> ]<br />
2021-05-11 02:29:21 +02:00
Test if input is available before attempting to read. If <code>num</code> is
present, it must begin with a digit and will be evaluated to give a
2022-08-24 15:22:41 +02:00
number of seconds, which may be a floating point number; in this case
the read times out if input is not available within this time. If <code>num</code>
is not present, it is taken to be zero, so that read returns immediately
if no input is available. If no input is available, return status 1 and
do not set any variables.</p>
<p>This option is not available when reading from the editor buffer with
-z, when called from within completion with -c or -l, with -q which
clears the input queue before reading, or within zle where other
mechanisms should be used to test for input.</p>
<p>Note that read does not attempt to alter the input processing mode. The
default mode is canonical input, in which an entire line is read at a
time, so usually read -t will not read anything until an entire line
has been typed. However, when reading from the terminal with -k input is
processed one key at a time; in this case, only availability of the
first character is tested, so that e.g. read -t -k 2 can still block
on the second character. Use two instances of read -t -k if this is
not what is wanted.</p>
<p>If the first argument contains a ?, the remainder of this word is used
as a <code>prompt</code> on standard error when the shell is interactive.</p>
<p>The value (exit status) of read is 1 when an end-of-file is encountered,
or when -c or -l is present and the command is not called from a compctl
function, or as described for -q. Otherwise the value is 0.</p>
<p>The behavior of some combinations of the -k, -p, -q, -u and -z flags is
undefined. Presently -q cancels all the others, -p cancels -u, -k
cancels -z, and otherwise -z cancels both -p and -u.</p>
<p>The -c or -l flags cancel any and all of -kpquz.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-parameters_002c-marking-readonly"></span></p>
2022-08-24 15:22:41 +02:00
<p>readonly</p>
<p>Same as typeset -r. With the POSIX_BUILTINS option set, same as typeset
-gr.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-rehash"></span></p>
2022-08-24 15:22:41 +02:00
<p>rehash</p>
<p>Same as hash -r.</p>
<p><span id="index-return"></span> <span
id="index-functions_002c-returning-from"></span></p>
<p>return [ <code>n</code> ]</p>
<p>Causes a shell function or . script to return to the invoking script
with the return status specified by an arithmetic expression <code>n</code>. For
example, the following prints 42:</p>
<div class="example">
<pre><code class="language-zsh">() { integer foo=40; return &quot;foo + 2&quot; }
echo $?
</code></pre>
</div>
<p>If <code>n</code> is omitted, the return status is that of the last command
executed.</p>
<p>If return was executed from a trap in a TRAP<code>NAL</code> function, the effect
is different for zero and non-zero return status. With zero status (or
after an implicit return at the end of the trap), the shell will return
to whatever it was previously processing; with a non-zero status, the
shell will behave as interrupted except that the return status of the
trap is retained. Note that the numeric value of the signal which caused
the trap is passed as the first argument, so the statement return
&quot;128+$1&quot; will return the same status as if the signal had not been
trapped.</p>
<p>sched</p>
2021-05-11 02:29:21 +02:00
<p>See <a href="Zsh-Modules.html#The-zsh_002fsched-Module">The zsh/sched Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-set"></span> <span
id="index-parameters_002c-listing"></span> <span
id="index-parameters_002c-positional"></span> <span
id="index-parameters_002c-setting-array"></span> <span
id="index-array-parameters_002c-setting"></span> <span
id="index-KSH_005fARRAYS_002c-use-of-1"></span></p>
<p>set [ {+|-}<code>options</code> | {+|-}o [ <code>option_name</code> ] ] ... [ {+|-}A
[ <code>name</code> ] ]</p>
<p>    [ <code>arg</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>Set the options for the shell and/or set the positional parameters, or
2022-08-24 15:22:41 +02:00
declare and set an array. If the -s option is given, it causes the
2021-05-11 02:29:21 +02:00
specified arguments to be sorted before assigning them to the positional
2022-08-24 15:22:41 +02:00
parameters (or to the array <code>name</code> if -A is used). With +s sort
2021-05-11 02:29:21 +02:00
arguments in descending order. For the meaning of the other flags, see
<a href="Options.html#Options">Options</a>. Flags may be specified by name using
2022-08-24 15:22:41 +02:00
the -o option. If no option name is supplied with -o, the current option
states are printed: see the description of setopt below for more
information on the format. With +o they are printed in a form that can
be used as input to the shell.</p>
<p>If the -A flag is specified, <code>name</code> is set to an array containing the
2021-05-11 02:29:21 +02:00
given <code>arg</code>s; if no <code>name</code> is specified, all arrays are printed together
with their values.</p>
2022-08-24 15:22:41 +02:00
<p>If +A is used and <code>name</code> is an array, the given arguments will replace
2021-05-11 02:29:21 +02:00
the initial elements of that array; if no <code>name</code> is specified, all
arrays are printed without their values.</p>
2022-08-24 15:22:41 +02:00
<p>The behaviour of arguments after -A <code>name</code> or +A <code>name</code> depends on
whether the option KSH_ARRAYS is set. If it is not set, all arguments
2021-05-11 02:29:21 +02:00
following <code>name</code> are treated as values for the array, regardless of
their form. If the option is set, normal option processing continues at
that point; only regular arguments are treated as values for the array.
This means that</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">set -A array -x -- foo
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>sets array to -x -- foo if KSH_ARRAYS is not set, but sets the array
to foo and turns on the option -x if it is set.</p>
<p>If the -A flag is not present, but there are arguments beyond the
2021-05-11 02:29:21 +02:00
options, the positional parameters are set. If the option list (if any)
2022-08-24 15:22:41 +02:00
is terminated by --, and there are no further arguments, the
2021-05-11 02:29:21 +02:00
positional parameters will be unset.</p>
2022-08-24 15:22:41 +02:00
<p>If no arguments and no -- are given, then the names and values of all
parameters are printed on the standard output. If the only argument is
+, the names of all parameters are printed.</p>
<p>For historical reasons, set - is treated as set +xv and set -
<code>args</code> as set +xv <code>args</code> when in any other emulation mode than
2021-05-11 02:29:21 +02:00
zshs native mode.</p>
2022-08-24 15:22:41 +02:00
<p>setcap</p>
2021-05-11 02:29:21 +02:00
<p>See <a href="Zsh-Modules.html#The-zsh_002fcap-Module">The zsh/cap Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-setopt"></span> <span
id="index-options_002c-setting"></span></p>
<p>setopt [ {+|-}<code>options</code> | {+|-}o <code>option_name</code> ] [ -m ] [ <code>name</code>
... ]</p>
2021-05-11 02:29:21 +02:00
<p>Set the options for the shell. All options specified either with flags
or by name are set.</p>
<p>If no arguments are supplied, the names of all options currently set are
printed. The form is chosen so as to minimize the differences from the
default options for the current emulation (the default emulation being
2022-08-24 15:22:41 +02:00
native zsh, shown as &lt;Z&gt; in <a href="Options.html#Description-of-Options">Description of
2021-05-11 02:29:21 +02:00
Options</a>). Options that are on by
2022-08-24 15:22:41 +02:00
default for the emulation are shown with the prefix no only if they are
off, while other options are shown without the prefix no and only if
they are on. In addition to options changed from the default state by
2021-05-11 02:29:21 +02:00
the user, any options activated automatically by the shell (for example,
2022-08-24 15:22:41 +02:00
SHIN_STDIN or INTERACTIVE) will be shown in the list. The format is
further modified by the option KSH_OPTION_PRINT, however the rationale
for choosing options with or without the no prefix remains the same in
2021-05-11 02:29:21 +02:00
this case.</p>
2022-08-24 15:22:41 +02:00
<p>If the -m flag is given the arguments are taken as patterns (which
2021-05-11 02:29:21 +02:00
should be quoted to protect them from filename expansion), and all
options with names matching these patterns are set.</p>
<p>Note that a bad option name does not cause execution of subsequent shell
2022-08-24 15:22:41 +02:00
code to be aborted; this is behaviour is different from that of set
-o. This is because set is regarded as a special builtin by the POSIX
standard, but setopt is not.</p>
<p><span id="index-shift"></span> <span
id="index-parameters_002c-positional-1"></span></p>
<p>shift [ -p ] [ <code>n</code> ] [ <code>name</code> ... ]</p>
<p>The positional parameters ${<code>n</code>+1} ... are renamed to $1 ..., where <code>n</code>
is an arithmetic expression that defaults to 1. If any <code>name</code>s are given
then the arrays with these names are shifted instead of the positional
parameters.</p>
<p>If the option -p is given arguments are instead removed (popped) from
2021-05-11 02:29:21 +02:00
the end rather than the start of the array.</p>
<p><span id="index-source"></span></p>
2022-08-24 15:22:41 +02:00
<p>source <code>file</code> [ <code>arg</code> ... ]</p>
<p>Same as ., except that the current directory is always searched and is
always searched first, before directories in $path.</p>
<p>stat</p>
2021-05-11 02:29:21 +02:00
<p>See <a href="Zsh-Modules.html#The-zsh_002fstat-Module">The zsh/stat Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-suspend"></span> <span
id="index-shell_002c-suspending"></span> <span
id="index-suspending-the-shell"></span></p>
<p>suspend [ -f ]</p>
<p>Suspend the execution of the shell (send it a SIGTSTP) until it receives
a SIGCONT. Unless the -f option is given, this will refuse to suspend a
login shell.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-test"></span></p>
2022-08-24 15:22:41 +02:00
<p>test [ <code>arg</code> ... ]</p>
<p>[ [ <code>arg</code> ... ] ]</p>
<p>Like the system version of test. Added for compatibility; use
2021-05-11 02:29:21 +02:00
conditional expressions instead (see <a href="Conditional-Expressions.html#Conditional-Expressions">Conditional
Expressions</a>). The
2022-08-24 15:22:41 +02:00
main differences between the conditional expression syntax and the test
and [ builtins are: these commands are not handled syntactically, so
for example an empty variable expansion may cause an argument to be
omitted; syntax errors cause status 2 to be returned instead of a shell
error; and arithmetic operators expect integer arguments rather than
arithmetic expressions.</p>
2021-05-11 02:29:21 +02:00
<p>The command attempts to implement POSIX and its extensions where these
are specified. Unfortunately there are intrinsic ambiguities in the
syntax; in particular there is no distinction between test operators and
strings that resemble them. The standard attempts to resolve these for
small numbers of arguments (up to four); for five or more arguments
compatibility cannot be relied on. Users are urged wherever possible to
2022-08-24 15:22:41 +02:00
use the [[ test syntax which does not have these ambiguities.</p>
<p><span id="index-times"></span> <span
id="index-shell_002c-timing"></span> <span
id="index-timing-the-shell"></span></p>
<p>times</p>
2021-05-11 02:29:21 +02:00
<p>Print the accumulated user and system times for the shell and for
processes run from the shell.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-trap"></span> <span
id="index-signals_002c-trapping-1"></span> <span
id="index-trapping-signals-1"></span></p>
<p>trap [ <code>arg</code> ] [ <code>sig</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p><code>arg</code> is a series of commands (usually quoted to protect it from
immediate evaluation by the shell) to be read and executed when the
shell receives any of the signals specified by one or more <code>sig</code> args.
Each <code>sig</code> can be given as a number, or as the name of a signal either
2022-08-24 15:22:41 +02:00
with or without the string SIG in front (e.g. 1, HUP, and SIGHUP are all
the same signal).</p>
<p>If <code>arg</code> is -, then the specified signals are reset to their defaults,
or, if no <code>sig</code> args are present, all traps are reset.</p>
2021-05-11 02:29:21 +02:00
<p>If <code>arg</code> is an empty string, then the specified signals are ignored by
the shell (and by the commands it invokes).</p>
<p>If <code>arg</code> is omitted but one or more <code>sig</code> args are provided (i.e. the
first argument is a valid signal number or name), the effect is the same
2022-08-24 15:22:41 +02:00
as if <code>arg</code> had been specified as -.</p>
<p>The trap command with no arguments prints a list of commands associated
with each signal.</p>
<p>If <code>sig</code> is ZERR then <code>arg</code> will be executed after each command with a
nonzero exit status. ERR is an alias for ZERR on systems that have no
SIGERR signal (this is the usual case).</p>
<p>If <code>sig</code> is DEBUG then <code>arg</code> will be executed before each command if the
option DEBUG_BEFORE_CMD is set (as it is by default), else after each
command. Here, a command is what is described as a sublist in the
shell grammar, see <a href="Shell-Grammar.html#Simple-Commands-_0026-Pipelines">Simple Commands &amp;
2021-05-11 02:29:21 +02:00
Pipelines</a>. If
2022-08-24 15:22:41 +02:00
DEBUG_BEFORE_CMD is set various additional features are available.
2021-05-11 02:29:21 +02:00
First, it is possible to skip the next command by setting the option
2022-08-24 15:22:41 +02:00
ERR_EXIT; see the description of the ERR_EXIT option in <a href="Options.html#Description-of-Options">Description of
Options</a>. Also, the shell parameter
ZSH_DEBUG_CMD is set to the string corresponding to the command to be
executed following the trap. Note that this string is reconstructed from
the internal format and may not be formatted the same way as the
original text. The parameter is unset after the trap is executed.</p>
<p>If <code>sig</code> is 0 or EXIT and the trap statement is executed inside the body
of a function, then the command <code>arg</code> is executed after the function
completes. The value of $? at the start of execution is the exit status
of the shell or the return status of the function exiting. If <code>sig</code> is 0
or EXIT and the trap statement is not executed inside the body of a
function, then the command <code>arg</code> is executed when the shell terminates;
the trap runs before any zshexit hook functions.</p>
<p>ZERR, DEBUG, and EXIT traps are not executed inside other traps. ZERR
and DEBUG traps are kept within subshells, while other traps are reset.</p>
<p>Note that traps defined with the trap builtin are slightly different
from those defined as TRAP<code>NAL</code> () { ... }, as the latter have their
2021-05-11 02:29:21 +02:00
own function environment (line numbers, local variables, etc.) while the
former use the environment of the command in which they were called. For
example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">trap 'print $LINENO' DEBUG
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>will print the line number of a command executed after it has run, while</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">TRAPDEBUG() { print $LINENO; }
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>will always print the number zero.</p>
2022-08-24 15:22:41 +02:00
<p>Alternative signal names are allowed as described under kill above.
2021-05-11 02:29:21 +02:00
Defining a trap under either name causes any trap under an alternative
name to be removed. However, it is recommended that for consistency
users stick exclusively to one name or another.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-true"></span> <span
id="index-doing-nothing_002c-successfully"></span></p>
<p>true [ <code>arg</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>Do nothing and return an exit status of 0.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-ttyctl"></span> <span
id="index-tty_002c-freezing"></span></p>
<p>ttyctl [ -fu ]</p>
<p>The -f option freezes the tty (i.e. terminal or terminal emulator), and
-u unfreezes it. When the tty is frozen, no changes made to the tty
settings by external programs will be honored by the shell, except for
changes in the size of the screen; the shell will simply reset the
2021-05-11 02:29:21 +02:00
settings to their previous values as soon as each command exits or is
2022-08-24 15:22:41 +02:00
suspended. Thus, stty and similar programs have no effect when the tty
2021-05-11 02:29:21 +02:00
is frozen. Freezing the tty does not cause the current state to be
remembered: instead, it causes future changes to the state to be
blocked.</p>
<p>Without options it reports whether the terminal is frozen or not.</p>
<p>Note that, regardless of whether the tty is frozen or not, the shell
needs to change the settings when the line editor starts, so unfreezing
the tty does not guarantee settings made on the command line are
preserved. Strings of commands run between editing the command line will
2022-08-24 15:22:41 +02:00
see a consistent tty state. See also the shell variable STTY for a means
of initialising the tty before running external commands and/or freezing
the tty around a single command.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-type"></span></p>
2022-08-24 15:22:41 +02:00
<p>type [ -wfpamsS ] <code>name</code> ...</p>
<p>Equivalent to whence -v.</p>
<p><span id="index-typeset"></span> <span
id="index-parameters_002c-setting"></span> <span
id="index-parameters_002c-declaring"></span></p>
<p>typeset [ {+|-}AHUaghlmrtux ] [ {+|-}EFLRZip [ <code>n</code> ] ]</p>
<p>        [ + ] [ <code>name</code>[=<code>value</code>] ... ]</p>
<p>typeset -T [ {+|-}Uglrux ] [ {+|-}LRZp [ <code>n</code> ] ]</p>
<p>        [ + | <code>SCALAR</code>[=<code>value</code>] <code>array</code>[=(<code>value</code> ...)] [ <code>sep</code>
2021-05-11 02:29:21 +02:00
] ]</p>
2022-08-24 15:22:41 +02:00
<p>typeset -f [ {+|-}TUkmtuz ] [ + ] [ <code>name</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>Set or display attributes and values for shell parameters.</p>
<p>Except as noted below for control flags that change the behavior, a
parameter is created for each <code>name</code> that does not already refer to one.
When inside a function, a new parameter is created for every <code>name</code>
(even those that already exist), and is unset again when the function
completes. See <a href="Parameters.html#Local-Parameters">Local Parameters</a>. The
same rules apply to special shell parameters, which retain their special
attributes when made local.</p>
2022-08-24 15:22:41 +02:00
<p>For each <code>name</code>=<code>value</code> assignment, the parameter <code>name</code> is set to
<code>value</code>. If the assignment is omitted and <code>name</code> does <em>not</em> refer to an
existing parameter, a new parameter is intialized to empty string, zero,
or empty array (as appropriate), <em>unless</em> the shell option
TYPESET_TO_UNSET is set. When that option is set, the parameter
attributes are recorded but the parameter remains unset.</p>
<p>If the shell option TYPESET_SILENT is not set, for each remaining <code>name</code>
that refers to a parameter that is already set, the name and value of
the parameter are printed in the form of an assignment. Nothing is
printed for newly-created parameters, or when any attribute flags listed
below are given along with the <code>name</code>. Using + instead of minus to
introduce an attribute turns it off.</p>
2021-05-11 02:29:21 +02:00
<p>If no <code>name</code> is present, the names and values of all parameters are
printed. In this case the attribute flags restrict the display to only
2022-08-24 15:22:41 +02:00
those parameters that have the specified attributes, and using +
rather than - to introduce the flag suppresses printing of the values
of parameters when there is no parameter name.</p>
2021-05-11 02:29:21 +02:00
<p>All forms of the command handle scalar assignment. Array assignment is
2022-08-24 15:22:41 +02:00
possible if any of the reserved words declare, export, float, integer,
local, readonly or typeset is matched when the line is parsed (N.B. not
when it is executed). In this case the arguments are parsed as
assignments, except that the += syntax and the GLOB_ASSIGN option are
not supported, and scalar values after = are <em>not</em> split further into
words, even if expanded (regardless of the setting of the KSH_TYPESET
option; this option is obsolete).</p>
2021-05-11 02:29:21 +02:00
<p>Examples of the differences between command and reserved word parsing:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh"># Reserved word parsing
2021-05-11 02:29:21 +02:00
typeset svar=$(echo one word) avar=(several words)
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The above creates a scalar parameter svar and an array parameter avar as
if the assignments had been</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">svar=&quot;one word&quot;
2021-05-11 02:29:21 +02:00
avar=(several words)
</code></pre>
</div>
<p>On the other hand:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh"># Normal builtin interface
2021-05-11 02:29:21 +02:00
builtin typeset svar=$(echo two words)
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The builtin keyword causes the above to use the standard builtin
interface to typeset in which argument parsing is performed in the same
way as for other commands. This example creates a scalar svar containing
the value two and another scalar parameter words with no value. An array
value in this case would either cause an error or be treated as an
obscure set of glob qualifiers.</p>
2021-05-11 02:29:21 +02:00
<p>Arbitrary arguments are allowed if they take the form of assignments
after command line expansion; however, these only perform scalar
assignment:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">var='svar=val'
2021-05-11 02:29:21 +02:00
typeset $var
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The above sets the scalar parameter svar to the value val. Parentheses
around the value within var would not cause array assignment as they
will be treated as ordinary characters when $var is substituted. Any
non-trivial expansion in the name part of the assignment causes the
argument to be treated in this fashion:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">typeset {var1,var2,var3}=name
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>The above syntax is valid, and has the expected effect of setting the
three parameters to the same value, but the command line is parsed as a
2022-08-24 15:22:41 +02:00
set of three normal command line arguments to typeset after expansion.
2021-05-11 02:29:21 +02:00
Hence it is not possible to assign to multiple arrays by this means.</p>
2022-08-24 15:22:41 +02:00
<p>Note that each interface to any of the commands may be disabled
separately. For example, disable -r typeset disables the reserved word
interface to typeset, exposing the builtin interface, while disable
typeset disables the builtin. Note that disabling the reserved word
interface for typeset may cause problems with the output of typeset
-p, which assumes the reserved word interface is available in order to
restore array and associative array values.</p>
<p>Unlike parameter assignment statements, typesets exit status on an
2021-05-11 02:29:21 +02:00
assignment that involves a command substitution does not reflect the
exit status of the command substitution. Therefore, to test for an error
in a command substitution, separate the declaration of the parameter
from its initialization:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh"># WRONG
2021-05-11 02:29:21 +02:00
typeset var1=$(exit 1) || echo &quot;Trouble with var1&quot;
# RIGHT
typeset var1 &amp;&amp; var1=$(exit 1) || echo &quot;Trouble with var1&quot;
</code></pre>
</div>
<p>To initialize a parameter <code>param</code> to a command output and mark it
2022-08-24 15:22:41 +02:00
readonly, use typeset -r <code>param</code> or readonly <code>param</code> after the parameter
assignment statement.</p>
2021-05-11 02:29:21 +02:00
<p>If no attribute flags are given, and either no <code>name</code> arguments are
2022-08-24 15:22:41 +02:00
present or the flag +m is used, then each parameter name printed is
preceded by a list of the attributes of that parameter (array,
association, exported, float, integer, readonly, or undefined for
autoloaded parameters not yet loaded). If +m is used with attribute
flags, and all those flags are introduced with +, the matching parameter
names are printed but their values are not.</p>
<p>The following control flags change the behavior of typeset:</p>
<p>+<br />
If + appears by itself in a separate word as the last option, then the
names of all parameters (functions with -f) are printed, but the values
(function bodies) are not. No <code>name</code> arguments may appear, and it is an
error for any other options to follow +. The effect of + is as if
all attribute flags which precede it were given with a + prefix. For
example, typeset -U + is equivalent to typeset +U and displays the
names of all arrays having the uniqueness attribute, whereas typeset -f
-U + displays the names of all autoloadable functions. If + is the only
option, then type information (array, readonly, etc.) is also printed
for each parameter, in the same manner as typeset +m &quot;*&quot;.</p>
<p>-g<br />
The -g (global) means that any resulting parameter will not be
restricted to local scope. Note that this does not necessarily mean that
the parameter will be global, as the flag will apply to any existing
parameter (even if unset) from an enclosing function. This flag does not
affect the parameter after creation, hence it has no effect when listing
existing parameters, nor does the flag +g have any effect except in
combination with -m (see below).</p>
<p>-m<br />
If the -m flag is given the <code>name</code> arguments are taken as patterns (use
quoting to prevent these from being interpreted as file patterns). With
no attribute flags, all parameters (or functions with the -f flag) with
matching names are printed (the shell option TYPESET_SILENT is not used
in this case).</p>
<p>If the +g flag is combined with -m, a new local parameter is created for
every matching parameter that is not already local. Otherwise -m applies
all other flags or assignments to the existing parameters.</p>
<p>Except when assignments are made with <code>name</code>=<code>value</code>, using +m forces
the matching parameters and their attributes to be printed, even inside
a function. Note that -m is ignored if no patterns are given, so
typeset -m displays attributes but typeset -a +m does not.</p>
<p>-p [ <code>n</code> ]<br />
If the -p option is given, parameters and values are printed in the form
of a typeset command with an assignment, regardless of other flags and
options. Note that the -H flag on parameters is respected; no value will
be shown for these parameters.</p>
<p>-p may be followed by an optional integer argument. Currently only the
value 1 is supported. In this case arrays and associative arrays are
printed with newlines between indented elements for readability.</p>
<p>-T [ <code>scalar</code>[=<code>value</code>] <code>array</code>[=(<code>value</code> ...)] [ <code>sep</code> ] ]<br />
This flag has a different meaning when used with -f; see below.
Otherwise the -T option requires zero, two, or three arguments to be
present. With no arguments, the list of parameters created in this
fashion is shown. With two or three arguments, the first two are the
name of a scalar and of an array parameter (in that order) that will be
tied together in the manner of $PATH and $path. The optional third
argument is a single-character separator which will be used to join the
elements of the array to form the scalar; if absent, a colon is used, as
with $PATH. Only the first character of the separator is significant;
any remaining characters are ignored. Multibyte characters are not yet
supported.</p>
<p>Only one of the scalar and array parameters may be assigned an initial
value (the restrictions on assignment forms described above also apply).</p>
<p>Both the scalar and the array may be manipulated as normal. If one is
unset, the other will automatically be unset too. There is no way of
untying the variables without unsetting them, nor of converting the type
of one of them with another typeset command; +T does not work, assigning
an array to <code>scalar</code> is an error, and assigning a scalar to <code>array</code> sets
it to be a single-element array.</p>
<p>Note that both typeset -xT ... and export -T ... work, but only the
scalar will be marked for export. Setting the value using the scalar
version causes a split on all separators (which cannot be quoted). It is
possible to apply -T to two previously tied variables but with a
different separator character, in which case the variables remain joined
as before but the separator is changed.</p>
<p>When an existing scalar is tied to a new array, the value of the scalar
is preserved but no attribute other than export will be preserved.</p>
<p>Attribute flags that transform the final value (-L, -R, -Z, -l, -u) are
only applied to the expanded value at the point of a parameter expansion
expression using $. They are not applied when a parameter is retrieved
internally by the shell for any purpose.</p>
2021-05-11 02:29:21 +02:00
<p>The following attribute flags may be specified:</p>
2022-08-24 15:22:41 +02:00
<p>-A<br />
2021-05-11 02:29:21 +02:00
The names refer to associative array parameters; see <a href="Parameters.html#Array-Parameters">Array
Parameters</a>.</p>
2022-08-24 15:22:41 +02:00
<p>-L [ <code>n</code> ]<br />
Left justify and remove leading blanks from the value when the parameter
is expanded. If <code>n</code> is nonzero, it defines the width of the field. If
<code>n</code> is zero, the width is determined by the width of the value of the
first assignment. In the case of numeric parameters, the length of the
complete value assigned to the parameter is used to determine the width,
not the value that would be output.</p>
<p>The width is the count of characters, which may be multibyte characters
if the MULTIBYTE option is in effect. Note that the screen width of the
character is not taken into account; if this is required, use padding
with parameter expansion flags ${(ml<code>...</code>)<code>...</code>} as described in
Parameter Expansion Flags in <a href="Expansion.html#Parameter-Expansion">Parameter
Expansion</a>.</p>
<p>When the parameter is expanded, it is filled on the right with blanks or
truncated if necessary to fit the field. Note truncation can lead to
unexpected results with numeric parameters. Leading zeros are removed if
the -Z flag is also set.</p>
<p>-R [ <code>n</code> ]<br />
Similar to -L, except that right justification is used; when the
parameter is expanded, the field is left filled with blanks or truncated
from the end. May not be combined with the -Z flag.</p>
<p>-U<br />
2021-05-11 02:29:21 +02:00
For arrays (but not for associative arrays), keep only the first
occurrence of each duplicated value. This may also be set for tied
2022-08-24 15:22:41 +02:00
parameters (see -T) or colon-separated special parameters like PATH or
FIGNORE, etc. Note the flag takes effect on assignment, and the type of
the variable being assigned to is determinative; for variables with
shared values it is therefore recommended to set the flag for all
interfaces, e.g. typeset -U PATH path.</p>
<p>This flag has a different meaning when used with -f; see below.</p>
<p>-Z [ <code>n</code> ]<br />
Specially handled if set along with the -L flag. Otherwise, similar to
-R, except that leading zeros are used for padding instead of blanks if
the first non-blank character is a digit. Numeric parameters are
specially handled: they are always eligible for padding with zeroes, and
the zeroes are inserted at an appropriate place in the output.</p>
<p>-a<br />
The names refer to array parameters. An array parameter may be created
this way, but it may be assigned to in the typeset statement only if the
reserved word form of typeset is enabled (as it is by default). When
displaying, both normal and associative arrays are shown.</p>
<p>-f<br />
The names refer to functions rather than parameters. No assignments can
be made, and the only other valid flags are -t, -T, -k, -u, -U and -z.
The flag -t turns on execution tracing for this function; the flag -T
does the same, but turns off tracing for any named (not anonymous)
function called from the present one, unless that function also has the
-t or -T flag. The -u and -U flags cause the function to be marked for
autoloading; -U also causes alias expansion to be suppressed when the
function is loaded. See the description of the autoload builtin for
details.</p>
<p>Note that the builtin functions provides the same basic capabilities as
typeset -f but gives access to a few extra options; autoload gives
further additional options for the case typeset -fu and typeset -fU.</p>
<p>-h<br />
-H<br />
Hide value: specifies that typeset will not display the value of the
parameter when listing parameters; the display for such parameters is
always as if the + flag had been given. Use of the parameter is in
other respects normal, and the option does not apply if the parameter is
specified by name, or by pattern with the -m option. This is on by
default for the parameters in the zsh/parameter and zsh/mapfile modules.
Note, however, that unlike the -h flag this is also useful for
non-special parameters.</p>
<p>-i [ <code>n</code> ]<br />
Use an internal integer representation. If <code>n</code> is nonzero it defines the
output arithmetic base, otherwise it is determined by the first
2021-05-11 02:29:21 +02:00
assignment. Bases from 2 to 36 inclusive are allowed.</p>
2022-08-24 15:22:41 +02:00
<p>-E [ <code>n</code> ]<br />
2021-05-11 02:29:21 +02:00
Use an internal double-precision floating point representation. On
2022-08-24 15:22:41 +02:00
output the variable will be converted to scientific notation. If <code>n</code> is
nonzero it defines the number of significant figures to display; the
default is ten.</p>
<p>-F [ <code>n</code> ]<br />
2021-05-11 02:29:21 +02:00
Use an internal double-precision floating point representation. On
2022-08-24 15:22:41 +02:00
output the variable will be converted to fixed-point decimal notation.
If <code>n</code> is nonzero it defines the number of digits to display after the
decimal point; the default is ten.</p>
<p>-l<br />
Convert the result to lower case whenever the parameter is expanded. The
value is <em>not</em> converted when assigned.</p>
<p>-r<br />
The given <code>name</code>s are marked readonly. Note that if <code>name</code> is a special
parameter, the readonly attribute can be turned on, but cannot then be
turned off.</p>
<p>If the POSIX_BUILTINS option is set, the readonly attribute is more
restrictive: unset variables can be marked readonly and cannot then be
set; furthermore, the readonly attribute cannot be removed from any
variable.</p>
<p>It is still possible to change other attributes of the variable though,
some of which like -U or -Z would affect the value. More generally, the
readonly attribute should not be relied on as a security mechanism.</p>
2021-05-11 02:29:21 +02:00
<p>Note that in zsh (like in pdksh but unlike most other shells) it is
2022-08-24 15:22:41 +02:00
still possible to create a local variable of the same name as this is
considered a different variable (though this variable, too, can be
marked readonly). Special variables that have been made readonly retain
their value and readonly attribute when made local.</p>
<p>-t<br />
Tags the named parameters. Tags have no special meaning to the shell.
This flag has a different meaning when used with -f; see above.</p>
<p>-u<br />
Convert the result to upper case whenever the parameter is expanded. The
value is <em>not</em> converted when assigned. This flag has a different
meaning when used with -f; see above.</p>
<p>-x<br />
Mark for automatic export to the environment of subsequently executed
commands. If the option GLOBAL_EXPORT is set, this implies the option
-g, unless +g is also explicitly given; in other words the parameter is
not made local to the enclosing function. This is for compatibility with
previous versions of zsh.</p>
<p><span id="index-ulimit"></span> <span
id="index-resource-limits-1"></span> <span
id="index-limits_002c-resource-1"></span></p>
<p>ulimit [ -HSa ] [ { -bcdfiklmnpqrsTtvwx | -N <code>resource</code> } [ <code>limit</code>
] ... ]</p>
2021-05-11 02:29:21 +02:00
<p>Set or display resource limits of the shell and the processes started by
the shell. The value of <code>limit</code> can be a number in the unit specified
2022-08-24 15:22:41 +02:00
below or one of the values unlimited, which removes the limit on the
resource, or hard, which uses the current value of the hard limit on
2021-05-11 02:29:21 +02:00
the resource.</p>
2022-08-24 15:22:41 +02:00
<p>By default, only soft limits are manipulated. If the -H flag is given
use hard limits instead of soft limits. If the -S flag is given together
with the -H flag set both hard and soft limits.</p>
<p>If no options are used, the file size limit (-f) is assumed.</p>
2021-05-11 02:29:21 +02:00
<p>If <code>limit</code> is omitted the current value of the specified resources are
printed. When more than one resource value is printed, the limit name
and unit is printed before each value.</p>
<p>When looping over multiple resources, the shell will abort immediately
if it detects a badly formed argument. However, if it fails to set a
limit for some other reason it will continue trying to set the remaining
limits.</p>
<p>Not all the following resources are supported on all systems. Running
2022-08-24 15:22:41 +02:00
ulimit -a will show which are supported.</p>
<p>-a<br />
2021-05-11 02:29:21 +02:00
Lists all of the current resource limits.</p>
2022-08-24 15:22:41 +02:00
<p>-b<br />
2021-05-11 02:29:21 +02:00
Socket buffer size in bytes (N.B. not kilobytes)</p>
2022-08-24 15:22:41 +02:00
<p>-c<br />
2021-05-11 02:29:21 +02:00
512-byte blocks on the size of core dumps.</p>
2022-08-24 15:22:41 +02:00
<p>-d<br />
2021-05-11 02:29:21 +02:00
Kilobytes on the size of the data segment.</p>
2022-08-24 15:22:41 +02:00
<p>-f<br />
2021-05-11 02:29:21 +02:00
512-byte blocks on the size of files written.</p>
2022-08-24 15:22:41 +02:00
<p>-i<br />
2021-05-11 02:29:21 +02:00
The number of pending signals.</p>
2022-08-24 15:22:41 +02:00
<p>-k<br />
2021-05-11 02:29:21 +02:00
The number of kqueues allocated.</p>
2022-08-24 15:22:41 +02:00
<p>-l<br />
2021-05-11 02:29:21 +02:00
Kilobytes on the size of locked-in memory.</p>
2022-08-24 15:22:41 +02:00
<p>-m<br />
2021-05-11 02:29:21 +02:00
Kilobytes on the size of physical memory.</p>
2022-08-24 15:22:41 +02:00
<p>-n<br />
2021-05-11 02:29:21 +02:00
open file descriptors.</p>
2022-08-24 15:22:41 +02:00
<p>-p<br />
2021-05-11 02:29:21 +02:00
The number of pseudo-terminals.</p>
2022-08-24 15:22:41 +02:00
<p>-q<br />
2021-05-11 02:29:21 +02:00
Bytes in POSIX message queues.</p>
2022-08-24 15:22:41 +02:00
<p>-r<br />
Maximum real time priority. On some systems where this is not available,
such as NetBSD, this has the same effect as -T for compatibility with
sh.</p>
<p>-s<br />
2021-05-11 02:29:21 +02:00
Kilobytes on the size of the stack.</p>
2022-08-24 15:22:41 +02:00
<p>-T<br />
2021-05-11 02:29:21 +02:00
The number of simultaneous threads available to the user.</p>
2022-08-24 15:22:41 +02:00
<p>-t<br />
2021-05-11 02:29:21 +02:00
CPU seconds to be used.</p>
2022-08-24 15:22:41 +02:00
<p>-u<br />
2021-05-11 02:29:21 +02:00
The number of processes available to the user.</p>
2022-08-24 15:22:41 +02:00
<p>-v<br />
Kilobytes on the size of virtual memory. On some systems this refers to
the limit called address space.</p>
<p>-w<br />
2021-05-11 02:29:21 +02:00
Kilobytes on the size of swapped out memory.</p>
2022-08-24 15:22:41 +02:00
<p>-x<br />
2021-05-11 02:29:21 +02:00
The number of locks on files.</p>
2022-08-24 15:22:41 +02:00
<p>A resource may also be specified by integer in the form -N <code>resource</code>,
where <code>resource</code> corresponds to the integer defined for the resource by
the operating system. This may be used to set the limits for resources
known to the shell which do not correspond to option letters. Such
limits will be shown by number in the output of ulimit -a.</p>
2021-05-11 02:29:21 +02:00
<p>The number may alternatively be out of the range of limits compiled into
the shell. The shell will try to read or write the limit anyway, and
will report an error if this fails.</p>
<p><span id="index-umask"></span> <span id="index-umask-1"></span></p>
2022-08-24 15:22:41 +02:00
<p>umask [ -S ] [ <code>mask</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>The umask is set to <code>mask</code>. <code>mask</code> can be either an octal number or a
2022-08-24 15:22:41 +02:00
symbolic value as described in the chmod(1) man page. If <code>mask</code> is
omitted, the current value is printed. The -S option causes the mask to
be printed as a symbolic value. Otherwise, the mask is printed as an
octal number. Note that in the symbolic form the permissions you specify
are those which are to be allowed (not denied) to the users specified.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-aliases_002c-removing"></span></p>
2022-08-24 15:22:41 +02:00
<p>unalias [ -ams ] <code>name</code> ...</p>
<p>Removes aliases. This command works the same as unhash -a, except that
the -a option removes all regular or global aliases, or with -s all
2021-05-11 02:29:21 +02:00
suffix aliases: in this case no <code>name</code> arguments may appear. The options
2022-08-24 15:22:41 +02:00
-m (remove by pattern) and -s without -a (remove listed suffix aliases)
behave as for unhash -a. Note that the meaning of -a is different
between unalias and unhash.</p>
<p><span id="index-functions_002c-removing"></span> <span
id="index-unfunction"></span></p>
<p>unfunction</p>
<p>Same as unhash -f.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-unhash"></span></p>
2022-08-24 15:22:41 +02:00
<p>unhash [ -adfms ] <code>name</code> ...</p>
<p>option causes unhash to remove regular or global aliases; note when
2021-05-11 02:29:21 +02:00
removing a global aliases that the argument must be quoted to prevent it
2022-08-24 15:22:41 +02:00
from being expanded before being passed to the command. The -s option
causes unhash to remove suffix aliases. The -f option causes unhash to
remove shell functions. The -d options causes unhash to remove named
directories. If the -m flag is given the arguments are taken as patterns
(should be quoted) and all elements</p>
<p><span id="index-unlimit"></span> <span
id="index-resource-limits-2"></span> <span
id="index-limits_002c-resource-2"></span></p>
<p>unlimit [ -hs ] <code>resource</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>The resource limit for each <code>resource</code> is set to the hard limit. If the
2022-08-24 15:22:41 +02:00
-h flag is given and the shell has appropriate privileges, the hard
2021-05-11 02:29:21 +02:00
resource limit for each <code>resource</code> is removed. The resources of the
2022-08-24 15:22:41 +02:00
shell process are only changed if the -s flag is given.</p>
<p>The unlimit command is not made available by default when the shell
2021-05-11 02:29:21 +02:00
starts in a mode emulating another shell. It can be made available with
2022-08-24 15:22:41 +02:00
the command zmodload -F zsh/rlimits b:unlimit.</p>
<p><span id="index-unset"></span> <span
id="index-parameters_002c-unsetting"></span></p>
<p>unset [ -fmv ] <code>name</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>Each named parameter is unset. Local parameters remain local even if
unset; they appear unset within scope, but the previous value will still
reappear when the scope ends.</p>
<p>Individual elements of associative array parameters may be unset by
using subscript syntax on <code>name</code>, which should be quoted (or the entire
2022-08-24 15:22:41 +02:00
command prefixed with noglob) to protect the subscript from filename
2021-05-11 02:29:21 +02:00
generation.</p>
2022-08-24 15:22:41 +02:00
<p>If the -m flag is specified the arguments are taken as patterns (should
be quoted) and all parameters with matching names are unset. Note that
this cannot be used when unsetting associative array elements, as the
subscript will be treated as part of the pattern.</p>
<p>The -v flag specifies that <code>name</code> refers to parameters. This is the
2021-05-11 02:29:21 +02:00
default behaviour.</p>
2022-08-24 15:22:41 +02:00
<p>unset -f is equivalent to unfunction.</p>
<p><span id="index-unsetopt"></span> <span
id="index-options_002c-unsetting"></span></p>
<p>unsetopt [ {+|-}<code>options</code> | {+|-}o <code>option_name</code> ] [ <code>name</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>Unset the options for the shell. All options specified either with flags
or by name are unset. If no arguments are supplied, the names of all
2022-08-24 15:22:41 +02:00
options currently unset are printed. If the -m flag is given the
2021-05-11 02:29:21 +02:00
arguments are taken as patterns (which should be quoted to preserve them
from being interpreted as glob patterns), and all options with names
matching these patterns are unset.</p>
2022-08-24 15:22:41 +02:00
<p>vared</p>
2021-05-11 02:29:21 +02:00
<p>See <a href="Zsh-Line-Editor.html#Zle-Builtins">Zle Builtins</a>.</p>
<p><span id="index-wait"></span> <span id="index-waiting-for-jobs"></span>
<span id="index-jobs_002c-waiting-for"></span></p>
2022-08-24 15:22:41 +02:00
<p>wait [ <code>job</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>Wait for the specified jobs or processes. If <code>job</code> is not given then all
currently active child processes are waited for. Each <code>job</code> can be
either a job specification or the process ID The exit status from this
command is that of the job waited for. If <code>job</code> represents an unknown
2022-08-24 15:22:41 +02:00
job or process ID, a warning is printed (unless the POSIX_BUILTINS
2021-05-11 02:29:21 +02:00
option is set) and the exit status is 127.</p>
<p>It is possible to wait for recent processes (specified by process ID,
not by job) that were running in the background even if the process has
exited. Typically the process ID will be recorded by capturing the value
2022-08-24 15:22:41 +02:00
of the variable $! immediately after the process has been started. There
is a limit on the number of process IDs remembered by the shell; this is
given by the value of the system configuration parameter CHILD_MAX. When
this limit is reached, older process IDs are discarded, least recently
started processes first.</p>
2021-05-11 02:29:21 +02:00
<p>Note there is no protection against the process ID wrapping, i.e. if the
wait is not executed soon enough there is a chance the process waited
for is the wrong one. A conflict implies both process IDs have been
generated by the shell, as other processes are not recorded, and that
the user is potentially interested in both, so this problem is intrinsic
to process IDs.</p>
<p><span id="index-whence"></span></p>
2022-08-24 15:22:41 +02:00
<p>whence [ -vcwfpamsS ] [ -x <code>num</code> ] <code>name</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>For each <code>name</code>, indicate how it would be interpreted if used as a
command name.</p>
<p>If <code>name</code> is not an alias, built-in command, external command, shell
function, hashed command, or a reserved word, the exit status shall be
2022-08-24 15:22:41 +02:00
non-zero, and — if -v, -c, or -w was passed — a message will be written
to standard output. (This is different from other shells that write that
message to standard error.)</p>
<p>whence is most useful when <code>name</code> is only the last path component of a
command, i.e. does not include a /; in particular, pattern matching
2021-05-11 02:29:21 +02:00
only succeeds if just the non-directory component of the command is
passed.</p>
2022-08-24 15:22:41 +02:00
<p>-v<br />
2021-05-11 02:29:21 +02:00
Produce a more verbose report.</p>
2022-08-24 15:22:41 +02:00
<p>-c<br />
Print the results in a csh-like format. This takes precedence over -v.</p>
<p>-w<br />
For each <code>name</code>, print <code>name</code>: <code>word</code> where <code>word</code> is one of alias,
builtin, command, function, hashed, reserved or none, according as
<code>name</code> corresponds to an alias, a built-in command, an external command,
a shell function, a command defined with the hash builtin, a reserved
word, or is not recognised. This takes precedence over -v and -c.</p>
<p>-f<br />
2021-05-11 02:29:21 +02:00
Causes the contents of a shell function to be displayed, which would
2022-08-24 15:22:41 +02:00
otherwise not happen unless the -c flag were used.</p>
<p>-p<br />
Do a path search for <code>name</code> even if it is an alias, reserved word, shell
function or builtin.</p>
<p>-a<br />
Do a search for all occurrences of <code>name</code> throughout the command path.
Normally only the first occurrence is printed.</p>
<p>-m<br />
2021-05-11 02:29:21 +02:00
The arguments are taken as patterns (pattern characters should be
2022-08-24 15:22:41 +02:00
quoted), and the information is displayed for each command matching one
of these patterns.</p>
<p>-s<br />
2021-05-11 02:29:21 +02:00
If a pathname contains symlinks, print the symlink-free pathname as
well.</p>
2022-08-24 15:22:41 +02:00
<p>-S<br />
As -s, but if the pathname had to be resolved by following multiple
symlinks, the intermediate steps are printed, too. The symlink resolved
at each step might be anywhere in the path.</p>
<p>-x <code>num</code><br />
Expand tabs when outputting shell functions using the -c option. This
has the same effect as the -x option to the functions builtin.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-where"></span></p>
2022-08-24 15:22:41 +02:00
<p>where [ -wpmsS ] [ -x <code>num</code> ] <code>name</code> ...</p>
<p>Equivalent to whence -ca.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-which"></span></p>
2022-08-24 15:22:41 +02:00
<p>which [ -wpamsS ] [ -x <code>num</code> ] <code>name</code> ...</p>
<p>Equivalent to whence -c.</p>
<p><span id="index-zcompile"></span> <span
id="index-_002ezwc-files_002c-creation"></span> <span
id="index-compilation"></span></p>
<p>zcompile [ -U ] [ -z | -k ] [ -R | -M ] <code>file</code> [ <code>name</code> ... ]</p>
<p>zcompile -ca [ -m ] [ -R | -M ] <code>file</code> [ <code>name</code> ... ]</p>
<p>zcompile -t <code>file</code> [ <code>name</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>This builtin command can be used to compile functions or scripts,
storing the compiled form in a file, and to examine files containing the
compiled form. This allows faster autoloading of functions and sourcing
of scripts by avoiding parsing of the text when the files are read.</p>
2022-08-24 15:22:41 +02:00
<p>The first form (without the -c, -a or -t options) creates a compiled
file. If only the <code>file</code> argument is given, the output file has the name
<code>file</code>.zwc and will be placed in the same directory as the <code>file</code>. The
shell will load the compiled file instead of the normal function file
when the function is autoloaded; see
2021-05-11 02:29:21 +02:00
<a href="Functions.html#Functions">Functions</a> for a description of how
2022-08-24 15:22:41 +02:00
autoloaded functions are searched. The extension .zwc stands for zsh
2021-05-11 02:29:21 +02:00
word code.</p>
<p><span id="index-fpath_002c-with-zcompile"></span></p>
<p>If there is at least one <code>name</code> argument, all the named files are
compiled into the output <code>file</code> given as the first argument. If <code>file</code>
2022-08-24 15:22:41 +02:00
does not end in .zwc, this extension is automatically appended. Files
2021-05-11 02:29:21 +02:00
containing multiple compiled functions are called digest files, and
2022-08-24 15:22:41 +02:00
are intended to be used as elements of the FPATH/fpath special array.</p>
<p>The second form, with the -c or -a options, writes the compiled
definitions for all the named functions into <code>file</code>. For -c, the names
2021-05-11 02:29:21 +02:00
must be functions currently defined in the shell, not those marked for
autoloading. Undefined functions that are marked for autoloading may be
2022-08-24 15:22:41 +02:00
written by using the -a option, in which case the fpath is searched and
the contents of the definition files for those functions, if found, are
compiled into <code>file</code>. If both -c and -a are given, names of both defined
functions and functions marked for autoloading may be given. In either
case, the functions in files written with the -c or -a option will be
autoloaded as if the KSH_AUTOLOAD option were unset.</p>
2021-05-11 02:29:21 +02:00
<p>The reason for handling loaded and not-yet-loaded functions with
different options is that some definition files for autoloading define
multiple functions, including the function with the same name as the
file, and, at the end, call that function. In such cases the output of
2022-08-24 15:22:41 +02:00
zcompile -c does not include the additional functions defined in the
file, and any other initialization code in the file is lost. Using
zcompile -a captures all this extra information.</p>
<p>If the -m option is combined with -c or -a, the <code>name</code>s are used as
patterns and all functions whose names match one of these patterns will
be written. If no <code>name</code> is given, the definitions of all functions
2021-05-11 02:29:21 +02:00
currently defined or marked as autoloaded will be written.</p>
<p>Note the second form cannot be used for compiling functions that include
redirections as part of the definition rather than within the body of
the function; for example</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">fn1() { { ... } &gt;~/logfile }
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>can be compiled but</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">fn1() { ... } &gt;~/logfile
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>cannot. It is possible to use the first form of zcompile to compile
2021-05-11 02:29:21 +02:00
autoloadable functions that include the full function definition instead
of just the body of the function.</p>
2022-08-24 15:22:41 +02:00
<p>The third form, with the -t option, examines an existing compiled file.
Without further arguments, the names of the original files compiled into
it are listed. The first line of output shows the version of the shell
which compiled the file and how the file will be used (i.e. by reading
it directly or by mapping it into memory). With arguments, nothing is
output and the return status is set to zero if definitions for <em>all</em>
<code>name</code>s were found in the compiled file, and non-zero if the definition
for at least one <code>name</code> was not found.</p>
2021-05-11 02:29:21 +02:00
<p>Other options:</p>
2022-08-24 15:22:41 +02:00
<p>-U<br />
2021-05-11 02:29:21 +02:00
Aliases are not expanded when compiling the <code>name</code>d files.</p>
2022-08-24 15:22:41 +02:00
<p>-R<br />
When the compiled file is read, its contents are copied into the shells
memory, rather than memory-mapped (see -M). This happens automatically
on systems that do not support memory mapping.</p>
<p>When compiling scripts instead of autoloadable functions, it is often
desirable to use this option; otherwise the whole file, including the
code to define functions which have already been defined, will remain
mapped, consequently wasting memory.</p>
<p>-M<br />
The compiled file is mapped into the shells memory when read. This is
done in such a way that multiple instances of the shell running on the
same host will share this mapped file. If neither -R nor -M is given,
the zcompile builtin decides what to do based on the size of the
compiled file.</p>
<p>-k<br />
-z<br />
These options are used when the compiled file contains functions which
are to be autoloaded. If -z is given, the function will be autoloaded as
if the KSH_AUTOLOAD option is <em>not</em> set, even if it is set at the time
the compiled file is read, while if the -k is given, the function will
be loaded as if KSH_AUTOLOAD <em>is</em> set. These options also take
precedence over any -k or -z options specified to the autoload builtin.
If neither of these options is given, the function will be loaded as
determined by the setting of the KSH_AUTOLOAD option at the time the
compiled file is read.</p>
2021-05-11 02:29:21 +02:00
<p>These options may also appear as many times as necessary between the
2022-08-24 15:22:41 +02:00
listed <code>name</code>s to specify the loading style of all following functions,
up to the next -k or -z.</p>
2021-05-11 02:29:21 +02:00
<p>The created file always contains two versions of the compiled format,
one for big-endian machines and one for small-endian machines. The
upshot of this is that the compiled file is machine independent and if
it is read or mapped, only one half of the file is actually used (and
mapped).</p>
2022-08-24 15:22:41 +02:00
<p>zformat</p>
2021-05-11 02:29:21 +02:00
<p>See <a href="Zsh-Modules.html#The-zsh_002fzutil-Module">The zsh/zutil Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p>zftp</p>
2021-05-11 02:29:21 +02:00
<p>See <a href="Zsh-Modules.html#The-zsh_002fzftp-Module">The zsh/zftp Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p>zle</p>
2021-05-11 02:29:21 +02:00
<p>See <a href="Zsh-Line-Editor.html#Zle-Builtins">Zle Builtins</a>.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-zmodload"></span> <span
id="index-modules_002c-loading"></span> <span
id="index-loading-modules"></span></p>
<p>zmodload [ -dL ] [ -s ] [ ... ]</p>
<p>zmodload -F [ -alLme -P <code>param</code> ] <code>module</code> [ [+-]<code>feature</code> ... ]</p>
<p>zmodload -e [ -A ] [ ... ]</p>
<p>zmodload [ -a [ -bcpf [ -I ] ] ] [ -iL ] ...</p>
<p>zmodload -u [ -abcdpf [ -I ] ] [ -iL ] ...</p>
<p>zmodload -A [ -L ] [ <code>modalias</code>[=<code>module</code>] ... ]</p>
<p>zmodload -R <code>modalias</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>Performs operations relating to zshs loadable modules. Loading of
modules while the shell is running (dynamical loading) is not
available on all operating systems, or on all installations on a
2022-08-24 15:22:41 +02:00
particular operating system, although the zmodload command itself is
2021-05-11 02:29:21 +02:00
always available and can be used to manipulate modules built into
versions of the</p>
<p>Without arguments the names of all currently loaded binary modules are
2022-08-24 15:22:41 +02:00
printed. The -L option causes this list to be in the form of a series of
zmodload commands. Forms with arguments are:</p>
<p>zmodload [ -is ] <code>name</code> ...<br />
zmodload -u [ -i ] <code>name</code> ...<br />
In the simplest case, zmodload loads a binary module. The module must be
in a file with a name consisting of the specified <code>name</code> followed by a
standard suffix, usually .so (.sl on HPUX). If the module to be
loaded is already loaded the duplicate module is ignored. If zmodload
detects an inconsistency, such as an invalid module name or circular
dependency list, the current code block is aborted. If it is available,
the module is loaded if necessary, while if it is not available,
non-zero status is silently returned. The option -i is accepted for
compatibility but has no effect.</p>
<p>The <code>name</code>d module is searched for in the same way a command is, using
$module_path instead of $path. However, the path search is performed
even when the module name contains a /, which it usually does. There
is no way to prevent the path search.</p>
<p>If the module supports features (see below), zmodload tries to enable
all features when loading a module. If the module was successfully
loaded but not all features could be enabled, zmodload returns status 2.</p>
<p>If the option -s is given, no error is printed if the module was not
available (though other errors indicating a problem with the module are
printed). The return status indicates if the module was loaded. This is
appropriate if the caller considers the module optional.</p>
<p>With -u, zmodload unloads modules. The same <code>name</code> must be given that
was given when the module was loaded, but it is not necessary for the
module to exist in the file system. The -i option suppresses the error
if the module is already unloaded (or was never loaded).</p>
<p>Each module has a boot and a cleanup function. The module will not be
loaded if its boot function fails. Similarly a module can only be
2021-05-11 02:29:21 +02:00
unloaded if its cleanup function runs successfully.</p>
2022-08-24 15:22:41 +02:00
<p>zmodload -F [ -almLe -P <code>param</code> ] <code>module</code> [ [+-]<code>feature</code> ... ]<br />
zmodload -F allows more selective control over the features provided by
modules. With no options apart from -F, the module named <code>module</code> is
loaded, if it was not already loaded, and the list of <code>feature</code>s is set
to the required state. If no <code>feature</code>s are specified, the module is
loaded, if it was not already loaded, but the state of features is
unchanged. Each feature may be preceded by a + to turn the feature on,
or - to turn it off; the + is assumed if neither character is present.
Any feature not explicitly mentioned is left in its current state; if
the module was not previously loaded this means any such features will
remain disabled. The return status is zero if all features were set, 1
if the module failed to load, and 2 if some features could not be set
(for example, a parameter couldnt be added because there was a
different parameter of the same name) but the module was loaded.</p>
2021-05-11 02:29:21 +02:00
<p>The standard features are builtins, conditions, parameters and math
2022-08-24 15:22:41 +02:00
functions; these are indicated by the prefix b:, c: (C: for an
infix condition), p: and f:, respectively, followed by the name that
the corresponding feature would have in the shell. For example,
b:strftime indicates a builtin named strftime and p:EPOCHSECONDS
indicates a parameter named EPOCHSECONDS. The module may provide other
(abstract) features of its own as indicated by its documentation;
these have no prefix.</p>
<p>With -l or -L, features provided by the module are listed. With -l
alone, a list of features together with their states is shown, one
feature per line. With -L alone, a zmodload -F command that would cause
enabled features of the module to be turned on is shown. With -lL, a
zmodload -F command that would cause all the features to be set to their
current state is shown. If one of these combinations is given with the
option -P <code>param</code> then the parameter <code>param</code> is set to an array of
features, either features together with their state or (if -L alone is
given) enabled features.</p>
<p>With the option -L the module name may be omitted; then a list of all
enabled features for all modules providing features is printed in the
form of zmodload -F commands. If -l is also given, the state of both
enabled and disabled features is output in that form.</p>
<p>A set of features may be provided together with -l or -L and a module
name; in that case only the state of those features is considered. Each
feature may be preceded by + or - but the character has no effect. If no
set of features is provided, all features are considered.</p>
<p>With -e, the command first tests that the module is loaded; if it is
not, status 1 is returned. If the module is loaded, the list of features
given as an argument is examined. Any feature given with no prefix is
simply tested to see if the module provides it; any feature given with a
prefix + or - is tested to see if is provided and in the given state. If
the tests on all features in the list succeed, status 0 is returned,
else status 1.</p>
<p>With -m, each entry in the given list of features is taken as a pattern
to be matched against the list of features provided by the module. An
initial + or - must be given explicitly. This may not be combined with
the -a option as autoloads must be specified explicitly.</p>
<p>With -a, the given list of features is marked for autoload from the
specified module, which may not yet be loaded. An optional + may appear
before the feature name. If the feature is prefixed with -, any existing
autoload is removed. The options -l and -L may be used to list
autoloads. Autoloading is specific to individual features; when the
module is loaded only the requested feature is enabled. Autoload
requests are preserved if the module is subsequently unloaded until an
explicit zmodload -Fa <code>module</code> -<code>feature</code> is issued. It is not an
error to request an autoload for a feature of a module that is already
loaded.</p>
<p>When the module is loaded each autoload is checked against the features
actually provided by the module; if the feature is not provided the
autoload request is deleted. A warning message is output; if the module
is being loaded to provide a different feature, and that autoload is
successful, there is no effect on the status of the current command. If
the module is already loaded at the time when zmodload -Fa is run, an
error message is printed and status 1 returned.</p>
<p>zmodload -Fa can be used with the -l, -L, -e and -P options for listing
and testing the existence of autoloadable features. In this case -l is
ignored if -L is specified. zmodload -FaL with no module name lists
autoloads for all modules.</p>
<p>Note that only standard features as described above can be autoloaded;
other features require the module to be loaded before enabling.</p>
<p>zmodload -d [ -L ] [ <code>name</code> ]<br />
zmodload -d <code>name</code> <code>dep</code> ...<br />
zmodload -ud <code>name</code> [ <code>dep</code> ... ]<br />
The -d option can be used to specify module dependencies. The modules
named in the second and subsequent arguments will be loaded before the
module named in the first argument.</p>
<p>With -d and one argument, all dependencies for that module are listed.
With -d and no arguments, all module dependencies are listed. This
listing is by default in a Makefile-like format. The -L option changes
this format to a list of zmodload -d commands.</p>
<p>If -d and -u are both used, dependencies are removed. If only one
argument is given, all dependencies for that module are removed.</p>
<p>zmodload -ab [ -L ]<br />
zmodload -ab [ -i ] <code>name</code> [ <code>builtin</code> ... ]<br />
zmodload -ub [ -i ] <code>builtin</code> ...<br />
The -ab option defines autoloaded builtins. It defines the specified
<code>builtin</code>s. When any of those builtins is called, the module specified
in the first argument is loaded and all its features are enabled (for
selective control of features use zmodload -F -a as described above).
If only the <code>name</code> is given, one builtin is defined, with the same name
as the module. -i suppresses the error if the builtin is already defined
or autoloaded, but not if another builtin of the same name is already
2021-05-11 02:29:21 +02:00
defined.</p>
2022-08-24 15:22:41 +02:00
<p>With -ab and no arguments, all autoloaded builtins are listed, with the
module name (if different) shown in parentheses after the builtin name.
The -L option changes this format to a list of zmodload -a commands.</p>
<p>If -b is used together with the -u option, it removes builtins
previously defined with -ab. This is only possible if the builtin is not
yet loaded. -i suppresses the error if the builtin is already removed
(or never existed).</p>
<p>Autoload requests are retained if the module is subsequently unloaded
until an explicit zmodload -ub <code>builtin</code> is issued.</p>
<p>zmodload -ac [ -IL ]<br />
zmodload -ac [ -iI ] <code>name</code> [ <code>cond</code> ... ]<br />
zmodload -uc [ -iI ] <code>cond</code> ...<br />
The -ac option is used to define autoloaded condition codes. The <code>cond</code>
strings give the names of the conditions defined by the module. The
optional -I option is used to define infix condition names. Without this
option prefix condition names are defined.</p>
<p>If given no condition names, all defined names are listed (as a series
of zmodload commands if the -L option is given).</p>
<p>The -uc option removes definitions for autoloaded conditions.</p>
<p>zmodload -ap [ -L ]<br />
zmodload -ap [ -i ] <code>name</code> [ <code>parameter</code> ... ]<br />
zmodload -up [ -i ] <code>parameter</code> ...<br />
The -p option is like the -b and -c options, but makes zmodload work on
autoloaded parameters instead.</p>
<p>zmodload -af [ -L ]<br />
zmodload -af [ -i ] <code>name</code> [ <code>function</code> ... ]<br />
zmodload -uf [ -i ] <code>function</code> ...<br />
The -f option is like the -b, -p, and -c options, but makes zmodload
work on autoloaded math functions instead.</p>
<p>zmodload -a [ -L ]<br />
zmodload -a [ -i ] <code>name</code> [ <code>builtin</code> ... ]<br />
zmodload -ua [ -i ] <code>builtin</code> ...<br />
Equivalent to -ab and -ub.</p>
<p>zmodload -e [ -A ] [ <code>string</code> ... ]<br />
The -e option without arguments lists all loaded modules; if the -A
option is also given, module aliases corresponding to loaded modules are
also shown. If arguments are provided, nothing is printed; the return
status is set to zero if all <code>string</code>s given as arguments are names of
loaded modules and to one if at least on <code>string</code> is not the name of a
loaded module. This can be used to test for the availability of things
implemented by modules. In this case, any aliases are automatically
resolved and the -A flag is not used.</p>
<p>zmodload -A [ -L ] [ <code>modalias</code>[=<code>module</code>] ... ]<br />
2021-05-11 02:29:21 +02:00
For each argument, if both <code>modalias</code> and <code>module</code> are given, define
<code>modalias</code> to be an alias for the module <code>module</code>. If the module
2022-08-24 15:22:41 +02:00
<code>modalias</code> is ever subsequently requested, either via a call to zmodload
or implicitly, the shell will attempt to load <code>module</code> instead. If
<code>module</code> is not given, show the definition of <code>modalias</code>. If no
arguments are given, list all defined module aliases. When listing, if
the -L flag was also given, list the definition as a zmodload command to
recreate the alias.</p>
2021-05-11 02:29:21 +02:00
<p>The existence of aliases for modules is completely independent of
whether the name resolved is actually loaded as a module: while the
alias exists, loading and unloading the module under any alias has
2022-08-24 15:22:41 +02:00
exactly the same effect as using the resolved name, and does not affect
the connection between the alias and the resolved name which can be
removed either by zmodload -R or by redefining the alias. Chains of
aliases (i.e. where the first resolved name is itself an alias) are
valid so long as these are not circular. As the aliases take the same
format as module names, they may include path separators: in this case,
there is no requirement for any part of the path named to exist as the
alias will be resolved first. For example, any/old/alias is always a
valid alias.</p>
<p>Dependencies added to aliased modules are actually added to the resolved
module; these remain if the alias is removed. It is valid to create an
alias whose name is one of the standard shell modules and which resolves
to a different module. However, if a module has dependencies, it will
not be possible to use the module name as an alias as the module will
already be marked as a loadable module in its own right.</p>
<p>Apart from the above, aliases can be used in the zmodload command
anywhere module names are required. However, aliases will not be shown
in lists of loaded modules with a bare zmodload.</p>
<p>zmodload -R <code>modalias</code> ...<br />
2021-05-11 02:29:21 +02:00
For each <code>modalias</code> argument that was previously defined as a module
2022-08-24 15:22:41 +02:00
alias via zmodload -A, delete the alias. If any was not defined, an
error is caused and the remainder of the line is ignored.</p>
<p>Note that zsh makes no distinction between modules that were linked into
the shell and modules that are loaded dynamically. In both cases this
builtin command has to be used to make available the builtins and other
things defined by modules (unless the module is autoloaded on these
definitions). This is true even for systems that dont support dynamic
loading of modules.</p>
<p>zparseopts</p>
2021-05-11 02:29:21 +02:00
<p>See <a href="Zsh-Modules.html#The-zsh_002fzutil-Module">The zsh/zutil Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p>zprof</p>
2021-05-11 02:29:21 +02:00
<p>See <a href="Zsh-Modules.html#The-zsh_002fzprof-Module">The zsh/zprof Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p>zpty</p>
2021-05-11 02:29:21 +02:00
<p>See <a href="Zsh-Modules.html#The-zsh_002fzpty-Module">The zsh/zpty Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p>zregexparse</p>
2021-05-11 02:29:21 +02:00
<p>See <a href="Zsh-Modules.html#The-zsh_002fzutil-Module">The zsh/zutil Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p>zsocket</p>
2021-05-11 02:29:21 +02:00
<p>See <a href="Zsh-Modules.html#The-zsh_002fnet_002fsocket-Module">The zsh/net/socket
Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p>zstyle</p>
2021-05-11 02:29:21 +02:00
<p>See <a href="Zsh-Modules.html#The-zsh_002fzutil-Module">The zsh/zutil Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p>ztcp</p>
2021-05-11 02:29:21 +02:00
<p>See <a href="Zsh-Modules.html#The-zsh_002fnet_002ftcp-Module">The zsh/net/tcp
Module</a>.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="Zsh-Line-Editor.html#18-zsh-line-editor">18 Zsh Line Editor</a>
<ul>
<li><a href="Zsh-Line-Editor.html#181-description">18.1 Description</a></li>
<li><a href="Zsh-Line-Editor.html#182-keymaps">18.2 Keymaps</a>
<ul>
<li><a href="Zsh-Line-Editor.html#1821-reading-commands">18.2.1 Reading Commands</a></li>
<li><a href="Zsh-Line-Editor.html#1822-local-keymaps">18.2.2 Local Keymaps</a></li>
</ul>
</li>
<li><a href="Zsh-Line-Editor.html#183-zle-builtins">18.3 Zle Builtins</a></li>
2022-08-24 15:22:41 +02:00
<li><a href="Zsh-Line-Editor.html#184-zle-widgets">18.4 Zle Widgets</a></li>
2021-05-11 02:29:21 +02:00
<li><a href="Zsh-Line-Editor.html#185-user-defined-widgets">18.5 User-Defined Widgets</a>
<ul>
<li><a href="Zsh-Line-Editor.html#1851-special-widgets">18.5.1 Special Widgets</a></li>
</ul>
</li>
<li><a href="Zsh-Line-Editor.html#186-standard-widgets">18.6 Standard Widgets</a>
<ul>
<li><a href="Zsh-Line-Editor.html#1861-movement">18.6.1 Movement</a></li>
<li><a href="Zsh-Line-Editor.html#1862-history-control">18.6.2 History Control</a></li>
<li><a href="Zsh-Line-Editor.html#1863-modifying-text">18.6.3 Modifying Text</a></li>
<li><a href="Zsh-Line-Editor.html#1864-arguments">18.6.4 Arguments</a></li>
<li><a href="Zsh-Line-Editor.html#1865-completion">18.6.5 Completion</a></li>
<li><a href="Zsh-Line-Editor.html#1866-miscellaneous">18.6.6 Miscellaneous</a></li>
<li><a href="Zsh-Line-Editor.html#1867-text-objects">18.6.7 Text Objects</a></li>
</ul>
</li>
<li><a href="Zsh-Line-Editor.html#187-character-highlighting">18.7 Character Highlighting</a></li>
</ul>
</li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<p><span id="Zsh-Line-Editor"></span> <span id="Zsh-Line-Editor-1"></span></p>
<h1 id="18-zsh-line-editor"><a class="header" href="#18-zsh-line-editor">18 Zsh Line Editor</a></h1>
2022-08-24 15:22:41 +02:00
<p><span id="index-line-editor"></span> <span
id="index-editor_002c-line"></span> <span id="index-ZLE-1"></span></p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Description-6"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="181-description"><a class="header" href="#181-description">18.1 Description</a></h2>
<p><span id="index-ZLE_002c-use-of"></span></p>
2022-08-24 15:22:41 +02:00
<p>If the ZLE option is set (which it is by default in interactive shells)
and the shell input is attached to the terminal, the user is able to
edit command lines.</p>
2021-05-11 02:29:21 +02:00
<p>There are two display modes. The first, multiline mode, is the default.
2022-08-24 15:22:41 +02:00
It only works if the TERM parameter is set to a valid terminal type that
can move the cursor up. The second, single line mode, is used if TERM is
invalid or incapable of moving the cursor up, or if the SINGLE_LINE_ZLE
option is set. <span
id="index-SINGLE_005fLINE_005fZLE_002c-use-of"></span> <span
id="index-ksh_002c-editor-mode"></span> <span
id="index-editor-ksh-style"></span> This mode is similar to ksh, and
uses no termcap sequences. If TERM is &quot;emacs&quot;, the ZLE option will be
unset by default.</p>
<p><span id="index-BAUD_002c-use-of"></span> <span
id="index-COLUMNS_002c-use-of"></span> <span
id="index-LINES_002c-use-of"></span></p>
<p>The parameters BAUD, COLUMNS, and LINES are also used by the line
2021-05-11 02:29:21 +02:00
editor. See <a href="Parameters.html#Parameters-Used-By-The-Shell">Parameters Used By The
Shell</a>.</p>
<p><span id="index-zle_005fhighlight_002c-use-of"></span></p>
2022-08-24 15:22:41 +02:00
<p>The parameter zle_highlight is also used by the line editor; see
2021-05-11 02:29:21 +02:00
<a href="Zsh-Line-Editor.html#Character-Highlighting">Character Highlighting</a>. Highlighting of
special characters and the region between the cursor and the mark (as
2022-08-24 15:22:41 +02:00
set with set-mark-command in Emacs mode, or by visual-mode in Vi mode)
is enabled by default; consult this reference for more information.
Irascible conservatives will wish to know that all highlighting may be
disabled by the following setting:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zle_highlight=(none)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>In many places, references are made to the numeric argument. This can by
default be entered in emacs mode by holding the alt key and typing a
2021-05-11 02:29:21 +02:00
number, or pressing escape before each digit, and in vi command mode by
typing the number before entering a command. Generally the numeric
argument causes the next command entered to be repeated the specified
number of times, unless otherwise noted below; this is implemented by
2022-08-24 15:22:41 +02:00
the digit-argument widget. See also <a href="Zsh-Line-Editor.html#Arguments">Arguments</a>for some
2021-05-11 02:29:21 +02:00
other ways the numeric argument can be modified.</p>
<hr />
<p><span id="Keymaps"></span> <span id="Keymaps-1"></span></p>
<h2 id="182-keymaps"><a class="header" href="#182-keymaps">18.2 Keymaps</a></h2>
<p><span id="index-keymaps"></span> <span id="index-key-bindings"></span>
<span id="index-bindings_002c-key"></span></p>
<p>A keymap in ZLE contains a set of bindings between key sequences and ZLE
commands. The empty key sequence cannot be bound.</p>
<p>There can be any number of keymaps at any time, and each keymap has one
or more names. If all of a keymaps names are deleted, it disappears.
2022-08-24 15:22:41 +02:00
<span id="index-bindkey_002c-use-of"></span> bindkey can be used to
2021-05-11 02:29:21 +02:00
manipulate keymap names.</p>
<p>Initially, there are eight keymaps:</p>
2022-08-24 15:22:41 +02:00
<p>emacs<br />
2021-05-11 02:29:21 +02:00
EMACS emulation</p>
2022-08-24 15:22:41 +02:00
<p>viins<br />
2021-05-11 02:29:21 +02:00
vi emulation - insert mode</p>
2022-08-24 15:22:41 +02:00
<p>vicmd<br />
2021-05-11 02:29:21 +02:00
vi emulation - command mode</p>
2022-08-24 15:22:41 +02:00
<p>viopp<br />
2021-05-11 02:29:21 +02:00
vi emulation - operator pending</p>
2022-08-24 15:22:41 +02:00
<p>visual<br />
2021-05-11 02:29:21 +02:00
vi emulation - selection active</p>
2022-08-24 15:22:41 +02:00
<p>isearch<br />
2021-05-11 02:29:21 +02:00
incremental search mode</p>
2022-08-24 15:22:41 +02:00
<p>command<br />
2021-05-11 02:29:21 +02:00
read a command name</p>
2022-08-24 15:22:41 +02:00
<p>.safe<br />
2021-05-11 02:29:21 +02:00
fallback keymap</p>
2022-08-24 15:22:41 +02:00
<p>The .safe keymap is special. It can never be altered, and the name can
never be removed. However, it can be linked to other names, which can be
removed. In the future other special keymaps may be added; users should
avoid using names beginning with . for their own keymaps.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-VISUAL"></span> <span id="index-EDITOR"></span></p>
2022-08-24 15:22:41 +02:00
<p>In addition to these names, either emacs or viins is also linked to
the name main. If one of the VISUAL or EDITOR environment variables
contain the string vi when the shell starts up then it will be
viins, otherwise it will be emacs. bindkeys -e and -v options
provide a convenient way to override this default choice.</p>
<p>When the editor starts up, it will select the main keymap. If that
keymap doesnt exist, it will use .safe instead.</p>
<p>In the .safe keymap, each single key is bound to self-insert, except
for ^J (line feed) and ^M (return) which are bound to accept-line. This
is deliberately not pleasant to use; if you are using it, it means you
deleted the main keymap, and you should put it back.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Reading-Commands"></span></p>
<h3 id="1821-reading-commands"><a class="header" href="#1821-reading-commands">18.2.1 Reading Commands</a></h3>
<p>When ZLE is reading a command from the terminal, it may read a sequence
that is bound to some command and is also a prefix of a longer bound
string. In this case ZLE will wait a certain time to see if more
characters are typed, and if not (or they dont match any longer string)
2022-08-24 15:22:41 +02:00
it will execute the binding. This timeout is defined by the KEYTIMEOUT
2021-05-11 02:29:21 +02:00
parameter; its default is 0.4 sec. There is no timeout if the prefix
string is not itself bound to a command.</p>
<p>The key timeout is also applied when ZLE is reading the bytes from a
multibyte character string when it is in the appropriate mode. (This
requires that the shell was compiled with multibyte mode enabled;
typically also the locale has characters with the UTF-8 encoding,
although any multibyte encoding known to the operating system is
supported.) If the second or a subsequent byte is not read within the
2022-08-24 15:22:41 +02:00
timeout period, the shell acts as if ? were typed and resets the input
2021-05-11 02:29:21 +02:00
state.</p>
<p>As well as ZLE commands, key sequences can be bound to other strings, by
2022-08-24 15:22:41 +02:00
using bindkey -s. When such a sequence is read, the replacement string
is pushed back as input, and the command reading process starts again
using these fake keystrokes. This input can itself invoke further
2021-05-11 02:29:21 +02:00
replacement strings, but in order to detect loops the process will be
stopped if there are twenty such replacements without a real command
being read.</p>
<p>A key sequence typed by the user can be turned into a command name for
2022-08-24 15:22:41 +02:00
use in user-defined widgets with the read-command widget, described in
2021-05-11 02:29:21 +02:00
<a href="Zsh-Line-Editor.html#Miscellaneous">Miscellaneous</a> below.</p>
<hr />
<p><span id="Local-Keymaps"></span></p>
<h3 id="1822-local-keymaps"><a class="header" href="#1822-local-keymaps">18.2.2 Local Keymaps</a></h3>
<p><span id="index-local-keymaps"></span></p>
<p>While for normal editing a single keymap is used exclusively, in many
modes a local keymap allows for some keys to be customised. For example,
2022-08-24 15:22:41 +02:00
in an incremental search mode, a binding in the isearch keymap will
override a binding in the main keymap but all keys that are not
2021-05-11 02:29:21 +02:00
overridden can still be used.</p>
<p>If a key sequence is defined in a local keymap, it will hide a key
sequence in the global keymap that is a prefix of that sequence. An
2022-08-24 15:22:41 +02:00
example of this occurs with the binding of iw in viopp as this hides the
binding of i in vicmd. However, a longer sequence in the global keymap
that shares the same prefix can still apply so for example the binding
of ^Xa in the global keymap will be unaffected by the binding of ^Xb in
the local keymap.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Zle-Builtins"></span> <span id="Zle-Builtins-1"></span></p>
<h2 id="183-zle-builtins"><a class="header" href="#183-zle-builtins">18.3 Zle Builtins</a></h2>
<p><span id="index-zle_002c-builtin-commands"></span></p>
2022-08-24 15:22:41 +02:00
<p>The ZLE module contains three related builtin commands. The bindkey
command manipulates keymaps and key bindings; the vared command invokes
ZLE on the value of a shell parameter; and the zle command manipulates
editing widgets and allows command line access to ZLE commands from
within shell functions.</p>
<p><span id="index-bindkey"></span> <span
id="index-keys_002c-rebinding"></span> <span
id="index-rebinding-keys"></span> <span
id="index-keys_002c-binding"></span> <span
id="index-binding-keys"></span> <span id="index-keymaps-1"></span></p>
<p>bindkey [ <code>options</code> ] -l [ -L ] [ <code>keymap</code> ... ]</p>
<p>bindkey [ <code>options</code> ] -d</p>
<p>bindkey [ <code>options</code> ] -D <code>keymap</code> ...</p>
<p>bindkey [ <code>options</code> ] -A <code>old-keymap new-keymap</code></p>
<p>bindkey [ <code>options</code> ] -N <code>new-keymap</code> [ <code>old-keymap</code> ]</p>
<p>bindkey [ <code>options</code> ] -m</p>
<p>bindkey [ <code>options</code> ] -r <code>in-string</code> ...</p>
<p>bindkey [ <code>options</code> ] -s <code>in-string out-string</code> ...</p>
<p>bindkey [ <code>options</code> ] <code>in-string command</code> ...</p>
<p>bindkey [ <code>options</code> ] [ <code>in-string</code> ]</p>
<p>bindkeys options can be divided into three categories: keymap selection
for the current command, operation selection, and others. The keymap
selection options are:</p>
<p>-e<br />
Selects keymap emacs for any operations by the current command, and
also links emacs to main so that it is selected by default the next
time the editor starts.</p>
<p>-v<br />
Selects keymap viins for any operations by the current command, and
also links viins to main so that it is selected by default the next
time the editor starts.</p>
<p>-a<br />
Selects keymap vicmd for any operations by the current command.</p>
<p>-M <code>keymap</code><br />
The <code>keymap</code> specifies a keymap name that is selected for any operations
by the current command.</p>
2021-05-11 02:29:21 +02:00
<p>If a keymap selection is required and none of the options above are
2022-08-24 15:22:41 +02:00
used, the main keymap is used. Some operations do not permit a keymap
to be selected, namely:</p>
<p>-l<br />
List all existing keymap names; if any arguments are given, list just
those keymaps.</p>
<p>If the -L option is also used, list in the form of bindkey commands to
create or link the keymaps. bindkey -lL main shows which keymap is
linked to main, if any, and hence if the standard emacs or vi
emulation is in effect. This option does not show the .safe keymap
because it cannot be created in that fashion; however, neither is
bindkey -lL .safe reported as an error, it simply outputs nothing.</p>
<p>-d<br />
2021-05-11 02:29:21 +02:00
Delete all existing keymaps and reset to the default state.</p>
2022-08-24 15:22:41 +02:00
<p>-D <code>keymap</code> ...<br />
2021-05-11 02:29:21 +02:00
Delete the named <code>keymap</code>s.</p>
2022-08-24 15:22:41 +02:00
<p>-A <code>old-keymap new-keymap</code><br />
Make the <code>new-keymap</code> name an alias for <code>old-keymap</code>, so that both names
refer to the same keymap. The names have equal standing; if either is
deleted, the other remains. If there is already a keymap with the
<code>new-keymap</code> name, it is deleted.</p>
<p>-N <code>new-keymap</code> [ <code>old-keymap</code> ]<br />
Create a new keymap, named <code>new-keymap</code>. If a keymap already has that
name, it is deleted. If an <code>old-keymap</code> name is given, the new keymap is
initialized to be a duplicate of it, otherwise the new keymap will be
empty.</p>
<p>To use a newly created keymap, it should be linked to main. Hence the
sequence of commands to create and use a new keymap mymap initialized
from the emacs keymap (which remains unchanged) is:</p>
<div class="example">
<pre><code class="language-zsh">bindkey -N mymap emacs
2021-05-11 02:29:21 +02:00
bindkey -A mymap main
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Note that while bindkey -A <code>newmap</code> main will work when <code>newmap</code> is
emacs or viins, it will not work for vicmd, as switching from vi insert
to command mode becomes impossible.</p>
<p>The following operations act on the main keymap if no keymap selection
option was given:</p>
<p>-m<br />
Add the built-in set of meta-key bindings to the selected keymap. Only
keys that are unbound or bound to self-insert are affected.</p>
<p>-r <code>in-string</code> ...<br />
2021-05-11 02:29:21 +02:00
Unbind the specified <code>in-string</code>s in the selected keymap. This is
2022-08-24 15:22:41 +02:00
exactly equivalent to binding the strings to undefined-key.</p>
<p>When -R is also used, interpret the <code>in-string</code>s as ranges.</p>
<p>When -p is also used, the <code>in-string</code>s specify prefixes. Any binding
that has the given <code>in-string</code> as a prefix, not including the binding
for the <code>in-string</code> itself, if any, will be removed. For example,</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">bindkey -rpM viins '^['
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>will remove all bindings in the vi-insert keymap beginning with an
2022-08-24 15:22:41 +02:00
escape character (probably cursor keys), but leave the binding for the
escape character itself (probably vi-cmd-mode). This is incompatible
with the option -R.</p>
<p>-s <code>in-string out-string</code> ...<br />
Bind each <code>in-string</code> to each <code>out-string</code>. When <code>in-string</code> is typed,
<code>out-string</code> will be pushed back and treated as input to the line
editor. When -R is also used, interpret the <code>in-string</code>s as ranges.</p>
<p>Note that both <code>in-string</code> and <code>out-string</code> are subject to the same form
of interpretation, as described below.</p>
2021-05-11 02:29:21 +02:00
<p><code>in-string command</code> ...<br />
2022-08-24 15:22:41 +02:00
Bind each <code>in-string</code> to each <code>command</code>. When -R is used, interpret the
<code>in-string</code>s as ranges.</p>
2021-05-11 02:29:21 +02:00
<p>[ <code>in-string</code> ]<br />
2022-08-24 15:22:41 +02:00
List key bindings. If an <code>in-string</code> is specified, the binding of that
string in the selected keymap is displayed. Otherwise, all key bindings
in the selected keymap are displayed. (As a special case, if the -e or
-v option is used alone, the keymap is <em>not</em> displayed - the implicit
linking of keymaps is the only thing that happens.)</p>
<p>When the option -p is used, the <code>in-string</code> must be present. The listing
shows all bindings which have the given key sequence as a prefix, not
including any bindings for the key sequence itself.</p>
<p>When the -L option is used, the list is in the form of bindkey commands
to create the key bindings.</p>
<p>When the -R option is used as noted above, a valid range consists of two
characters, with an optional - between them. All characters between
the two specified, inclusive, are bound as specified.</p>
2021-05-11 02:29:21 +02:00
<p>For either <code>in-string</code> or <code>out-string</code>, the following escape sequences
are recognised:</p>
2022-08-24 15:22:41 +02:00
<p>\a<br />
2021-05-11 02:29:21 +02:00
bell character</p>
2022-08-24 15:22:41 +02:00
<p>\b<br />
2021-05-11 02:29:21 +02:00
backspace</p>
2022-08-24 15:22:41 +02:00
<p>\e, \E<br />
2021-05-11 02:29:21 +02:00
escape</p>
2022-08-24 15:22:41 +02:00
<p>\f<br />
2021-05-11 02:29:21 +02:00
form feed</p>
2022-08-24 15:22:41 +02:00
<p>\n<br />
2021-05-11 02:29:21 +02:00
linefeed (newline)</p>
2022-08-24 15:22:41 +02:00
<p>\r<br />
2021-05-11 02:29:21 +02:00
carriage return</p>
2022-08-24 15:22:41 +02:00
<p>\t<br />
2021-05-11 02:29:21 +02:00
horizontal tab</p>
2022-08-24 15:22:41 +02:00
<p>\v<br />
2021-05-11 02:29:21 +02:00
vertical tab</p>
2022-08-24 15:22:41 +02:00
<p>\<code>NNN</code><br />
2021-05-11 02:29:21 +02:00
character code in octal</p>
2022-08-24 15:22:41 +02:00
<p>\x<code>NN</code><br />
2021-05-11 02:29:21 +02:00
character code in hexadecimal</p>
2022-08-24 15:22:41 +02:00
<p>\u<code>NNNN</code><br />
2021-05-11 02:29:21 +02:00
unicode character code in hexadecimal</p>
2022-08-24 15:22:41 +02:00
<p>\U<code>NNNNNNNN</code><br />
2021-05-11 02:29:21 +02:00
unicode character code in hexadecimal</p>
2022-08-24 15:22:41 +02:00
<p>\M[-]<code>X</code><br />
2021-05-11 02:29:21 +02:00
character with meta bit set</p>
2022-08-24 15:22:41 +02:00
<p>\C[-]<code>X</code><br />
2021-05-11 02:29:21 +02:00
control character</p>
2022-08-24 15:22:41 +02:00
<p>^<code>X</code><br />
2021-05-11 02:29:21 +02:00
control character</p>
2022-08-24 15:22:41 +02:00
<p>In all other cases, \ escapes the following character. Delete is
written as ^?. Note that \M^? and ^\M? are not the same, and
that (unlike emacs), the bindings \M-<code>X</code> and \e<code>X</code> are entirely
distinct, although they are initialized to the same bindings by bindkey
-m.</p>
<p><span id="index-vared"></span> <span
id="index-parameters_002c-editing"></span> <span
id="index-editing-parameters"></span></p>
<p>vared [ -Aacghe ] [ -p <code>prompt</code> ] [ -r <code>rprompt</code> ]</p>
<p>      [ -M <code>main-keymap</code> ] [ -m <code>vicmd-keymap</code> ]</p>
<p>      [ -i <code>init-widget</code> ] [ -f <code>finish-widget</code> ]</p>
<p>      [ -t <code>tty</code> ] <code>name</code></p>
2021-05-11 02:29:21 +02:00
<p>The value of the parameter <code>name</code> is loaded into the edit buffer, and
the line editor is invoked. When the editor exits, <code>name</code> is set to the
2022-08-24 15:22:41 +02:00
string value returned by the editor. When the -c flag is given, the
parameter is created if it doesnt already exist. The -a flag may be
given with -c to create an array parameter, or the -A flag to create an
associative array. If the type of an existing parameter does not match
the type to be created, the parameter is unset and recreated. The -g
flag may be given to suppress warnings from the WARN_CREATE_GLOBAL and
WARN_NESTED_VAR options.</p>
2021-05-11 02:29:21 +02:00
<p>If an array or array slice is being edited, separator characters as
2022-08-24 15:22:41 +02:00
defined in $IFS will be shown quoted with a backslash, as will
2021-05-11 02:29:21 +02:00
backslashes themselves. Conversely, when the edited text is split into
an array, a backslash quotes an immediately following separator
character or backslash; no other special handling of backslashes, or any
handling of quotes, is performed.</p>
<p>Individual elements of existing array or associative array parameters
may be edited by using subscript syntax on <code>name</code>. New elements are
2022-08-24 15:22:41 +02:00
created automatically, even without -c.</p>
<p>If the -p flag is given, the following string will be taken as the
prompt to display at the left. If the -r flag is given, the following
string gives the prompt to display at the right. If the -h flag is
specified, the history can be accessed from ZLE. If the -e flag is
given, typing ^D (Control-D) on an empty line causes vared to exit
2021-05-11 02:29:21 +02:00
immediately with a non-zero return value.</p>
2022-08-24 15:22:41 +02:00
<p>The -M option gives a keymap to link to the main keymap during editing,
and the -m option gives a keymap to link to the vicmd keymap during
editing. For vi-style editing, this allows a pair of keymaps to override
viins and vicmd. For emacs-style editing, only -M is normally needed but
the -m option may still be used. On exit, the previous keymaps will be
restored.</p>
<p>Vared calls the usual zle-line-init and zle-line-finish hooks before
and after it takes control. Using the -i and -f options, it is possible
to replace these with other custom widgets.</p>
<p>If -t <code>tty</code> is given, <code>tty</code> is the name of a terminal device to be
used instead of the default /dev/tty. If <code>tty</code> does not refer to a
2021-05-11 02:29:21 +02:00
terminal an error is reported.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-zle"></span> <span
id="index-widgets_002c-rebinding"></span> <span
id="index-rebinding-widgets"></span> <span
id="index-widgets_002c-binding"></span> <span
id="index-binding-widgets"></span> <span
id="index-widgets_002c-invoking"></span> <span
id="index-invoking-widgets"></span> <span
id="index-widgets_002c-calling"></span> <span
id="index-calling-widgets"></span> <span
id="index-widgets_002c-defining"></span> <span
id="index-defining-widgets"></span></p>
<p>zle</p>
<p>zle -l [ -L | -a ] [ <code>string</code> ... ]</p>
<p>zle -D <code>widget</code> ...</p>
<p>zle -A <code>old-widget</code> <code>new-widget</code></p>
<p>zle -N <code>widget</code> [ <code>function</code> ]</p>
<p>zle -f <code>flag</code> [ <code>flag</code>... ]</p>
<p>zle -C <code>widget</code> <code>completion-widget</code> <code>function</code></p>
<p>zle -R [ -c ] [ <code>display-string</code> ] [ <code>string</code> ... ]</p>
<p>zle -M <code>string</code></p>
<p>zle -U <code>string</code></p>
<p>zle -K <code>keymap</code></p>
<p>zle -F [ -L | -w ] [ <code>fd</code> [ <code>handler</code> ] ]</p>
<p>zle -I</p>
<p>zle -T [ tc <code>function</code> | -r tc | -L ]</p>
<p>zle <code>widget</code> [ -n <code>num</code> ] [ -f <code>flag</code> ] [ -Nw ] [ -K <code>keymap</code> ]
<code>args</code> ...</p>
<p>The zle builtin performs a number of different actions concerning ZLE.</p>
2021-05-11 02:29:21 +02:00
<p>With no options and no arguments, only the return status will be set. It
is zero if ZLE is currently active and widgets could be invoked using
this builtin command and non-zero otherwise. Note that even if non-zero
status is returned, zle may still be active as part of the completion
system; this does not allow direct calls to ZLE widgets.</p>
<p>Otherwise, which operation it performs depends on its options:</p>
2022-08-24 15:22:41 +02:00
<p>-l [ -L | -a ] [ <code>string</code> ]<br />
List all existing user-defined widgets. If the -L option is used, list
in the form of zle commands to create the widgets.</p>
<p>When combined with the -a option, all widget names are listed, including
the builtin ones. In this case the -L option is ignored.</p>
<p>If at least one <code>string</code> is given, and -a is present or -L is not used,
nothing will be printed. The return status will be zero if all <code>string</code>s
are names of existing widgets and non-zero if at least one <code>string</code> is
not a name of a defined widget. If -a is also present, all widget names
are used for the comparison including builtin widgets, else only
user-defined widgets are used.</p>
<p>If at least one <code>string</code> is present and the -L option is used,
user-defined widgets matching any <code>string</code> are listed in the form of zle
commands to create the widgets.</p>
<p>-D <code>widget</code> ...<br />
2021-05-11 02:29:21 +02:00
Delete the named <code>widget</code>s.</p>
2022-08-24 15:22:41 +02:00
<p>-A <code>old-widget</code> <code>new-widget</code><br />
Make the <code>new-widget</code> name an alias for <code>old-widget</code>, so that both names
refer to the same widget. The names have equal standing; if either is
deleted, the other remains. If there is already a widget with the
<code>new-widget</code> name, it is deleted.</p>
<p>-N <code>widget</code> [ <code>function</code> ]<br />
2021-05-11 02:29:21 +02:00
Create a user-defined widget. If there is already a widget with the
2022-08-24 15:22:41 +02:00
specified name, it is overwritten. When the new widget is invoked from
within the editor, the specified shell <code>function</code> is called. If no
function name is specified, it defaults to the same name as the widget.
For further information, see <a href="Zsh-Line-Editor.html#Zle-Widgets">Zle Widgets</a>.</p>
<p>-f <code>flag</code> [ <code>flag</code>... ]<br />
Set various flags on the running widget. Possible values for <code>flag</code> are:</p>
<p>yank for indicating that the widget has yanked text into the buffer. If
the widget is wrapping an existing internal widget, no further action is
necessary, but if it has inserted the text manually, then it should also
take care to set YANK_START and YANK_END correctly. yankbefore does the
same but is used when the yanked text appears after the cursor.</p>
<p>kill for indicating that text has been killed into the cutbuffer. When
repeatedly invoking a kill widget, text is appended to the cutbuffer
instead of replacing it, but when wrapping such widgets, it is necessary
to call zle -f kill to retain this effect.</p>
<p>vichange for indicating that the widget represents a vi change that can
be repeated as a whole with vi-repeat-change. The flag should be set
early in the function before inspecting the value of NUMERIC or invoking
other widgets. This has no effect for a widget invoked from insert mode.
If insert mode is active when the widget finishes, the change extends
until next returning to command mode.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-completion-widgets_002c-creating"></span></p>
2022-08-24 15:22:41 +02:00
<p>-C <code>widget</code> <code>completion-widget</code> <code>function</code><br />
Create a user-defined completion widget named <code>widget</code>. The completion
widget will behave like the built-in completion-widget whose name is
given as <code>completion-widget</code>. To generate the completions, the shell
function <code>function</code> will be called. For further information, see
<a href="Completion-Widgets.html#Completion-Widgets">Completion Widgets</a>.</p>
<p>-R [ -c ] [ <code>display-string</code> ] [ <code>string</code> ... ]<br />
Redisplay the command line. If a <code>display-string</code> is given and not
empty, this is shown in the status line (immediately below the line
being edited).</p>
<p>If the optional <code>string</code>s are given they are listed below the prompt in
the same way as completion lists are printed. If no <code>string</code>s are given
but the -c option is used such a list is cleared.</p>
<p>Note that immediately after returning from running widgets, the command
line will be redisplayed and the strings displayed will be erased.
Therefore, this option is only useful for widgets that do not exit
immediately after using it.</p>
<p>This command can safely be called outside user defined widgets; if zle
is active, the display will be refreshed, while if zle is not active,
the command has no effect. In this case there will usually be no other
arguments.</p>
2021-05-11 02:29:21 +02:00
<p>The status is zero if zle was active, else one.</p>
2022-08-24 15:22:41 +02:00
<p>-M <code>string</code><br />
As with the -R option, the <code>string</code> will be displayed below the command
line; unlike the -R option, the string will not be put into the status
line but will instead be printed normally below the prompt. This means
that the <code>string</code> will still be displayed after the widget returns
(until it is overwritten by subsequent commands).</p>
<p>-U <code>string</code><br />
This pushes the characters in the <code>string</code> onto the input stack of ZLE.
After the widget currently executed finishes ZLE will behave as if the
characters in the <code>string</code> were typed by the user.</p>
<p>As ZLE uses a stack, if this option is used repeatedly the last string
pushed onto the stack will be processed first. However, the characters
in each <code>string</code> will be processed in the order in which they appear in
the string.</p>
<p>-K <code>keymap</code><br />
Selects the keymap named <code>keymap</code>. An error message will be displayed if
there is no such keymap.</p>
<p>This keymap selection affects the interpretation of following keystrokes
within this invocation of ZLE. Any following invocation (e.g., the next
command line) will start as usual with the main keymap selected.</p>
<p>-F [ -L | -w ] [ <code>fd</code> [ <code>handler</code> ] ]<br />
2021-05-11 02:29:21 +02:00
Only available if your system supports one of the poll or select
system calls; most modern systems do.</p>
2022-08-24 15:22:41 +02:00
<p>Installs <code>handler</code> (the name of a shell function) to handle input from
file descriptor <code>fd</code>. Installing a handler for an <code>fd</code> which is already
handled causes the existing handler to be replaced. Any number of
handlers for any number of readable file descriptors may be installed.
Note that zle makes no attempt to check whether this <code>fd</code> is actually
readable when installing the handler. The user must make their own
arrangements for handling the file descriptor when zle is not active.</p>
<p>When zle is attempting to read data, it will examine both the terminal
and the list of handled <code>fd</code>s. If data becomes available on a handled
<code>fd</code>, zle calls <code>handler</code> with the fd which is ready for reading as the
first argument. Under normal circumstances this is the only argument,
but if an error was detected, a second argument provides details: hup
for a disconnect, nval for a closed or otherwise invalid descriptor,
or err for any other condition. Systems that support only the select
system call always use err.</p>
<p>If the option -w is also given, the <code>handler</code> is instead a line editor
widget, typically a shell function made into a widget using zle -N. In
that case <code>handler</code> can use all the facilities of zle to update the
current editing line. Note, however, that as handling <code>fd</code> takes place
at a low level changes to the display will not automatically appear; the
widget should call zle -R to force redisplay. As of this writing,
widget handlers only support a single argument and thus are never passed
a string for error state, so widgets must be prepared to test the
descriptor themselves.</p>
2021-05-11 02:29:21 +02:00
<p>If either type of handler produces output to the terminal, it should
2022-08-24 15:22:41 +02:00
call zle -I before doing so (see below). Handlers should not attempt
to read from the terminal.</p>
<p>If no <code>handler</code> is given, but an <code>fd</code> is present, any handler for that
<code>fd</code> is removed. If there is none, an error message is printed and
status 1 is returned.</p>
<p>If no arguments are given, or the -L option is supplied, a list of
handlers is printed in a form which can be stored for later execution.</p>
<p>An <code>fd</code> (but not a <code>handler</code>) may optionally be given with the -L
option; in this case, the function will list the handler if any, else
silently return status 1.</p>
<p>Note that this feature should be used with care. Activity on one of the
<code>fd</code>s which is not properly handled can cause the terminal to become
unusable. Removing an <code>fd</code> handler from within a signal trap may cause</p>
<p>Here is a simple example of using this feature. A connection to a remote
TCP port is created using the ztcp command; see <a href="Zsh-Modules.html#The-zsh_002fnet_002ftcp-Module">The zsh/net/tcp
Module</a>. Then a handler
is installed which simply prints out any data which arrives on this
connection. Note that select will indicate that the file descriptor
needs handling if the remote side has closed the connection; we handle
that by testing for a failed read.</p>
<div class="example">
<pre><code class="language-zsh">if ztcp pwspc 2811; then
2021-05-11 02:29:21 +02:00
tcpfd=$REPLY
handler() {
zle -I
local line
if ! read -r line &lt;&amp;$1; then
# select marks this fd if we reach EOF,
# so handle this specially.
print &quot;[Read on fd $1 failed, removing.]&quot; &gt;&amp;2
zle -F $1
return 1
fi
print -r - $line
}
zle -F $tcpfd handler
fi
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>-I<br />
Unusually, this option is most useful outside ordinary widget functions,
though it may be used within if normal output to the terminal is
required. It invalidates the current zle display in preparation for
output; typically this will be from a trap function. It has no effect if
zle is not active. When a trap exits, the shell checks to see if the
display needs restoring, hence the following will print output in such a
way as not to disturb the line being edited:</p>
<div class="example">
<pre><code class="language-zsh">TRAPUSR1() {
2021-05-11 02:29:21 +02:00
# Invalidate zle display
[[ -o zle ]] &amp;&amp; zle -I
# Show output
print Hello
}
</code></pre>
</div>
<p>In general, the trap function may need to test whether zle is active
2022-08-24 15:22:41 +02:00
before using this method (as shown in the example), since the zsh/zle
module may not even be loaded; if it is not, the command can be skipped.</p>
<p>It is possible to call zle -I several times before control is returned
to the editor; the display will only be invalidated the first time to
minimise disruption.</p>
2021-05-11 02:29:21 +02:00
<p>Note that there are normally better ways of manipulating the display
2022-08-24 15:22:41 +02:00
from within zle widgets; see, for example, zle -R above.</p>
<p>The returned status is zero if zle was invalidated, even though this may
have been by a previous call to zle -I or by a system notification. To
test if a zle widget may be called at this point, execute zle with no
arguments and examine the return status.</p>
<p>-T<br />
2021-05-11 02:29:21 +02:00
This is used to add, list or remove internal transformations on the
2022-08-24 15:22:41 +02:00
processing performed by the line editor. It is typically used only for
debugging or testing and is therefore of little interest to the general
user.</p>
<p>zle -T <code>transformation</code> <code>func</code> specifies that the given
2021-05-11 02:29:21 +02:00
<code>transformation</code> (see below) is effected by shell function <code>func</code>.</p>
2022-08-24 15:22:41 +02:00
<p>zle -Tr <code>transformation</code> removes the given <code>transformation</code> if it was
present (it is not an error if none was).</p>
<p>zle -TL can be used to list all transformations currently in
2021-05-11 02:29:21 +02:00
operation.</p>
2022-08-24 15:22:41 +02:00
<p>Currently the only transformation is tc. This is used instead of
outputting termcap codes to the terminal. When the transformation is in
operation the shell function is passed the termcap code that would be
output as its first argument; if the operation required a numeric
argument, that is passed as a second argument. The function should set
the shell variable REPLY to the transformed termcap code. Typically this
is used to produce some simply formatted version of the code and
optional argument for debugging or testing. Note that this
transformation is not applied to other non-printing characters such as
carriage returns and newlines.</p>
<p><code>widget</code> [ -n <code>num</code> ] [ -f <code>flag</code> ] [ -Nw ] [ -K <code>keymap</code> ] <code>args</code> ...<br />
Invoke the specified <code>widget</code>. This can only be done when ZLE is active;
normally this will be within a user-defined widget.</p>
<p>With the options -n and -N, the current numeric argument will be saved
and then restored after the call to <code>widget</code>; -n <code>num</code> sets the
numeric argument temporarily to <code>num</code>, while -N sets it to the
default, i.e. as if there were none.</p>
<p>With the option -K, <code>keymap</code> will be used as the current keymap during
the execution of the widget. The previous keymap will be restored when
the widget exits.</p>
2021-05-11 02:29:21 +02:00
<p>Normally, calling a widget in this way does not set the special
2022-08-24 15:22:41 +02:00
parameter WIDGET and related parameters, so that the environment appears
as if the top-level widget called by the user were still active. With
the option -w, WIDGET and related parameters are set to reflect the
widget being executed by the zle call.</p>
<p>Normally, when <code>widget</code> returns the special parameter LASTWIDGET will
point to it. This can be inhibited by passing the option -f nolast.</p>
2021-05-11 02:29:21 +02:00
<p>Any further arguments will be passed to the widget; note that as
standard argument handling is performed, any general argument list
2022-08-24 15:22:41 +02:00
should be preceded by --. If it is a shell function, these are passed
down as positional parameters; for builtin widgets it is up to the
widget in question what it does with them. Currently arguments are only
handled by the incremental-search commands, the history-search-forward
and -backward and the corresponding functions prefixed by vi-, and by
universal-argument. No error is flagged if the command does not use the
arguments, or only uses some of them.</p>
2021-05-11 02:29:21 +02:00
<p>The return status reflects the success or failure of the operation
2022-08-24 15:22:41 +02:00
carried out by the widget, or if it is a user-defined widget the return
status of the shell function.</p>
<p>A non-zero return status causes the shell to beep when the widget exits,
unless the BEEP options was unset or the widget was called via the zle
command. Thus if a user defined widget requires an immediate beep, it
should call the beep widget directly.</p>
<hr />
<p><span id="Zle-Widgets"></span> <span id="Zle-Widgets-1"></span></p>
<h2 id="184-zle-widgets"><a class="header" href="#184-zle-widgets">18.4 Zle Widgets</a></h2>
2021-05-11 02:29:21 +02:00
<p><span id="index-widgets"></span></p>
<p>All actions in the editor are performed by widgets. A widgets job is
simply to perform some small action. The ZLE commands that key sequences
in keymaps are bound to are in fact widgets. Widgets can be user-defined
or built in.</p>
2022-08-24 15:22:41 +02:00
<p>The standard widgets built into ZLE are listed in <a href="Zsh-Line-Editor.html#Standard-Widgets">Standard
Widgets</a>. Other built-in widgets can be defined by
other modules (see <a href="Zsh-Modules.html#Zsh-Modules">Zsh Modules</a>). Each
built-in widget has two names: its normal canonical name, and the same
name preceded by a .. The . name is special: it cant be rebound to
a different widget. This makes the widget available even when its usual
name has been redefined.</p>
<p>User-defined widgets are defined using zle -N, and implemented as
2021-05-11 02:29:21 +02:00
shell functions. When the widget is executed, the corresponding shell
function is executed, and can perform editing (or other) actions. It is
recommended that user-defined widgets should not have names starting
2022-08-24 15:22:41 +02:00
with ..</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="User_002dDefined-Widgets"></span> <span
id="User_002dDefined-Widgets-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="185-user-defined-widgets"><a class="header" href="#185-user-defined-widgets">18.5 User-Defined Widgets</a></h2>
<p><span id="index-widgets_002c-user_002ddefined"></span></p>
<p>User-defined widgets, being implemented as shell functions, can execute
any normal shell command. They can also run other widgets (whether
2022-08-24 15:22:41 +02:00
built-in or user-defined) using the zle builtin command. The standard
2021-05-11 02:29:21 +02:00
input of the function is redirected from /dev/null to prevent external
commands from unintentionally blocking ZLE by reading from the terminal,
2022-08-24 15:22:41 +02:00
but read -k or read -q can be used to read characters. Finally, they can
examine and edit the ZLE buffer being edited by reading and setting the
special parameters described below.</p>
<p><span id="index-parameters_002c-editor"></span> <span
id="index-parameters_002c-zle"></span></p>
2021-05-11 02:29:21 +02:00
<p>These special parameters are always available in widget functions, but
are not in any way special outside ZLE. If they have some normal value
outside ZLE, that value is temporarily inaccessible, but will return
when the widget function exits. These special parameters in fact have
2022-08-24 15:22:41 +02:00
local scope, like parameters created in a function using local.</p>
2021-05-11 02:29:21 +02:00
<p>Inside completion widgets and traps called while ZLE is active, these
parameters are available read-only.</p>
<p>Note that the parameters appear as local to any ZLE widget in which they
appear. Hence if it is desired to override them this needs to be done
within a nested function:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">widget-function() {
2021-05-11 02:29:21 +02:00
# $WIDGET here refers to the special variable
# that is local inside widget-function
() {
# This anonymous nested function allows WIDGET
# to be used as a local variable. The -h
# removes the special status of the variable.
local -h WIDGET
}
}
</code></pre>
</div>
<p><span id="index-BUFFER"></span></p>
2022-08-24 15:22:41 +02:00
<p>BUFFER (scalar)</p>
2021-05-11 02:29:21 +02:00
<p>The entire contents of the edit buffer. If it is written to, the cursor
remains at the same offset, unless that would put it outside the buffer.</p>
<p><span id="index-BUFFERLINES"></span></p>
2022-08-24 15:22:41 +02:00
<p>BUFFERLINES (integer)</p>
2021-05-11 02:29:21 +02:00
<p>The number of screen lines needed for the edit buffer currently
displayed on screen (i.e. without any changes to the preceding
parameters done after the last redisplay); read-only.</p>
<p><span id="index-CONTEXT"></span></p>
2022-08-24 15:22:41 +02:00
<p>CONTEXT (scalar)</p>
2021-05-11 02:29:21 +02:00
<p>The context in which zle was called to read a line; read-only. One of
the values:</p>
2022-08-24 15:22:41 +02:00
<p>start<br />
The start of a command line (at prompt PS1).</p>
<p>cont<br />
A continuation to a command line (at prompt PS2).</p>
<p>select<br />
In a select loop (at prompt PS3).</p>
<p>vared<br />
Editing a variable in vared.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-CURSOR"></span></p>
2022-08-24 15:22:41 +02:00
<p>CURSOR (integer)</p>
2021-05-11 02:29:21 +02:00
<p>The offset of the cursor, within the edit buffer. This is in the range 0
2022-08-24 15:22:41 +02:00
to $#BUFFER, and is by definition equal to $#LBUFFER. Attempts to move
the cursor outside the buffer will result in the cursor being moved to
the appropriate end of the buffer.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-CUTBUFFER"></span></p>
2022-08-24 15:22:41 +02:00
<p>CUTBUFFER (scalar)</p>
<p>The last item cut using one of the kill- commands; the string which
2021-05-11 02:29:21 +02:00
the next yank would insert in the line. Later entries in the kill ring
2022-08-24 15:22:41 +02:00
are in the array killring. Note that the command zle
copy-region-as-kill <code>string</code> can be used to set the text of the cut
2021-05-11 02:29:21 +02:00
buffer from a shell function and cycle the kill ring in the same way as
interactively killing text.</p>
<p><span id="index-HISTNO"></span></p>
2022-08-24 15:22:41 +02:00
<p>HISTNO (integer)</p>
2021-05-11 02:29:21 +02:00
<p>The current history number. Setting this has the same effect as moving
up or down in the history to the corresponding history line. An attempt
to set it is ignored if the line is not stored in the history. Note this
2022-08-24 15:22:41 +02:00
is not the same as the parameter HISTCMD, which always gives the number
of the history line being added to the main shells history. HISTNO
refers to the line being retrieved within zle.</p>
<p><span id="index-ISEARCHMATCH_005fACTIVE"></span> <span
id="index-ISEARCHMATCH_005fSTART"></span> <span
id="index-ISEARCHMATCH_005fEND"></span></p>
<p>ISEARCHMATCH_ACTIVE (integer)</p>
<p>ISEARCHMATCH_START (integer)</p>
<p>ISEARCHMATCH_END (integer)</p>
<p>ISEARCHMATCH_ACTIVE indicates whether a part of the BUFFER is currently
matched by an incremental search pattern. ISEARCHMATCH_START and
ISEARCHMATCH_END give the location of the matched part and are in the
same units as CURSOR. They are only valid for reading when
ISEARCHMATCH_ACTIVE is non-zero.</p>
2021-05-11 02:29:21 +02:00
<p>All parameters are read-only.</p>
<p><span id="index-KEYMAP"></span></p>
2022-08-24 15:22:41 +02:00
<p>KEYMAP (scalar)</p>
2021-05-11 02:29:21 +02:00
<p>The name of the currently selected keymap; read-only.</p>
<p><span id="index-KEYS"></span></p>
2022-08-24 15:22:41 +02:00
<p>KEYS (scalar)</p>
2021-05-11 02:29:21 +02:00
<p>The keys typed to invoke this widget, as a literal string; read-only.</p>
<p><span id="index-KEYS_005fQUEUED_005fCOUNT"></span></p>
2022-08-24 15:22:41 +02:00
<p>KEYS_QUEUED_COUNT (integer)</p>
2021-05-11 02:29:21 +02:00
<p>The number of bytes pushed back to the input queue and therefore
available for reading immediately before any I/O is done; read-only. See
2022-08-24 15:22:41 +02:00
also PENDING; the two values are distinct.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-killring"></span></p>
2022-08-24 15:22:41 +02:00
<p>killring (array)</p>
2021-05-11 02:29:21 +02:00
<p>The array of previously killed items, with the most recently killed
2022-08-24 15:22:41 +02:00
first. This gives the items that would be retrieved by a yank-pop in the
same order. Note, however, that the most recently killed item is in
$CUTBUFFER; $killring shows the array of previous entries.</p>
2021-05-11 02:29:21 +02:00
<p>The default size for the kill ring is eight, however the length may be
changed by normal array operations. Any empty string in the kill ring is
2022-08-24 15:22:41 +02:00
ignored by the yank-pop command, hence the size of the array effectively
sets the maximum length of the kill ring, while the number of non-zero
strings gives the current length, both as seen by the user at the
command line.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-LASTABORTEDSEARCH"></span></p>
2022-08-24 15:22:41 +02:00
<p>LASTABORTEDSEARCH (scalar)</p>
2021-05-11 02:29:21 +02:00
<p>The last search string used by an interactive search that was aborted by
the user (status 3 returned by the search widget).</p>
<p><span id="index-LASTSEARCH"></span></p>
2022-08-24 15:22:41 +02:00
<p>LASTSEARCH (scalar)</p>
2021-05-11 02:29:21 +02:00
<p>The last search string used by an interactive search; read-only. This is
set even if the search failed (status 0, 1 or 2 returned by the search
widget), but not if it was aborted by the user.</p>
<p><span id="index-LASTWIDGET"></span></p>
2022-08-24 15:22:41 +02:00
<p>LASTWIDGET (scalar)</p>
2021-05-11 02:29:21 +02:00
<p>The name of the last widget that was executed; read-only.</p>
<p><span id="index-LBUFFER"></span></p>
2022-08-24 15:22:41 +02:00
<p>LBUFFER (scalar)</p>
2021-05-11 02:29:21 +02:00
<p>The part of the buffer that lies to the left of the cursor position. If
it is assigned to, only that part of the buffer is replaced, and the
2022-08-24 15:22:41 +02:00
cursor remains between the new $LBUFFER and the old $RBUFFER.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-MARK"></span></p>
2022-08-24 15:22:41 +02:00
<p>MARK (integer)</p>
<p>Like CURSOR, but for the mark. With vi-mode operators that wait for a
movement command to select a region of text, setting MARK allows the
2021-05-11 02:29:21 +02:00
selection to extend in both directions from the initial cursor position.</p>
<p><span id="index-NUMERIC"></span></p>
2022-08-24 15:22:41 +02:00
<p>NUMERIC (integer)</p>
2021-05-11 02:29:21 +02:00
<p>The numeric argument. If no numeric argument was given, this parameter
is unset. When this is set inside a widget function, builtin widgets
2022-08-24 15:22:41 +02:00
called with the zle builtin command will use the value assigned. If it
2021-05-11 02:29:21 +02:00
is unset inside a widget function, builtin widgets called behave as if
no numeric argument was given.</p>
<p><span id="index-PENDING"></span></p>
2022-08-24 15:22:41 +02:00
<p>PENDING (integer)</p>
2021-05-11 02:29:21 +02:00
<p>The number of bytes pending for input, i.e. the number of bytes which
have already been typed and can immediately be read. On systems where
the shell is not able to get this information, this parameter will
2022-08-24 15:22:41 +02:00
always have a value of zero. Read-only. See also KEYS_QUEUED_COUNT; the
two values are distinct.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-PREBUFFER"></span></p>
2022-08-24 15:22:41 +02:00
<p>PREBUFFER (scalar)</p>
2021-05-11 02:29:21 +02:00
<p>In a multi-line input at the secondary prompt, this read-only parameter
contains the contents of the lines before the one the cursor is
currently in.</p>
<p><span id="index-PREDISPLAY"></span></p>
2022-08-24 15:22:41 +02:00
<p>PREDISPLAY (scalar)</p>
2021-05-11 02:29:21 +02:00
<p>does not have to be a complete line; to display a complete line, a
newline must be appended explicitly. The text is reset on each new
invocation (but not recursive invocation) of zle.</p>
<p><span id="index-POSTDISPLAY"></span></p>
2022-08-24 15:22:41 +02:00
<p>POSTDISPLAY (scalar)</p>
2021-05-11 02:29:21 +02:00
<p>does not have to be a complete line; to display a complete line, a
newline must be prepended explicitly. The text is reset on each new
invocation (but not recursive invocation) of zle.</p>
<p><span id="index-RBUFFER"></span></p>
2022-08-24 15:22:41 +02:00
<p>RBUFFER (scalar)</p>
2021-05-11 02:29:21 +02:00
<p>The part of the buffer that lies to the right of the cursor position. If
it is assigned to, only that part of the buffer is replaced, and the
2022-08-24 15:22:41 +02:00
cursor remains between the old $LBUFFER and the new $RBUFFER.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-REGION_005fACTIVE"></span></p>
2022-08-24 15:22:41 +02:00
<p>REGION_ACTIVE (integer)</p>
2021-05-11 02:29:21 +02:00
<p>Indicates if the region is currently active. It can be assigned 0 or 1
to deactivate and activate the region respectively. A value of 2
activates the region in line-wise mode with the highlighted text
extending for whole lines only; see <a href="Zsh-Line-Editor.html#Character-Highlighting">Character
Highlighting</a>.</p>
<p><span id="index-region_005fhighlight"></span></p>
2022-08-24 15:22:41 +02:00
<p>region_highlight (array)</p>
2021-05-11 02:29:21 +02:00
<p>Each element of this array may be set to a string that describes
highlighting for an arbitrary region of the command line that will take
effect the next time the command line is redisplayed. Highlighting and
2022-08-24 15:22:41 +02:00
POSTDISPLAY are possible, but note that the P flag is needed for
character indexing to include PREDISPLAY.</p>
<p>Each string consists of the following whitespace-separated parts:</p>
2021-05-11 02:29:21 +02:00
<ul>
2022-08-24 15:22:41 +02:00
<li>
<p>Optionally, a P to signify that the start and end offset that
follow include any string set by the PREDISPLAY special parameter;
2021-05-11 02:29:21 +02:00
this is needed if the predisplay string itself is to be highlighted.
2022-08-24 15:22:41 +02:00
Whitespace between the P and the start offset is optional.</p>
</li>
<li>
<p>A start offset in the same units as CURSOR.</p>
</li>
<li>
<p>An end offset in the same units as CURSOR.</p>
</li>
<li>
<p>A highlight specification in the same format as used for contexts in
the parameter zle_highlight, see <a href="Zsh-Line-Editor.html#Character-Highlighting">Character
Highlighting</a>; for example, standout or
fg=red,bold.</p>
</li>
<li>
<p>Optionally, a string of the form memo=<code>token</code>. The <code>token</code>
consists of everything between the = and the next whitespace,
comma, NUL, or the end of the string. The <code>token</code> is preserved
verbatim but not parsed in any way.</p>
<p>Plugins may use this to identify array elements they have added: for
example, a plugin might set <code>token</code> to its (the plugins) name and
then use region_highlight=( ${region_highlight:#*memo=<code>token</code>} )
in order to remove array elements it have added.</p>
<p>(This example uses the ${<code>name</code>:#<code>pattern</code>} array-grepping syntax
described in <a href="Expansion.html#Parameter-Expansion">Parameter
Expansion</a>.)</p>
</li>
2021-05-11 02:29:21 +02:00
</ul>
<p>For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">region_highlight=(&quot;P0 20 bold memo=foobar&quot;)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>specifies that the first twenty characters of the text including any
predisplay string should be highlighted in bold.</p>
2022-08-24 15:22:41 +02:00
<p>Note that the effect of region_highlight is not saved and disappears as
soon as the line is accepted.</p>
<p>Note that zsh 5.8 and older do not support the memo=<code>token</code> field and
may misparse the third (highlight specification) field when a memo is
given.</p>
2021-05-11 02:29:21 +02:00
<p>The final highlighting on the command line depends on both
2022-08-24 15:22:41 +02:00
region_highlight and zle_highlight; see <a href="Zsh-Line-Editor.html#Character-Highlighting">Character
2021-05-11 02:29:21 +02:00
Highlighting</a> for details.</p>
<p><span id="index-registers"></span></p>
2022-08-24 15:22:41 +02:00
<p>registers (associative array)</p>
2021-05-11 02:29:21 +02:00
<p>The contents of each of the vi register buffers. These are typically set
2022-08-24 15:22:41 +02:00
using vi-set-buffer followed by a delete, change or yank command.</p>
<p><span id="index-SUFFIX_005fACTIVE"></span> <span
id="index-SUFFIX_005fSTART"></span> <span
id="index-SUFFIX_005fEND"></span></p>
<p>SUFFIX_ACTIVE (integer)</p>
<p>SUFFIX_START (integer)</p>
<p>SUFFIX_END (integer)</p>
<p>SUFFIX_ACTIVE indicates whether an auto-removable completion suffix is
currently active. SUFFIX_START and SUFFIX_END give the location of the
suffix and are in the same units as CURSOR. They are only valid for
reading when SUFFIX_ACTIVE is non-zero.</p>
2021-05-11 02:29:21 +02:00
<p>All parameters are read-only.</p>
<p><span id="index-UNDO_005fCHANGE_005fNO"></span></p>
2022-08-24 15:22:41 +02:00
<p>UNDO_CHANGE_NO (integer)</p>
2021-05-11 02:29:21 +02:00
<p>A number representing the state of the undo history. The only use of
2022-08-24 15:22:41 +02:00
this is passing as an argument to the undo widget in order to undo back
to the recorded point. Read-only.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-UNDO_005fLIMIT_005fNO"></span></p>
2022-08-24 15:22:41 +02:00
<p>UNDO_LIMIT_NO (integer)</p>
2021-05-11 02:29:21 +02:00
<p>A number corresponding to an existing change in the undo history;
2022-08-24 15:22:41 +02:00
compare UNDO_CHANGE_NO. If this is set to a value greater than zero, the
undo command will not allow the line to be undone beyond the given
change number. It is still possible to use zle undo <code>change</code> in a
2021-05-11 02:29:21 +02:00
widget to undo beyond that point; in that case, it will not be possible
2022-08-24 15:22:41 +02:00
to undo at all until UNDO_LIMIT_NO is reduced. Set to 0 to disable the
2021-05-11 02:29:21 +02:00
limit.</p>
<p>A typical use of this variable in a widget function is as follows (note
the additional function scope is required):</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">() {
2021-05-11 02:29:21 +02:00
local UNDO_LIMIT_NO=$UNDO_CHANGE_NO
# Perform some form of recursive edit.
}
</code></pre>
</div>
<p><span id="index-WIDGET"></span></p>
2022-08-24 15:22:41 +02:00
<p>WIDGET (scalar)</p>
2021-05-11 02:29:21 +02:00
<p>The name of the widget currently being executed; read-only.</p>
<p><span id="index-WIDGETFUNC"></span></p>
2022-08-24 15:22:41 +02:00
<p>WIDGETFUNC (scalar)</p>
2021-05-11 02:29:21 +02:00
<p>The name of the shell function that implements a widget defined with
2022-08-24 15:22:41 +02:00
either zle -N or zle -C. In the former case, this is the second argument
to the zle -N command that defined the widget, or the first argument if
there was no second argument. In the latter case this is the third
argument to the zle -C command that defined the widget. Read-only.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-WIDGETSTYLE"></span></p>
2022-08-24 15:22:41 +02:00
<p>WIDGETSTYLE (scalar)</p>
2021-05-11 02:29:21 +02:00
<p>Describes the implementation behind the completion widget currently
2022-08-24 15:22:41 +02:00
being executed; the second argument that followed zle -C when the widget
was defined. This is the name of a builtin completion widget. For
widgets defined with zle -N this is set to the empty string. Read-only.</p>
<p><span id="index-YANK_005fACTIVE"></span> <span
id="index-YANK_005fSTART"></span> <span id="index-YANK_005fEND"></span></p>
<p>YANK_ACTIVE (integer)</p>
<p>YANK_START (integer)</p>
<p>YANK_END (integer)</p>
<p>YANK_ACTIVE indicates whether text has just been yanked (pasted) into
the buffer. YANK_START and YANK_END give the location of the pasted text
and are in the same units as CURSOR. They are only valid for reading
when YANK_ACTIVE is non-zero. They can also be assigned by widgets that
insert text in a yank-like fashion, for example wrappers of
bracketed-paste. See also zle -f.</p>
<p>YANK_ACTIVE is read-only.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-ZLE_005fRECURSIVE"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZLE_RECURSIVE (integer)</p>
<p>Usually zero, but incremented inside any instance of recursive-edit.
2021-05-11 02:29:21 +02:00
Hence indicates the current recursion level.</p>
2022-08-24 15:22:41 +02:00
<p>ZLE_RECURSIVE is read-only.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-ZLE_005fSTATE"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZLE_STATE (scalar)</p>
<p>Contains a set of space-separated words that describe the current zle
2021-05-11 02:29:21 +02:00
state.</p>
<p>Currently, the states shown are the insert mode as set by the
2022-08-24 15:22:41 +02:00
overwrite-mode or vi-replace widgets and whether history commands will
visit imported entries as controlled by the set-local-history widget.
The string contains insert if characters to be inserted on the command
line move existing characters to the right or overwrite if characters
to be inserted overwrite existing characters. It contains localhistory
if only local history commands will be visited or globalhistory if
imported history commands will also be visited.</p>
2021-05-11 02:29:21 +02:00
<p>The substrings are sorted in alphabetical order so that if you want to
test for two specific substrings in a future-proof way, you can do match
by doing:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">if [[ $ZLE_STATE == *globalhistory*insert* ]]; then ...; fi
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<hr />
<p><span id="Special-Widgets"></span></p>
<h3 id="1851-special-widgets"><a class="header" href="#1851-special-widgets">18.5.1 Special Widgets</a></h3>
<p>There are a few user-defined widgets which are special to the shell. If
they do not exist, no special action is taken. The environment provided
is identical to that for any other editing widget.</p>
<p><span id="index-zle_002disearch_002dexit"></span></p>
2022-08-24 15:22:41 +02:00
<p>zle-isearch-exit</p>
2021-05-11 02:29:21 +02:00
<p>Executed at the end of incremental search at the point where the isearch
2022-08-24 15:22:41 +02:00
prompt is removed from the display. See zle-isearch-update for an
2021-05-11 02:29:21 +02:00
example.</p>
<p><span id="index-zle_002disearch_002dupdate"></span></p>
2022-08-24 15:22:41 +02:00
<p>zle-isearch-update</p>
2021-05-11 02:29:21 +02:00
<p>Executed within incremental search when the display is about to be
redrawn. Additional output below the incremental search prompt can be
2022-08-24 15:22:41 +02:00
generated by using zle -M within the widget. For example,</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zle-isearch-update() { zle -M &quot;Line $HISTNO&quot;; }
2021-05-11 02:29:21 +02:00
zle -N zle-isearch-update
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Note the line output by zle -M is not deleted on exit from incremental
search. This can be done from a zle-isearch-exit widget:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zle-isearch-exit() { zle -M &quot;&quot;; }
2021-05-11 02:29:21 +02:00
zle -N zle-isearch-exit
</code></pre>
</div>
<p><span id="index-zle_002dline_002dpre_002dredraw"></span></p>
2022-08-24 15:22:41 +02:00
<p>zle-line-pre-redraw</p>
2021-05-11 02:29:21 +02:00
<p>Executed whenever the input line is about to be redrawn, providing an
opportunity to update the region_highlight array.</p>
<p><span id="index-zle_002dline_002dinit"></span></p>
2022-08-24 15:22:41 +02:00
<p>zle-line-init</p>
2021-05-11 02:29:21 +02:00
<p>Executed every time the line editor is started to read a new line of
input. The following example puts the line editor into vi command mode
when it starts up.</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zle-line-init() { zle -K vicmd; }
2021-05-11 02:29:21 +02:00
zle -N zle-line-init
</code></pre>
</div>
<p>(The command inside the function sets the keymap directly; it is
2022-08-24 15:22:41 +02:00
equivalent to zle vi-cmd-mode.)</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zle_002dline_002dfinish"></span></p>
2022-08-24 15:22:41 +02:00
<p>zle-line-finish</p>
<p>This is similar to zle-line-init but is executed every time the line
2021-05-11 02:29:21 +02:00
editor has finished reading a line of input.</p>
<p><span id="index-zle_002dhistory_002dline_002dset"></span></p>
2022-08-24 15:22:41 +02:00
<p>zle-history-line-set</p>
2021-05-11 02:29:21 +02:00
<p>Executed when the history line changes.</p>
<p><span id="index-zle_002dkeymap_002dselect"></span></p>
2022-08-24 15:22:41 +02:00
<p>zle-keymap-select</p>
2021-05-11 02:29:21 +02:00
<p>Executed every time the keymap changes, i.e. the special parameter
2022-08-24 15:22:41 +02:00
KEYMAP is set to a different value, while the line editor is active.
2021-05-11 02:29:21 +02:00
Initialising the keymap when the line editor starts does not cause the
widget to be called.</p>
2022-08-24 15:22:41 +02:00
<p>The value $KEYMAP within the function reflects the new keymap. The old
2021-05-11 02:29:21 +02:00
keymap is passed as the sole argument.</p>
2022-08-24 15:22:41 +02:00
<p>This can be used for detecting switches between the vi command (vicmd)
and insert (usually main) keymaps.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Standard-Widgets"></span> <span
id="Standard-Widgets-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="186-standard-widgets"><a class="header" href="#186-standard-widgets">18.6 Standard Widgets</a></h2>
<p><span id="index-widgets_002c-standard"></span></p>
<p>The following is a list of all the standard widgets, and their default
2022-08-24 15:22:41 +02:00
bindings in emacs mode, vi command mode and vi insert mode (the emacs,
vicmd and viins keymaps, respectively).</p>
2021-05-11 02:29:21 +02:00
<p>Note that cursor keys are bound to movement keys in all three keymaps;
the shell assumes that the cursor keys send the key sequences reported
by the terminal-handling library (termcap or terminfo). The key
sequences shown in the list are those based on the VT100, common on many
modern terminals, but in fact these are not necessarily bound. In the
2022-08-24 15:22:41 +02:00
case of the viins keymap, the initial escape character of the sequences
serves also to return to the vicmd keymap: whether this happens is
determined by the KEYTIMEOUT parameter, see
2021-05-11 02:29:21 +02:00
<a href="Parameters.html#Parameters">Parameters</a>.</p>
<hr />
<p><span id="Movement"></span> <span id="Movement-1"></span></p>
<h3 id="1861-movement"><a class="header" href="#1861-movement">18.6.1 Movement</a></h3>
<p><span id="index-vi_002dbackward_002dblank_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-backward-blank-word (unbound) (B) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move backward one word, where a word is defined as a series of non-blank
characters.</p>
<p><span id="index-vi_002dbackward_002dblank_002dword_002dend"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-backward-blank-word-end (unbound) (gE) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move to the end of the previous word, where a word is defined as a
series of non-blank characters.</p>
<p><span id="index-backward_002dchar"></span></p>
2022-08-24 15:22:41 +02:00
<p>backward-char (^B ESC-[D) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move backward one character.</p>
<p><span id="index-vi_002dbackward_002dchar"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-backward-char (unbound) (^H h ^?) (ESC-[D)</p>
2021-05-11 02:29:21 +02:00
<p>Move backward one character, without changing lines.</p>
<p><span id="index-backward_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>backward-word (ESC-B ESC-b) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move to the beginning of the previous word.</p>
<p><span id="index-emacs_002dbackward_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>emacs-backward-word</p>
2021-05-11 02:29:21 +02:00
<p>Move to the beginning of the previous word.</p>
<p><span id="index-vi_002dbackward_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-backward-word (unbound) (b) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move to the beginning of the previous word, vi-style.</p>
<p><span id="index-vi_002dbackward_002dword_002dend"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-backward-word-end (unbound) (ge) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move to the end of the previous word, vi-style.</p>
<p><span id="index-beginning_002dof_002dline"></span></p>
2022-08-24 15:22:41 +02:00
<p>beginning-of-line (^A) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move to the beginning of the line. If already at the beginning of the
line, move to the beginning of the previous line, if any.</p>
<p><span id="index-vi_002dbeginning_002dof_002dline"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-beginning-of-line</p>
2021-05-11 02:29:21 +02:00
<p>Move to the beginning of the line, without changing lines.</p>
<p><span id="index-down_002dline"></span></p>
2022-08-24 15:22:41 +02:00
<p>down-line (unbound) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move down a line in the buffer.</p>
<p><span id="index-end_002dof_002dline"></span></p>
2022-08-24 15:22:41 +02:00
<p>end-of-line (^E) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move to the end of the line. If already at the end of the line, move to
the end of the next line, if any.</p>
<p><span id="index-vi_002dend_002dof_002dline"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-end-of-line (unbound) ($) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move to the end of the line. If an argument is given to this command,
the cursor will be moved to the end of the line (argument - 1) lines
down.</p>
<p><span id="index-vi_002dforward_002dblank_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-forward-blank-word (unbound) (W) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move forward one word, where a word is defined as a series of non-blank
characters.</p>
<p><span id="index-vi_002dforward_002dblank_002dword_002dend"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-forward-blank-word-end (unbound) (E) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move to the end of the current word, or, if at the end of the current
word, to the end of the next word, where a word is defined as a series
of non-blank characters.</p>
<p><span id="index-forward_002dchar"></span></p>
2022-08-24 15:22:41 +02:00
<p>forward-char (^F ESC-[C) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move forward one character.</p>
<p><span id="index-vi_002dforward_002dchar"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-forward-char (unbound) (space l) (ESC-[C)</p>
2021-05-11 02:29:21 +02:00
<p>Move forward one character.</p>
<p><span id="index-vi_002dfind_002dnext_002dchar"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-find-next-char (^X^F) (f) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Read a character from the keyboard, and move to the next occurrence of
it in the line.</p>
<p><span id="index-vi_002dfind_002dnext_002dchar_002dskip"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-find-next-char-skip (unbound) (t) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Read a character from the keyboard, and move to the position just before
the next occurrence of it in the line.</p>
<p><span id="index-vi_002dfind_002dprev_002dchar"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-find-prev-char (unbound) (F) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Read a character from the keyboard, and move to the previous occurrence
of it in the line.</p>
<p><span id="index-vi_002dfind_002dprev_002dchar_002dskip"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-find-prev-char-skip (unbound) (T) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Read a character from the keyboard, and move to the position just after
the previous occurrence of it in the line.</p>
<p><span id="index-vi_002dfirst_002dnon_002dblank"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-first-non-blank (unbound) (^) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move to the first non-blank character in the line.</p>
<p><span id="index-vi_002dforward_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-forward-word (unbound) (w) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move forward one word, vi-style.</p>
<p><span id="index-forward_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>forward-word (ESC-F ESC-f) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move to the beginning of the next word. The editors idea of a word is
2022-08-24 15:22:41 +02:00
specified with the WORDCHARS parameter.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-emacs_002dforward_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>emacs-forward-word</p>
2021-05-11 02:29:21 +02:00
<p>Move to the end of the next word.</p>
<p><span id="index-vi_002dforward_002dword_002dend"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-forward-word-end (unbound) (e) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move to the end of the next word.</p>
<p><span id="index-vi_002dgoto_002dcolumn"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-goto-column (ESC-|) (|) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move to the column specified by the numeric argument.</p>
<p><span id="index-vi_002dgoto_002dmark"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-goto-mark (unbound) () (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move to the specified mark.</p>
<p><span id="index-vi_002dgoto_002dmark_002dline"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-goto-mark-line (unbound) () (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move to beginning of the line containing the specified mark.</p>
<p><span id="index-vi_002drepeat_002dfind"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-repeat-find (unbound) (;) (unbound)</p>
<p>Repeat the last vi-find command.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-vi_002drev_002drepeat_002dfind"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-rev-repeat-find (unbound) (,) (unbound)</p>
<p>Repeat the last vi-find command in the opposite direction.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-up_002dline"></span></p>
2022-08-24 15:22:41 +02:00
<p>up-line (unbound) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move up a line in the buffer.</p>
<hr />
<p><span id="History-Control"></span> <span id="History-Control-1"></span></p>
<h3 id="1862-history-control"><a class="header" href="#1862-history-control">18.6.2 History Control</a></h3>
<p><span id="index-beginning_002dof_002dbuffer_002dor_002dhistory"></span></p>
2022-08-24 15:22:41 +02:00
<p>beginning-of-buffer-or-history (ESC-&lt;) (gg) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move to the beginning of the buffer, or if already there, move to the
first event in the history list.</p>
<p><span id="index-beginning_002dof_002dline_002dhist"></span></p>
2022-08-24 15:22:41 +02:00
<p>beginning-of-line-hist</p>
2021-05-11 02:29:21 +02:00
<p>Move to the beginning of the line. If already at the beginning of the
buffer, move to the previous history line.</p>
<p><span id="index-beginning_002dof_002dhistory"></span></p>
2022-08-24 15:22:41 +02:00
<p>beginning-of-history</p>
2021-05-11 02:29:21 +02:00
<p>Move to the first event in the history list.</p>
<p><span id="index-down_002dline_002dor_002dhistory"></span></p>
2022-08-24 15:22:41 +02:00
<p>down-line-or-history (^N ESC-[B) (j) (ESC-[B)</p>
2021-05-11 02:29:21 +02:00
<p>Move down a line in the buffer, or if already at the bottom line, move
to the next event in the history list.</p>
<p><span id="index-vi_002ddown_002dline_002dor_002dhistory"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-down-line-or-history (unbound) (+) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move down a line in the buffer, or if already at the bottom line, move
to the next event in the history list. Then move to the first non-blank
character on the line.</p>
<p><span id="index-down_002dline_002dor_002dsearch"></span></p>
2022-08-24 15:22:41 +02:00
<p>down-line-or-search</p>
2021-05-11 02:29:21 +02:00
<p>Move down a line in the buffer, or if already at the bottom line, search
forward in the history for a line beginning with the first word in the
buffer.</p>
2022-08-24 15:22:41 +02:00
<p>If called from a function by the zle command with arguments, the first
2021-05-11 02:29:21 +02:00
argument is taken as the string for which to search, rather than the
first word in the buffer.</p>
<p><span id="index-down_002dhistory"></span></p>
2022-08-24 15:22:41 +02:00
<p>down-history (unbound) (^N) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move to the next event in the history list.</p>
<p><span id="index-history_002dbeginning_002dsearch_002dbackward"></span></p>
2022-08-24 15:22:41 +02:00
<p>history-beginning-search-backward</p>
2021-05-11 02:29:21 +02:00
<p>Search backward in the history for a line beginning with the current
line up to the cursor. This leaves the cursor in its original position.</p>
<p><span id="index-end_002dof_002dbuffer_002dor_002dhistory"></span></p>
2022-08-24 15:22:41 +02:00
<p>end-of-buffer-or-history (ESC-&gt;) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move to the end of the buffer, or if already there, move to the last
event in the history list.</p>
<p><span id="index-end_002dof_002dline_002dhist"></span></p>
2022-08-24 15:22:41 +02:00
<p>end-of-line-hist</p>
2021-05-11 02:29:21 +02:00
<p>Move to the end of the line. If already at the end of the buffer, move
to the next history line.</p>
<p><span id="index-end_002dof_002dhistory"></span></p>
2022-08-24 15:22:41 +02:00
<p>end-of-history</p>
2021-05-11 02:29:21 +02:00
<p>Move to the last event in the history list.</p>
<p><span id="index-vi_002dfetch_002dhistory"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-fetch-history (unbound) (G) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Fetch the history line specified by the numeric argument. This defaults
to the current history line (i.e. the one that isnt history yet).</p>
<p><span id="index-history_002dincremental_002dsearch_002dbackward"></span></p>
2022-08-24 15:22:41 +02:00
<p>history-incremental-search-backward (^R ^Xr) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Search backward incrementally for a specified string. The search is
case-insensitive if the search string does not have uppercase letters
2022-08-24 15:22:41 +02:00
and no numeric argument was given. The string may begin with ^ to
2021-05-11 02:29:21 +02:00
anchor the search to the beginning of the line. When called from a
user-defined function returns the following statuses: 0, if the search
succeeded; 1, if the search failed; 2, if the search term was a bad
2022-08-24 15:22:41 +02:00
pattern; 3, if the search was aborted by the send-break command.</p>
2021-05-11 02:29:21 +02:00
<p>A restricted set of editing functions is available in the mini-buffer.
2022-08-24 15:22:41 +02:00
Keys are looked up in the special isearch keymap, and if not found there
in the main keymap (note that by default the isearch keymap is empty).
An interrupt signal, as defined by the stty setting, will stop the
search and go back to the original line. An undefined key will have the
same effect. Note that the following always perform the same task within
incremental searches and cannot be replaced by user defined widgets, nor
can the set of functions be extended. The supported functions are:</p>
<p>accept-and-hold<br />
accept-and-infer-next-history<br />
accept-line<br />
accept-line-and-down-history<br />
Perform the usual function after exiting incremental search. The command
line displayed is executed.</p>
<p>backward-delete-char<br />
vi-backward-delete-char<br />
Back up one place in the search history. If the search has been repeated
this does not immediately erase a character in the minibuffer.</p>
<p>accept-search<br />
Exit incremental search, retaining the command line but performing no
further action. Note that this function is not bound by default and has
no effect outside incremental search.</p>
<p>backward-delete-word<br />
backward-kill-word<br />
vi-backward-kill-word<br />
Back up one character in the minibuffer; if multiple searches have been
performed since the character was inserted the search history is rewound
to the point just before the character was entered. Hence this has the
effect of repeating backward-delete-char.</p>
<p>clear-screen<br />
2021-05-11 02:29:21 +02:00
Clear the screen, remaining in incremental search mode.</p>
2022-08-24 15:22:41 +02:00
<p>history-incremental-search-backward<br />
2021-05-11 02:29:21 +02:00
Find the next occurrence of the contents of the mini-buffer. If the
2022-08-24 15:22:41 +02:00
mini-buffer is empty, the most recent previously used search string is
reinstated.</p>
<p>history-incremental-search-forward<br />
2021-05-11 02:29:21 +02:00
Invert the sense of the search.</p>
2022-08-24 15:22:41 +02:00
<p>magic-space<br />
2021-05-11 02:29:21 +02:00
Inserts a non-magical space.</p>
2022-08-24 15:22:41 +02:00
<p>quoted-insert<br />
vi-quoted-insert<br />
2021-05-11 02:29:21 +02:00
Quote the character to insert into the minibuffer.</p>
2022-08-24 15:22:41 +02:00
<p>redisplay<br />
2021-05-11 02:29:21 +02:00
Redisplay the command line, remaining in incremental search mode.</p>
2022-08-24 15:22:41 +02:00
<p>vi-cmd-mode<br />
Select the vicmd keymap; the main keymap (insert mode) will be
selected initially.</p>
<p>In addition, the modifications that were made while in vi insert mode
are merged to form a single undo event.</p>
<p>vi-repeat-search<br />
vi-rev-repeat-search<br />
2021-05-11 02:29:21 +02:00
Repeat the search. The direction of the search is indicated in the
mini-buffer.</p>
<p>Any character that is not bound to one of the above functions, or
2022-08-24 15:22:41 +02:00
self-insert or self-insert-unmeta, will cause the mode to be exited. The
character is then looked up and executed in the keymap in effect at that
point.</p>
<p>When called from a widget function by the zle command, the incremental
2021-05-11 02:29:21 +02:00
search commands can take a string argument. This will be treated as a
2022-08-24 15:22:41 +02:00
string of keys, as for arguments to the bindkey command, and used as
2021-05-11 02:29:21 +02:00
initial input for the command. Any characters in the string which are
unused by the incremental search will be silently ignored. For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zle history-incremental-search-backward forceps
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>will search backwards for forceps, leaving the minibuffer containing the
string forceps.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-history_002dincremental_002dsearch_002dforward"></span></p>
2022-08-24 15:22:41 +02:00
<p>history-incremental-search-forward (^S ^Xs) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Search forward incrementally for a specified string. The search is
case-insensitive if the search string does not have uppercase letters
2022-08-24 15:22:41 +02:00
and no numeric argument was given. The string may begin with ^ to
2021-05-11 02:29:21 +02:00
anchor the search to the beginning of the line. The functions available
in the mini-buffer are the same as for
2022-08-24 15:22:41 +02:00
history-incremental-search-backward.</p>
<p><span
id="index-history_002dincremental_002dpattern_002dsearch_002dbackward"></span>
<span
id="index-history_002dincremental_002dpattern_002dsearch_002dforward"></span></p>
<p>history-incremental-pattern-search-backward</p>
<p>history-incremental-pattern-search-forward</p>
2021-05-11 02:29:21 +02:00
<p>These widgets behave similarly to the corresponding widgets with no
2022-08-24 15:22:41 +02:00
-pattern, but the search string typed by the user is treated as a
2021-05-11 02:29:21 +02:00
pattern, respecting the current settings of the various options
affecting pattern matching. See <a href="Expansion.html#Filename-Generation">Filename
Generation</a> for a description of
patterns. If no numeric argument was given lowercase letters in the
search string may match uppercase letters in the history. The string may
2022-08-24 15:22:41 +02:00
begin with ^ to anchor the search to the beginning of the line.</p>
2021-05-11 02:29:21 +02:00
<p>The prompt changes to indicate an invalid pattern; this may simply
indicate the pattern is not yet complete.</p>
<p>Note that only non-overlapping matches are reported, so an expression
with wildcards may return fewer matches on a line than are visible by
inspection.</p>
<p><span id="index-history_002dsearch_002dbackward"></span></p>
2022-08-24 15:22:41 +02:00
<p>history-search-backward (ESC-P ESC-p) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Search backward in the history for a line beginning with the first word
in the buffer.</p>
2022-08-24 15:22:41 +02:00
<p>If called from a function by the zle command with arguments, the first
2021-05-11 02:29:21 +02:00
argument is taken as the string for which to search, rather than the
first word in the buffer.</p>
<p><span id="index-vi_002dhistory_002dsearch_002dbackward"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-history-search-backward (unbound) (/) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Search backward in the history for a specified string. The string may
2022-08-24 15:22:41 +02:00
begin with ^ to anchor the search to the beginning of the line.</p>
2021-05-11 02:29:21 +02:00
<p>A restricted set of editing functions is available in the mini-buffer.
An interrupt signal, as defined by the stty setting, will stop the
2022-08-24 15:22:41 +02:00
search. The functions available in the mini-buffer are: accept-line,
backward-delete-char, vi-backward-delete-char, backward-kill-word,
vi-backward-kill-word, clear-screen, redisplay, quoted-insert and
vi-quoted-insert.</p>
<p>vi-cmd-mode is treated the same as accept-line, and magic-space is
2021-05-11 02:29:21 +02:00
treated as a space. Any other character that is not bound to self-insert
or self-insert-unmeta will beep and be ignored. If the function is
called from vi command mode, the bindings of the current insert mode
will be used.</p>
2022-08-24 15:22:41 +02:00
<p>If called from a function by the zle command with arguments, the first
2021-05-11 02:29:21 +02:00
argument is taken as the string for which to search, rather than the
first word in the buffer.</p>
<p><span id="index-history_002dsearch_002dforward"></span></p>
2022-08-24 15:22:41 +02:00
<p>history-search-forward (ESC-N ESC-n) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Search forward in the history for a line beginning with the first word
in the buffer.</p>
2022-08-24 15:22:41 +02:00
<p>If called from a function by the zle command with arguments, the first
2021-05-11 02:29:21 +02:00
argument is taken as the string for which to search, rather than the
first word in the buffer.</p>
<p><span id="index-vi_002dhistory_002dsearch_002dforward"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-history-search-forward (unbound) (?) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Search forward in the history for a specified string. The string may
2022-08-24 15:22:41 +02:00
begin with ^ to anchor the search to the beginning of the line. The
2021-05-11 02:29:21 +02:00
functions available in the mini-buffer are the same as for
2022-08-24 15:22:41 +02:00
vi-history-search-backward. Argument handling is also the same as for
2021-05-11 02:29:21 +02:00
that command.</p>
<p><span id="index-infer_002dnext_002dhistory"></span></p>
2022-08-24 15:22:41 +02:00
<p>infer-next-history (^X^N) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Search in the history list for a line matching the current one and fetch
the event following it.</p>
<p><span id="index-insert_002dlast_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>insert-last-word (ESC-_ ESC-.) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Insert the last word from the previous history event at the cursor
position. If a positive numeric argument is given, insert that word from
the end of the previous history event. If the argument is zero or
negative insert that word from the left (zero inserts the previous
command word). Repeating this command replaces the word just inserted
with the last word from the history event prior to the one just used;
numeric arguments can be used in the same way to pick a word from that
event.</p>
<p>When called from a shell function invoked from a user-defined widget,
the command can take one to three arguments. The first argument
specifies a history offset which applies to successive calls to this
widget: if it is -1, the default behaviour is used, while if it is 1,
successive calls will move forwards through the history. The value 0 can
be used to indicate that the history line examined by the previous
execution of the command will be reexamined. Note that negative numbers
2022-08-24 15:22:41 +02:00
should be preceded by a -- argument to avoid confusing them with
2021-05-11 02:29:21 +02:00
options.</p>
<p>If two arguments are given, the second specifies the word on the command
line in normal array index notation (as a more natural alternative to
the numeric argument). Hence 1 is the first word, and -1 (the default)
is the last word.</p>
<p>If a third argument is given, its value is ignored, but it is used to
signify that the history offset is relative to the current history line,
rather than the one remembered after the previous invocations of
2022-08-24 15:22:41 +02:00
insert-last-word.</p>
2021-05-11 02:29:21 +02:00
<p>For example, the default behaviour of the command corresponds to</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zle insert-last-word -- -1 -1
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>while the command</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zle insert-last-word -- -1 1 -
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>always copies the first word of the line in the history immediately
before the line being edited. This has the side effect that later
invocations of the widget will be relative to that line.</p>
<p><span id="index-vi_002drepeat_002dsearch"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-repeat-search (unbound) (n) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Repeat the last vi history search.</p>
<p><span id="index-vi_002drev_002drepeat_002dsearch"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-rev-repeat-search (unbound) (N) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Repeat the last vi history search, but in reverse.</p>
<p><span id="index-up_002dline_002dor_002dhistory"></span></p>
2022-08-24 15:22:41 +02:00
<p>up-line-or-history (^P ESC-[A) (k) (ESC-[A)</p>
2021-05-11 02:29:21 +02:00
<p>Move up a line in the buffer, or if already at the top line, move to the
previous event in the history list.</p>
<p><span id="index-vi_002dup_002dline_002dor_002dhistory"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-up-line-or-history (unbound) (-) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move up a line in the buffer, or if already at the top line, move to the
previous event in the history list. Then move to the first non-blank
character on the line.</p>
<p><span id="index-up_002dline_002dor_002dsearch"></span></p>
2022-08-24 15:22:41 +02:00
<p>up-line-or-search</p>
2021-05-11 02:29:21 +02:00
<p>Move up a line in the buffer, or if already at the top line, search
backward in the history for a line beginning with the first word in the
buffer.</p>
2022-08-24 15:22:41 +02:00
<p>If called from a function by the zle command with arguments, the first
2021-05-11 02:29:21 +02:00
argument is taken as the string for which to search, rather than the
first word in the buffer.</p>
<p><span id="index-up_002dhistory"></span></p>
2022-08-24 15:22:41 +02:00
<p>up-history (unbound) (^P) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move to the previous event in the history list.</p>
<p><span id="index-history_002dbeginning_002dsearch_002dforward"></span></p>
2022-08-24 15:22:41 +02:00
<p>history-beginning-search-forward</p>
2021-05-11 02:29:21 +02:00
<p>Search forward in the history for a line beginning with the current line
up to the cursor. This leaves the cursor in its original position.</p>
<p><span id="index-set_002dlocal_002dhistory"></span></p>
2022-08-24 15:22:41 +02:00
<p>set-local-history</p>
2021-05-11 02:29:21 +02:00
<p>By default, history movement commands visit the imported lines as well
as the local lines. This widget lets you toggle this on and off, or set
it with the numeric argument. Zero for both local and imported lines and
nonzero for only local lines.</p>
<hr />
<p><span id="Modifying-Text"></span> <span id="Modifying-Text-1"></span></p>
<h3 id="1863-modifying-text"><a class="header" href="#1863-modifying-text">18.6.3 Modifying Text</a></h3>
<p><span id="index-vi_002dadd_002deol"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-add-eol (unbound) (A) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move to the end of the line and enter insert mode.</p>
<p><span id="index-vi_002dadd_002dnext"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-add-next (unbound) (a) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Enter insert mode after the current cursor position, without changing
lines.</p>
<p><span id="index-backward_002ddelete_002dchar"></span></p>
2022-08-24 15:22:41 +02:00
<p>backward-delete-char (^H ^?) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Delete the character behind the cursor.</p>
<p><span id="index-vi_002dbackward_002ddelete_002dchar"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-backward-delete-char (unbound) (X) (^H)</p>
2021-05-11 02:29:21 +02:00
<p>Delete the character behind the cursor, without changing lines. If in
insert mode, this wont delete past the point where insert mode was last
entered.</p>
<p><span id="index-backward_002ddelete_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>backward-delete-word</p>
2021-05-11 02:29:21 +02:00
<p>Delete the word behind the cursor.</p>
<p><span id="index-backward_002dkill_002dline"></span></p>
2022-08-24 15:22:41 +02:00
<p>backward-kill-line</p>
2021-05-11 02:29:21 +02:00
<p>Kill from the beginning of the line to the cursor position.</p>
<p><span id="index-backward_002dkill_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>backward-kill-word (^W ESC-^H ESC-^?) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Kill the word behind the cursor.</p>
<p><span id="index-vi_002dbackward_002dkill_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-backward-kill-word (unbound) (unbound) (^W)</p>
2021-05-11 02:29:21 +02:00
<p>Kill the word behind the cursor, without going past the point where
insert mode was last entered.</p>
<p><span id="index-capitalize_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>capitalize-word (ESC-C ESC-c) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Capitalize the current word and move past it.</p>
<p><span id="index-vi_002dchange"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-change (unbound) (c) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Read a movement command from the keyboard, and kill from the cursor
position to the endpoint of the movement. Then enter insert mode. If the
2022-08-24 15:22:41 +02:00
command is vi-change, change the current line.</p>
<p>For compatibility with vi, if the command is vi-forward-word or
vi-forward-blank-word, the whitespace after the word is not included. If
you prefer the more consistent behaviour with the whitespace included
2021-05-11 02:29:21 +02:00
use the following key binding:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">bindkey -a -s cw dwi
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p><span id="index-vi_002dchange_002deol"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-change-eol (unbound) (C) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Kill to the end of the line and enter insert mode.</p>
<p><span id="index-vi_002dchange_002dwhole_002dline"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-change-whole-line (unbound) (S) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Kill the current line and enter insert mode.</p>
<p><span id="index-copy_002dregion_002das_002dkill"></span></p>
2022-08-24 15:22:41 +02:00
<p>copy-region-as-kill (ESC-W ESC-w) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Copy the area from the cursor to the mark to the kill buffer.</p>
2022-08-24 15:22:41 +02:00
<p>If called from a ZLE widget function in the form zle
copy-region-as-kill <code>string</code> then <code>string</code> will be taken as the text to
copy to the kill buffer. The cursor, the mark and the text on the
2021-05-11 02:29:21 +02:00
command line are not used in this case.</p>
<p><span id="index-copy_002dprev_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>copy-prev-word (ESC-^_) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Duplicate the word to the left of the cursor.</p>
<p><span id="index-copy_002dprev_002dshell_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>copy-prev-shell-word</p>
<p>Like copy-prev-word, but the word is found by using shell parsing,
whereas copy-prev-word looks for blanks. This makes a difference when
2021-05-11 02:29:21 +02:00
the word is quoted and contains spaces.</p>
<p><span id="index-vi_002ddelete"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-delete (unbound) (d) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Read a movement command from the keyboard, and kill from the cursor
2022-08-24 15:22:41 +02:00
position to the endpoint of the movement. If the command is vi-delete,
2021-05-11 02:29:21 +02:00
kill the current line.</p>
<p><span id="index-delete_002dchar"></span></p>
2022-08-24 15:22:41 +02:00
<p>delete-char</p>
2021-05-11 02:29:21 +02:00
<p>Delete the character under the cursor.</p>
<p><span id="index-vi_002ddelete_002dchar"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-delete-char (unbound) (x) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Delete the character under the cursor, without going past the end of the
line.</p>
<p><span id="index-delete_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>delete-word</p>
2021-05-11 02:29:21 +02:00
<p>Delete the current word.</p>
<p><span id="index-down_002dcase_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>down-case-word (ESC-L ESC-l) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Convert the current word to all lowercase and move past it.</p>
<p><span id="index-vi_002ddown_002dcase"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-down-case (unbound) (gu) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Read a movement command from the keyboard, and convert all characters
from the cursor position to the endpoint of the movement to lowercase.
2022-08-24 15:22:41 +02:00
If the movement command is vi-down-case, swap the case of all characters
on the current line.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-kill_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>kill-word (ESC-D ESC-d) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Kill the current word.</p>
<p><span id="index-gosmacs_002dtranspose_002dchars"></span></p>
2022-08-24 15:22:41 +02:00
<p>gosmacs-transpose-chars</p>
2021-05-11 02:29:21 +02:00
<p>Exchange the two characters behind the cursor.</p>
<p><span id="index-vi_002dindent"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-indent (unbound) (&gt;) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Indent a number of lines.</p>
<p><span id="index-vi_002dinsert"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-insert (unbound) (i) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Enter insert mode.</p>
<p><span id="index-vi_002dinsert_002dbol"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-insert-bol (unbound) (I) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Move to the first non-blank character on the line and enter insert mode.</p>
<p><span id="index-vi_002djoin"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-join (^X^J) (J) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Join the current line with the next one.</p>
<p><span id="index-kill_002dline"></span></p>
2022-08-24 15:22:41 +02:00
<p>kill-line (^K) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Kill from the cursor to the end of the line. If already on the end of
the line, kill the newline character.</p>
<p><span id="index-vi_002dkill_002dline"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-kill-line (unbound) (unbound) (^U)</p>
2021-05-11 02:29:21 +02:00
<p>Kill from the cursor back to wherever insert mode was last entered.</p>
<p><span id="index-vi_002dkill_002deol"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-kill-eol (unbound) (D) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Kill from the cursor to the end of the line.</p>
<p><span id="index-kill_002dregion"></span></p>
2022-08-24 15:22:41 +02:00
<p>kill-region</p>
2021-05-11 02:29:21 +02:00
<p>Kill from the cursor to the mark.</p>
<p><span id="index-kill_002dbuffer"></span></p>
2022-08-24 15:22:41 +02:00
<p>kill-buffer (^X^K) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Kill the entire buffer.</p>
<p><span id="index-kill_002dwhole_002dline"></span></p>
2022-08-24 15:22:41 +02:00
<p>kill-whole-line (^U) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Kill the current line.</p>
<p><span id="index-vi_002dmatch_002dbracket"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-match-bracket (^X^B) (%) (unbound)</p>
<p>Move to the bracket character (one of {}, () or []) that matches the
one under the cursor. If the cursor is not on a bracket character, move
forward without going past the end of the line to find one, and then go
to the matching bracket.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-vi_002dopen_002dline_002dabove"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-open-line-above (unbound) (O) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Open a line above the cursor and enter insert mode.</p>
<p><span id="index-vi_002dopen_002dline_002dbelow"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-open-line-below (unbound) (o) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Open a line below the cursor and enter insert mode.</p>
<p><span id="index-vi_002doper_002dswap_002dcase"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-oper-swap-case (unbound) (g~) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Read a movement command from the keyboard, and swap the case of all
characters from the cursor position to the endpoint of the movement. If
2022-08-24 15:22:41 +02:00
the movement command is vi-oper-swap-case, swap the case of all
2021-05-11 02:29:21 +02:00
characters on the current line.</p>
<p><span id="index-overwrite_002dmode"></span></p>
2022-08-24 15:22:41 +02:00
<p>overwrite-mode (^X^O) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Toggle between overwrite mode and insert mode.</p>
<p><span id="index-vi_002dput_002dbefore"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-put-before (unbound) (P) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Insert the contents of the kill buffer before the cursor. If the kill
buffer contains a sequence of lines (as opposed to characters), paste it
above the current line.</p>
<p><span id="index-vi_002dput_002dafter"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-put-after (unbound) (p) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Insert the contents of the kill buffer after the cursor. If the kill
buffer contains a sequence of lines (as opposed to characters), paste it
below the current line.</p>
<p><span id="index-put_002dreplace_002dselection"></span></p>
2022-08-24 15:22:41 +02:00
<p>put-replace-selection (unbound) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Replace the contents of the current region or selection with the
contents of the kill buffer. If the kill buffer contains a sequence of
lines (as opposed to characters), the current line will be split by the
pasted lines.</p>
<p><span id="index-quoted_002dinsert"></span></p>
2022-08-24 15:22:41 +02:00
<p>quoted-insert (^V) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Insert the next character typed into the buffer literally. An interrupt
character will not be inserted.</p>
<p><span id="index-vi_002dquoted_002dinsert"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-quoted-insert (unbound) (unbound) (^Q ^V)</p>
<p>Display a ^ at the cursor position, and insert the next character
2021-05-11 02:29:21 +02:00
typed into the buffer literally. An interrupt character will not be
inserted.</p>
<p><span id="index-quote_002dline"></span></p>
2022-08-24 15:22:41 +02:00
<p>quote-line (ESC-) (unbound) (unbound)</p>
<p>Quote the current line; that is, put a character at the beginning
and the end, and convert all characters to \.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-quote_002dregion"></span></p>
2022-08-24 15:22:41 +02:00
<p>quote-region (ESC-&quot;) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Quote the region from the cursor to the mark.</p>
<p><span id="index-vi_002dreplace"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-replace (unbound) (R) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Enter overwrite mode.</p>
<p><span id="index-vi_002drepeat_002dchange"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-repeat-change (unbound) (.) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Repeat the last vi mode text modification. If a count was used with the
modification, it is remembered. If a count is given to this command, it
overrides the remembered count, and is remembered for future uses of
this command. The cut buffer specification is similarly remembered.</p>
<p><span id="index-vi_002dreplace_002dchars"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-replace-chars (unbound) (r) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Replace the character under the cursor with a character read from the
keyboard.</p>
<p><span id="index-self_002dinsert"></span></p>
<p>Insert a character into the buffer at the cursor position.</p>
<p><span id="index-self_002dinsert_002dunmeta"></span></p>
2022-08-24 15:22:41 +02:00
<p>self-insert-unmeta (ESC-^I ESC-^J ESC-^M) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Insert a character into the buffer after stripping the meta bit and
converting ^M to ^J.</p>
<p><span id="index-vi_002dsubstitute"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-substitute (unbound) (s) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Substitute the next character(s).</p>
<p><span id="index-vi_002dswap_002dcase"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-swap-case (unbound) (~) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Swap the case of the character under the cursor and move past it.</p>
<p><span id="index-transpose_002dchars"></span></p>
2022-08-24 15:22:41 +02:00
<p>transpose-chars (^T) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Exchange the two characters to the left of the cursor if at end of line,
else exchange the character under the cursor with the character to the
left.</p>
<p><span id="index-transpose_002dwords"></span></p>
2022-08-24 15:22:41 +02:00
<p>transpose-words (ESC-T ESC-t) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Exchange the current word with the one before it.</p>
<p>With a positive numeric argument <em>N</em>, the word around the cursor, or
following it if the cursor is between words, is transposed with the
preceding <em>N</em> words. The cursor is put at the end of the resulting group
of words.</p>
<p>With a negative numeric argument <em>-N</em>, the effect is the same as using a
positive argument <em>N</em> except that the original cursor position is
retained, regardless of how the words are rearranged.</p>
<p><span id="index-vi_002dunindent"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-unindent (unbound) (&lt;) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Unindent a number of lines.</p>
<p><span id="index-vi_002dup_002dcase"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-up-case (unbound) (gU) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Read a movement command from the keyboard, and convert all characters
from the cursor position to the endpoint of the movement to lowercase.
2022-08-24 15:22:41 +02:00
If the movement command is vi-up-case, swap the case of all characters
2021-05-11 02:29:21 +02:00
on the current line.</p>
<p><span id="index-up_002dcase_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>up-case-word (ESC-U ESC-u) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Convert the current word to all caps and move past it.</p>
<p><span id="index-yank"></span></p>
2022-08-24 15:22:41 +02:00
<p>yank (^Y) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Insert the contents of the kill buffer at the cursor position.</p>
<p><span id="index-yank_002dpop"></span></p>
2022-08-24 15:22:41 +02:00
<p>yank-pop (ESC-y) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Remove the text just yanked, rotate the kill-ring (the history of
2022-08-24 15:22:41 +02:00
previously killed text) and yank the new top. Only works following yank,
vi-put-before, vi-put-after or yank-pop.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-vi_002dyank"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-yank (unbound) (y) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Read a movement command from the keyboard, and copy the region from the
cursor position to the endpoint of the movement into the kill buffer. If
2022-08-24 15:22:41 +02:00
the command is vi-yank, copy the current line.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-vi_002dyank_002dwhole_002dline"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-yank-whole-line (unbound) (Y) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Copy the current line into the kill buffer.</p>
<p><span id="index-vi_002dyank_002deol"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-yank-eol</p>
2021-05-11 02:29:21 +02:00
<p>Copy the region from the cursor position to the end of the line into the
kill buffer. Arguably, this is what Y should do in vi, but it isnt what
it actually does.</p>
<hr />
<p><span id="Arguments"></span> <span id="Arguments-1"></span></p>
<h3 id="1864-arguments"><a class="header" href="#1864-arguments">18.6.4 Arguments</a></h3>
<p><span id="index-digit_002dargument"></span></p>
2022-08-24 15:22:41 +02:00
<p>digit-argument (ESC-0..ESC-9) (1-9) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Start a new numeric argument, or add to the current one. See also
2022-08-24 15:22:41 +02:00
vi-digit-or-beginning-of-line. This only works if bound to a key
2021-05-11 02:29:21 +02:00
sequence ending in a decimal digit.</p>
<p>Inside a widget function, a call to this function treats the last key of
the key sequence which called the widget as the digit.</p>
<p><span id="index-neg_002dargument"></span></p>
2022-08-24 15:22:41 +02:00
<p>neg-argument (ESC--) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Changes the sign of the following argument.</p>
<p><span id="index-universal_002dargument"></span></p>
2022-08-24 15:22:41 +02:00
<p>universal-argument</p>
2021-05-11 02:29:21 +02:00
<p>Multiply the argument of the next command by 4. Alternatively, if this
command is followed by an integer (positive or negative), use that as
the argument for the next command. Thus digits cannot be repeated using
this command. For example, if this command occurs twice, followed
2022-08-24 15:22:41 +02:00
immediately by forward-char, move forward sixteen spaces; if instead it
is followed by -2, then forward-char, move backward two spaces.</p>
<p>Inside a widget function, if passed an argument, i.e. zle
universal-argument <code>num</code>, the numeric argument will be set to <code>num</code>;
this is equivalent to NUMERIC=<code>num</code>.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-argument_002dbase"></span></p>
2022-08-24 15:22:41 +02:00
<p>argument-base</p>
2021-05-11 02:29:21 +02:00
<p>Use the existing numeric argument as a numeric base, which must be in
2022-08-24 15:22:41 +02:00
the range 2 to 36 inclusive. Subsequent use of digit-argument and
universal-argument will input a new numeric argument in the given base.
The usual hexadecimal convention is used: the letter a or A corresponds
to 10, and so on. Arguments in bases requiring digits from 10 upwards
are more conveniently input with universal-argument, since ESC-a etc.
are not usually bound to digit-argument.</p>
2021-05-11 02:29:21 +02:00
<p>The function can be used with a command argument inside a user-defined
widget. The following code sets the base to 16 and lets the user input a
hexadecimal argument until a key out of the digit range is typed:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zle argument-base 16
2021-05-11 02:29:21 +02:00
zle universal-argument
</code></pre>
</div>
<hr />
<p><span id="Completion"></span> <span id="Completion-2"></span></p>
<h3 id="1865-completion"><a class="header" href="#1865-completion">18.6.5 Completion</a></h3>
<p><span id="index-accept_002dand_002dmenu_002dcomplete"></span></p>
2022-08-24 15:22:41 +02:00
<p>accept-and-menu-complete</p>
2021-05-11 02:29:21 +02:00
<p>In a menu completion, insert the current completion into the buffer, and
advance to the next possible completion.</p>
<p><span id="index-complete_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>complete-word</p>
2021-05-11 02:29:21 +02:00
<p>Attempt completion on the current word.</p>
<p><span id="index-delete_002dchar_002dor_002dlist"></span></p>
2022-08-24 15:22:41 +02:00
<p>delete-char-or-list (^D) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Delete the character under the cursor. If the cursor is at the end of
the line, list possible completions for the current word.</p>
<p><span id="index-expand_002dcmd_002dpath"></span></p>
2022-08-24 15:22:41 +02:00
<p>expand-cmd-path</p>
2021-05-11 02:29:21 +02:00
<p>Expand the current command to its full pathname.</p>
<p><span id="index-expand_002dor_002dcomplete"></span></p>
2022-08-24 15:22:41 +02:00
<p>expand-or-complete (TAB) (unbound) (TAB)</p>
2021-05-11 02:29:21 +02:00
<p>Attempt shell expansion on the current word. If that fails, attempt
completion.</p>
<p><span id="index-expand_002dor_002dcomplete_002dprefix"></span></p>
2022-08-24 15:22:41 +02:00
<p>expand-or-complete-prefix</p>
2021-05-11 02:29:21 +02:00
<p>Attempt shell expansion on the current word up to cursor.</p>
<p><span id="index-expand_002dhistory"></span></p>
2022-08-24 15:22:41 +02:00
<p>expand-history (ESC-space ESC-!) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Perform history expansion on the edit buffer.</p>
<p><span id="index-expand_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>expand-word (^X*) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Attempt shell expansion on the current word.</p>
<p><span id="index-list_002dchoices"></span></p>
2022-08-24 15:22:41 +02:00
<p>list-choices (ESC-^D) (^D =) (^D)</p>
2021-05-11 02:29:21 +02:00
<p>List possible completions for the current word.</p>
<p><span id="index-list_002dexpand"></span></p>
2022-08-24 15:22:41 +02:00
<p>list-expand (^Xg ^XG) (^G) (^G)</p>
2021-05-11 02:29:21 +02:00
<p>List the expansion of the current word.</p>
<p><span id="index-magic_002dspace"></span></p>
2022-08-24 15:22:41 +02:00
<p>magic-space</p>
2021-05-11 02:29:21 +02:00
<p>Perform history expansion and insert a space into the buffer. This is
intended to be bound to space.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-menu_002dcomplete"></span> <span
id="index-MENU_005fCOMPLETE_002c-use-of"></span></p>
<p>menu-complete</p>
<p>Like complete-word, except that menu completion is used. See the
MENU_COMPLETE option.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-menu_002dexpand_002dor_002dcomplete"></span></p>
2022-08-24 15:22:41 +02:00
<p>menu-expand-or-complete</p>
<p>Like expand-or-complete, except that menu completion is used.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-reverse_002dmenu_002dcomplete"></span></p>
2022-08-24 15:22:41 +02:00
<p>reverse-menu-complete</p>
<p>Perform menu completion, like menu-complete, except that if a menu
2021-05-11 02:29:21 +02:00
completion is already in progress, move to the <em>previous</em> completion
rather than the next.</p>
<p><span id="index-end_002dof_002dlist"></span></p>
2022-08-24 15:22:41 +02:00
<p>end-of-list</p>
2021-05-11 02:29:21 +02:00
<p>When a previous completion displayed a list below the prompt, this
widget can be used to move the prompt below the list.</p>
<hr />
<p><span id="Miscellaneous"></span> <span id="Miscellaneous-1"></span></p>
<h3 id="1866-miscellaneous"><a class="header" href="#1866-miscellaneous">18.6.6 Miscellaneous</a></h3>
<p><span id="index-accept_002dand_002dhold"></span></p>
2022-08-24 15:22:41 +02:00
<p>accept-and-hold (ESC-A ESC-a) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Push the contents of the buffer on the buffer stack and execute it.</p>
<p><span id="index-accept_002dand_002dinfer_002dnext_002dhistory"></span></p>
2022-08-24 15:22:41 +02:00
<p>accept-and-infer-next-history</p>
2021-05-11 02:29:21 +02:00
<p>Execute the contents of the buffer. Then search the history list for a
line matching the current one and push the event following onto the
buffer stack.</p>
<p><span id="index-accept_002dline"></span></p>
2022-08-24 15:22:41 +02:00
<p>accept-line (^J ^M) (^J ^M) (^J ^M)</p>
2021-05-11 02:29:21 +02:00
<p>Finish editing the buffer. Normally this causes the buffer to be
executed as a shell command.</p>
<p><span id="index-accept_002dline_002dand_002ddown_002dhistory"></span></p>
2022-08-24 15:22:41 +02:00
<p>accept-line-and-down-history (^O) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Execute the current line, and push the next history event on the buffer
stack.</p>
<p><span id="index-auto_002dsuffix_002dremove"></span></p>
2022-08-24 15:22:41 +02:00
<p>auto-suffix-remove</p>
2021-05-11 02:29:21 +02:00
<p>If the previous action added a suffix (space, slash, etc.) to the word
on the command line, remove it. Otherwise do nothing. Removing the
suffix ends any active menu completion or menu selection.</p>
<p>This widget is intended to be called from user-defined widgets to
enforce a desired suffix-removal behavior.</p>
<p><span id="index-auto_002dsuffix_002dretain"></span></p>
2022-08-24 15:22:41 +02:00
<p>auto-suffix-retain</p>
2021-05-11 02:29:21 +02:00
<p>If the previous action added a suffix (space, slash, etc.) to the word
on the command line, force it to be preserved. Otherwise do nothing.
Retaining the suffix ends any active menu completion or menu selection.</p>
<p>This widget is intended to be called from user-defined widgets to
enforce a desired suffix-preservation behavior.</p>
<p><span id="index-beep"></span></p>
2022-08-24 15:22:41 +02:00
<p>beep</p>
<p>Beep, unless the BEEP option is unset.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-bracketed_002dpaste"></span></p>
2022-08-24 15:22:41 +02:00
<p>bracketed-paste (^[[200~) (^[[200~) (^[[200~)</p>
2021-05-11 02:29:21 +02:00
<p>This widget is invoked when text is pasted to the terminal emulator. It
is not intended to be bound to actual keys but instead to the special
sequence generated by the terminal emulator when text is pasted.</p>
<p>When invoked interactively, the pasted text is inserted to the buffer
and placed in the cutbuffer. If a numeric argument is given, shell
quoting will be applied to the pasted text before it is inserted.</p>
2022-08-24 15:22:41 +02:00
<p>When a named buffer is specified with vi-set-buffer (&quot;x), the pasted
2021-05-11 02:29:21 +02:00
text is stored in that named buffer but not inserted.</p>
2022-08-24 15:22:41 +02:00
<p>When called from a widget function as bracketed-paste <code>name</code>, the
2021-05-11 02:29:21 +02:00
pasted text is assigned to the variable <code>name</code> and no other processing
is done.</p>
2022-08-24 15:22:41 +02:00
<p>See also the zle_bracketed_paste parameter.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-vi_002dcmd_002dmode"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-cmd-mode (^X^V) (unbound) (^[)</p>
<p>Enter command mode; that is, select the vicmd keymap. Yes, this is
2021-05-11 02:29:21 +02:00
bound by default in emacs mode.</p>
<p><span id="index-vi_002dcaps_002dlock_002dpanic"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-caps-lock-panic</p>
2021-05-11 02:29:21 +02:00
<p>Hang until any lowercase key is pressed. This is for vi users without
the mental capacity to keep track of their caps lock key (like the
author).</p>
<p><span id="index-clear_002dscreen"></span></p>
2022-08-24 15:22:41 +02:00
<p>clear-screen (^L ESC-^L) (^L) (^L)</p>
2021-05-11 02:29:21 +02:00
<p>Clear the screen and redraw the prompt.</p>
<p><span id="index-deactivate_002dregion"></span></p>
2022-08-24 15:22:41 +02:00
<p>deactivate-region</p>
2021-05-11 02:29:21 +02:00
<p>Make the current region inactive. This disables vim-style visual
selection mode if it is active.</p>
<p><span id="index-describe_002dkey_002dbriefly"></span></p>
2022-08-24 15:22:41 +02:00
<p>describe-key-briefly</p>
2021-05-11 02:29:21 +02:00
<p>Reads a key sequence, then prints the function bound to that sequence.</p>
<p><span id="index-exchange_002dpoint_002dand_002dmark"></span></p>
2022-08-24 15:22:41 +02:00
<p>exchange-point-and-mark (^X^X) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Exchange the cursor position (point) with the position of the mark.
Unless a negative numeric argument is given, the region between point
and mark is activated so that it can be highlighted. If a zero numeric
argument is given, the region is activated but point and mark are not
swapped.</p>
<p><span id="index-execute_002dnamed_002dcmd"></span></p>
2022-08-24 15:22:41 +02:00
<p>execute-named-cmd (ESC-x) (:) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Read the name of an editor command and execute it. Aliasing this widget
2022-08-24 15:22:41 +02:00
with zle -A or replacing it with zle -N has no effect when
interpreting key bindings, but zle execute-named-cmd will invoke such
an alias or replacement.</p>
2021-05-11 02:29:21 +02:00
<p>A restricted set of editing functions is available in the mini-buffer.
2022-08-24 15:22:41 +02:00
Keys are looked up in the special command keymap, and if not found there
in the main keymap. An interrupt signal, as defined by the stty setting,
will abort the function. Note that the following always perform the same
task within the executed-named-cmd environment and cannot be replaced by
user defined widgets, nor can the set of functions be extended. The
allowed functions are: backward-delete-char, vi-backward-delete-char,
clear-screen, redisplay, quoted-insert, vi-quoted-insert,
backward-kill-word, vi-backward-kill-word, kill-whole-line,
vi-kill-line, backward-kill-line, list-choices, delete-char-or-list,
complete-word, accept-line, expand-or-complete and
expand-or-complete-prefix.</p>
<p>kill-region kills the last word, and vi-cmd-mode is treated the same as
accept-line. The space and tab characters, if not bound to one of these
functions, will complete the name and then list the possibilities if the
AUTO_LIST option is set. Any other character that is not bound to
self-insert or self-insert-unmeta will beep and be ignored. The bindings
of the current insert mode will be used.</p>
2021-05-11 02:29:21 +02:00
<p>Currently this command may not be redefined or called by name.</p>
<p><span id="index-execute_002dlast_002dnamed_002dcmd"></span></p>
2022-08-24 15:22:41 +02:00
<p>execute-last-named-cmd (ESC-z) (unbound) (unbound)</p>
<p>Redo the last function executed with execute-named-cmd.</p>
<p>Like execute-named-cmd, this command may not be redefined, but it may be
called by name.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-get_002dline"></span></p>
2022-08-24 15:22:41 +02:00
<p>get-line (ESC-G ESC-g) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Pop the top line off the buffer stack and insert it at the cursor
position.</p>
<p><span id="index-pound_002dinsert"></span></p>
2022-08-24 15:22:41 +02:00
<p>pound-insert (unbound) (#) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>If there is no # character at the beginning of the buffer, add one to
the beginning of each line. If there is one, remove a # from each line
that has one. In either case, accept the current line. The
2022-08-24 15:22:41 +02:00
INTERACTIVE_COMMENTS option must be set for this to have any usefulness.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-vi_002dpound_002dinsert"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-pound-insert</p>
2021-05-11 02:29:21 +02:00
<p>If there is no # character at the beginning of the current line, add
2022-08-24 15:22:41 +02:00
one. If there is one, remove it. The INTERACTIVE_COMMENTS option must be
set for this to have any usefulness.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-push_002dinput"></span></p>
2022-08-24 15:22:41 +02:00
<p>push-input</p>
2021-05-11 02:29:21 +02:00
<p>Push the entire current multiline construct onto the buffer stack and
2022-08-24 15:22:41 +02:00
return to the top-level (PS1) prompt. If the current parser construct is
only a single line, this is exactly like push-line. Next time the editor
starts up or is popped with get-line, the construct will be popped off
the top of the buffer stack and loaded into the editing buffer.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-push_002dline"></span></p>
2022-08-24 15:22:41 +02:00
<p>push-line (^Q ESC-Q ESC-q) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Push the current buffer onto the buffer stack and clear the buffer. Next
time the editor starts up, the buffer will be popped off the top of the
buffer stack and loaded into the editing buffer.</p>
<p><span id="index-push_002dline_002dor_002dedit"></span></p>
2022-08-24 15:22:41 +02:00
<p>push-line-or-edit</p>
<p>At the top-level (PS1) prompt, equivalent to push-line. At a secondary
(PS2) prompt, move the entire current multiline construct into the
editor buffer. The latter is equivalent to push-input followed by
get-line.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-read_002dcommand"></span></p>
2022-08-24 15:22:41 +02:00
<p>read-command</p>
2021-05-11 02:29:21 +02:00
<p>Only useful from a user-defined widget. A keystroke is read just as in
normal operation, but instead of the command being executed the name of
the command that would be executed is stored in the shell parameter
2022-08-24 15:22:41 +02:00
REPLY. This can be used as the argument of a future zle command. If the
key sequence is not bound, status 1 is returned; typically, however,
REPLY is set to undefined-key to indicate a useless key sequence.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-recursive_002dedit"></span></p>
2022-08-24 15:22:41 +02:00
<p>recursive-edit</p>
2021-05-11 02:29:21 +02:00
<p>Only useful from a user-defined widget. At this point in the function,
the editor regains control until one of the standard widgets which would
2022-08-24 15:22:41 +02:00
normally cause zle to exit (typically an accept-line caused by hitting
2021-05-11 02:29:21 +02:00
the return key) is executed. Instead, control returns to the
user-defined widget. The status returned is non-zero if the return was
caused by an error, but the function still continues executing and hence
may tidy up. This makes it safe for the user-defined widget to alter the
command line or key bindings temporarily.</p>
2022-08-24 15:22:41 +02:00
<p>The following widget, caps-lock, serves as an example.</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">self-insert-ucase() {
2021-05-11 02:29:21 +02:00
LBUFFER+=${(U)KEYS[-1]}
}
integer stat
zle -N self-insert self-insert-ucase
zle -A caps-lock save-caps-lock
zle -A accept-line caps-lock
zle recursive-edit
stat=$?
zle -A .self-insert self-insert
zle -A save-caps-lock caps-lock
zle -D save-caps-lock
(( stat )) &amp;&amp; zle send-break
return $stat
</code></pre>
</div>
<p>This causes typed letters to be inserted capitalised until either
2022-08-24 15:22:41 +02:00
accept-line (i.e. typically the return key) is typed or the caps-lock
widget is invoked again; the later is handled by saving the old
definition of caps-lock as save-caps-lock and then rebinding it to
invoke accept-line. Note that an error from the recursive edit is
2021-05-11 02:29:21 +02:00
detected as a non-zero return status and propagated by using the
2022-08-24 15:22:41 +02:00
send-break widget.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-redisplay"></span></p>
2022-08-24 15:22:41 +02:00
<p>redisplay (unbound) (^R) (^R)</p>
2021-05-11 02:29:21 +02:00
<p>Redisplays the edit buffer.</p>
<p><span id="index-reset_002dprompt"></span></p>
2022-08-24 15:22:41 +02:00
<p>reset-prompt (unbound) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Force the prompts on both the left and right of the screen to be
re-expanded, then redisplay the edit buffer. This reflects changes both
to the prompt variables themselves and changes in the expansion of the
values (for example, changes in time or directory, or changes to the
value of variables referred to by the prompt).</p>
<p>Otherwise, the prompt is only expanded each time zle starts, and when
the display has been interrupted by output from another part of the
shell (such as a job notification) which causes the command line to be
reprinted.</p>
2022-08-24 15:22:41 +02:00
<p>reset-prompt doesnt alter the special parameter LASTWIDGET.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-send_002dbreak"></span></p>
2022-08-24 15:22:41 +02:00
<p>send-break (^G ESC-^G) (unbound) (unbound)</p>
<p>Abort the current editor function, e.g. execute-named-command, or the
editor itself, e.g. if you are in vared. Otherwise abort the parsing of
the current line; in this case the aborted line is available in the
shell variable ZLE_LINE_ABORTED. If the editor is aborted from within
vared, the variable ZLE_VARED_ABORTED is set.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-run_002dhelp"></span></p>
2022-08-24 15:22:41 +02:00
<p>run-help (ESC-H ESC-h) (unbound) (unbound)</p>
<p>Push the buffer onto the buffer stack, and execute the command run-help
<code>cmd</code>, where <code>cmd</code> is the current command. run-help is normally aliased
to man.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-vi_002dset_002dbuffer"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-set-buffer (unbound) (&quot;) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Specify a buffer to be used in the following command. There are 37
2022-08-24 15:22:41 +02:00
buffers that can be specified: the 26 named buffers &quot;a to &quot;z, the
yank buffer &quot;0, the nine queued buffers &quot;1 to &quot;9 and the black
hole buffer &quot;_. The named buffers can also be specified as &quot;A to &quot;Z.</p>
2021-05-11 02:29:21 +02:00
<p>When a buffer is specified for a cut, change or yank command, the text
concerned replaces the previous contents of the specified buffer. If a
named buffer is specified using a capital, the newly cut text is
2022-08-24 15:22:41 +02:00
appended to the buffer instead of overwriting it. When using the &quot;_
2021-05-11 02:29:21 +02:00
buffer, nothing happens. This can be useful for deleting text without
affecting any buffers.</p>
2022-08-24 15:22:41 +02:00
<p>If no buffer is specified for a cut or change command, &quot;1 is used, and
the contents of &quot;1 to &quot;8 are each shifted along one buffer; the contents
of &quot;9 is lost. If no buffer is specified for a yank command, &quot;0 is used.
Finally, a paste command without a specified buffer will paste the text
from the most recent command regardless of any buffer that might have
been used with that command.</p>
<p>When called from a widget function by the zle command, the buffer can
2021-05-11 02:29:21 +02:00
optionally be specified with an argument. For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zle vi-set-buffer A
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p><span id="index-vi_002dset_002dmark"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-set-mark (unbound) (m) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Set the specified mark at the cursor position.</p>
<p><span id="index-set_002dmark_002dcommand"></span></p>
2022-08-24 15:22:41 +02:00
<p>set-mark-command (^@) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Set the mark at the cursor position. If called with a negative numeric
argument, do not set the mark but deactivate the region so that it is no
longer highlighted (it is still usable for other purposes). Otherwise
the region is marked as active.</p>
<p><span id="index-spell_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>spell-word (ESC-$ ESC-S ESC-s) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Attempt spelling correction on the current word.</p>
<p><span id="index-split_002dundo"></span></p>
2022-08-24 15:22:41 +02:00
<p>split-undo</p>
2021-05-11 02:29:21 +02:00
<p>Breaks the undo sequence at the current change. This is useful in vi
mode as changes made in insert mode are coalesced on entering command
2022-08-24 15:22:41 +02:00
mode. Similarly, undo will normally revert as one all the changes made
2021-05-11 02:29:21 +02:00
by a user-defined widget.</p>
<p><span id="index-undefined_002dkey"></span></p>
2022-08-24 15:22:41 +02:00
<p>undefined-key</p>
2021-05-11 02:29:21 +02:00
<p>This command is executed when a key sequence that is not bound to any
command is typed. By default it beeps.</p>
<p><span id="index-undo"></span></p>
2022-08-24 15:22:41 +02:00
<p>undo (^_ ^Xu ^X^U) (u) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Incrementally undo the last text modification. When called from a
user-defined widget, takes an optional argument indicating a previous
2022-08-24 15:22:41 +02:00
state of the undo history as returned by the UNDO_CHANGE_NO variable;
2021-05-11 02:29:21 +02:00
modifications are undone until that state is reached, subject to any
2022-08-24 15:22:41 +02:00
limit imposed by the UNDO_LIMIT_NO variable.</p>
2021-05-11 02:29:21 +02:00
<p>Note that when invoked from vi command mode, the full prior change made
in insert mode is reverted, the changes having been merged when command
mode was selected.</p>
<p><span id="index-redo"></span></p>
2022-08-24 15:22:41 +02:00
<p>redo (unbound) (^R) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Incrementally redo undone text modifications.</p>
<p><span id="index-vi_002dundo_002dchange"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-undo-change (unbound) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Undo the last text modification. If repeated, redo the modification.</p>
<p><span id="index-visual_002dmode"></span></p>
2022-08-24 15:22:41 +02:00
<p>visual-mode (unbound) (v) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Toggle vim-style visual selection mode. If line-wise visual mode is
currently enabled then it is changed to being character-wise. If used
following an operator, it forces the subsequent movement command to be
treated as a character-wise movement.</p>
<p><span id="index-visual_002dline_002dmode"></span></p>
2022-08-24 15:22:41 +02:00
<p>visual-line-mode (unbound) (V) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Toggle vim-style line-wise visual selection mode. If character-wise
visual mode is currently enabled then it is changed to being line-wise.
If used following an operator, it forces the subsequent movement command
to be treated as a line-wise movement.</p>
<p><span id="index-what_002dcursor_002dposition"></span></p>
2022-08-24 15:22:41 +02:00
<p>what-cursor-position (^X=) (ga) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Print the character under the cursor, its code as an octal, decimal and
hexadecimal number, the current cursor position within the buffer and
the column of the cursor in the current line.</p>
<p><span id="index-where_002dis"></span></p>
2022-08-24 15:22:41 +02:00
<p>where-is</p>
2021-05-11 02:29:21 +02:00
<p>Read the name of an editor command and print the listing of key
sequences that invoke the specified command. A restricted set of editing
functions is available in the mini-buffer. Keys are looked up in the
2022-08-24 15:22:41 +02:00
special command keymap, and if not found there in the main keymap.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-which_002dcommand"></span></p>
2022-08-24 15:22:41 +02:00
<p>which-command (ESC-?) (unbound) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>Push the buffer onto the buffer stack, and execute the command
2022-08-24 15:22:41 +02:00
which-command <code>cmd</code>. where <code>cmd</code> is the current command. which-command
is normally aliased to whence.</p>
<p><span
id="index-vi_002ddigit_002dor_002dbeginning_002dof_002dline"></span></p>
<p>vi-digit-or-beginning-of-line (unbound) (0) (unbound)</p>
2021-05-11 02:29:21 +02:00
<p>If the last command executed was a digit as part of an argument,
continue the argument. Otherwise, execute vi-beginning-of-line.</p>
<hr />
<p><span id="Text-Objects"></span> <span id="Text-Objects-1"></span></p>
<h3 id="1867-text-objects"><a class="header" href="#1867-text-objects">18.6.7 Text Objects</a></h3>
<p><span id="index-text-objects"></span></p>
<p>Text objects are commands that can be used to select a block of text
according to some criteria. They are a feature of the vim text editor
and so are primarily intended for use with vi operators or from visual
selection mode. However, they can also be used from vi-insert or emacs
2022-08-24 15:22:41 +02:00
mode. Key bindings listed below apply to the viopp and visual keymaps.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-select_002da_002dblank_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>select-a-blank-word (aW)</p>
2021-05-11 02:29:21 +02:00
<p>Select a word including adjacent blanks, where a word is defined as a
series of non-blank characters. With a numeric argument, multiple words
will be selected.</p>
<p><span id="index-select_002da_002dshell_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>select-a-shell-word (aa)</p>
2021-05-11 02:29:21 +02:00
<p>Select the current command argument applying the normal rules for
quoting.</p>
<p><span id="index-select_002da_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>select-a-word (aw)</p>
2021-05-11 02:29:21 +02:00
<p>Select a word including adjacent blanks, using the normal vi-style word
definition. With a numeric argument, multiple words will be selected.</p>
<p><span id="index-select_002din_002dblank_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>select-in-blank-word (iW)</p>
2021-05-11 02:29:21 +02:00
<p>Select a word, where a word is defined as a series of non-blank
characters. With a numeric argument, multiple words will be selected.</p>
<p><span id="index-select_002din_002dshell_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>select-in-shell-word (ia)</p>
2021-05-11 02:29:21 +02:00
<p>Select the current command argument applying the normal rules for
quoting. If the argument begins and ends with matching quote characters,
these are not included in the selection.</p>
<p><span id="index-select_002din_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>select-in-word (iw)</p>
2021-05-11 02:29:21 +02:00
<p>Select a word, using the normal vi-style word definition. With a numeric
argument, multiple words will be selected.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Character-Highlighting"></span> <span
id="Character-Highlighting-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="187-character-highlighting"><a class="header" href="#187-character-highlighting">18.7 Character Highlighting</a></h2>
<p><span id="index-zle_005fhighlight_002c-setting"></span></p>
<p>The line editor has the ability to highlight characters or regions of
the line that have a particular significance. This is controlled by the
2022-08-24 15:22:41 +02:00
array parameter zle_highlight, if it has been set by the user.</p>
<p>If the parameter contains the single entry none all highlighting is
2021-05-11 02:29:21 +02:00
turned off. Note the parameter is still expected to be an array.</p>
<p>Otherwise each entry of the array should consist of a word indicating a
context for highlighting, then a colon, then a comma-separated list of
the types of highlighting to apply in that context.</p>
<p>The contexts available for highlighting are the following:</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-region_002c-highlighting"></span> <span
id="index-highlighting_002c-region"></span></p>
<p>default</p>
2021-05-11 02:29:21 +02:00
<p>Any text within the command line not affected by any other highlighting.</p>
2022-08-24 15:22:41 +02:00
<p>isearch</p>
2021-05-11 02:29:21 +02:00
<p>When one of the incremental history search widgets is active, the area
of the command line matched by the search string or pattern.</p>
2022-08-24 15:22:41 +02:00
<p>region</p>
2021-05-11 02:29:21 +02:00
<p>The currently selected text. In emacs terminology, this is referred to
as the region and is bounded by the cursor (point) and the mark. The
region is only highlighted if it is active, which is the case after the
2022-08-24 15:22:41 +02:00
mark is modified with set-mark-command or exchange-point-and-mark. Note
that whether or not the region is active has no effect on its use within
emacs style widgets, it simply determines whether it is highlighted. In
vi mode, the region corresponds to selected text in visual mode.</p>
<p><span id="index-special-characters_002c-highlighting"></span> <span
id="index-highlighting_002c-special-characters"></span></p>
<p>special</p>
2021-05-11 02:29:21 +02:00
<p>representation but are shown in a special manner by the line editor.
These characters are described below.</p>
<p><span id="index-completion-removable-suffix_002c-highlighting"></span>
2022-08-24 15:22:41 +02:00
<span
id="index-suffix_002c-highlighting-removable_002c-in-completion"></span>
<span
id="index-removable-suffix_002c-highlighting-in-completion"></span></p>
<p>suffix</p>
2021-05-11 02:29:21 +02:00
<p>This context is used in completion for characters that are marked as
suffixes that will be removed if the completion ends at that point, the
2022-08-24 15:22:41 +02:00
most obvious example being a slash (/) after a directory name. Note that
suffix removal is configurable; the circumstances under which the suffix
will be removed may differ for different completions.</p>
<p>paste</p>
2021-05-11 02:29:21 +02:00
<p>Following a command to paste text, the characters that were inserted.</p>
2022-08-24 15:22:41 +02:00
<p>When region_highlight is set, the contexts that describe a region —
isearch, region, suffix, and paste — are applied first, then
region_highlight is applied, then the remaining zle_highlight contexts
are applied. If a particular character is affected by multiple
2021-05-11 02:29:21 +02:00
specifications, the last specification wins.</p>
2022-08-24 15:22:41 +02:00
<p>zle_highlight may contain additional fields for controlling how terminal
sequences to change colours are output. Each of the following is
followed by a colon and a string in the same form as for key bindings.
This will not be necessary for the vast majority of terminals as the
defaults shown in parentheses are widely used.</p>
<p><span
id="index-escape-sequences_002c-terminal_002c-for-highlighting"></span>
2021-05-11 02:29:21 +02:00
<span id="index-terminal-escape-sequences-for-highlighting"></span></p>
2022-08-24 15:22:41 +02:00
<p>fg_start_code (\e[3)</p>
2021-05-11 02:29:21 +02:00
<p>The start of the escape sequence for the foreground colour. This is
followed by one to three ASCII digits representing the colour. Only used
for palette colors, i.e. not 24-bit colors specified via a color
triplet.</p>
2022-08-24 15:22:41 +02:00
<p>fg_default_code (9)</p>
2021-05-11 02:29:21 +02:00
<p>The number to use instead of the colour to reset the default foreground
colour.</p>
2022-08-24 15:22:41 +02:00
<p>fg_end_code (m)</p>
2021-05-11 02:29:21 +02:00
<p>The end of the escape sequence for the foreground colour.</p>
2022-08-24 15:22:41 +02:00
<p>bg_start_code (\e[4)</p>
2021-05-11 02:29:21 +02:00
<p>The start of the escape sequence for the background colour. See
2022-08-24 15:22:41 +02:00
fg_start_code above.</p>
<p>bg_default_code (9)</p>
2021-05-11 02:29:21 +02:00
<p>The number to use instead of the colour to reset the default background
colour.</p>
2022-08-24 15:22:41 +02:00
<p>bg_end_code (m)</p>
2021-05-11 02:29:21 +02:00
<p>The end of the escape sequence for the background colour.</p>
<p>The available types of highlighting are the following. Note that not all
types of highlighting are available on all terminals:</p>
2022-08-24 15:22:41 +02:00
<p>none<br />
No highlighting is applied to the given context. It is not useful for
this to appear with other types of highlighting; it is used to override
a default.</p>
<p>fg=<code>colour</code><br />
The foreground colour should be set to <code>colour</code>, a decimal integer, the
name of one of the eight most widely-supported colours or as a #
followed by an RGB triplet in hexadecimal format.</p>
<p>Not all terminals support this and, of those that do, not all provide
facilities to test the support, hence the user should decide based on
the terminal type. Most terminals support the colours black, red, green,
yellow, blue, magenta, cyan and white, which can be set by name. In
addition. default may be used to set the terminals default foreground
colour. Abbreviations are allowed; b or bl selects black. Some terminals
may generate additional colours if the bold attribute is also present.</p>
<p>On recent terminals and on systems with an up-to-date terminal database
the number of colours supported may be tested by the command echotc
Co; if this succeeds, it indicates a limit on the number of colours
which will be enforced by the line editor. The number of colours is in
any case limited to 256 (i.e. the range 0 to 255).</p>
<p>Some modern terminal emulators have support for 24-bit true colour (16
million colours). In this case, the hex triplet format can be used. This
consists of a # followed by either a three or six digit hexadecimal
number describing the red, green and blue components of the colour. Hex
triplets can also be used with 88 and 256 colour terminals via the
zsh/nearcolor module (see <a href="Zsh-Modules.html#The-zsh_002fnearcolor-Module">The zsh/nearcolor
2021-05-11 02:29:21 +02:00
Module</a>).</p>
<p>Colour is also known as color.</p>
2022-08-24 15:22:41 +02:00
<p>bg=<code>colour</code><br />
The background colour should be set to <code>colour</code>. This works similarly to
the foreground colour, except the background is not usually affected by
the bold attribute.</p>
<p>bold<br />
The characters in the given context are shown in a bold font. Not all
terminals distinguish bold fonts.</p>
<p>standout<br />
The characters in the given context are shown in the terminals standout
mode. The actual effect is specific to the terminal; on many terminals
it is inverse video. On some such terminals, where the cursor does not
blink it appears with standout mode negated, making it less than clear
where the cursor actually is. On such terminals one of the other effects
may be preferable for highlighting the region and matched search string.</p>
<p>underline<br />
The characters in the given context are shown underlined. Some terminals
show the foreground in a different colour instead; in this case
whitespace will not be highlighted.</p>
2021-05-11 02:29:21 +02:00
<p>The characters described above as special are as follows. The
formatting described here is used irrespective of whether the characters
are highlighted:</p>
<p>ASCII control characters<br />
2022-08-24 15:22:41 +02:00
Control characters in the ASCII range are shown as ^ followed by the
base character.</p>
2021-05-11 02:29:21 +02:00
<p>This item applies to control characters not in the ASCII range, plus
2022-08-24 15:22:41 +02:00
other characters as follows. If the MULTIBYTE option is in effect,
multibyte characters not in the ASCII character set that are reported as
having zero width are treated as combining characters when the option
COMBINING_CHARS is on. If the option is off, or if a character appears
where a combining character is not valid, the character</p>
2021-05-11 02:29:21 +02:00
<p>angle brackets. The number is the code point of the character in the
wide character set; this may or may not be Unicode, depending on the
operating system.</p>
<p>Invalid multibyte characters<br />
2022-08-24 15:22:41 +02:00
If the MULTIBYTE option is in effect, any sequence of one or more bytes
that does not form a valid character in the current character set is
treated as a series of bytes each shown as a special character. as the
bytes are represented as two hexadecimal digits between angle brackets,
as distinct from the four or eight digits that are used for character
set.</p>
2021-05-11 02:29:21 +02:00
<p>Not all systems support this: for it to work, the systems
2022-08-24 15:22:41 +02:00
representation of wide characters must be code values from the Universal
Character Set, as defined by IS0 10646 (also known as Unicode).</p>
2021-05-11 02:29:21 +02:00
<p>Wrapped double-width characters<br />
2022-08-24 15:22:41 +02:00
When a double-width character appears in the final column of a line, it
is instead shown on the next line. The empty space left in the original
position is highlighted as a special character.</p>
<p>If zle_highlight is not set or no value applies to a particular context,
the defaults applied are equivalent to</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zle_highlight=(region:standout special:standout
2021-05-11 02:29:21 +02:00
suffix:bold isearch:underline paste:standout)
</code></pre>
</div>
<p>i.e. both the region and special characters are shown in standout mode.</p>
<p>Within widgets, arbitrary regions may be highlighted by setting the
2022-08-24 15:22:41 +02:00
special array parameter region_highlight; see <a href="Zsh-Line-Editor.html#Zle-Widgets">Zle
Widgets</a>.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="Completion-Widgets.html#19-completion-widgets">19 Completion Widgets</a>
<ul>
<li><a href="Completion-Widgets.html#191-description">19.1 Description</a></li>
<li><a href="Completion-Widgets.html#192-completion-special-parameters">19.2 Completion Special Parameters</a></li>
<li><a href="Completion-Widgets.html#193-completion-builtin-commands">19.3 Completion Builtin Commands</a></li>
2022-08-24 15:22:41 +02:00
<li><a href="Completion-Widgets.html#%5C-">-</a></li>
2021-05-11 02:29:21 +02:00
<li><a href="Completion-Widgets.html#194-completion-condition-codes">19.4 Completion Condition Codes</a></li>
<li><a href="Completion-Widgets.html#195-completion-matching-control">19.5 Completion Matching Control</a></li>
<li><a href="Completion-Widgets.html#196-completion-widget-example">19.6 Completion Widget Example</a></li>
</ul>
</li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2022-08-24 15:22:41 +02:00
<p><span id="Completion-Widgets"></span> <span
id="Completion-Widgets-1"></span></p>
2021-05-11 02:29:21 +02:00
<h1 id="19-completion-widgets"><a class="header" href="#19-completion-widgets">19 Completion Widgets</a></h1>
2022-08-24 15:22:41 +02:00
<p><span id="index-completion_002c-widgets"></span> <span
id="index-completion_002c-programmable"></span> <span
id="index-completion_002c-controlling"></span></p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Description"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="191-description"><a class="header" href="#191-description">19.1 Description</a></h2>
<p>The shells programmable completion mechanism can be manipulated in two
ways; here the low-level features supporting the newer, function-based
mechanism are defined. A complete set of shell functions based on these
features is described in the next chapter, <a href="Completion-System.html#Completion-System">Completion
System</a>, and users with no
interest in adding to that system (or, potentially, writing their own —
see dictionary entry for hubris) should skip the current section. The
2022-08-24 15:22:41 +02:00
older system based on the compctl builtin command is described in
2021-05-11 02:29:21 +02:00
<a href="Completion-Using-compctl.html#Completion-Using-compctl">Completion Using
compctl</a>.</p>
2022-08-24 15:22:41 +02:00
<p>Completion widgets are defined by the -C option to the zle builtin
command provided by the zsh/zle module (see <a href="Zsh-Modules.html#The-zsh_002fzle-Module">The zsh/zle
2021-05-11 02:29:21 +02:00
Module</a>). For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zle -C complete expand-or-complete completer
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>defines a widget named complete. The second argument is the name of
any of the builtin widgets that handle completions: complete-word,
expand-or-complete, expand-or-complete-prefix, menu-complete,
menu-expand-or-complete, reverse-menu-complete, list-choices, or
delete-char-or-list. Note that this will still work even if the widget
2021-05-11 02:29:21 +02:00
in question has been re-bound.</p>
2022-08-24 15:22:41 +02:00
<p>When this newly defined widget is bound to a key using the bindkey
builtin command defined in the zsh/zle module (<a href="Zsh-Line-Editor.html#Zsh-Line-Editor">Zsh Line
2021-05-11 02:29:21 +02:00
Editor</a>), typing that key will
2022-08-24 15:22:41 +02:00
call the shell function completer. This function is responsible for
generating completion matches using the builtins described below. As
2021-05-11 02:29:21 +02:00
with other ZLE widgets, the function is called with its standard input
closed.</p>
<p>Once the function returns, the completion code takes over control again
and treats the matches in the same manner as the specified builtin
2022-08-24 15:22:41 +02:00
widget, in this case expand-or-complete.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Completion-Special-Parameters"></span> <span
id="Completion-Special-Parameters-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="192-completion-special-parameters"><a class="header" href="#192-completion-special-parameters">19.2 Completion Special Parameters</a></h2>
2022-08-24 15:22:41 +02:00
<p>The parameters ZLE_REMOVE_SUFFIX_CHARS and ZLE_SPACE_SUFFIX_CHARS are
used by the completion mechanism, but are not special. See <a href="Parameters.html#Parameters-Used-By-The-Shell">Parameters
Used By The Shell</a>.</p>
2021-05-11 02:29:21 +02:00
<p>Inside completion widgets, and any functions called from them, some
parameters have special meaning; outside these functions they are not
special to the shell in any way. These parameters are used to pass
information between the completion code and the completion widget. Some
of the builtin commands and the condition codes use or change the
current values of these parameters. Any existing values will be hidden
2022-08-24 15:22:41 +02:00
during execution of completion widgets; except for compstate, the
2021-05-11 02:29:21 +02:00
parameters are reset on each function exit (including nested function
calls from within the completion widget) to the values they had when the
function was entered.</p>
<p><span id="index-CURRENT"></span></p>
2022-08-24 15:22:41 +02:00
<p>CURRENT</p>
2021-05-11 02:29:21 +02:00
<p>This is the number of the current word, i.e. the word the cursor is
2022-08-24 15:22:41 +02:00
currently on in the words array. Note that this value is only correct if
the ksharrays option is not set.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-IPREFIX"></span></p>
2022-08-24 15:22:41 +02:00
<p>IPREFIX</p>
2021-05-11 02:29:21 +02:00
<p>Initially this will be set to the empty string. This parameter functions
2022-08-24 15:22:41 +02:00
like PREFIX; it contains a string which precedes the one in PREFIX and
is not considered part of the list of matches. Typically, a string is
transferred from the beginning of PREFIX to the end of IPREFIX, for
example:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">IPREFIX=${PREFIX%%\=*}=
2021-05-11 02:29:21 +02:00
PREFIX=${PREFIX#*=}
</code></pre>
</div>
<p>causes the part of the prefix up to and including the first equal sign
not to be treated as part of a matched string. This can be done
2022-08-24 15:22:41 +02:00
automatically by the compset builtin, see below.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-ISUFFIX"></span></p>
2022-08-24 15:22:41 +02:00
<p>ISUFFIX</p>
<p>As IPREFIX, but for a suffix that should not be considered part of the
matches; note that the ISUFFIX string follows the SUFFIX string.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-PREFIX"></span></p>
2022-08-24 15:22:41 +02:00
<p>PREFIX</p>
2021-05-11 02:29:21 +02:00
<p>Initially this will be set to the part of the current word from the
beginning of the word up to the position of the cursor; it may be
altered to give a common prefix for all matches.</p>
<p><span id="index-QIPREFIX"></span></p>
2022-08-24 15:22:41 +02:00
<p>QIPREFIX</p>
2021-05-11 02:29:21 +02:00
<p>This parameter is read-only and contains the quoted string up to the
2022-08-24 15:22:41 +02:00
word being completed. E.g. when completing &quot;foo, this parameter
contains the double quote. If the -q option of compset is used (see
below), and the original string was &quot;foo bar with the cursor on the
bar, this parameter contains &quot;foo .</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-QISUFFIX"></span></p>
2022-08-24 15:22:41 +02:00
<p>QISUFFIX</p>
<p>Like QIPREFIX, but containing the suffix.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-SUFFIX"></span></p>
2022-08-24 15:22:41 +02:00
<p>SUFFIX</p>
2021-05-11 02:29:21 +02:00
<p>Initially this will be set to the part of the current word from the
cursor position to the end; it may be altered to give a common suffix
2022-08-24 15:22:41 +02:00
for all matches. It is most useful when the option COMPLETE_IN_WORD is
2021-05-11 02:29:21 +02:00
set, as otherwise the whole word on the command line is treated as a
prefix.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-compstate"></span> <span
id="index-completion-widgets_002c-examining-and-setting-state-in"></span></p>
<p>compstate</p>
2021-05-11 02:29:21 +02:00
<p>This is an associative array with various keys and values that the
completion code uses to exchange information with the completion widget.
The keys are:</p>
<p><span id="index-all_005fquotes_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>all_quotes</p>
<p>The -q option of the compset builtin command (see below) allows a quoted
string to be broken into separate words; if the cursor is on one of
those words, that word will be completed, possibly invoking compset -q
recursively. With this key it is possible to test the types of quoted
strings which are currently broken into parts in this fashion. Its value
contains one character for each quoting level. The characters are a
single quote or a double quote for strings quoted with these characters,
a dollars sign for strings quoted with $<code>...</code> and a backslash for
strings not starting with a quote character. The first character in the
value always corresponds to the innermost quoting level.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-context_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>context</p>
2021-05-11 02:29:21 +02:00
<p>This will be set by the completion code to the overall context in which
completion is attempted. Possible values are:</p>
2022-08-24 15:22:41 +02:00
<p>array_value<br />
when completing inside the value of an array parameter assignment; in
this case the words array contains the words inside the parentheses.</p>
<p>brace_parameter<br />
2021-05-11 02:29:21 +02:00
when completing the name of a parameter in a parameter expansion
2022-08-24 15:22:41 +02:00
beginning with ${. This context will also be set when completing
parameter flags following ${(; the full command line argument is
2021-05-11 02:29:21 +02:00
presented and the handler must test the value to be completed to
ascertain that this is the case.</p>
2022-08-24 15:22:41 +02:00
<p>assign_parameter<br />
2021-05-11 02:29:21 +02:00
when completing the name of a parameter in a parameter assignment.</p>
2022-08-24 15:22:41 +02:00
<p>command<br />
when completing for a normal command (either in command position or for
an argument of the command).</p>
<p>condition<br />
when completing inside a [[...]] conditional expression; in this
case the words array contains only the words inside the conditional
expression.</p>
<p>math<br />
when completing in a mathematical environment such as a ((...))
construct.</p>
<p>parameter<br />
2021-05-11 02:29:21 +02:00
when completing the name of a parameter in a parameter expansion
2022-08-24 15:22:41 +02:00
beginning with $ but not ${.</p>
<p>redirect<br />
2021-05-11 02:29:21 +02:00
when completing after a redirection operator.</p>
2022-08-24 15:22:41 +02:00
<p>subscript<br />
2021-05-11 02:29:21 +02:00
when completing inside a parameter subscript.</p>
2022-08-24 15:22:41 +02:00
<p>value<br />
2021-05-11 02:29:21 +02:00
when completing the value of a parameter assignment.</p>
<p><span id="index-exact_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>exact</p>
<p>Controls the behaviour when the REC_EXACT option is set. It will be set
to accept if an exact match would be accepted, and will be unset
2021-05-11 02:29:21 +02:00
otherwise.</p>
<p>If it was set when at least one match equal to the string on the line
was generated, the match is accepted.</p>
<p><span id="index-exact_005fstring_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>exact_string</p>
2021-05-11 02:29:21 +02:00
<p>The string of an exact match if one was found, otherwise unset.</p>
<p><span id="index-ignored_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>ignored</p>
<p>The number of completions that were ignored because they matched one of
the patterns given with the -F option to the compadd builtin command.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-insert_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>insert</p>
2021-05-11 02:29:21 +02:00
<p>This controls the manner in which a match is inserted into the command
line. On entry to the widget function, if it is unset the command line
2022-08-24 15:22:41 +02:00
is not to be changed; if set to unambiguous, any prefix common to all
matches is to be inserted; if set to automenu-unambiguous, the common
2021-05-11 02:29:21 +02:00
prefix is to be inserted and the next invocation of the completion code
2022-08-24 15:22:41 +02:00
may start menu completion (due to the AUTO_MENU option being set); if
set to menu or automenu menu completion will be started for the matches
currently generated (in the latter case this will happen because the
AUTO_MENU is set). The value may also contain the string tab when the
completion code would normally not really do completion, but only insert
the TAB character.</p>
2021-05-11 02:29:21 +02:00
<p>On exit it may be set to any of the values above (where setting it to
the empty string is the same as unsetting it), or to a number, in which
case the match whose number is given will be inserted into the command
2022-08-24 15:22:41 +02:00
line. Negative numbers count backward from the last match (with -1
2021-05-11 02:29:21 +02:00
selecting the last match) and out-of-range values are wrapped around, so
that a value of zero selects the last match and a value one more than
the maximum selects the first. Unless the value of this key ends in a
space, the match is inserted as in a menu completion, i.e. without
automatically appending a space.</p>
2022-08-24 15:22:41 +02:00
<p>Both menu and automenu may also specify the number of the match to
insert, given after a colon. For example, menu:2 says to start menu
2021-05-11 02:29:21 +02:00
completion, beginning with the second match.</p>
2022-08-24 15:22:41 +02:00
<p>Note that a value containing the substring tab makes the matches
2021-05-11 02:29:21 +02:00
generated be ignored and only the TAB be inserted.</p>
2022-08-24 15:22:41 +02:00
<p>Finally, it may also be set to all, which makes all matches generated be
inserted into the line.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-insert_005fpositions_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>insert_positions</p>
2021-05-11 02:29:21 +02:00
<p>When the completion system inserts an unambiguous string into the line,
there may be multiple places where characters are missing or where the
character inserted differs from at least one match. The value of this
key contains a colon separated list of all these positions, as indexes
into the command line.</p>
<p><span id="index-last_005fprompt_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>last_prompt</p>
2021-05-11 02:29:21 +02:00
<p>If this is set to a non-empty string for every match added, the
completion code will move the cursor back to the previous prompt after
the list of completions has been displayed. Initially this is set or
2022-08-24 15:22:41 +02:00
unset according to the ALWAYS_LAST_PROMPT option.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-list_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>list</p>
2021-05-11 02:29:21 +02:00
<p>This controls whether or how the list of matches will be displayed. If
it is unset or empty they will never be listed; if its value begins with
2022-08-24 15:22:41 +02:00
list, they will always be listed; if it begins with autolist or
ambiguous, they will be listed when the AUTO_LIST or LIST_AMBIGUOUS
options respectively would normally cause them to be.</p>
<p>If the substring force appears in the value, this makes the list be
2021-05-11 02:29:21 +02:00
shown even if there is only one match. Normally, the list would be shown
only if there are at least two matches.</p>
2022-08-24 15:22:41 +02:00
<p>The value contains the substring packed if the LIST_PACKED option is
2021-05-11 02:29:21 +02:00
set. If this substring is given for all matches added to a group, this
2022-08-24 15:22:41 +02:00
group will show the LIST_PACKED behavior. The same is done for the
LIST_ROWS_FIRST option with the substring rows.</p>
<p>Finally, if the value contains the string explanations, only the
explanation strings, if any, will be listed and if it contains messages,
only the messages (added with the -x option of compadd) will be listed.
If it contains both explanations and messages both kinds of explanation
strings will be listed. It will be set appropriately on entry to a
completion widget and may be changed there.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-list_005flines_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>list_lines</p>
2021-05-11 02:29:21 +02:00
<p>This gives the number of lines that are needed to display the full list
of completions. Note that to calculate the total number of lines to
display you need to add the number of lines needed for the command line
2022-08-24 15:22:41 +02:00
to this value, this is available as the value of the BUFFERLINES special
parameter.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-list_005fmax_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>list_max</p>
<p>Initially this is set to the value of the LISTMAX parameter. It may be
2021-05-11 02:29:21 +02:00
set to any other value; when the widget exits this value will be used in
2022-08-24 15:22:41 +02:00
the same way as the value of LISTMAX.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-nmatches_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>nmatches</p>
<p>The number of matches added by the completion code so far.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-old_005finsert_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>old_insert</p>
2021-05-11 02:29:21 +02:00
<p>On entry to the widget this will be set to the number of the match of an
old list of completions that is currently inserted into the command
line. If no match has been inserted, this is unset.</p>
2022-08-24 15:22:41 +02:00
<p>As with old_list, the value of this key will only be used if it is the
string keep. If it was set to this value by the widget and there was an
old match inserted into the command line, this match will be kept and if
the value of the insert key specifies that another match should be
2021-05-11 02:29:21 +02:00
inserted, this will be inserted after the old one.</p>
<p><span id="index-old_005flist_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>old_list</p>
<p>This is set to yes if there is still a valid list of completions from a
previous completion at the time the widget is invoked. This will usually
be the case if and only if the previous editing operation was a
2021-05-11 02:29:21 +02:00
completion widget or one of the builtin completion functions. If there
is a valid list and it is also currently shown on the screen, the value
2022-08-24 15:22:41 +02:00
of this key is shown.</p>
2021-05-11 02:29:21 +02:00
<p>After the widget has exited the value of this key is only used if it was
2022-08-24 15:22:41 +02:00
set to keep. In this case the completion code will continue to use this
old list. If the widget generated new matches, they will not be used.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-parameter_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>parameter</p>
2021-05-11 02:29:21 +02:00
<p>The name of the parameter when completing in a subscript or in the value
of a parameter assignment.</p>
<p><span id="index-pattern_005finsert_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>pattern_insert</p>
<p>Normally this is set to menu, which specifies that menu completion will
be used whenever a set of matches was generated using pattern_match (see
below). If it is set to any other non-empty string by the user and menu
completion is not selected by other option settings, the code will
2021-05-11 02:29:21 +02:00
instead insert any common prefix for the generated matches as with
normal completion.</p>
<p><span id="index-pattern_005fmatch_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>pattern_match</p>
<p>Locally controls the behaviour given by the GLOB_COMPLETE option.
Initially it is set to * if and only if the option is set. The
2021-05-11 02:29:21 +02:00
completion widget may set it to this value, to an empty string (which
has the same effect as unsetting it), or to any other non-empty string.
If it is non-empty, unquoted metacharacters on the command line will be
2022-08-24 15:22:41 +02:00
treated as patterns; if it is *, then additionally a wildcard * is
assumed at the cursor position; if it is empty or unset, metacharacters
will be treated literally.</p>
<p>Note that the match specifications given to the compadd builtin command
are not used if this is set to a non-empty string.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-quote_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>quote</p>
2021-05-11 02:29:21 +02:00
<p>When completing inside quotes, this contains the quotation character
(i.e. either a single quote, a double quote, or a backtick). Otherwise
it is unset.</p>
<p><span id="index-quoting_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>quoting</p>
<p>When completing inside single quotes, this is set to the string single;
inside double quotes, the string double; inside backticks, the string
backtick. Otherwise it is unset.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-redirect_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>redirect</p>
2021-05-11 02:29:21 +02:00
<p>The redirection operator when completing in a redirection position, i.e.
2022-08-24 15:22:41 +02:00
one of &lt;, &gt;, etc.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-restore_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>restore</p>
<p>This is set to auto before a function is entered, which forces the
special parameters mentioned above (words, CURRENT, PREFIX, IPREFIX,
SUFFIX, and ISUFFIX) to be restored to their previous values when the
function exits. If a function unsets it or sets it to any other string,
they will not be restored.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-to_005fend_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>to_end</p>
2021-05-11 02:29:21 +02:00
<p>Specifies the occasions on which the cursor is moved to the end of a
string when a match is inserted. On entry to a widget function, it may
2022-08-24 15:22:41 +02:00
be single if this will happen when a single unambiguous match was
inserted or match if it will happen any time a match is inserted (for
2021-05-11 02:29:21 +02:00
example, by menu completion; this is likely to be the effect of the
2022-08-24 15:22:41 +02:00
ALWAYS_TO_END option).</p>
<p>On exit, it may be set to single as above. It may also be set to always,
or to the empty string or unset; in those cases the cursor will be moved
to the end of the string always or never respectively. Any other string
is treated as match.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-unambiguous_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>unambiguous</p>
2021-05-11 02:29:21 +02:00
<p>This key is read-only and will always be set to the common (unambiguous)
prefix the completion code has generated for all matches added so far.</p>
<p><span id="index-unambiguous_005fcursor_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>unambiguous_cursor</p>
2021-05-11 02:29:21 +02:00
<p>This gives the position the cursor would be placed at if the common
2022-08-24 15:22:41 +02:00
prefix in the unambiguous key were inserted, relative to the value of
2021-05-11 02:29:21 +02:00
that key. The cursor would be placed before the character whose index is
given by this key.</p>
<p><span id="index-unambiguous_005fpositions_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>unambiguous_positions</p>
2021-05-11 02:29:21 +02:00
<p>This contains all positions where characters in the unambiguous string
are missing or where the character inserted differs from at least one of
the matches. The positions are given as indexes into the string given by
2022-08-24 15:22:41 +02:00
the value of the unambiguous key.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-vared_002c-compstate"></span></p>
2022-08-24 15:22:41 +02:00
<p>vared</p>
<p>If completion is called while editing a line using the vared builtin,
2021-05-11 02:29:21 +02:00
the value of this key is set to the name of the parameter given as an
2022-08-24 15:22:41 +02:00
argument to vared. This key is only set while a vared command is active.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-words"></span></p>
2022-08-24 15:22:41 +02:00
<p>words</p>
2021-05-11 02:29:21 +02:00
<p>This array contains the words present on the command line currently
being edited.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Completion-Builtin-Commands"></span> <span
id="Completion-Builtin-Commands-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="193-completion-builtin-commands"><a class="header" href="#193-completion-builtin-commands">19.3 Completion Builtin Commands</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-compadd"></span> <span
id="index-completion-widgets_002c-adding-specified-matches"></span></p>
<p>compadd [ -akqQfenUl12C ] [ -F <code>array</code> ]</p>
<p>        [-P <code>prefix</code> ] [ -S <code>suffix</code> ]</p>
<p>        [-p <code>hidden-prefix</code> ] [ -s <code>hidden-suffix</code> ]</p>
<p>        [-i <code>ignored-prefix</code> ] [ -I <code>ignored-suffix</code> ]</p>
<p>        [-W <code>file-prefix</code> ] [ -d <code>array</code> ]</p>
<p>        [-J <code>group-name</code> ] [ -X <code>explanation</code> ] [ -x <code>message</code> ]</p>
<p>        [-V <code>group-name</code> ] [ -o [ <code>order</code> ] ]</p>
<p>        [-r <code>remove-chars</code> ] [ -R <code>remove-func</code> ]</p>
<p>        [-D <code>array</code> ] [ -O <code>array</code> ] [ -A <code>array</code> ]</p>
<p>        [-E <code>number</code> ]</p>
<p>        [-M <code>match-spec</code> ] [ -- ] [ <code>completions</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>This builtin command can be used to add matches directly and control all
2022-08-24 15:22:41 +02:00
the information the completion code stores with each possible
completion. The return status is zero if at least one match was added
and non-zero if no matches were added.</p>
<p>The completion code breaks each match into seven fields in the order:</p>
2021-05-11 02:29:21 +02:00
<blockquote>
2022-08-24 15:22:41 +02:00
<p><code>&lt;ipre&gt;&lt;apre&gt;&lt;hpre&gt;&lt;body&gt;&lt;hsuf&gt;&lt;asuf&gt;&lt;isuf&gt;</code></p>
2021-05-11 02:29:21 +02:00
</blockquote>
<p>The first field is an ignored prefix taken from the command line, the
2022-08-24 15:22:41 +02:00
contents of the IPREFIX parameter plus the string given with the -i
option. With the -U option, only the string from the -i option is used.
The field <code>&lt;apre&gt;</code> is an optional prefix string given with the -P
option. The <code>&lt;hpre&gt;</code> field is a string that is considered part of the
match but that should not be shown when listing completions, given with
the -p option; for example, functions that do filename generation might
specify a common path prefix this way. <code>&lt;body&gt;</code> is the part of the match
that should appear in the list of matches shown to the user. The
suffixes <code>&lt;hsuf&gt;</code>, <code>&lt;asuf&gt;</code> and <code>&lt;isuf&gt;</code> correspond to the prefixes
<code>&lt;hpre&gt;</code>, <code>&lt;apre&gt;</code> and <code>&lt;ipre&gt;</code> and are given by the options -s, -S and
-I, respectively.</p>
2021-05-11 02:29:21 +02:00
<p>The supported flags are:</p>
2022-08-24 15:22:41 +02:00
<p>-P <code>prefix</code><br />
This gives a string to be inserted before each match. The string given
is not considered as part of the match and any shell metacharacters in
it will not be quoted when the string is inserted.</p>
<p>-S <code>suffix</code><br />
Like -P, but gives a string to be inserted after each match.</p>
<p>-p <code>hidden-prefix</code><br />
This gives a string that should be inserted before each match but that
should not appear in the list of matches. Unless the -U option is given,
this string must be matched as part of the string on the command line.</p>
<p>-s <code>hidden-suffix</code><br />
Like -p, but gives a string to insert after each match.</p>
<p>-i <code>ignored-prefix</code><br />
This gives a string to insert just before any string given with the -P
option. Without -P the string is inserted before the string given with
-p or directly before each match.</p>
<p>-I <code>ignored-suffix</code><br />
Like -i, but gives an ignored suffix.</p>
<p>-a<br />
With this flag the <code>completions</code> are taken as names of arrays and the
actual completions are their values. If only some elements of the arrays
are needed, the <code>completions</code> may also contain subscripts, as in
foo[2,-1].</p>
<p>-k<br />
With this flag the <code>completions</code> are taken as names of associative
arrays and the actual completions are their keys. As for -a, the <code>words</code>
may also contain subscripts, as in foo[(R)*bar*].</p>
<p>-d <code>array</code><br />
This adds per-completion display strings. The <code>array</code> should contain one
element per <code>completion</code> given. The completion code will then display
the first element instead of the first <code>completion</code>, and so on. The
<code>array</code> may be given as the name of an array parameter or directly as a
2021-05-11 02:29:21 +02:00
space-separated list of words in parentheses.</p>
2022-08-24 15:22:41 +02:00
<p>If there are fewer display strings than <code>completions</code>, the leftover
<code>completions</code> will be displayed unchanged and if there are more display
strings than <code>completions</code>, the leftover display strings will be
silently ignored.</p>
<p>-l<br />
This option only has an effect if used together with the -d option. If
it is given, the display strings are listed one per line, not arrayed in
columns.</p>
<p>-o [ <code>order</code> ]<br />
2021-05-11 02:29:21 +02:00
This controls the order in which matches are sorted. <code>order</code> is a
comma-separated list comprising the following possible values. These
2022-08-24 15:22:41 +02:00
values can be abbreviated to their initial two or three characters. Note
that the order forms part of the group name space so matches with
different orderings will not be in the same group.</p>
<p>match<br />
If given, the order of the output is determined by the match strings;
otherwise it is determined by the display strings (i.e. the strings
given by the -d option). This is the default if -o is specified but
the <code>order</code> argument is omitted.</p>
<p>nosort<br />
This specifies that the <code>completions</code> are pre-sorted and their order
should be preserved. This value only makes sense alone and cannot be
combined with any others.</p>
<p>numeric<br />
If the matches include numbers, sort them numerically rather than
lexicographically.</p>
<p>reverse<br />
2021-05-11 02:29:21 +02:00
Arrange the matches backwards by reversing the sort ordering.</p>
2022-08-24 15:22:41 +02:00
<p>-J <code>group-name</code><br />
Gives the name of the group that the matches should be stored in.</p>
<p>-V <code>group-name</code><br />
Like -J but naming an unsorted group. This option is identical to the
combination of -J and -o nosort.</p>
<p>-1<br />
If given together with the -V option, makes only consecutive duplicates
in the group be removed. If combined with the -J option, this has no
visible effect. Note that groups with and without this flag are in
different name spaces.</p>
<p>-2<br />
If given together with the -J or -V option, makes all duplicates be
kept. Again, groups with and without this flag are in different name
spaces.</p>
<p>-X <code>explanation</code><br />
The <code>explanation</code> string will be printed with the list of matches, above
the group currently selected.</p>
<p>Within the <code>explanation</code>, the following sequences may be used to specify
output attributes (see <a href="Prompt-Expansion.html#Prompt-Expansion">Prompt
Expansion</a>): %B, %S, %U,
%F, %K and their lower case counterparts, as well as %{...%}.
%F, %K and %{...%} take arguments in the same form as prompt
expansion. (Note that the sequence %G is not available; an argument to
%{ should be used instead.) The sequence %% produces a literal %.</p>
<p>These sequences are most often employed by users when customising the
format style (see <a href="Completion-System.html#Completion-System">Completion
System</a>), but they must also
be taken into account when writing completion functions, as passing
descriptions with unescaped % characters to utility functions such as
_arguments and _message may produce unexpected results. If arbitrary
text is to be passed in a description, it can be escaped using e.g.
${my_str//\%/%%}.</p>
<p>-x <code>message</code><br />
Like -X, but the <code>message</code> will be printed even if there are no matches
in the group.</p>
<p>-q<br />
The suffix given with -S will be automatically removed if the next
character typed is a blank or does not insert anything, or if the suffix
consists of only one character and the next character typed is the same
character.</p>
<p>-r <code>remove-chars</code><br />
This is a more versatile form of the -q option. The suffix given with -S
or the slash automatically added after completing directories will be
automatically removed if the next character typed inserts one of the
characters given in the <code>remove-chars</code>. This string is parsed as a
characters class and understands the backslash sequences used by the
print command. For example, -r &quot;a-z\t&quot; removes the suffix if the next
character typed inserts a lower case character or a TAB, and -r &quot;^0-9&quot;
removes the suffix if the next character typed inserts anything but a
digit. One extra backslash sequence is understood in this string: \-
stands for all characters that insert nothing. Thus -S &quot;=&quot; -q is the
same as -S &quot;=&quot; -r &quot;= \t\n\-&quot;.</p>
<p>This option may also be used without the -S option; then any
automatically added space will be removed when one of the characters in
the list is typed.</p>
<p>-R <code>remove-func</code><br />
This is another form of the -r option. When a match has been accepted
and a suffix has been inserted, the function <code>remove-func</code> will be
called after the next character typed. It is passed the length of the
suffix as an argument and can use the special parameters available in
ordinary (non-completion) zle widgets (see <a href="Zsh-Line-Editor.html#Zsh-Line-Editor">Zsh Line
Editor</a>) to analyse and modify the
command line.</p>
<p>-f<br />
If this flag is given, all of the matches built from the <code>completions</code>
are marked as being the names of files. They are not required to be
actual filenames, but if they are, and the option LIST_TYPES is set, the
characters describing the types of the files in the completion lists
will be shown. This also forces a slash to be added when the name of a
directory is completed.</p>
<p>-e<br />
This flag can be used to tell the completion code that the matches added
are parameter names for a parameter expansion. This will make the
AUTO_PARAM_SLASH and AUTO_PARAM_KEYS options be used for the matches.</p>
<p>-W <code>file-prefix</code><br />
This string is a pathname that will be prepended to each match together
with any prefix specified by the -p option to form a complete filename
for testing. Hence it is only useful if combined with the -f flag, as
2021-05-11 02:29:21 +02:00
the tests will not otherwise be performed.</p>
2022-08-24 15:22:41 +02:00
<p>-F <code>array</code><br />
Specifies an array containing patterns. <code>completions</code> that match one of
these patterns are ignored, that is, not considered to be matches.</p>
<p>The <code>array</code> may be the name of an array parameter or a list of literal
patterns enclosed in parentheses and quoted, as in -F &quot;(*?.o *?.h)&quot;.
If the name of an array is given, the elements of the array are taken as
the patterns.</p>
<p>-Q<br />
This flag instructs the completion code not to quote any metacharacters
in the matches when inserting them into the command line.</p>
<p>-M <code>match-spec</code><br />
This gives local match specifications as described below in <a href="Completion-Widgets.html#Completion-Matching-Control">Completion
Matching Control</a>. This option may be
given more than once. In this case all <code>match-spec</code>s given are
concatenated with spaces between them to form the specification string
to use. Note that they will only be used if the -U option is not given.</p>
<p>-n<br />
Specifies that matching <code>completions</code> are to be added to the set of
matches, but are not to be listed to the user.</p>
<p>-U<br />
If this flag is given, all <code>completions</code> are added to the set of matches
and no matching will be done by the completion code. Normally this is
used in functions that do the matching themselves.</p>
<p>-O <code>array</code><br />
If this option is given, the <code>completions</code> are <em>not</em> added to the set of
matches. Instead, matching is done as usual and all of the <code>completions</code>
that match will be stored in the array parameter whose name is given as
2021-05-11 02:29:21 +02:00
<code>array</code>.</p>
2022-08-24 15:22:41 +02:00
<p>-A <code>array</code><br />
As the -O option, except that instead of those of the <code>completions</code>
which match being stored in <code>array</code>, the strings generated internally by
the completion code are stored. For example, with a match specification
of -M &quot;L:|no=&quot;, a current word of nof and <code>completions</code> of foo,
this option stores the string nofoo in the array, whereas the -O
option stores the foo originally given.</p>
<p>-D <code>array</code><br />
As with -O, the <code>completions</code> are not added to the set of matches.
Instead, whenever the <code>n</code>th <code>completion</code> does not match, the <code>n</code>th
element of the <code>array</code> is removed. Elements for which the corresponding
<code>completion</code> matches are retained. This option can be used more than
once to remove elements from multiple arrays.</p>
<p>-C<br />
This option adds a special match which expands to all other matches when
inserted into the line, even those that are added after this option is
used. Together with the -d option it is possible to specify a string
that should be displayed in the list for this special match. If no
string is given, it will be shown as a string containing the strings
that would be inserted for the other matches, truncated to the width of
the screen.</p>
<p>-E <code>number</code><br />
This option adds <code>number</code> empty matches after matching <code>completions</code>
have been added. An empty match takes up space in completion listings
but will never be inserted in the line and cant be selected with menu
completion or menu selection. This makes empty matches only useful to
format completion lists and to make explanatory string be shown in
completion lists (since empty matches can be given display strings with
the -d option). And because all but one empty string would otherwise be
removed, this option implies the -V and -2 options (even if an explicit
-J option is given). This can be important to note as it affects the
name space into which matches are added.</p>
<h2 id="-"><a class="header" href="#-">-</a></h2>
<p>This flag ends the list of flags and options. All arguments after it
will be taken as the <code>completions</code> even if they begin with hyphens.</p>
<p>Except for the -M flag, if any of these flags is given more than once,
2021-05-11 02:29:21 +02:00
the first one (and its argument) will be used.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-compset"></span> <span
id="index-completion-widgets_002c-modifying-special-parameters"></span></p>
<p>compset -p <code>number</code></p>
<p>compset -P [ <code>number</code> ] <code>pattern</code></p>
<p>compset -s <code>number</code></p>
<p>compset -S [ <code>number</code> ] <code>pattern</code></p>
<p>compset -n <code>begin</code> [ <code>end</code> ]</p>
<p>compset -N <code>beg-pat</code> [ <code>end-pat</code> ]</p>
<p>compset -q</p>
2021-05-11 02:29:21 +02:00
<p>This command simplifies modification of the special parameters, while
its return status allows tests on them to be carried out.</p>
<p>The options are:</p>
2022-08-24 15:22:41 +02:00
<p>-p <code>number</code><br />
If the value of the PREFIX parameter is at least <code>number</code> characters
long, the first <code>number</code> characters are removed from it and appended to
the contents of the IPREFIX parameter.</p>
<p>-P [ <code>number</code> ] <code>pattern</code><br />
If the value of the PREFIX parameter begins with anything that matches
the <code>pattern</code>, the matched portion is removed from PREFIX and appended
to IPREFIX.</p>
2021-05-11 02:29:21 +02:00
<p>Without the optional <code>number</code>, the longest match is taken, but if
2022-08-24 15:22:41 +02:00
<code>number</code> is given, anything up to the <code>number</code>th match is moved. If the
<code>number</code> is negative, the <code>number</code>th longest match is moved. For
example, if PREFIX contains the string a=b=c, then compset -P *\=
will move the string a=b= into the IPREFIX parameter, but compset -P 1
*\= will move only the string a=.</p>
<p>-s <code>number</code><br />
As -p, but transfer the last <code>number</code> characters from the value of
SUFFIX to the front of the value of ISUFFIX.</p>
<p>-S [ <code>number</code> ] <code>pattern</code><br />
As -P, but match the last portion of SUFFIX and transfer the matched
portion to the front of the value of ISUFFIX.</p>
<p>-n <code>begin</code> [ <code>end</code> ]<br />
If the current word position as specified by the parameter CURRENT is
greater than or equal to <code>begin</code>, anything up to the <code>begin</code>th word is
removed from the words array and the value of the parameter CURRENT is
decremented by <code>begin</code>.</p>
2021-05-11 02:29:21 +02:00
<p>If the optional <code>end</code> is given, the modification is done only if the
2022-08-24 15:22:41 +02:00
current word position is also less than or equal to <code>end</code>. In this case,
the words from position <code>end</code> onwards are also removed from the words
array.</p>
<p>Both <code>begin</code> and <code>end</code> may be negative to count backwards from the last
element of the words array.</p>
<p>-N <code>beg-pat</code> [ <code>end-pat</code> ]<br />
If one of the elements of the words array before the one at the index
given by the value of the parameter CURRENT matches the pattern
<code>beg-pat</code>, all elements up to and including the matching one are removed
from the words array and the value of CURRENT is changed to point to the
same word in the changed array.</p>
<p>If the optional pattern <code>end-pat</code> is also given, and there is an element
in the words array matching this pattern, the parameters are modified
only if the index of this word is higher than the one given by the
CURRENT parameter (so that the matching word has to be after the
cursor). In this case, the words starting with the one matching end-pat
are also removed from the words array. If words contains no word
matching <code>end-pat</code>, the testing and modification is performed as if it
were not given.</p>
<p>-q<br />
2021-05-11 02:29:21 +02:00
The word currently being completed is split on spaces into separate
words, respecting the usual shell quoting conventions. The resulting
2022-08-24 15:22:41 +02:00
words are stored in the words array, and CURRENT, PREFIX, SUFFIX,
QIPREFIX, and QISUFFIX are modified to reflect the word part that is
completed.</p>
2021-05-11 02:29:21 +02:00
<p>In all the above cases the return status is zero if the test succeeded
and the parameters were modified and non-zero otherwise. This allows one
to use this builtin in tests such as:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">if compset -P '*\='; then ...
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>This forces anything up to and including the last equal sign to be
ignored by the completion code.</p>
2022-08-24 15:22:41 +02:00
<p>compcall [ -TD ]</p>
<p>This allows the use of completions defined with the compctl builtin from
within completion widgets. The list of matches will be generated as if
one of the non-widget completion functions (complete-word, etc.) had
been called, except that only compctls given for specific commands are
used. To force the code to try completions defined with the -T option of
compctl and/or the default completion (whether defined by compctl -D or
the builtin default) in the appropriate places, the -T and/or -D flags
can be passed to compcall.</p>
<p>The return status can be used to test if a matching compctl definition
was found. It is non-zero if a compctl was found and zero otherwise.</p>
<p>Note that this builtin is defined by the zsh/compctl module.</p>
<hr />
<p><span id="Completion-Condition-Codes"></span> <span
id="Completion-Condition-Codes-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="194-completion-condition-codes"><a class="header" href="#194-completion-condition-codes">19.4 Completion Condition Codes</a></h2>
<p><span id="index-completion-widgets_002c-condition-codes"></span></p>
2022-08-24 15:22:41 +02:00
<p>The following additional condition codes for use within the [[ <code>...</code>
]] construct are available in completion widgets. These work on the
2021-05-11 02:29:21 +02:00
special parameters. All of these tests can also be performed by the
2022-08-24 15:22:41 +02:00
compset builtin, but in the case of the condition codes the contents of
the special parameters are not modified.</p>
<p>-prefix [ <code>number</code> ] <code>pattern</code><br />
true if the test for the -P option of compset would succeed.</p>
<p>-suffix [ <code>number</code> ] <code>pattern</code><br />
true if the test for the -S option of compset would succeed.</p>
<p>-after <code>beg-pat</code><br />
true if the test of the -N option with only the <code>beg-pat</code> given would
2021-05-11 02:29:21 +02:00
succeed.</p>
2022-08-24 15:22:41 +02:00
<p>-between <code>beg-pat end-pat</code><br />
true if the test for the -N option with both patterns would succeed.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Completion-Matching-Control"></span> <span
id="Completion-Matching-Control-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="195-completion-matching-control"><a class="header" href="#195-completion-matching-control">19.5 Completion Matching Control</a></h2>
2022-08-24 15:22:41 +02:00
<p>When the user invokes completion, the current <em>word</em> on the command line
(that is, the word the cursor is currently on) is used to generate a
<em>match pattern</em>. Only those <em>completions</em> that match the pattern are
offered to the user as <em>matches</em>.</p>
<p>The default match pattern is generated from the current word by either</p>
<ul>
<li>appending a * (matching any number of characters in a completion)
<em>or,</em></li>
<li>if the shell option COMPLETE_IN_WORD is set, inserting a * at the
cursor position.</li>
</ul>
<p>This narrow pattern can be broadened selectively by passing a <em>match
specification</em> to the compadd builtin command through its -M option (see
<a href="Completion-Widgets.html#Completion-Builtin-Commands">Completion Builtin Commands</a>). A match
specification consists of one or more <code>matchers</code> separated by
whitespace. Matchers in a match specification are applied one at a time,
from left to right. Once all matchers have been applied, completions are
compared to the final match pattern and non-matching ones are discarded.</p>
<ul>
<li>Note that the -M option is ignored if the current word contains a
glob pattern and the shell option GLOB_COMPLETE is set or if the
pattern_match key of the special associative array compstate is set
to a non-empty value (see <a href="Completion-Widgets.html#Completion-Special-Parameters">Completion Special
Parameters</a>).</li>
<li>Users of the <a href="Completion-System.html#Completion-System">Completion
System</a> should generally
not use the -M option directly, but rather use the matcher-list and
matcher styles (see the subsection <em>Standard Styles</em> in <a href="Completion-System.html#Completion-System-Configuration">Completion
System
Configuration</a>).</li>
</ul>
<p>Each matcher consists of</p>
<ul>
<li>a case-sensitive letter</li>
<li>a :,</li>
<li>one or more patterns separated by pipes (|),</li>
<li>an equals sign (=), and</li>
<li>another pattern.</li>
</ul>
<p>The patterns before the = are used to match substrings of the current
word. For each matched substring, the corresponding part of the match
pattern is broadened with the pattern after the =, by means of a
logical OR.</p>
<p>Each pattern in a matcher cosists of either</p>
<ul>
<li>the empty string or</li>
<li>a sequence of
<ul>
<li>literal characters (which may be quoted with a \),</li>
<li>question marks (?),</li>
<li>bracket expressions ([...]; see the subsection <em>Glob
Operators</em> in <a href="Expansion.html#Filename-Generation">Filename
Generation</a>), and/or</li>
<li>brace expressions (see below).</li>
</ul>
</li>
</ul>
<p>Other shell patterns are not allowed.</p>
<p>A brace expression, like a bracket expression, consists of a list of</p>
<ul>
<li>literal characters,</li>
<li>ranges (0-9), and/or</li>
<li>character classes ([:<code>name</code>:]).</li>
</ul>
<p>However, they differ from each other as follows:</p>
<ul>
<li>A brace expression is delimited by a pair of braces ({...}).</li>
<li>Brace expressions do not support negations. That is, an initial !
or ^ has no special meaning and will be interpreted as a literal
character.</li>
<li>When a character in the current word matches the <code>n</code>th pattern in a
brace expression, the corresponding part of the match pattern is
broadened only with the <code>n</code>th pattern of the brace expression on the
other side of the =, if there is one; if there is no brace
expression on the other side, then this pattern is the empty string.
However, if either brace expression has more elements than the
other, then the excess entries are simply ignored. When comparing
indexes, each literal character or character class counts as one
element, but each range is instead expanded to the full list of
literal characters it represents. Additionally, if on <em>both</em> sides
of the =, the <code>n</code>th pattern is [:upper:] or [:lower:],
then these are expanded as ranges, too.</li>
</ul>
<p>Note that, although the matching system does not yet handle multibyte
characters, this is likely to be a future extension. Hence, using
[:upper:] and [:lower:] is recommended over A-Z and a-z.</p>
<p>Below are the different forms of matchers supported. Each <em>uppercase</em>
form behaves exactly like its lowercase counterpart, but adds an
additional step <em>after</em> the match pattern has filtered out non-matching
completions: Each of a matchs substrings that was matched by a
subpattern from an uppercase matcher is replaced with the corresponding
substring of the current word. However, patterns from <em>lowercase</em>
matchers have higher weight: If a substring of the current word was
matched by patterns from both a lowercase and an uppercase matcher, then
the lowercase matchers pattern wins and the corresponding part of the
match is not modified.</p>
<p>Unless indicated otherwise, each example listed assumes COMPLETE_IN_WORD
to be unset (as it is by default).</p>
<p>m:<code>word-pat</code>=<code>match-pat</code><br />
M:<code>word-pat</code>=<code>match-pat</code><br />
For each substring of the current word that matches <code>word-pat</code>, broaden
the corresponding part of the match pattern to additionally match
<code>match-pat</code>.</p>
<p>Examples:<br />
m:{[:lower:]}={[:upper:]} lets any lower case character in the
current word be completed to itself or its uppercase counterpart. So,
the completions foo, FOO and Foo will are be considered matches
for the word fo.</p>
<p>M:_= inserts every underscore from the current word into each match, in
the same relative position, determined by matching the substrings around
it. So, given a completion foo, the word f_o will be completed to
the match f_oo, even though the latter was not present as a
completion.</p>
<p>b:<code>word-pat</code>=<code>match-pat</code><br />
B:<code>word-pat</code>=<code>match-pat</code><br />
e:<code>word-pat</code>=<code>match-pat</code><br />
E:<code>word-pat</code>=<code>match-pat</code><br />
For each consecutive substring at the b:eginning or e:nd of the current
word that matches <code>word-pat</code>, broaden the corresponding part of the
match pattern to additionally match <code>match-pat</code>.</p>
<p>Examples:<br />
b:-=+ lets any number of minuses at the start of the current word be
completed to a minus or a plus.</p>
<p>B:0= adds all zeroes at the beginning of the current word to the
beginning of each match.</p>
<p>l:|<code>word-pat</code>=<code>match-pat</code><br />
L:|<code>word-pat</code>=<code>match-pat</code><br />
R:<code>word-pat</code>|=<code>match-pat</code><br />
r:<code>word-pat</code>|=<code>match-pat</code><br />
If there is a substring at the l:eft or r:ight edge of the current word
that matches <code>word-pat</code>, then broaden the corresponding part of the
match pattern to additionally match <code>match-pat</code>.</p>
<p>For each l:, L:, r: and R: matcher (including the ones below), the
pattern <code>match-pat</code> may also be a *. This matches any number of
characters in a completion.</p>
<p>Examples:<br />
r:|=* appends a * to the match pattern, even when
COMPLETE_IN_WORD is set and the cursor is not at the end of the current
word.</p>
<p>If the current word starts with a minus, then L:|-= will prepend it
to each match.</p>
<p>l:<code>anchor</code>|<code>word-pat</code>=<code>match-pat</code><br />
L:<code>anchor</code>|<code>word-pat</code>=<code>match-pat</code><br />
r:<code>word-pat</code>|<code>anchor</code>=<code>match-pat</code><br />
R:<code>word-pat</code>|<code>anchor</code>=<code>match-pat</code><br />
For each substring of the current word that matches <code>word-pat</code> and has
on its l:eft or r:ight another substring matching <code>anchor</code>, broaden the
corresponding part of the match pattern to additionally match
<code>match-pat</code>.</p>
<p>Note that these matchers (and the ones below) modify only what is
matched by <code>word-pat</code>; they do not change the matching behavior of what
is matched by <code>anchor</code> (or <code>coanchor</code>; see the matchers below). Thus,
unless its corresponding part of the match pattern has been modified,
the anchor in the current word has to match literally in each
completion, just like any other substring of the current word.</p>
<p>If a matcher includes at least one anchor (which includes the matchers
with two anchors, below), then <code>match-pat</code> may also be * or **.
* can match any part of a completion that does not contain any
substrings matching <code>anchor</code>, whereas a ** can match any part of a
completion, period. (Note that this is different from the behavior of
* in the anchorless forms of l: and r: and and also different
from * and ** in glob expressions.)</p>
<p>Examples:<br />
r:|.=* makes the completion comp.sources.unix a match for the word
..u — but <em>not</em> for the word .u.</p>
<p>Given a completion --foo, the matcher L:|no-= will complete the
word --no- to the match --no-foo.</p>
<p>l:<code>anchor</code>||<code>coanchor</code>=<code>match-pat</code><br />
L:<code>anchor</code>||<code>coanchor</code>=<code>match-pat</code><br />
r:<code>coanchor</code>||<code>anchor</code>=<code>match-pat</code><br />
R:<code>coanchor</code>||<code>anchor</code>=<code>match-pat</code><br />
For any two consecutive substrings of the current word that match
<code>anchor</code> and <code>coanchor</code>, in the order given, insert the pattern
<code>match-pat</code> between their corresponding parts in the match pattern.</p>
<p>Note that, unlike <code>anchor</code>, the pattern <code>coanchor</code> does not change what
* can match.</p>
<p>Examples:<br />
r:?||[[:upper:]]=* will complete the current word fB to
fooBar, but it will not complete it to fooHooBar (because * here
cannot match anything that includes a match for [[:upper:]]), nor
will it complete B to fooBar (because there is no character in the
current word to match <code>coanchor</code>).</p>
<p>Given the current word pass.n and a completion pass.byname, the
matcher L:.||[[:alpha:]]=by will produce the match pass.name.</p>
<p>x:<br />
Ignore this matcher and all matchers to its right.</p>
<p>This matcher is used to mark the end of a match specification. In a
single standalone list of matchers, this has no use, but where match
specifications are concatenated, as is often the case when using the
<a href="Completion-System.html#Completion-System">Completion System</a>, it can
allow one match specification to override another.</p>
<hr />
<p><span id="Completion-Widget-Example"></span> <span
id="Completion-Widget-Example-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="196-completion-widget-example"><a class="header" href="#196-completion-widget-example">19.6 Completion Widget Example</a></h2>
<p><span id="index-completion-widgets_002c-example"></span></p>
<p>The first step is to define the widget:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zle -C complete complete-word complete-files
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Then the widget can be bound to a key using the bindkey builtin command:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">bindkey '^X\t' complete
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>After that the shell function complete-files will be invoked after
2021-05-11 02:29:21 +02:00
typing control-X and TAB. The function should then generate the matches,
e.g.:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">complete-files () { compadd - * }
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>This function will complete files in the current directory matching the
current word.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="Completion-System.html#20-completion-system">20 Completion System</a>
<ul>
<li><a href="Completion-System.html#201-description">20.1 Description</a></li>
<li><a href="Completion-System.html#202-initialization">20.2 Initialization</a>
<ul>
<li><a href="Completion-System.html#2021-use-of-compinit">20.2.1 Use of compinit</a></li>
<li><a href="Completion-System.html#2022-autoloaded-files">20.2.2 Autoloaded files</a></li>
<li><a href="Completion-System.html#2023-functions">20.2.3 Functions</a></li>
</ul>
</li>
<li><a href="Completion-System.html#203-completion-system-configuration">20.3 Completion System Configuration</a>
<ul>
<li><a href="Completion-System.html#2031-overview">20.3.1 Overview</a></li>
<li><a href="Completion-System.html#2032-standard-tags">20.3.2 Standard Tags</a></li>
<li><a href="Completion-System.html#2033-standard-styles">20.3.3 Standard Styles</a></li>
</ul>
</li>
<li><a href="Completion-System.html#204-control-functions">20.4 Control Functions</a></li>
<li><a href="Completion-System.html#205-bindable-commands">20.5 Bindable Commands</a></li>
<li><a href="Completion-System.html#206-utility-functions">20.6 Utility Functions</a></li>
<li><a href="Completion-System.html#207-completion-system-variables">20.7 Completion System Variables</a></li>
<li><a href="Completion-System.html#208-completion-directories">20.8 Completion Directories</a></li>
</ul>
</li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2022-08-24 15:22:41 +02:00
<p><span id="Completion-System"></span> <span
id="Completion-System-1"></span></p>
2021-05-11 02:29:21 +02:00
<h1 id="20-completion-system"><a class="header" href="#20-completion-system">20 Completion System</a></h1>
2022-08-24 15:22:41 +02:00
<p><span id="index-completion-system"></span> <span
id="index-completion_002c-programmable-1"></span> <span
id="index-completion_002c-controlling-1"></span></p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Description-2"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="201-description"><a class="header" href="#201-description">20.1 Description</a></h2>
<p>This describes the shell code for the new completion system, referred
2022-08-24 15:22:41 +02:00
to as compsys. It is written in shell functions based on the features
2021-05-11 02:29:21 +02:00
described in the previous chapter, <a href="Completion-Widgets.html#Completion-Widgets">Completion
Widgets</a>.</p>
<p>The features are contextual, sensitive to the point at which completion
is started. Many completions are already provided. For this reason, a
user can perform a great many tasks without knowing any details beyond
how to initialize the system, which is described in
<a href="Completion-System.html#Initialization">Initialization</a>.</p>
<p>The context that decides what completion is to be performed may be</p>
<ul>
<li>an argument or option position: these describe the position on the
command line at which completion is requested. For example first
argument to rmdir, the word being completed names a directory;</li>
<li>a special context, denoting an element in the shells syntax. For
example a word in command position or an array subscript.</li>
</ul>
<p>A full context specification contains other elements, as we shall
describe.</p>
<p>Besides commands names and contexts, the system employs two more
concepts, <em>styles</em> and <em>tags</em>. These provide ways for the user to
configure the systems behaviour.</p>
<p>Tags play a dual role. They serve as a classification system for the
matches, typically indicating a class of object that the user may need
2022-08-24 15:22:41 +02:00
to distinguish. For example, when completing arguments of the ls command
the user may prefer to try files before directories, so both of these
are tags. They also appear as the rightmost element in a context
specification.</p>
2021-05-11 02:29:21 +02:00
<p>Styles modify various operations of the completion system, such as
output formatting, but also what kinds of completers are used (and in
what order), or which tags are examined. Styles may accept arguments and
2022-08-24 15:22:41 +02:00
are manipulated using the zstyle command described in <a href="Zsh-Modules.html#The-zsh_002fzutil-Module">The zsh/zutil
2021-05-11 02:29:21 +02:00
Module</a>.</p>
<p>In summary, tags describe <em>what</em> the completion objects are, and style
2022-08-24 15:22:41 +02:00
how they are to be completed. At various points of execution, the
2021-05-11 02:29:21 +02:00
completion system checks what styles and/or tags are defined for the
current context, and uses that to modify its behavior. The full
description of context handling, which determines how tags and other
elements of the context influence the behaviour of styles, is described
in <a href="Completion-System.html#Completion-System-Configuration">Completion System Configuration</a>.</p>
<p>When a completion is requested, a dispatcher function is called; see the
2022-08-24 15:22:41 +02:00
description of _main_complete in the list of control functions below.
2021-05-11 02:29:21 +02:00
This dispatcher decides which function should be called to produce the
completions, and calls it. The result is passed to one or more
<em>completers</em>, functions that implement individual completion strategies:
simple completion, error correction, completion with error correction,
menu selection, etc.</p>
<p>More generally, the shell functions contained in the completion system
are of two types:</p>
<ul>
2022-08-24 15:22:41 +02:00
<li>those beginning comp are to be called directly; there are only a
2021-05-11 02:29:21 +02:00
few of these;</li>
2022-08-24 15:22:41 +02:00
<li>those beginning _ are called by the completion code. The shell
2021-05-11 02:29:21 +02:00
functions of this set, which implement completion behaviour and may
be bound to keystrokes, are referred to as widgets. These
proliferate as new completions are required.</li>
</ul>
<hr />
<p><span id="Initialization"></span> <span id="Initialization-1"></span></p>
<h2 id="202-initialization"><a class="header" href="#202-initialization">20.2 Initialization</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-compinstall"></span> <span
id="index-completion-system_002c-installing"></span></p>
2021-05-11 02:29:21 +02:00
<p>If the system was installed completely, it should be enough to call the
2022-08-24 15:22:41 +02:00
shell function compinit from your initialization file; see the next
section. However, the function compinstall can be run by a user to
2021-05-11 02:29:21 +02:00
configure various aspects of the completion system.</p>
2022-08-24 15:22:41 +02:00
<p>Usually, compinstall will insert code into .zshrc, although if files
location. Note that it is up to you to make sure that the lines added to
.zshrc are actually run; you may, for example, need to move them to an
earlier place in the file if .zshrc usually returns early. So long as
you keep them all together (including the comment lines at the start and
finish), you can rerun compinstall and it will correctly locate and
modify these lines. Note, however, that any code you add to this section
by hand is likely to be lost if you rerun compinstall, although lines
using the command zstyle should be gracefully handled.</p>
2021-05-11 02:29:21 +02:00
<p>The new code will take effect next time you start the shell, or run
2022-08-24 15:22:41 +02:00
.zshrc by hand; there is also an option to make them take effect
immediately. However, if compinstall has removed definitions, you will
2021-05-11 02:29:21 +02:00
need to restart the shell to see the changes.</p>
2022-08-24 15:22:41 +02:00
<p>To run compinstall you will need to make sure it is in a directory
mentioned in your fpath parameter, which should already be the case if
2021-05-11 02:29:21 +02:00
zsh was properly configured as long as your startup files do not remove
2022-08-24 15:22:41 +02:00
the appropriate directories from fpath. Then it must be autoloaded
(autoload -U compinstall is recommended). You can abort the
2021-05-11 02:29:21 +02:00
installation any time you are being prompted for information, and your
2022-08-24 15:22:41 +02:00
.zshrc will not be altered at all; changes only take place right at the
end, where you are specifically asked for confirmation.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Use-of-compinit"></span></p>
<h3 id="2021-use-of-compinit"><a class="header" href="#2021-use-of-compinit">20.2.1 Use of compinit</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-compinit"></span> <span
id="index-completion-system_002c-initializing"></span></p>
<p>This section describes the use of compinit to initialize completion for
the current session when called directly; if you have run compinstall it
will be called automatically from your .zshrc.</p>
<p>To initialize the system, the function compinit should be in a directory
mentioned in the fpath parameter, and should be autoloaded (autoload -U
compinit is recommended), and then run simply as compinit. This will
define a few utility functions, arrange for all the necessary shell
functions to be autoloaded, and will then re-define all widgets that do
completion to use the new system. If you use the menu-select widget,
which is part of the zsh/complist module, you should make sure that that
module is loaded before the call to compinit so that that widget is also
re-defined. If completion styles (see below) are set up to perform
expansion as well as completion by default, and the TAB key is bound to
expand-or-complete, compinit will rebind it to complete-word; this is
necessary to use the correct form of expansion.</p>
2021-05-11 02:29:21 +02:00
<p>Should you need to use the original completion commands, you can still
2022-08-24 15:22:41 +02:00
bind keys to the old widgets by putting a . in front of the widget
name, e.g. .expand-or-complete.</p>
<p>To speed up the running of compinit, it can be made to produce a dumped
configuration that will be read in on future invocations; this is the
default, but can be turned off by calling compinit with the option -D.
The dumped file is .zcompdump in the same directory as the startup files
(i.e. $ZDOTDIR or $HOME); alternatively, an explicit file name can be
given by compinit -d <code>dumpfile</code>. The next invocation of compinit will
read the dumped file instead of performing a full initialization.</p>
<p>If the number of completion files changes, compinit will recognise this
and produce a new dump file. However, if the name of a function or the
arguments in the first line of a #compdef function (as described below)
change, it is easiest to delete the dump file by hand so that compinit
will re-create it the next time it is run. The check performed to see if
there are new functions can be omitted by giving the option -C. In this
case the dump file will only be created if there isnt one already.</p>
<p>The dumping is actually done by another function, compdump, but you will
only need to run this yourself if you change the configuration (e.g.
using compdef) and then want to dump the new one. The name of the old
dumped file will be remembered for this purpose.</p>
<p>If the parameter _compdir is set, compinit uses it as a directory where
completion functions can be found; this is only necessary if they are
not already in the function search path.</p>
<p>For security reasons compinit also checks if the completion system would
use files not owned by root or by the current user, or files in root or
by the current user. If such files or directories are found, compinit
will ask if the completion system should really be used. To avoid these
tests and make all files found be used without asking, use the option
-u, and to make compinit silently ignore all insecure files and
directories use the option -i. This security check is skipped entirely
when the -C option is given, provided the dumpfile exists.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-compaudit"></span></p>
<p>The security check can be retried at any time by running the function
2022-08-24 15:22:41 +02:00
compaudit. This is the same check used by compinit, but when it is
executed directly any changes to fpath are made local to the function so
they do not persist. The directories to be checked may be passed as
arguments; if none are given, compaudit uses fpath and _compdir to find
completion system directories, adding missing ones to fpath as
2021-05-11 02:29:21 +02:00
necessary. To force a check of exactly the directories currently named
2022-08-24 15:22:41 +02:00
in fpath, set _compdir to an empty string before calling compaudit or
compinit.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-bashcompinit"></span></p>
2022-08-24 15:22:41 +02:00
<p>The function bashcompinit provides compatibility with bashs
2021-05-11 02:29:21 +02:00
programmable completion system. When run it will define the functions,
2022-08-24 15:22:41 +02:00
compgen and complete which correspond to the bash builtins with the same
names. It will then be possible to use completion specifications and
functions written for bash.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Autoloaded-files"></span></p>
<h3 id="2022-autoloaded-files"><a class="header" href="#2022-autoloaded-files">20.2.2 Autoloaded files</a></h3>
<p><span id="index-completion-system_002c-autoloaded-functions"></span></p>
<p>The convention for autoloaded functions used in completion is that they
2022-08-24 15:22:41 +02:00
start with an underscore; as already mentioned, the fpath/FPATH
parameter must contain the directory in which they are stored. If zsh
was properly installed on your system, then fpath/FPATH automatically
2021-05-11 02:29:21 +02:00
contains the required directories for the standard functions.</p>
2022-08-24 15:22:41 +02:00
<p>For incomplete installations, if compinit does not find enough files
2021-05-11 02:29:21 +02:00
beginning with an underscore (fewer than twenty) in the search path, it
2022-08-24 15:22:41 +02:00
will try to find more by adding the directory _compdir to the search
path. If that directory has a subdirectory named Base, all
2021-05-11 02:29:21 +02:00
subdirectories will be added to the path. Furthermore, if the
2022-08-24 15:22:41 +02:00
subdirectory Base has a subdirectory named Core, compinit will add all
subdirectories of the subdirectories to the path: this allows the
functions to be in the same format as in the zsh source distribution.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-compdef_002c-use-of-by-compinit"></span></p>
2022-08-24 15:22:41 +02:00
<p>When compinit is run, it searches all such files accessible via
fpath/FPATH and reads the first line of each of them. This line should
2021-05-11 02:29:21 +02:00
contain one of the tags described below. Files whose first line does not
start with one of these tags are not considered to be part of the
completion system and will not be treated specially.</p>
<p>The tags are:</p>
2022-08-24 15:22:41 +02:00
<p>#compdef <code>name</code> ... [ -{p|P} <code>pattern</code> ... [ -N <code>name</code> ... ] ]<br />
The file will be made autoloadable and the function defined in it will
be called when completing <code>name</code>s, each of which is either the name of a
command whose arguments are to be completed or one of a number of
special contexts in the form -<code>context</code>- described below.</p>
<p>Each <code>name</code> may also be of the form <code>cmd</code>=<code>service</code>. When completing
the command <code>cmd</code>, the function typically behaves as if the command (or
special context) <code>service</code> was being completed instead. This provides a
way of altering the behaviour of functions that can perform many
different completions. It is implemented by setting the parameter
$service when calling the function; the function may choose to interpret
this how it wishes, and simpler functions will probably ignore it.</p>
<p>If the #compdef line contains one of the options -p or -P, the words
following are taken to be patterns. The function will be called when
completion is attempted for a command or context that matches one of the
patterns. The options -p and -P are used to specify patterns to be tried
before or after other completions respectively. Hence -P may be used to
specify default actions.</p>
<p>The option -N is used after a list following -p or -P; it specifies that
remaining words no longer define patterns. It is possible to toggle
between the three options as many times as necessary.</p>
<p>#compdef -k <code>style key-sequence</code> ...<br />
This option creates a widget behaving like the builtin widget <code>style</code>
and binds it to the given <code>key-sequence</code>s, if any. The <code>style</code> must be
one of the builtin widgets that perform completion, namely
complete-word, delete-char-or-list, expand-or-complete,
expand-or-complete-prefix, list-choices, menu-complete,
menu-expand-or-complete, or reverse-menu-complete. If the zsh/complist
module is loaded (see <a href="Zsh-Modules.html#The-zsh_002fcomplist-Module">The zsh/complist
2021-05-11 02:29:21 +02:00
Module</a>) the widget
2022-08-24 15:22:41 +02:00
menu-select is also available.</p>
<p>When one of the <code>key-sequence</code>s is typed, the function in the file will
be invoked to generate the matches. Note that a key will not be re-bound
if it already was (that is, was bound to something other than
undefined-key). The widget created has the same name as the file and can
be bound to any other keys using bindkey as usual.</p>
<p>#compdef -K <code>widget-name</code> <code>style</code> <code>key-sequence</code> [ <code>name</code> <code>style</code> <code>seq</code> ... ]<br />
This is similar to -k except that only one <code>key-sequence</code> argument may
be given for each <code>widget-name</code> <code>style</code> pair. However, the entire set of
three arguments may be repeated with a different set of arguments. Note
in particular that the <code>widget-name</code> must be distinct in each set. If it
does not begin with _ this will be added. The <code>widget-name</code> should
not clash with the name of any existing widget: names based on the name
of the function are most useful. For example,</p>
<div class="example">
<pre><code class="language-zsh">#compdef -K _foo_complete complete-word &quot;^X^C&quot; \
2021-05-11 02:29:21 +02:00
_foo_list list-choices &quot;^X^D&quot;
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>(all on one line) defines a widget _foo_complete for completion, bound
to ^X^C, and a widget _foo_list for listing, bound to ^X^D.</p>
<p>#autoload [ <code>options</code> ]<br />
Functions with the #autoload tag are marked for autoloading but are not
otherwise treated specially. Typically they are to be called from within
one of the completion functions. Any <code>options</code> supplied will be passed
to the autoload builtin; a typical use is +X to force the function to be
loaded immediately. Note that the -U and -z flags are always added
implicitly.</p>
<p>The # is part of the tag name and no white space is allowed after it.
The #compdef tags use the compdef function described below; the main
2021-05-11 02:29:21 +02:00
difference is that the name of the function is supplied implicitly.</p>
<p>The special contexts for which completion functions can be defined are:</p>
2022-08-24 15:22:41 +02:00
<p><span
id="index-_002darray_002dvalue_002d_002c-completion-context"></span></p>
<p>-array-value-</p>
<p>The right hand side of an array-assignment (<code>name</code>=(<code>...</code>))</p>
<p><span
id="index-_002dassign_002dparameter_002d_002c-completion-context"></span></p>
<p>-assign-parameter-</p>
2021-05-11 02:29:21 +02:00
<p>The name of a parameter in an assignment, i.e. on the left hand side of
2022-08-24 15:22:41 +02:00
an =</p>
<p><span
id="index-_002dbrace_002dparameter_002d_002c-completion-context"></span></p>
<p>-brace-parameter-</p>
<p>The name of a parameter expansion within braces (${<code>...</code>})</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_002dcommand_002d_002c-completion-context"></span></p>
2022-08-24 15:22:41 +02:00
<p>-command-</p>
2021-05-11 02:29:21 +02:00
<p>A word in command position</p>
<p><span id="index-_002dcondition_002d_002c-completion-context"></span></p>
2022-08-24 15:22:41 +02:00
<p>-condition-</p>
<p>A word inside a condition ([[<code>...</code>]])</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_002ddefault_002d_002c-completion-context"></span></p>
2022-08-24 15:22:41 +02:00
<p>-default-</p>
2021-05-11 02:29:21 +02:00
<p>Any word for which no other completion is defined</p>
<p><span id="index-_002dequal_002d_002c-completion-context"></span></p>
2022-08-24 15:22:41 +02:00
<p>-equal-</p>
2021-05-11 02:29:21 +02:00
<p>A word beginning with an equals sign</p>
<p><span id="index-_002dfirst_002d_002c-completion-context"></span></p>
2022-08-24 15:22:41 +02:00
<p>-first-</p>
2021-05-11 02:29:21 +02:00
<p>This is tried before any other completion function. The function called
2022-08-24 15:22:41 +02:00
may set the _compskip parameter to one of various values: all: no
2021-05-11 02:29:21 +02:00
further completion is attempted; a string containing the substring
2022-08-24 15:22:41 +02:00
patterns: no pattern completion functions will be called; a string
containing default: the function for the -default- context will not be
called, but functions defined for commands will be.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_002dmath_002d_002c-completion-context"></span></p>
2022-08-24 15:22:41 +02:00
<p>-math-</p>
<p>Inside mathematical contexts, such as ((<code>...</code>))</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_002dparameter_002d_002c-completion-context"></span></p>
2022-08-24 15:22:41 +02:00
<p>-parameter-</p>
<p>The name of a parameter expansion ($<code>...</code>)</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_002dredirect_002d_002c-completion-context"></span></p>
2022-08-24 15:22:41 +02:00
<p>-redirect-</p>
2021-05-11 02:29:21 +02:00
<p>The word after a redirection operator.</p>
<p><span id="index-_002dsubscript_002d_002c-completion-context"></span></p>
2022-08-24 15:22:41 +02:00
<p>-subscript-</p>
2021-05-11 02:29:21 +02:00
<p>The contents of a parameter subscript.</p>
<p><span id="index-_002dtilde_002d_002c-completion-context"></span></p>
2022-08-24 15:22:41 +02:00
<p>-tilde-</p>
<p>After an initial tilde (~), but before the first slash in the word.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_002dvalue_002d_002c-completion-context"></span></p>
2022-08-24 15:22:41 +02:00
<p>-value-</p>
2021-05-11 02:29:21 +02:00
<p>On the right hand side of an assignment.</p>
<p>Default implementations are supplied for each of these contexts. In most
2022-08-24 15:22:41 +02:00
cases the context -<code>context</code>- is implemented by a corresponding function
_<code>context</code>, for example the context -tilde- and the function
_tilde).</p>
<p>The contexts -redirect- and -value- allow extra context-specific
2021-05-11 02:29:21 +02:00
information. (Internally, this is handled by the functions for each
2022-08-24 15:22:41 +02:00
context calling the function _dispatch.) The extra information is added
separated by commas.</p>
<p>For the -redirect- context, the extra information is in the form
-redirect-,<code>op</code>,<code>command</code>, where <code>op</code> is the redirection operator and
<code>command</code> is the name of the command on the line. If there is no command
on the line yet, the <code>command</code> field will be empty.</p>
<p>For the -value- context, the form is -value-,<code>name</code>,<code>command</code>, where
<code>name</code> is the name of the parameter on the left hand side of the
2021-05-11 02:29:21 +02:00
assignment. In the case of elements of an associative array, for example
2022-08-24 15:22:41 +02:00
assoc=(key &lt;TAB&gt;, <code>name</code> is expanded to <code>name</code>-<code>key</code>. In certain
special contexts, such as completing after make CFLAGS=, the <code>command</code>
part gives the name of the command, here make; otherwise it is empty.</p>
2021-05-11 02:29:21 +02:00
<p>It is not necessary to define fully specific completions as the
functions provided will try to generate completions by progressively
2022-08-24 15:22:41 +02:00
replacing the elements with -default-. For example, when completing
after foo=&lt;TAB&gt;, _value will try the names -value-,foo, (note the
empty <code>command</code> part), -value-,foo,-default-
and-value-,-default-,-default-, in that order, until it finds a
2021-05-11 02:29:21 +02:00
function to handle the context.</p>
<p>As an example:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">compdef '_files -g &quot;*.log&quot;' '-redirect-,2&gt;,-default-'
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>completes files matching *.log after 2&gt; &lt;TAB&gt; for any command with
no more specific handler defined.</p>
2021-05-11 02:29:21 +02:00
<p>Also:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">compdef _foo -value-,-default-,-default-
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>specifies that _foo provides completions for the values of parameters
2021-05-11 02:29:21 +02:00
for which no special function has been defined. This is usually handled
2022-08-24 15:22:41 +02:00
by the function _value itself.</p>
2021-05-11 02:29:21 +02:00
<p>The same lookup rules are used when looking up styles (as described
below); for example</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*:*:-redirect-,2&gt;,*:*' file-patterns '*.log'
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>is another way to make completion after 2&gt; &lt;TAB&gt; complete files
matching *.log.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Functions-3"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="2023-functions"><a class="header" href="#2023-functions">20.2.3 Functions</a></h3>
2022-08-24 15:22:41 +02:00
<p>The following function is defined by compinit and may be called
2021-05-11 02:29:21 +02:00
directly.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-compdef"></span> <span
id="index-completion-system_002c-adding-definitions"></span></p>
<p>compdef [ -ane ] <code>function name</code> ... [ -{p|P} <code>pattern</code> ... [ -N <code>name</code> ...]]<br />
compdef -d <code>name</code> ...<br />
compdef -k [ -an ] <code>function style key-sequence</code> [ <code>key-sequence</code> ... ]<br />
compdef -K [ -an ] <code>function name style key-seq</code> [ <code>name style seq</code> ... ]<br />
2021-05-11 02:29:21 +02:00
The first form defines the <code>function</code> to call for completion in the
2022-08-24 15:22:41 +02:00
given contexts as described for the #compdef tag above.</p>
<p>Alternatively, all the arguments may have the form <code>cmd</code>=<code>service</code>.
Here <code>service</code> should already have been defined by <code>cmd1</code>=<code>service</code>
lines in #compdef files, as described above. The argument for <code>cmd</code> will
be completed in the same way as <code>service</code>.</p>
<p>The <code>function</code> argument may alternatively be a string containing almost
any shell code. If the string contains an equal sign, the above will
take precedence. The option -e may be used to specify the first argument
is to be evaluated as shell code even if it contains an equal sign. The
string will be executed using the eval builtin command to generate
completions. This provides a way of avoiding having to define a new
completion function. For example, to complete files ending in .h as
arguments to the command foo:</p>
<div class="example">
<pre><code class="language-zsh">compdef '_files -g &quot;*.h&quot;' foo
</code></pre>
</div>
<p>The option -n prevents any completions already defined for the command
or context from being overwritten.</p>
<p>The option -d deletes any completion defined for the command or contexts
listed.</p>
<p>The <code>name</code>s may also contain -p, -P and -N options as described for the
#compdef tag. The effect on the argument list is identical, switching
between definitions of patterns tried initially, patterns tried finally,
and normal commands and contexts.</p>
<p>The parameter $_compskip may be set by any function defined for a
2021-05-11 02:29:21 +02:00
pattern context. If it is set to a value containing the substring
2022-08-24 15:22:41 +02:00
patterns none of the pattern-functions will be called; if it is set to
a value containing the substring all, no other function will be
called. Setting $_compskip in this manner is of particular utility when
using the -p option, as otherwise the dispatcher will move on to
additional functions (likely the default one) after calling the
pattern-context one, which can mangle the display of completion
possibilities if not handled properly.</p>
<p>The form with -k defines a widget with the same name as the <code>function</code>
that will be called for each of the <code>key-sequence</code>s; this is like the
#compdef -k tag. The function should generate the completions needed and
will otherwise behave like the builtin widget whose name is given as the
<code>style</code> argument. The widgets usable for this are: complete-word,
delete-char-or-list, expand-or-complete, expand-or-complete-prefix,
list-choices, menu-complete, menu-expand-or-complete, and
reverse-menu-complete, as well as menu-select if the zsh/complist module
is loaded. The option -n prevents the key being bound if it is already
to bound to something other than undefined-key.</p>
<p>The form with -K is similar and defines multiple widgets based on the
same <code>function</code>, each of which requires the set of three arguments
<code>name</code>, <code>style</code> and <code>key-seq</code>uence, where the latter two are as for -k
and the first must be a unique widget name beginning with an underscore.</p>
<p>Wherever applicable, the -a option makes the <code>function</code> autoloadable,
equivalent to autoload -U <code>function</code>.</p>
<p>The function compdef can be used to associate existing completion
2021-05-11 02:29:21 +02:00
functions with new commands. For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">compdef _pids foo
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>uses the function _pids to complete process IDs for the command foo.</p>
<p>Note also the _gnu_generic function described below, which can be used
to complete options for commands that understand the --help option.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Completion-System-Configuration"></span> <span
id="Completion-System-Configuration-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="203-completion-system-configuration"><a class="header" href="#203-completion-system-configuration">20.3 Completion System Configuration</a></h2>
<p><span id="index-completion-system_002c-configuration"></span></p>
<p>This section gives a short overview of how the completion system works,
and then more detail on how users can configure how and when matches are
generated.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Overview-2"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="2031-overview"><a class="header" href="#2031-overview">20.3.1 Overview</a></h3>
<p>When completion is attempted somewhere on the command line the
completion system begins building the context. The context represents
everything that the shell knows about the meaning of the command line
and the significance of the cursor position. This takes account of a
2022-08-24 15:22:41 +02:00
number of things including the command word (such as grep or zsh)
and options to which the current word may be an argument (such as the
-o option to zsh which takes a shell option as an argument).</p>
2021-05-11 02:29:21 +02:00
<p>The context starts out very generic (&quot;we are beginning a completion&quot;)
and becomes more specific as more is learned (&quot;the current word is in a
position that is usually a command name&quot; or &quot;the current word might be a
variable name&quot; and so on). Therefore the context will vary during the
same call to the completion system.</p>
<p>This context information is condensed into a string consisting of
multiple fields separated by colons, referred to simply as the context
in the remainder of the documentation. Note that a user of the
completion system rarely needs to compose a context string, unless for
example a new function is being written to perform completion for a new
command. What a user may need to do is compose a <em>style</em> pattern, which
is matched against a context when needed to look up context-sensitive
options that configure the completion system.</p>
<p>The next few paragraphs explain how a context is composed within the
completion function suite. Following that is discussion of how <em>styles</em>
are defined. Styles determine such things as how the matches are
generated, similarly to shell options but with much more control. They
2022-08-24 15:22:41 +02:00
are defined with the zstyle builtin command (<a href="Zsh-Modules.html#The-zsh_002fzutil-Module">The zsh/zutil
2021-05-11 02:29:21 +02:00
Module</a>).</p>
<p>The context string always consists of a fixed set of fields, separated
by colons and with a leading colon before the first. Fields which are
not yet known are left empty, but the surrounding colons appear anyway.
The fields are always in the order
2022-08-24 15:22:41 +02:00
:completion:<code>function</code>:<code>completer</code>:<code>command</code>:<code>argument</code>:<code>tag</code>. These
have the following meaning:</p>
2021-05-11 02:29:21 +02:00
<ul>
2022-08-24 15:22:41 +02:00
<li>The literal string completion, saying that this style is used by the
completion system. This distinguishes the context from those used
by, for example, zle widgets and ZFTP functions.</li>
2021-05-11 02:29:21 +02:00
<li>The <code>function</code>, if completion is called from a named widget rather
than through the normal completion system. Typically this is blank,
2022-08-24 15:22:41 +02:00
but it is set by special widgets such as predict-on and the various
functions in the Widget directory of the distribution to the name of
that function, often in an abbreviated form.</li>
2021-05-11 02:29:21 +02:00
<li>The <code>completer</code> currently active, the name of the function without
the leading underscore and with other underscores converted to
hyphens. A completer is in overall control of how completion is to
2022-08-24 15:22:41 +02:00
be performed; complete is the simplest, but other completers exist
to perform related tasks such as correction, or to modify the
2021-05-11 02:29:21 +02:00
behaviour of a later completer. See <a href="Completion-System.html#Control-Functions">Control
Functions</a> for more information.</li>
2022-08-24 15:22:41 +02:00
<li>The <code>command</code> or a special -<code>context</code>-, just at it appears following
the #compdef tag or the compdef function. Completion functions for
commands that have sub-commands usually modify this field to contain
the name of the command followed by a minus sign and the
sub-command. For example, the completion function for the cvs
command sets this field to cvs-add when completing arguments to the
add subcommand.</li>
2021-05-11 02:29:21 +02:00
<li>The <code>argument</code>; this indicates which command line or option argument
we are completing. For command arguments this generally takes the
2022-08-24 15:22:41 +02:00
form argument-<code>n</code>, where <code>n</code> is the number of the argument, and for
arguments to options the form option-<code>opt</code>-<code>n</code> where <code>n</code> is the
number of the argument to option <code>opt</code>. However, this is only the
case if the command line is parsed with standard UNIX-style options
and arguments, so many completions do not set this.</li>
2021-05-11 02:29:21 +02:00
<li>The <code>tag</code>. As described previously, tags are used to discriminate
between the types of matches a completion function can generate in a
certain context. Any completion function may use any tag name it
likes, but a list of the more common ones is given below.</li>
</ul>
<p>The context is gradually put together as the functions are executed,
2022-08-24 15:22:41 +02:00
starting with the main entry point, which adds :completion: and the
2021-05-11 02:29:21 +02:00
<code>function</code> element if necessary. The completer then adds the <code>completer</code>
element. The contextual completion adds the <code>command</code> and <code>argument</code>
options. Finally, the <code>tag</code> is added when the types of completion are
known. For example, the context name</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">:completion::complete:dvips:option-o-1:files
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>says that normal completion was attempted as the first argument to the
2022-08-24 15:22:41 +02:00
option -o of the command dvips:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">dvips -o ...
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>and the completion function will generate filenames.</p>
<p>Usually completion will be tried for all possible tags in an order given
by the completion function. However, this can be altered by using the
2022-08-24 15:22:41 +02:00
tag-order style. Completion is then restricted to the list of given tags
in the given order.</p>
<p>The _complete_help bindable command shows all the contexts and tags
2021-05-11 02:29:21 +02:00
available for completion at a particular point. This provides an easy
2022-08-24 15:22:41 +02:00
way of finding information for tag-order and other styles. It is
2021-05-11 02:29:21 +02:00
described in <a href="Completion-System.html#Bindable-Commands">Bindable Commands</a>.</p>
<p>When looking up styles the completion system uses full context names,
including the tag. Looking up the value of a style therefore consists of
two things: the context, which is matched to the most specific (best
2022-08-24 15:22:41 +02:00
fitting) pattern, and the name of the style itself, which must be
matched exactly. The following examples demonstrate that patterns may be
loosely defined for styles that apply broadly, or as tightly defined as
desired for styles that apply in narrower circumstances.</p>
2021-05-11 02:29:21 +02:00
<p>For example, many completion functions can generate matches in a simple
2022-08-24 15:22:41 +02:00
and a verbose form and use the verbose style to decide which form should
be used. To make all such functions use the verbose form, put</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*' verbose yes
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>in a startup file (probably .zshrc). This gives the verbose style the
value yes in every context inside the completion system, unless that
context has a more specific definition. It is best to avoid giving the
pattern as * in case the style has some meaning outside the
2021-05-11 02:29:21 +02:00
completion system.</p>
<p>Many such general purpose styles can be configured simply by using the
2022-08-24 15:22:41 +02:00
compinstall function.</p>
<p>A more specific example of the use of the verbose style is by the
completion for the kill builtin. If the style is set, the builtin lists
full job texts and process command lines; otherwise it shows the bare
job numbers and PIDs. To turn the style off for this use only:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*:*:kill:*:*' verbose no
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>For even more control, the style can use one of the tags jobs or
processes. To turn off verbose display only for jobs:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*:*:kill:*:jobs' verbose no
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The -e option to zstyle even allows completion function code to appear
as the argument to a style; this requires some understanding of the
internals of completion functions (see <a href="Completion-Widgets.html#Completion-Widgets">Completion
2021-05-11 02:29:21 +02:00
Widgets</a>)). For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle -e ':completion:*' hosts 'reply=($myhosts)'
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>This forces the value of the hosts style to be read from the variable
myhosts each time a host name is needed; this is useful if the value of
myhosts can change dynamically. For another useful example, see the
example in the description of the file-list style below. This form can
be slow and should be avoided for commonly examined styles such as menu
and list-rows-first.</p>
2021-05-11 02:29:21 +02:00
<p>Note that the order in which styles are <em>defined</em> does not matter; the
style mechanism uses the most specific possible match for a particular
2022-08-24 15:22:41 +02:00
style to determine the set of values. Strings are preferred over
patterns (for example, :completion::complete:::foo is more specific
than :completion::complete:::*), and longer patterns are preferred
over the pattern *. See <a href="Zsh-Modules.html#The-zsh_002fzutil-Module">The zsh/zutil
Module</a> for details.</p>
<p>Context patterns that use something other than a wildcard (*) to match
the middle parts of the context — the <code>completer</code>, <code>command</code>, and
<code>argument</code> in
:completion:<code>function</code>:<code>completer</code>:<code>command</code>:<code>argument</code>:<code>tag</code> — should
include all six colons (:) explicitly. Without this, a pattern such as
:completion:*:foo:* could match foo against a component other than the
intended one (for example, against <code>completer</code> when a match against
<code>command</code> was intended).</p>
2021-05-11 02:29:21 +02:00
<p>Style names like those of tags are arbitrary and depend on the
completion function. However, the following two sections list some of
the most common tags and styles.</p>
<hr />
<p><span id="Standard-Tags"></span></p>
<h3 id="2032-standard-tags"><a class="header" href="#2032-standard-tags">20.3.2 Standard Tags</a></h3>
<p><span id="index-completion-system_002c-tags"></span></p>
<p>Some of the following are only used when looking up particular styles
and do not refer to a type of match.</p>
<p><span id="index-accounts_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>accounts</p>
<p>used to look up the users-hosts style</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-all_002dexpansions_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>all-expansions</p>
<p>used by the _expand completer when adding the single string containing
2021-05-11 02:29:21 +02:00
all possible expansions</p>
<p><span id="index-all_002dfiles_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>all-files</p>
2021-05-11 02:29:21 +02:00
<p>for the names of all files (as distinct from a particular subset, see
2022-08-24 15:22:41 +02:00
the globbed-files tag).</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-arguments_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>arguments</p>
2021-05-11 02:29:21 +02:00
<p>for arguments to a command</p>
<p><span id="index-arrays_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>arrays</p>
2021-05-11 02:29:21 +02:00
<p>for names of array parameters</p>
<p><span id="index-association_002dkeys_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>association-keys</p>
2021-05-11 02:29:21 +02:00
<p>for keys of associative arrays; used when completing inside a subscript
to a parameter of this type</p>
<p><span id="index-bookmarks_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>bookmarks</p>
<p>when completing bookmarks (e.g. for URLs and the zftp function suite)</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-builtins_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>builtins</p>
2021-05-11 02:29:21 +02:00
<p>for names of builtin commands</p>
<p><span id="index-characters_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>characters</p>
<p>for single characters in arguments of commands such as stty. Also used
2021-05-11 02:29:21 +02:00
when completing character classes after an opening bracket</p>
<p><span id="index-colormapids_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>colormapids</p>
2021-05-11 02:29:21 +02:00
<p>for X colormap ids</p>
<p><span id="index-colors_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>colors</p>
2021-05-11 02:29:21 +02:00
<p>for color names</p>
<p><span id="index-commands_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>commands</p>
2021-05-11 02:29:21 +02:00
<p>for names of external commands. Also used by complex commands such as
2022-08-24 15:22:41 +02:00
cvs when completing names subcommands.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-contexts_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>contexts</p>
<p>for contexts in arguments to the zstyle builtin command</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-corrections_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>corrections</p>
<p>used by the _approximate and _correct completers for possible
2021-05-11 02:29:21 +02:00
corrections</p>
<p><span id="index-cursors_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>cursors</p>
2021-05-11 02:29:21 +02:00
<p>for cursor names used by X programs</p>
<p><span id="index-default_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>default</p>
2021-05-11 02:29:21 +02:00
<p>used in some contexts to provide a way of supplying a default when more
specific tags are also valid. Note that this tag is used when only the
<code>function</code> field of the context name is set</p>
<p><span id="index-descriptions_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>descriptions</p>
<p>used when looking up the value of the format style to generate
2021-05-11 02:29:21 +02:00
descriptions for types of matches</p>
<p><span id="index-devices_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>devices</p>
2021-05-11 02:29:21 +02:00
<p>for names of device special files</p>
<p><span id="index-directories_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>directories</p>
<p>for names of directories — local-directories is used instead when
completing arguments of cd and related builtin commands when the cdpath
array is set</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-directory_002dstack_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>directory-stack</p>
2021-05-11 02:29:21 +02:00
<p>for entries in the directory stack</p>
<p><span id="index-displays_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>displays</p>
2021-05-11 02:29:21 +02:00
<p>for X display names</p>
<p><span id="index-domains_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>domains</p>
2021-05-11 02:29:21 +02:00
<p>for network domains</p>
<p><span id="index-email_002d_002a_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>email-<code>plugin</code></p>
<p>for email addresses from the _email-<code>plugin</code> backend of
_email_addresses</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-expansions_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>expansions</p>
<p>used by the _expand completer for individual words (as opposed to the
2021-05-11 02:29:21 +02:00
complete set of expansions) resulting from the expansion of a word on
the command line</p>
<p><span id="index-extensions_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>extensions</p>
2021-05-11 02:29:21 +02:00
<p>for X server extensions</p>
<p><span id="index-file_002ddescriptors_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>file-descriptors</p>
2021-05-11 02:29:21 +02:00
<p>for numbers of open file descriptors</p>
<p><span id="index-files_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>files</p>
2021-05-11 02:29:21 +02:00
<p>the generic file-matching tag used by functions completing filenames</p>
<p><span id="index-fonts_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>fonts</p>
2021-05-11 02:29:21 +02:00
<p>for X font names</p>
<p><span id="index-fstypes_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>fstypes</p>
<p>for file system types (e.g. for the mount command)</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-functions_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>functions</p>
2021-05-11 02:29:21 +02:00
<p>names of functions — normally shell functions, although certain commands
may understand other kinds of function</p>
<p><span id="index-globbed_002dfiles_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>globbed-files</p>
2021-05-11 02:29:21 +02:00
<p>for filenames when the name has been generated by pattern matching</p>
<p><span id="index-groups_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>groups</p>
2021-05-11 02:29:21 +02:00
<p>for names of user groups</p>
<p><span id="index-history_002dwords_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>history-words</p>
2021-05-11 02:29:21 +02:00
<p>for words from the history</p>
<p><span id="index-hosts_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>hosts</p>
2021-05-11 02:29:21 +02:00
<p>for hostnames</p>
<p><span id="index-indexes_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>indexes</p>
2021-05-11 02:29:21 +02:00
<p>for array indexes</p>
<p><span id="index-interfaces_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>interfaces</p>
2021-05-11 02:29:21 +02:00
<p>for network interfaces</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-jobs_002c-completion-tag"></span></p>
<p>jobs</p>
<p>for jobs (as listed by the jobs builtin)</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-keymaps_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>keymaps</p>
2021-05-11 02:29:21 +02:00
<p>for names of zsh keymaps</p>
<p><span id="index-keysyms_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>keysyms</p>
2021-05-11 02:29:21 +02:00
<p>for names of X keysyms</p>
<p><span id="index-libraries_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>libraries</p>
2021-05-11 02:29:21 +02:00
<p>for names of system libraries</p>
<p><span id="index-limits_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>limits</p>
2021-05-11 02:29:21 +02:00
<p>for system limits</p>
<p><span id="index-local_002ddirectories_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>local-directories</p>
2021-05-11 02:29:21 +02:00
<p>for names of directories that are subdirectories of the current working
2022-08-24 15:22:41 +02:00
directory when completing arguments of cd and related builtin commands
(compare path-directories) — when the cdpath array is unset, directories
is used instead</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-mailboxes_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>mailboxes</p>
2021-05-11 02:29:21 +02:00
<p>for e-mail folders</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-manuals_002c-completion-tag"></span></p>
<p>manuals</p>
<p>for names of manual pages</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-maps_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>maps</p>
2021-05-11 02:29:21 +02:00
<p>for map names (e.g. NIS maps)</p>
<p><span id="index-messages_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>messages</p>
<p>used to look up the format style for messages</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-modifiers_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>modifiers</p>
2021-05-11 02:29:21 +02:00
<p>for names of X modifiers</p>
<p><span id="index-modules_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>modules</p>
<p>for modules (e.g. zsh modules)</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-my_002daccounts_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>my-accounts</p>
<p>used to look up the users-hosts style</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-named_002ddirectories_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>named-directories</p>
2021-05-11 02:29:21 +02:00
<p>for named directories (you wouldnt have guessed that, would you?)</p>
<p><span id="index-names_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>names</p>
2021-05-11 02:29:21 +02:00
<p>for all kinds of names</p>
<p><span id="index-newsgroups_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>newsgroups</p>
2021-05-11 02:29:21 +02:00
<p>for USENET groups</p>
<p><span id="index-nicknames_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>nicknames</p>
2021-05-11 02:29:21 +02:00
<p>for nicknames of NIS maps</p>
<p><span id="index-options_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>options</p>
2021-05-11 02:29:21 +02:00
<p>for command options</p>
<p><span id="index-original_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>original</p>
<p>used by the _approximate, _correct and _expand completers when
2021-05-11 02:29:21 +02:00
offering the original string as a match</p>
<p><span id="index-other_002daccounts_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>other-accounts</p>
<p>used to look up the users-hosts style</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-packages_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>packages</p>
<p>for packages (e.g. rpm or installed Debian packages)</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-parameters_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>parameters</p>
2021-05-11 02:29:21 +02:00
<p>for names of parameters</p>
<p><span id="index-path_002ddirectories_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>path-directories</p>
<p>for names of directories found by searching the cdpath array when
completing arguments of cd and related builtin commands (compare
local-directories)</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-paths_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>paths</p>
<p>used to look up the values of the expand, ambiguous and special-dirs
styles</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-pods_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>pods</p>
2021-05-11 02:29:21 +02:00
<p>for perl pods (documentation files)</p>
<p><span id="index-ports_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>ports</p>
2021-05-11 02:29:21 +02:00
<p>for communication ports</p>
<p><span id="index-prefixes_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>prefixes</p>
2021-05-11 02:29:21 +02:00
<p>for prefixes (like those of a URL)</p>
<p><span id="index-printers_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>printers</p>
2021-05-11 02:29:21 +02:00
<p>for print queue names</p>
<p><span id="index-processes_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>processes</p>
2021-05-11 02:29:21 +02:00
<p>for process identifiers</p>
<p><span id="index-processes_002dnames_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>processes-names</p>
<p>used to look up the command style when generating the names of processes
for killall</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-sequences_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>sequences</p>
<p>for sequences (e.g. mh sequences)</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-sessions_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>sessions</p>
<p>for sessions in the zftp function suite</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-signals_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>signals</p>
2021-05-11 02:29:21 +02:00
<p>for signal names</p>
<p><span id="index-strings_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>strings</p>
<p>for strings (e.g. the replacement strings for the cd builtin command)</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-styles_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>styles</p>
2021-05-11 02:29:21 +02:00
<p>for styles used by the zstyle builtin command</p>
<p><span id="index-suffixes_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>suffixes</p>
2021-05-11 02:29:21 +02:00
<p>for filename extensions</p>
<p><span id="index-tags_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>tags</p>
<p>for tags (e.g. rpm tags)</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-targets_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>targets</p>
2021-05-11 02:29:21 +02:00
<p>for makefile targets</p>
<p><span id="index-time_002dzones_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>time-zones</p>
<p>for time zones (e.g. when setting the TZ parameter)</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-types_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>types</p>
<p>for types of whatever (e.g. address types for the xhost command)</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-urls_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>urls</p>
<p>used to look up the urls and local styles when completing URLs</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-users_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>users</p>
2021-05-11 02:29:21 +02:00
<p>for usernames</p>
<p><span id="index-values_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>values</p>
2021-05-11 02:29:21 +02:00
<p>for one of a set of values in certain lists</p>
<p><span id="index-variant_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>variant</p>
<p>used by _pick_variant to look up the command to run when determining
2021-05-11 02:29:21 +02:00
what program is installed for a particular command name.</p>
<p><span id="index-visuals_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>visuals</p>
2021-05-11 02:29:21 +02:00
<p>for X visuals</p>
<p><span id="index-warnings_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>warnings</p>
<p>used to look up the format style for warnings</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-widgets_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>widgets</p>
2021-05-11 02:29:21 +02:00
<p>for zsh widget names</p>
<p><span id="index-windows_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>windows</p>
2021-05-11 02:29:21 +02:00
<p>for IDs of X windows</p>
<p><span id="index-zsh_002doptions_002c-completion-tag"></span></p>
2022-08-24 15:22:41 +02:00
<p>zsh-options</p>
2021-05-11 02:29:21 +02:00
<p>for shell options</p>
<hr />
<p><span id="Standard-Styles"></span></p>
<h3 id="2033-standard-styles"><a class="header" href="#2033-standard-styles">20.3.3 Standard Styles</a></h3>
<p><span id="index-completion-system_002c-styles"></span></p>
<p>Note that the values of several of these styles represent boolean
2022-08-24 15:22:41 +02:00
values. Any of the strings true, on, yes, and 1 can be used for
the value true and any of the strings false, off, no, and 0
for the value false. The behavior for any other value is undefined
except where explicitly mentioned. The default value may be either
true or false if the style is not set.</p>
2021-05-11 02:29:21 +02:00
<p>Some of these styles are tested first for every possible tag
corresponding to a type of match, and if no style was found, for the
2022-08-24 15:22:41 +02:00
list-colors and styles controlling completion listing such as
list-packed and last-prompt. When tested for the default tag, only the
<code>function</code> field of the context will be set so that a style using the
default tag will normally be defined along the lines of:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*:default' menu ...
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p><span id="index-accept_002dexact_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>accept-exact</p>
<p>This is tested for the default tag in addition to the tags valid for the
current context. If it is set to true and any of the trial matches is
the same as the string on the command line, this match will immediately
be accepted (even if it would otherwise be considered ambiguous).</p>
<p>When completing pathnames (where the tag used is paths) this style
2021-05-11 02:29:21 +02:00
accepts any number of patterns as the value in addition to the boolean
values. Pathnames matching one of these patterns will be accepted
immediately even if the command line contains some more partially typed
pathname components and these match no file under the directory
accepted.</p>
2022-08-24 15:22:41 +02:00
<p>This style is also used by the _expand completer to decide if words
2021-05-11 02:29:21 +02:00
beginning with a tilde or parameter expansion should be expanded. For
2022-08-24 15:22:41 +02:00
example, if there are parameters foo and foobar, the string $foo will
only be expanded if accept-exact is set to true; otherwise the
completion system will be allowed to complete $foo to $foobar. If the
style is set to continue, _expand will add the expansion as a match
and the completion system will also be allowed to continue.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-accept_002dexact_002ddirs_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>accept-exact-dirs</p>
<p>This is used by filename completion. Unlike accept-exact it is a
2021-05-11 02:29:21 +02:00
boolean. By default, filename completion examines all components of a
path to see if there are completions of that component, even if the
component matches an existing directory. For example, when completion
2022-08-24 15:22:41 +02:00
after /usr/bin/, the function examines possible completions to /usr.</p>
2021-05-11 02:29:21 +02:00
<p>When this style is true, any prefix of a path that matches an existing
directory is accepted without any attempt to complete it further. Hence,
2022-08-24 15:22:41 +02:00
in the given example, the path /usr/bin/ is accepted immediately and
2021-05-11 02:29:21 +02:00
completion tried in that directory.</p>
<p>This style is also useful when completing after directories that
2022-08-24 15:22:41 +02:00
magically appear when referenced, such as ZFS .zfs directories or NetApp
.snapshot directories. When the style is set the shell does not check
for the existence of the directory within the parent directory.</p>
<p>If you wish to inhibit this behaviour entirely, set the path-completion
style (see below) to false.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-add_002dspace_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>add-space</p>
<p>This style is used by the _expand completer. If it is true (the
2021-05-11 02:29:21 +02:00
default), a space will be inserted after all words resulting from the
expansion, or a slash in the case of directory names. If the value is
2022-08-24 15:22:41 +02:00
file, the completer will only add a space to names of existing files.
Either a boolean true or the value file may be combined with
subst, in which case the completer will not add a space to words
generated from the expansion of a substitution of the form $(<code>...</code>) or
${<code>...</code>}.</p>
<p>The _prefix completer uses this style as a simple boolean value to
2021-05-11 02:29:21 +02:00
decide if a space should be inserted before the suffix.</p>
<p><span id="index-ambiguous_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>ambiguous</p>
2021-05-11 02:29:21 +02:00
<p>This applies when completing non-final components of filename paths, in
other words those with a trailing slash. If it is set, the cursor is
left after the first ambiguous component, even if menu completion is in
2022-08-24 15:22:41 +02:00
use. The style is always tested with the paths tag.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-assign_002dlist_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>assign-list</p>
2021-05-11 02:29:21 +02:00
<p>When completing after an equals sign that is being treated as an
assignment, the completion system normally completes only one filename.
In some cases the value may be a list of filenames separated by colons,
2022-08-24 15:22:41 +02:00
as with PATH and similar parameters. This style can be set to a list of
patterns matching the names of such parameters.</p>
2021-05-11 02:29:21 +02:00
<p>The default is to complete lists when the word on the line already
contains a colon.</p>
<p><span id="index-auto_002ddescription_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>auto-description</p>
2021-05-11 02:29:21 +02:00
<p>If set, this styles value will be used as the description for options
that are not described by the completion functions, but that have
2022-08-24 15:22:41 +02:00
exactly one argument. The sequence %d in the value will be replaced by
the description for this argument. Depending on personal preferences, it
may be useful to set this style to something like specify: %d. Note
that this may not work for some commands.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-avoid_002dcompleter_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>avoid-completer</p>
<p>This is used by the _all_matches completer to decide if the string
2021-05-11 02:29:21 +02:00
consisting of all matches should be added to the list currently being
generated. Its value is a list of names of completers. If any of these
is the name of the completer that generated the matches in this
completion, the string will not be added.</p>
2022-08-24 15:22:41 +02:00
<p>The default value for this style is _expand _old_list _correct
_approximate, i.e. it contains the completers for which a string with
2021-05-11 02:29:21 +02:00
all matches will almost never be wanted.</p>
<p><span id="index-cache_002dpath_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>cache-path</p>
2021-05-11 02:29:21 +02:00
<p>This style defines the path where any cache files containing dumped
2022-08-24 15:22:41 +02:00
completion data are stored. It defaults to $ZDOTDIR/.zcompcache, or
$HOME/.zcompcache if $ZDOTDIR is not defined. The completion cache
will not be used unless the use-cache style is set.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-cache_002dpolicy_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>cache-policy</p>
2021-05-11 02:29:21 +02:00
<p>This style defines the function that will be used to determine whether a
2022-08-24 15:22:41 +02:00
cache needs rebuilding. See the section on the _cache_invalid function
2021-05-11 02:29:21 +02:00
below.</p>
<p><span id="index-call_002dcommand_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>call-command</p>
<p>This style is used in the function for commands such as make and ant
2021-05-11 02:29:21 +02:00
where calling the command directly to generate matches suffers problems
2022-08-24 15:22:41 +02:00
such as being slow or, as in the case of make can potentially cause
2021-05-11 02:29:21 +02:00
actions in the makefile to be executed. If it is set to true the
command is called to generate matches. The default value of this style
is false.</p>
<p><span id="index-command_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>command</p>
2021-05-11 02:29:21 +02:00
<p>In many places, completion functions need to call external commands to
generate the list of completions. This style can be used to override the
command that is called in some such cases. The elements of the value are
joined with spaces to form a command line to execute. The value can also
start with a hyphen, in which case the usual command will be added to
2022-08-24 15:22:41 +02:00
the end; this is most useful for putting builtin or command in front
to make sure the appropriate version of a command is called, for example
to avoid calling a shell function with the same name as an external
command.</p>
2021-05-11 02:29:21 +02:00
<p>As an example, the completion function for process IDs uses this style
2022-08-24 15:22:41 +02:00
with the processes tag to generate the IDs to complete and the list of
processes to display (if the verbose style is true). The list produced
by the command should look like the output of the ps command. The first
line is not displayed, but is searched for the string PID (or pid)
to find the position of the process IDs in the following lines. If the
line does not contain PID, the first numbers in each of the other
lines are taken as the process IDs to complete.</p>
2021-05-11 02:29:21 +02:00
<p>Note that the completion function generally has to call the specified
command for each attempt to generate the completion list. Hence care
should be taken to specify only commands that take a short time to run,
and in particular to avoid any that may never terminate.</p>
<p><span id="index-command_002dpath_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>command-path</p>
2021-05-11 02:29:21 +02:00
<p>This is a list of directories to search for commands to complete. The
2022-08-24 15:22:41 +02:00
default for this style is the value of the special parameter path.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-commands_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>commands</p>
2021-05-11 02:29:21 +02:00
<p>This is used by the function completing sub-commands for the system
2022-08-24 15:22:41 +02:00
initialisation scripts (residing in /etc/init.d or somewhere not too far
away from that). Its values give the default commands to complete for
those commands for which the completion function isnt able to find them
out automatically. The default for this style are the two strings
start and stop.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-complete_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>complete</p>
<p>This is used by the _expand_alias function when invoked as a bindable
2021-05-11 02:29:21 +02:00
command. If set to true and the word on the command line is not the
name of an alias, matching alias names will be completed.</p>
<p><span id="index-complete_002doptions_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>complete-options</p>
<p>This is used by the completer for cd, chdir and pushd. For these
commands a - is used to introduce a directory stack entry and completion
of these is far more common than completing options. Hence unless the
value of this style is true options will not be completed, even after
an initial -. If it is true, options will be completed after an
initial - unless there is a preceding -- on the command line.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-completer_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>completer</p>
2021-05-11 02:29:21 +02:00
<p>The strings given as the value of this style provide the names of the
completer functions to use. The available completer functions are
described in <a href="Completion-System.html#Control-Functions">Control Functions</a>.</p>
<p>Each string may be either the name of a completer function or a string
2022-08-24 15:22:41 +02:00
of the form <code>function</code>:<code>name</code>. In the first case the <code>completer</code> field
of the context will contain the name of the completer without the
2021-05-11 02:29:21 +02:00
leading underscore and with all other underscores replaced by hyphens.
In the second case the <code>function</code> is the name of the completer to call,
but the context will contain the user-defined <code>name</code> in the <code>completer</code>
field of the context. If the <code>name</code> starts with a hyphen, the string for
the context will be build from the name of the completer function as in
the first case with the <code>name</code> appended to it. For example:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*' completer _complete _complete:-foo
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Here, completion will call the _complete completer twice, once using
complete and once using complete-foo in the <code>completer</code> field of the
context. Normally, using the same completer more than once only makes
sense when used with the <code>functions</code>:<code>name</code> form, because otherwise
the context name will be the same in all calls to the completer;
possible exceptions to this rule are the _ignored and _prefix
completers.</p>
<p>The default value for this style is _complete _ignored: only
completion will be done, first using the ignored-patterns style and the
$fignore array and then without ignoring matches.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-condition_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>condition</p>
<p>This style is used by the _list completer function to decide if
2021-05-11 02:29:21 +02:00
insertion of matches should be delayed unconditionally. The default is
true.</p>
<p><span id="index-delimiters_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>delimiters</p>
2021-05-11 02:29:21 +02:00
<p>This style is used when adding a delimiter for use with history
modifiers or glob qualifiers that have delimited arguments. It is an
array of preferred delimiters to add. Non-special characters are
preferred as the completion system may otherwise become confused. The
2022-08-24 15:22:41 +02:00
default list is :, +, /, -, %. The list may be empty to force a
delimiter to be typed.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-disabled_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>disabled</p>
<p>If this is set to true, the _expand_alias completer and bindable
2021-05-11 02:29:21 +02:00
command will try to expand disabled aliases, too. The default is
false.</p>
<p><span id="index-domains_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>domains</p>
2021-05-11 02:29:21 +02:00
<p>A list of names of network domains for completion. If this is not set,
2022-08-24 15:22:41 +02:00
domain names will be taken from the file /etc/resolv.conf.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-environ_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>environ</p>
<p>The environ style is used when completing for sudo. It is set to an
array of <code>VAR</code>=<code>value</code> assignments to be exported into the local
2021-05-11 02:29:21 +02:00
environment before the completion for the target command is invoked.</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*:sudo::' environ \
2021-05-11 02:29:21 +02:00
PATH=&quot;/sbin:/usr/sbin:$PATH&quot; HOME=&quot;/root&quot;
</code></pre>
</div>
<p><span id="index-expand_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>expand</p>
2021-05-11 02:29:21 +02:00
<p>This style is used when completing strings consisting of multiple parts,
such as path names.</p>
2022-08-24 15:22:41 +02:00
<p>If one of its values is the string prefix, the partially typed word
2021-05-11 02:29:21 +02:00
from the line will be expanded as far as possible even if trailing parts
cannot be completed.</p>
2022-08-24 15:22:41 +02:00
<p>If one of its values is the string suffix, matching names for
2021-05-11 02:29:21 +02:00
components after the first ambiguous one will also be added. This means
that the resulting string is the longest unambiguous string possible.
However, menu completion can be used to cycle through all matches.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-extra_002dverbose_002c-completion-style"></span></p>
<p>extra-verbose</p>
<p>If set, the completion listing is more verbose at the cost of a probable
decrease in completion speed. Completion performance will suffer if this
style is set to true.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-fake_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>fake</p>
2021-05-11 02:29:21 +02:00
<p>This style may be set for any completion context. It specifies
additional strings that will always be completed in that context. The
2022-08-24 15:22:41 +02:00
form of each string is <code>value</code>:<code>description</code>; the colon and
2021-05-11 02:29:21 +02:00
description may be omitted, but any literal colons in <code>value</code> must be
quoted with a backslash. Any <code>description</code> provided is shown alongside
the value in completion listings.</p>
<p>It is important to use a sufficiently restrictive context when
2022-08-24 15:22:41 +02:00
specifying fake strings. Note that the styles fake-files and
fake-parameters provide additional features when completing files or
2021-05-11 02:29:21 +02:00
parameters.</p>
<p><span id="index-fake_002dalways_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>fake-always</p>
<p>This works identically to the fake style except that the
ignored-patterns style is not applied to it. This makes it possible to
2021-05-11 02:29:21 +02:00
override a set of matches completely by setting the ignored patterns to
2022-08-24 15:22:41 +02:00
*.</p>
2021-05-11 02:29:21 +02:00
<p>The following shows a way of supplementing any tag with arbitrary data,
but having it behave for display purposes like a separate tag. In this
2022-08-24 15:22:41 +02:00
example we use the features of the tag-order style to divide the
named-directories tag into two when performing completion with the
standard completer complete for arguments of cd. The tag
named-directories-normal behaves as normal, but the tag
named-directories-mine contains a fixed set of directories. This has the
effect of adding the match group extra directories with the given
completions.</p>
<div class="example">
<pre><code class="language-zsh">zstyle ':completion::complete:cd:*' tag-order \
2021-05-11 02:29:21 +02:00
'named-directories:-mine:extra\ directories
named-directories:-normal:named\ directories *'
zstyle ':completion::complete:cd:*:named-directories-mine' \
fake-always mydir1 mydir2
zstyle ':completion::complete:cd:*:named-directories-mine' \
ignored-patterns '*'
</code></pre>
</div>
<p><span id="index-fake_002dfiles_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>fake-files</p>
2021-05-11 02:29:21 +02:00
<p>This style is used when completing files and looked up without a tag.
2022-08-24 15:22:41 +02:00
Its values are of the form <code>dir</code>:<code>names...</code>. This will add the <code>names</code>
(strings separated by spaces) as possible matches when completing in the
directory <code>dir</code>, even if no such files really exist. The dir may be a
pattern; pattern characters or colons in <code>dir</code> should be quoted with a
backslash to be treated literally.</p>
2021-05-11 02:29:21 +02:00
<p>This can be useful on systems that support special file systems whose
top-level pathnames can not be listed or generated with glob patterns
2022-08-24 15:22:41 +02:00
(but see accept-exact-dirs for a more general way of dealing with this
2021-05-11 02:29:21 +02:00
problem). It can also be used for directories for which one does not
have read permission.</p>
<p>The pattern form can be used to add a certain magic entry to all
directories on a particular file system.</p>
<p><span id="index-fake_002dparameters_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>fake-parameters</p>
2021-05-11 02:29:21 +02:00
<p>This is used by the completion function for parameter names. Its values
are names of parameters that might not yet be set but should be
completed nonetheless. Each name may also be followed by a colon and a
2022-08-24 15:22:41 +02:00
string specifying the type of the parameter (like scalar, array or
integer). If the type is given, the name will only be completed if
parameters of that type are required in the particular context. Names
2021-05-11 02:29:21 +02:00
for which no type is specified will always be completed.</p>
<p><span id="index-file_002dlist_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>file-list</p>
2021-05-11 02:29:21 +02:00
<p>This style controls whether files completed using the standard builtin
2022-08-24 15:22:41 +02:00
mechanism are to be listed with a long list similar to ls -l. Note that
this feature uses the shell module zsh/stat for file information; this
loads the builtin stat this the following code can be included in an
initialization file:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zmodload -i zsh/stat
2021-05-11 02:29:21 +02:00
disable stat
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The style may either be set to a true value (or all), or one of the
values insert or list, indicating that files are to be listed in
long format in all circumstances, or when attempting to insert a file
name, or when listing file names without attempting to insert one.</p>
2021-05-11 02:29:21 +02:00
<p>More generally, the value may be an array of any of the above values,
2022-08-24 15:22:41 +02:00
optionally followed by =<code>num</code>. If <code>num</code> is present it gives the maximum
number of matches for which long listing style will be used. For
2021-05-11 02:29:21 +02:00
example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*' file-list list=20 insert=10
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>specifies that long format will be used when listing up to 20 files or
inserting a file with up to 10 matches (assuming a listing is to be
shown at all, for example on an ambiguous completion), else short format
will be used.</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle -e ':completion:*' file-list \
2021-05-11 02:29:21 +02:00
'(( ${+NUMERIC} )) &amp;&amp; reply=(true)'
</code></pre>
</div>
<p>specifies that long format will be used any time a numeric argument is
supplied, else short format.</p>
<p><span id="index-file_002dpatterns_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>file-patterns</p>
<p>This is used by the standard function for completing filenames, _files.
If the style is unset up to three tags are offered,
globbed-files,directories and all-files, depending on the types of
files expected by the caller of _files. The first two (globbed-files
and directories) are normally offered together to make it easier to
complete files in sub-directories.</p>
<p>The file-patterns style provides alternatives to the default tags, which
are not used. Its value consists of elements of the form
<code>pattern</code>:<code>tag</code>; each string may contain any number of such
2021-05-11 02:29:21 +02:00
specifications separated by spaces.</p>
<p>The <code>pattern</code> is a pattern that is to be used to generate filenames. Any
2022-08-24 15:22:41 +02:00
occurrence of the sequence %p is replaced by any pattern(s) passed by
the function calling _files. Colons in the pattern must be preceded by
a backslash to make them distinguishable from the colon before the
2021-05-11 02:29:21 +02:00
<code>tag</code>. If more than one pattern is needed, the patterns can be given
inside braces, separated by commas.</p>
2022-08-24 15:22:41 +02:00
<p>The <code>tag</code>s of all strings in the value will be offered by _files and
2021-05-11 02:29:21 +02:00
used when looking up other styles. Any <code>tag</code>s in the same word will be
2022-08-24 15:22:41 +02:00
offered at the same time and before later words. If no :<code>tag</code> is given
the files tag will be used.</p>
2021-05-11 02:29:21 +02:00
<p>The <code>tag</code> may also be followed by an optional second colon and a
2022-08-24 15:22:41 +02:00
description, which will be used for the %d in the value of the format
style (if that is set) instead of the default description supplied by
the completion function. The inclusion of a description also gives
precedence to associated options such as for completion grouping so it
can be used where files should be separated.</p>
<p>For example, to make the rm command first complete only names of object
files and then the names of all files if there is no matching object
file:</p>
<div class="example">
<pre><code class="language-zsh">zstyle ':completion:*:*:rm:*:*' file-patterns \
2021-05-11 02:29:21 +02:00
'*.o:object-files' '%p:all-files'
</code></pre>
</div>
<p>To alter the default behaviour of file completion — offer files matching
a pattern and directories on the first attempt, then all files — to
offer only matching files on the first attempt, then directories, and
finally all files:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*' file-patterns \
2021-05-11 02:29:21 +02:00
'%p:globbed-files' '*(-/):directories' '*:all-files'
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>This works even where there is no special pattern: _files matches all
files using the pattern * at the first step and stops when it sees
2021-05-11 02:29:21 +02:00
this pattern. Note also it will never try a pattern more than once for a
single completion attempt.</p>
2022-08-24 15:22:41 +02:00
<p>To separate directories into a separate group from the files but still
complete them at the first attempt, a description needs to be given.
Note that directories need to be explicitly excluded from the
globbed-files because * will match directories. For grouping, it is
also necessary to set the group-name style.</p>
<div class="example">
<pre><code class="language-zsh">zstyle ':completion:*' file-patterns \
'%p(^-/):globbed-files *(-/):directories:location'
</code></pre>
</div>
<p>During the execution of completion functions, the EXTENDED_GLOB option
is in effect, so the characters #, ~ and ^ have special meanings
in the patterns.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-file_002dsort_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>file-sort</p>
2021-05-11 02:29:21 +02:00
<p>The standard filename completion function uses this style without a tag
to determine in which order the names should be listed; menu completion
will cycle through them in the same order. The possible values are:
2022-08-24 15:22:41 +02:00
size to sort by the size of the file; links to sort by the number of
links to the file; modification (or time or date) to sort by the
last modification time; access to sort by the last access time; and
inode (or change) to sort by the last inode change time. If the
style is set to any other value, or is unset, files will be sorted
alphabetically by name. If the value contains the string reverse,
sorting is done in the opposite order. If the value contains the string
follow, timestamps are associated with the targets of symbolic links;
the default is to use the timestamps of the links themselves.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-file_002dsplit_002dchars_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>file-split-chars</p>
2021-05-11 02:29:21 +02:00
<p>A set of characters that will cause <em>all</em> file completions for the given
context to be split at the point where any of the characters occurs. A
2022-08-24 15:22:41 +02:00
typical use is to set the style to :; then everything up to and
including the last : in the string so far is ignored when completing
2021-05-11 02:29:21 +02:00
files. As this is quite heavy-handed, it is usually preferable to update
completion functions for contexts where this behaviour is useful.</p>
<p><span id="index-filter_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>filter</p>
<p>The ldap plugin of email address completion (see _email_addresses) uses
this style to specify the attributes to match against when filtering
entries. So for example, if the style is set to sn, matching is done
against surnames. Standard LDAP filtering is used so normal completion
matching is bypassed. If this style is not set, the LDAP plugin is
skipped. You may also need to set the command style to specify how to
connect to your LDAP server.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-force_002dlist_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>force-list</p>
2021-05-11 02:29:21 +02:00
<p>This forces a list of completions to be shown at any point where listing
is done, even in cases where the list would usually be suppressed. For
example, normally the list is only shown if there are at least two
2022-08-24 15:22:41 +02:00
different matches. By setting this style to always, the list will
2021-05-11 02:29:21 +02:00
always be shown, even if there is only a single match that will
immediately be accepted. The style may also be set to a number. In this
case the list will be shown if there are at least that many matches,
even if they would all insert the same string.</p>
<p>This style is tested for the default tag as well as for each tag valid
for the current completion. Hence the listing can be forced only for
certain types of match.</p>
<p><span id="index-format_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>format</p>
<p>If this is set for the descriptions tag, its value is used as a string
to display above matches in completion lists. The sequence %d in this
string will be replaced with a short description of what these matches
are. This string may also contain the output attribute sequences
understood by compadd -X (see <a href="Completion-Widgets.html#Completion-Widgets">Completion
2021-05-11 02:29:21 +02:00
Widgets</a>).</p>
<p>The style is tested with each tag valid for the current completion
2022-08-24 15:22:41 +02:00
before it is tested for the descriptions tag. Hence different format
2021-05-11 02:29:21 +02:00
strings can be defined for different types of match.</p>
2022-08-24 15:22:41 +02:00
<p>Note also that some completer functions define additional %-sequences.
These are described for the completer functions that make use of them.</p>
2021-05-11 02:29:21 +02:00
<p>Some completion functions display messages that may be customised by
2022-08-24 15:22:41 +02:00
setting this style for the messages tag. Here, the %d is replaced with
a message given by the completion function.</p>
<p>Finally, the format string is looked up with the warnings tag, for use
when no matches could be generated at all. In this case the %d is
2021-05-11 02:29:21 +02:00
replaced with the descriptions for the matches that were expected
2022-08-24 15:22:41 +02:00
separated by spaces. The sequence %D is replaced with the same
2021-05-11 02:29:21 +02:00
descriptions separated by newlines.</p>
2022-08-24 15:22:41 +02:00
<p>It is possible to use printf-style field width specifiers with %d and
similar escape sequences. This is handled by the zformat builtin command
from the zsh/zutil module, see <a href="Zsh-Modules.html#The-zsh_002fzutil-Module">The zsh/zutil
2021-05-11 02:29:21 +02:00
Module</a>.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-gain_002dprivileges_002c-completion-style"></span></p>
<p>gain-privileges</p>
<p>If set to true, this style enables the use of commands like sudo or doas
to gain extra privileges when retrieving information for completion.
This is only done when a command such as sudo appears on the
command-line. To force the use of, e.g. sudo or to override any prefix
that might be added due to gain-privileges, the command style can be
used with a value that begins with a hyphen.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-glob_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>glob</p>
<p>This is used by the _expand completer. If it is set to true (the
2021-05-11 02:29:21 +02:00
default), globbing will be attempted on the words resulting from a
2022-08-24 15:22:41 +02:00
previous substitution (see the substitute style) or else the original
2021-05-11 02:29:21 +02:00
string from the line.</p>
<p><span id="index-global_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>global</p>
<p>If this is set to true (the default), the _expand_alias completer and
bindable command will try to expand global aliases.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-group_002dname_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>group-name</p>
2021-05-11 02:29:21 +02:00
<p>The completion system can group different types of matches, which appear
in separate lists. This style can be used to give the names of groups
for particular tags. For example, in command position the completion
system generates names of builtin and external commands, names of
aliases, shell functions and parameters and reserved words as possible
completions. To have the external commands and shell functions listed
separately:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*:*:-command-:*:commands' \
2021-05-11 02:29:21 +02:00
group-name commands
zstyle ':completion:*:*:-command-:*:functions' \
group-name functions
</code></pre>
</div>
<p>As a consequence, any match with the same tag will be displayed in the
same group.</p>
<p>If the name given is the empty string the name of the tag for the
matches will be used as the name of the group. So, to have all different
types of matches displayed separately, one can just set:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*' group-name ''
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>All matches for which no group name is defined will be put in a group
2022-08-24 15:22:41 +02:00
named -default-.</p>
<p>To display the group name in the output, see the format style (q.v.)
under the descriptions tag.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-group_002dorder_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>group-order</p>
<p>This style is additional to the group-name style to specify the order
for display of the groups defined by that style (compare tag-order,
2021-05-11 02:29:21 +02:00
which determines which completions appear at all). The groups named are
shown in the given order; any other groups are shown in the order
defined by the completion function.</p>
<p>For example, to have names of builtin commands, shell functions and
external commands appear in that order when completing in command
position:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*:*:-command-:*:*' group-order \
2021-05-11 02:29:21 +02:00
builtins functions commands
</code></pre>
</div>
<p><span id="index-groups_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>groups</p>
2021-05-11 02:29:21 +02:00
<p>A list of names of UNIX groups. If this is not set, group names are
2022-08-24 15:22:41 +02:00
taken from the YP database or the file /etc/group.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-hidden_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>hidden</p>
2021-05-11 02:29:21 +02:00
<p>If this is set to true, matches for the given context will not be
2022-08-24 15:22:41 +02:00
listed, although any description for the matches set with the format
style will be shown. If it is set to all, not even the description
2021-05-11 02:29:21 +02:00
will be displayed.</p>
<p>Note that the matches will still be completed; they are just not shown
in the list. To avoid having matches considered as possible completions
2022-08-24 15:22:41 +02:00
at all, the tag-order style can be modified as described below.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-hosts_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>hosts</p>
2021-05-11 02:29:21 +02:00
<p>A list of names of hosts that should be completed. If this is not set,
2022-08-24 15:22:41 +02:00
hostnames are taken from the file /etc/hosts.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-hosts_002dports_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>hosts-ports</p>
2021-05-11 02:29:21 +02:00
<p>This style is used by commands that need or accept hostnames and network
2022-08-24 15:22:41 +02:00
ports. The strings in the value should be of the form <code>host</code>:<code>port</code>.
2021-05-11 02:29:21 +02:00
Valid ports are determined by the presence of hostnames; multiple ports
for the same host may appear.</p>
<p><span id="index-ignore_002dline_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>ignore-line</p>
2021-05-11 02:29:21 +02:00
<p>This is tested for each tag valid for the current completion. If it is
set to true, none of the words that are already on the line will be
2022-08-24 15:22:41 +02:00
considered as possible completions. If it is set to current, the word
the cursor is on will not be considered as a possible completion. The
value current-shown is similar but only applies if the list of
2021-05-11 02:29:21 +02:00
completions is currently shown on the screen. Finally, if the style is
2022-08-24 15:22:41 +02:00
set to other, all words on the line except for the current one will be
excluded from the possible completions.</p>
<p>The values current and current-shown are a bit like the opposite of
the accept-exact style: only strings with missing characters will be
completed.</p>
2021-05-11 02:29:21 +02:00
<p>Note that you almost certainly dont want to set this to true or
2022-08-24 15:22:41 +02:00
other for a general context such as :completion:*. This is because
it would disallow completion of, for example, options multiple times
even if the command in question accepts the option more than once.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-ignore_002dparents_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>ignore-parents</p>
2021-05-11 02:29:21 +02:00
<p>The style is tested without a tag by the function completing pathnames
in order to determine whether to ignore the names of directories already
mentioned in the current word, or the name of the current working
directory. The value must include one or both of the following strings:</p>
2022-08-24 15:22:41 +02:00
<p>parent<br />
The name of any directory whose path is already contained in the word on
the line is ignored. For example, when completing after foo/../, the
directory foo will not be considered a valid completion.</p>
<p>pwd<br />
The name of the current working directory will not be completed; hence,
for example, completion after ../ will not use the name of the current
directory.</p>
2021-05-11 02:29:21 +02:00
<p>In addition, the value may include one or both of:</p>
2022-08-24 15:22:41 +02:00
<p>..<br />
Ignore the specified directories only when the word on the line contains
the substring ../.</p>
<p>directory<br />
2021-05-11 02:29:21 +02:00
Ignore the specified directories only when names of directories are
completed, not when completing names of files.</p>
<p>Excluded values act in a similar fashion to values of the
2022-08-24 15:22:41 +02:00
ignored-patterns style, so they can be restored to consideration by the
_ignored completer.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-ignored_002dpatterns_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>ignored-patterns</p>
2021-05-11 02:29:21 +02:00
<p>A list of patterns; any trial completion matching one of the patterns
2022-08-24 15:22:41 +02:00
will be excluded from consideration. The _ignored completer can appear
2021-05-11 02:29:21 +02:00
in the list of completers to restore the ignored matches. This is a more
2022-08-24 15:22:41 +02:00
configurable version of the shell parameter $fignore.</p>
<p>Note that the EXTENDED_GLOB option is set during the execution of
completion functions, so the characters #, ~ and ^ have special
meanings in the patterns.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-insert_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>insert</p>
<p>This style is used by the _all_matches completer to decide whether to
2021-05-11 02:29:21 +02:00
insert the list of all matches unconditionally instead of adding the
list as another match.</p>
<p><span id="index-insert_002dids_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>insert-ids</p>
<p>When completing process IDs, for example as arguments to the kill and
wait builtins the name of a command may be converted to the appropriate
process ID. A problem arises when the process name typed is not unique.
By default (or if this style is set explicitly to menu) the name will
be converted immediately to a set of possible IDs, and menu completion
will be started to cycle through them.</p>
<p>If the value of the style is single, the shell will wait until the
2021-05-11 02:29:21 +02:00
user has typed enough to make the command unique before converting the
name to an ID; attempts at completion will be unsuccessful until that
point. If the value is any other string, menu completion will be started
when the string typed by the user is longer than the common prefix to
the corresponding IDs.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-insert_002dsections_002c-completion-style"></span></p>
<p>insert-sections</p>
<p>This style is used with tags of the form manuals.<code>X</code> when completing
names of manual pages. If set and the <code>X</code> in the tag name matches the
section number of the page being completed, the section number is
inserted along with the page name. For example, given</p>
<div class="example">
<pre><code class="language-zsh">zstyle ':completion:*:manuals.*' insert-sections true
</code></pre>
</div>
<p>man ssh_&lt;TAB&gt; may be completed to man 5 ssh_config.</p>
<p>The value may also be set to one of prepend, or suffix. prepend
behaves the same as true as in the above example, while suffix would
complete man ssh_&lt;TAB&gt; as man ssh_config.5.</p>
<p>This is especially useful in conjunction with separate-sections, as it
ensures that the page requested of man corresponds to the one displayed
in the completion listing when there are multiple pages with the same
name (e.g., printf(1) and printf(3)).</p>
<p>The default for this style is false.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-insert_002dtab_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>insert-tab</p>
2021-05-11 02:29:21 +02:00
<p>If this is set to true, the completion system will insert a TAB
character (assuming that was used to start completion) instead of
performing completion when there is no non-blank character to the left
of the cursor. If it is set to false, completion will be done even
there.</p>
2022-08-24 15:22:41 +02:00
<p>The value may also contain the substrings pending or pending=<code>val</code>.
In this case, the typed character will be inserted instead of starting
completion when there is unprocessed input pending. If a <code>val</code> is given,
completion will not be done if there are at least that many characters
of unprocessed input. This is often useful when pasting characters into
a terminal. Note however, that it relies on the $PENDING special
parameter from the zsh/zle module being set properly which is not
guaranteed on all platforms.</p>
2021-05-11 02:29:21 +02:00
<p>The default value of this style is true except for completion within
2022-08-24 15:22:41 +02:00
vared builtin command where it is false.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-insert_002dunambiguous_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>insert-unambiguous</p>
<p>This is used by the _match and _approximate completers. These
2021-05-11 02:29:21 +02:00
completers are often used with menu completion since the word typed may
bear little resemblance to the final completion. However, if this style
is true, the completer will start menu completion only if it could
find no unambiguous initial string at least as long as the original
string typed by the user.</p>
2022-08-24 15:22:41 +02:00
<p>In the case of the _approximate completer, the completer field in the
context will already have been set to one of correct-<code>num</code> or
approximate-<code>num</code>, where <code>num</code> is the number of errors that were
2021-05-11 02:29:21 +02:00
accepted.</p>
2022-08-24 15:22:41 +02:00
<p>In the case of the _match completer, the style may also be set to the
string pattern. Then the pattern on the line is left unchanged if it
2021-05-11 02:29:21 +02:00
does not match unambiguously.</p>
<p><span id="index-keep_002dprefix_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>keep-prefix</p>
<p>This style is used by the _expand completer. If it is true, the
2021-05-11 02:29:21 +02:00
completer will try to keep a prefix containing a tilde or parameter
2022-08-24 15:22:41 +02:00
expansion. Hence, for example, the string ~/f* would be expanded to
~/foo instead of /home/user/foo. If the style is set to changed
(the default), the prefix will only be left unchanged if there were
other changes between the expanded words and the original word from the
command line. Any other value forces the prefix to be expanded
unconditionally.</p>
<p>The behaviour of _expand when this style is true is to cause _expand
to give up when a single expansion with the restored prefix is the same
as the original; hence any remaining completers may be called.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-known_002dhosts_002dfiles"></span></p>
2022-08-24 15:22:41 +02:00
<p>known-hosts-files</p>
2021-05-11 02:29:21 +02:00
<p>This style should contain a list of files to search for host names and
2022-08-24 15:22:41 +02:00
(if the use-ip style is set) IP addresses in a format compatible with
ssh known_hosts files. If it is not set, the files
/etc/ssh/ssh_known_hosts and ~/.ssh/known_hosts are used.</p>
<p><span id="index-last_002dprompt_002c-completion-style"></span></p>
<p>last-prompt</p>
<p>This is a more flexible form of the ALWAYS_LAST_PROMPT option. If it is
true, the completion system will try to return the cursor to the
previous command line after displaying a completion list. It is tested
for all tags valid for the current completion, then the default tag. The
cursor will be moved back to the previous line if this style is true
for all types of match. Note that unlike the ALWAYS_LAST_PROMPT option
this is independent of the numeric argument.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-list_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>list</p>
<p>This style is used by the _history_complete_word bindable command. If
2021-05-11 02:29:21 +02:00
it is set to true it has no effect. If it is set to false matches
will not be listed. This overrides the setting of the options
2022-08-24 15:22:41 +02:00
controlling listing behaviour, in particular AUTO_LIST. The context
always starts with :completion:history-words.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-list_002dcolors_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>list-colors</p>
<p>If the zsh/complist module is loaded, this style can be used to set
color specifications. This mechanism replaces the use of the ZLS_COLORS
and ZLS_COLOURS parameters described in <a href="Zsh-Modules.html#The-zsh_002fcomplist-Module">The zsh/complist
2021-05-11 02:29:21 +02:00
Module</a>, but the syntax is
the same.</p>
2022-08-24 15:22:41 +02:00
<p>If this style is set for the default tag, the strings in the value are
2021-05-11 02:29:21 +02:00
taken as specifications that are to be used everywhere. If it is set for
other tags, the specifications are used only for matches of the type
2022-08-24 15:22:41 +02:00
described by the tag. For this to work best, the group-name style must
2021-05-11 02:29:21 +02:00
be set to an empty string.</p>
<p>In addition to setting styles for specific tags, it is also possible to
2022-08-24 15:22:41 +02:00
use group names specified explicitly by the group-name tag together with
the (group) syntax allowed by the ZLS_COLORS and ZLS_COLOURS
parameters and simply using the default tag.</p>
2021-05-11 02:29:21 +02:00
<p>It is possible to use any color specifications already set up for the
2022-08-24 15:22:41 +02:00
GNU version of the ls command:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*:default' list-colors \
2021-05-11 02:29:21 +02:00
${(s.:.)LS_COLORS}
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The default colors are the same as for the GNU ls command and can be
obtained by setting the style to an empty string (i.e. ).</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-list_002ddirs_002dfirst_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>list-dirs-first</p>
<p>This is used by file completion and corresponds to a particular setting
of the file-patterns style. If set, the default directories to be
completed are listed separately from and before completion for other
files.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-list_002dgrouped_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>list-grouped</p>
2021-05-11 02:29:21 +02:00
<p>If this style is true (the default), the completion system will try to
make certain completion listings more compact by grouping matches. For
example, options for commands that have the same description (shown when
2022-08-24 15:22:41 +02:00
the verbose style is set to true) will appear as a single entry.
2021-05-11 02:29:21 +02:00
However, menu selection can be used to cycle through all the matches.</p>
<p><span id="index-list_002dpacked_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>list-packed</p>
2021-05-11 02:29:21 +02:00
<p>This is tested for each tag valid in the current context as well as the
2022-08-24 15:22:41 +02:00
default tag. If it is set to true, the corresponding matches appear in
listings as if the LIST_PACKED option were set. If it is set to false,
they are listed normally.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-list_002dprompt_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>list-prompt</p>
<p>If this style is set for the default tag, completion lists that dont
2021-05-11 02:29:21 +02:00
fit on the screen can be scrolled (see <a href="Zsh-Modules.html#The-zsh_002fcomplist-Module">The zsh/complist
Module</a>). The value, if
not the empty string, will be displayed after every screenful and the
shell will prompt for a key press; if the style is set to the empty
string, a default prompt will be used.</p>
2022-08-24 15:22:41 +02:00
<p>The value may contain the escape sequences: %l or %L, which will be
replaced by the number of the last line displayed and the total number
of lines; %m or %M, the number of the last match shown and the total
number of matches; and %p and %P, Top when at the beginning of the
list, Bottom when at the end and the position shown as a percentage of
the total length otherwise. In each case the form with the uppercase
letter will be replaced by a string of fixed width, padded to the right
with spaces, while the lowercase form will be replaced by a variable
width string. As in other prompt strings, the escape sequences %S,
%s, %B, %b, %U, %u for entering and leaving the display modes
standout, bold and underline, and %F, %f, %K, %k for changing
the foreground background colour, are also available, as is the form
%{...%} for enclosing escape sequences which display with zero (or,
with a numeric argument, some other) width.</p>
<p>After deleting this prompt the variable LISTPROMPT should be unset for
2021-05-11 02:29:21 +02:00
the removal to take effect.</p>
<p><span id="index-list_002drows_002dfirst_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>list-rows-first</p>
<p>This style is tested in the same way as the list-packed style and
2021-05-11 02:29:21 +02:00
determines whether matches are to be listed in a rows-first fashion as
2022-08-24 15:22:41 +02:00
if the LIST_ROWS_FIRST option were set.</p>
<p><span id="index-list_002dseparator_002c-completion-style"></span></p>
<p>list-separator</p>
<p>The value of this style is used in completion listing to separate the
string to complete from a description when possible (e.g. when
completing options). It defaults to -- (two hyphens).</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-list_002dsuffixes_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>list-suffixes</p>
2021-05-11 02:29:21 +02:00
<p>This style is used by the function that completes filenames. If it is
true, and completion is attempted on a string containing multiple
partially typed pathname components, all ambiguous components will be
shown. Otherwise, completion stops at the first ambiguous component.</p>
<p><span id="index-local_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>local</p>
2021-05-11 02:29:21 +02:00
<p>This is for use with functions that complete URLs for which the
corresponding files are available directly from the file system. Its
value should consist of three strings: a hostname, the path to the
default web pages for the server, and the directory name used by a user
placing web pages within their home area.</p>
<p>For example:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*' local toast \
2021-05-11 02:29:21 +02:00
/var/http/public/toast public_html
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Completion after http://toast/stuff/ will look for files in the
directory /var/http/public/toast/stuff, while completion after
http://toast/~yousir/ will look for files in the directory
~yousir/public_html.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-mail_002ddirectory_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>mail-directory</p>
2021-05-11 02:29:21 +02:00
<p>If set, zsh will assume that mailbox files can be found in the directory
2022-08-24 15:22:41 +02:00
specified. It defaults to ~/Mail.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-match_002doriginal_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>match-original</p>
<p>This is used by the _match completer. If it is set to only, _match
will try to generate matches without inserting a * at the cursor
2021-05-11 02:29:21 +02:00
position. If set to any other non-empty value, it will first try to
2022-08-24 15:22:41 +02:00
generate matches without inserting the * and if that yields no
matches, it will try again with the * inserted. If it is unset or set
to the empty string, matching will only be performed with the *
2021-05-11 02:29:21 +02:00
inserted.</p>
<p><span id="index-matcher_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>matcher</p>
2021-05-11 02:29:21 +02:00
<p>This style is tested separately for each tag valid in the current
context. Its value is placed before any match specifications given by
2022-08-24 15:22:41 +02:00
the matcher-list style so can override them via the use of an x:
2021-05-11 02:29:21 +02:00
specification. The value should be in the form described in <a href="Completion-Widgets.html#Completion-Matching-Control">Completion
Matching Control</a>.
2022-08-24 15:22:41 +02:00
For examples of this, see the description of the tag-order style.</p>
<p>For notes comparing the use of this and the matcher-list style, see
under the description of the tag-order style.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-matcher_002dlist_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>matcher-list</p>
2021-05-11 02:29:21 +02:00
<p>This style can be set to a list of match specifications that are to be
applied everywhere. Match specifications are described in <a href="Completion-Widgets.html#Completion-Matching-Control">Completion
Matching Control</a>.
The completion system will try them one after another for each completer
selected. For example, to try first simple completion and, if that
generates no matches, case-insensitive completion:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}'
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>By default each specification replaces the previous one; however, if a
2022-08-24 15:22:41 +02:00
specification is prefixed with +, it is added to the existing list.
2021-05-11 02:29:21 +02:00
Hence it is possible to create increasingly general specifications
without repetition:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*' matcher-list \
2021-05-11 02:29:21 +02:00
'' '+m:{a-z}={A-Z}' '+m:{A-Z}={a-z}'
</code></pre>
</div>
<p>It is possible to create match specifications valid for particular
completers by using the third field of the context. This applies only to
completers that override the global matcher-list, which as of this
2022-08-24 15:22:41 +02:00
writing includes only _prefix and _ignored. For example, to use the
completers _complete and _prefix but allow case-insensitive completion
only with _complete:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*' completer _complete _prefix
2021-05-11 02:29:21 +02:00
zstyle ':completion:*:complete:*:*:*' matcher-list \
'' 'm:{a-zA-Z}={A-Za-z}'
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>User-defined names, as explained for the completer style, are available.
This makes it possible to try the same completer more than once with
different match specifications each time. For example, to try normal
completion without a match specification, then normal completion with
case-insensitive matching, then correction, and finally partial-word
completion:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*' completer \
2021-05-11 02:29:21 +02:00
_complete _correct _complete:foo
zstyle ':completion:*:complete:*:*:*' matcher-list \
'' 'm:{a-zA-Z}={A-Za-z}'
zstyle ':completion:*:foo:*:*:*' matcher-list \
'm:{a-zA-Z}={A-Za-z} r:|[-_./]=* r:|=*'
</code></pre>
</div>
<p>If the style is unset in any context no match specification is applied.
2022-08-24 15:22:41 +02:00
Note also that some completers such as _correct and _approximate do
2021-05-11 02:29:21 +02:00
not use the match specifications at all, though these completers will
2022-08-24 15:22:41 +02:00
only ever be called once even if the matcher-list contains more than one
element.</p>
2021-05-11 02:29:21 +02:00
<p>Where multiple specifications are useful, note that the <em>entire</em>
2022-08-24 15:22:41 +02:00
completion is done for each element of matcher-list, which can quickly
2021-05-11 02:29:21 +02:00
reduce the shells performance. As a rough rule of thumb, hand, putting
multiple space-separated values into the same string does not have an
appreciable impact on performance.</p>
<p>If there is no current matcher or it is empty, and the option
2022-08-24 15:22:41 +02:00
NO_CASE_GLOB is in effect, the matching for files is performed
2021-05-11 02:29:21 +02:00
case-insensitively in any case. However, any matcher must explicitly
specify case-insensitive matching if that is required.</p>
2022-08-24 15:22:41 +02:00
<p>For notes comparing the use of this and the matcher style, see under the
description of the tag-order style.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-max_002derrors_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>max-errors</p>
<p>This is used by the _approximate and _correct completer functions to
2021-05-11 02:29:21 +02:00
determine the maximum number of errors to allow. The completer will try
to generate completions by first allowing one error, then two errors,
and so on, until either a match or matches were found or the maximum
number of errors given by this style has been reached.</p>
2022-08-24 15:22:41 +02:00
<p>If the value for this style contains the string numeric, the completer
function will take any numeric argument as the maximum number of errors
allowed. For example, with</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*:approximate:::' max-errors 2 numeric
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>two errors are allowed if no numeric argument is given, but with a
2022-08-24 15:22:41 +02:00
numeric argument of six (as in ESC-6 TAB), up to six errors are
accepted. Hence with a value of 0 numeric, no correcting completion
2021-05-11 02:29:21 +02:00
will be attempted unless a numeric argument is given.</p>
2022-08-24 15:22:41 +02:00
<p>If the value contains the string not-numeric, the completer will <em>not</em>
try to generate corrected completions when given a numeric argument, so
in this case the number given should be greater than zero. For example,
2 not-numeric specifies that correcting completion with two errors
will usually be performed, but if a numeric argument is given,
correcting completion will not be performed.</p>
<p>The default value for this style is 2 numeric.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-max_002dmatches_002dwidth_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>max-matches-width</p>
2021-05-11 02:29:21 +02:00
<p>This style is used to determine the trade off between the width of the
display used for matches and the width used for their descriptions when
2022-08-24 15:22:41 +02:00
the verbose style is in effect. The value gives the number of display
2021-05-11 02:29:21 +02:00
columns to reserve for the matches. The default is half the width of the
screen.</p>
<p>This has the most impact when several matches have the same description
and so will be grouped together. Increasing the style will allow more
matches to be grouped together; decreasing it will allow more of the
description to be visible.</p>
<p><span id="index-menu_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>menu</p>
2021-05-11 02:29:21 +02:00
<p>If this is true in the context of any of the tags defined for the
current completion menu completion will be used. The value for a
2022-08-24 15:22:41 +02:00
specific tag will take precedence over that for the default tag.</p>
2021-05-11 02:29:21 +02:00
<p>If none of the values found in this way is true but at least one is
2022-08-24 15:22:41 +02:00
set to auto, the shell behaves as if the AUTO_MENU option is set.</p>
2021-05-11 02:29:21 +02:00
<p>If one of the values is explicitly set to false, menu completion will
2022-08-24 15:22:41 +02:00
be explicitly turned off, overriding the MENU_COMPLETE option and other
settings.</p>
<p>In the form yes=<code>num</code>, where yes may be any of the true values
(yes, true, on and 1), menu completion will be turned on if
there are at least <code>num</code> matches. In the form yes=long, menu
2021-05-11 02:29:21 +02:00
completion will be turned on if the list does not fit on the screen.
This does not activate menu completion if the widget normally only lists
completions, but menu completion can be activated in that case with the
2022-08-24 15:22:41 +02:00
value yes=long-list (Typically, the value select=long-list described
later is more useful as it provides control over scrolling.)</p>
<p>Similarly, with any of the false values (as in no=10), menu
2021-05-11 02:29:21 +02:00
completion will <em>not</em> be used if there are <code>num</code> or more matches.</p>
<p>The value of this widget also controls menu selection, as implemented by
2022-08-24 15:22:41 +02:00
the zsh/complist module. The following values may appear either
2021-05-11 02:29:21 +02:00
alongside or instead of the values above.</p>
2022-08-24 15:22:41 +02:00
<p>If the value contains the string select, menu selection will be
2021-05-11 02:29:21 +02:00
started unconditionally.</p>
2022-08-24 15:22:41 +02:00
<p>In the form select=<code>num</code>, menu selection will only be started if there
are at least <code>num</code> matches. If the values for more than one tag provide
a number, the smallest number is taken.</p>
2021-05-11 02:29:21 +02:00
<p>Menu selection can be turned off explicitly by defining a value
2022-08-24 15:22:41 +02:00
containing the stringno-select.</p>
2021-05-11 02:29:21 +02:00
<p>It is also possible to start menu selection only if the list of matches
2022-08-24 15:22:41 +02:00
does not fit on the screen by using the value select=long. To start
2021-05-11 02:29:21 +02:00
menu selection even if the current widget only performs listing, use the
2022-08-24 15:22:41 +02:00
value select=long-list.</p>
2021-05-11 02:29:21 +02:00
<p>To turn on menu completion or menu selection when there are a certain
number of matches <em>or</em> the list of matches does not fit on the screen,
2022-08-24 15:22:41 +02:00
both of yes= and select= may be given twice, once with a number and
once with long or long-list.</p>
2021-05-11 02:29:21 +02:00
<p>Finally, it is possible to activate two special modes of menu selection.
2022-08-24 15:22:41 +02:00
The word interactive in the value causes interactive mode to be
2021-05-11 02:29:21 +02:00
entered immediately when menu selection is started; see <a href="Zsh-Modules.html#The-zsh_002fcomplist-Module">The
zsh/complist Module</a> for a
2022-08-24 15:22:41 +02:00
description of interactive mode. Including the string search does the
same for incremental search mode. To select backward incremental search,
include the string search-backward.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-muttrc_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>muttrc</p>
2021-05-11 02:29:21 +02:00
<p>If set, gives the location of the mutt configuration file. It defaults
2022-08-24 15:22:41 +02:00
to ~/.muttrc.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-numbers_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>numbers</p>
<p>This is used with the jobs tag. If it is true, the shell will complete
job numbers instead of the shortest unambiguous prefix of the job
command text. If the value is a number, job numbers will only be used if
that many words from the job descriptions are required to resolve
ambiguities. For example, if the value is 1, strings will only be used
if all jobs differ in the first word on their command lines.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-old_002dlist_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>old-list</p>
<p>This is used by the _oldlist completer. If it is set to always, then
standard widgets which perform listing will retain the current list of
matches, however they were generated; this can be turned off explicitly
with the value never, giving the behaviour without the _oldlist
completer. If the style is unset, or any other value, then the existing
list of completions is displayed if it is not already; otherwise, the
standard completion list is generated; this is the default behaviour of
_oldlist. However, if there is an old list and this style contains the
name of the completer function that generated the list, then the old
list will be used even if it was generated by a widget which does not do
listing.</p>
<p>For example, suppose you type ^Xc to use the _correct_word widget,
2021-05-11 02:29:21 +02:00
which generates a list of corrections for the word under the cursor.
2022-08-24 15:22:41 +02:00
Usually, typing ^D would generate a standard list of completions for the
word on the command line, and show that. With _oldlist, it will instead
show the list of corrections already generated.</p>
<p>As another example consider the _match completer: with the
insert-unambiguous style set to true it inserts only a common prefix
2021-05-11 02:29:21 +02:00
string, if there is any. However, this may remove parts of the original
pattern, so that further completion could produce more matches than on
2022-08-24 15:22:41 +02:00
the first attempt. By using the _oldlist completer and setting this
style to _match, the list of matches generated on the first attempt
2021-05-11 02:29:21 +02:00
will be used again.</p>
<p><span id="index-old_002dmatches_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>old-matches</p>
<p>This is used by the _all_matches completer to decide if an old list of
2021-05-11 02:29:21 +02:00
matches should be used if one exists. This is selected by one of the
2022-08-24 15:22:41 +02:00
true values or by the string only. If the value is only,
_all_matches will only use an old list and wont have any effect on the
list of matches currently being generated.</p>
<p>If this style is set it is generally unwise to call the _all_matches
2021-05-11 02:29:21 +02:00
completer unconditionally. One possible use is for either this style or
2022-08-24 15:22:41 +02:00
the completer style to be defined with the -e option to zstyle to make
the style conditional.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-old_002dmenu_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>old-menu</p>
<p>This is used by the _oldlist completer. It controls how menu completion
behaves when a completion has already been inserted and the user types a
standard completion key such as TAB. The default behaviour of _oldlist
is that menu completion always continues with the existing list of
completions. If this style is set to false, however, a new completion
is started if the old list was generated by a different completion
command; this is the behaviour without the _oldlist completer.</p>
<p>For example, suppose you type ^Xc to generate a list of corrections, and
menu completion is started in one of the usual ways. Usually, or with
this style set to false, typing TAB at this point would start trying
to complete the line as it now appears. With _oldlist, it instead
continues to cycle through the list of corrections.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-original_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>original</p>
<p>This is used by the _approximate and _correct completers to decide if
the original string should be added as a possible completion. Normally,
this is done only if there are at least two possible corrections, but if
this style is set to true, it is always added. Note that the style
will be examined with the completer field in the context name set to
correct-<code>num</code> or approximate-<code>num</code>, where <code>num</code> is the number of errors
that were accepted.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-packageset_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>packageset</p>
<p>This style is used when completing arguments of the Debian dpkg
2021-05-11 02:29:21 +02:00
program. It contains an override for the default package set for a given
context. For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*:complete:dpkg:option--status-1:*' \
2021-05-11 02:29:21 +02:00
packageset avail
</code></pre>
</div>
<p>causes available packages, rather than only installed packages, to be
2022-08-24 15:22:41 +02:00
completed for dpkg --status.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-path_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>path</p>
<p>The function that completes color names uses this style with the colors
tag. The value should be the pathname of a file containing color names
in the format of an X11 rgb.txt file. If the style is not set but this
file is found in one of various standard locations it will be used as
the default.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-path_002dcompletion_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>path-completion</p>
2021-05-11 02:29:21 +02:00
<p>This is used by filename completion. By default, filename completion
examines all components of a path to see if there are completions of
2022-08-24 15:22:41 +02:00
that component. For example, /u/b/z can be completed to /usr/bin/zsh.
Explicitly setting this style to false inhibits this behaviour for
path components up to the / before the cursor; this overrides the
setting of accept-exact-dirs.</p>
2021-05-11 02:29:21 +02:00
<p>Even with the style set to false, it is still possible to complete
2022-08-24 15:22:41 +02:00
multiple paths by setting the option COMPLETE_IN_WORD and moving the
2021-05-11 02:29:21 +02:00
cursor back to the first component in the path to be completed. For
2022-08-24 15:22:41 +02:00
example, /u/b/z can be completed to /usr/bin/zsh if the cursor is after
the /u.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-pine_002ddirectory_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>pine-directory</p>
2021-05-11 02:29:21 +02:00
<p>If set, specifies the directory containing PINE mailbox files. There is
no default, since recursively searching this directory is inconvenient
for anyone who doesnt use PINE.</p>
<p><span id="index-ports_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>ports</p>
2021-05-11 02:29:21 +02:00
<p>A list of Internet service names (network ports) to complete. If this is
2022-08-24 15:22:41 +02:00
not set, service names are taken from the file /etc/services.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-prefix_002dhidden_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>prefix-hidden</p>
2021-05-11 02:29:21 +02:00
<p>This is used for certain completions which share a common prefix, for
example command options beginning with dashes. If it is true, the
prefix will not be shown in the list of matches.</p>
<p>The default value for this style is false.</p>
<p><span id="index-prefix_002dneeded_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>prefix-needed</p>
2021-05-11 02:29:21 +02:00
<p>This style is also relevant for matches with a common prefix. If it is
set to true this common prefix must be typed by the user to generate
the matches.</p>
2022-08-24 15:22:41 +02:00
<p>The style is applicable to the options, signals, jobs, functions, and
parameters completion tags.</p>
<p>For command options, this means that the initial -, +, or -- must
be typed explicitly before option names will be completed.</p>
<p>For signals, an initial - is required before signal names will be
2021-05-11 02:29:21 +02:00
completed.</p>
2022-08-24 15:22:41 +02:00
<p>For jobs, an initial % is required before job names will be completed.</p>
<p>For function and parameter names, an initial _ or . is required
2021-05-11 02:29:21 +02:00
before function or parameter names starting with those characters will
be completed.</p>
2022-08-24 15:22:41 +02:00
<p>The default value for this style is false for function and parameter
completions, and true otherwise.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-preserve_002dprefix_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>preserve-prefix</p>
2021-05-11 02:29:21 +02:00
<p>This style is used when completing path names. Its value should be a
pattern matching an initial prefix of the word to complete that should
be left unchanged under all circumstances. For example, on some Unices
2022-08-24 15:22:41 +02:00
an initial // (double slash) has a special meaning; setting this style
to the string // will preserve it. As another example, setting this
style to ?:/ under Cygwin would allow completion after a:/... and so
on.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-range_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>range</p>
<p>This is used by the _history completer and the _history_complete_word
bindable command to decide which words should be completed.</p>
2021-05-11 02:29:21 +02:00
<p>If it is a single number, only the last <code>N</code> words from the history will
be completed.</p>
2022-08-24 15:22:41 +02:00
<p>If it is a range of the form <code>max</code>:<code>slice</code>, the last <code>slice</code> words
2021-05-11 02:29:21 +02:00
will be completed; then if that yields no matches, the <code>slice</code> words
before those will be tried and so on. This process stops either when at
least one match has been found, or <code>max</code> words have been tried.</p>
<p>The default is to complete all words from the history at once.</p>
<p><span id="index-recursive_002dfiles_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>recursive-files</p>
2021-05-11 02:29:21 +02:00
<p>If this style is set, its value is an array of patterns to be tested
2022-08-24 15:22:41 +02:00
against $PWD/: note the trailing slash, which allows directories in
2021-05-11 02:29:21 +02:00
the pattern to be delimited unambiguously by including slashes on both
sides. If an ordinary file completion fails and the word on the command
line does not yet have a directory part to its name, the style is
retrieved using the same tag as for the completion just attempted, then
2022-08-24 15:22:41 +02:00
the elements tested against $PWD/ in turn. If one matches, then the
2021-05-11 02:29:21 +02:00
shell reattempts completion by prepending the word on the command line
2022-08-24 15:22:41 +02:00
with each directory in the expansion of **/*(/) in turn. Typically
the elements of the style will be set to restrict the number of
directories beneath the current one to a manageable number, for example
*/.git/*.</p>
2021-05-11 02:29:21 +02:00
<p>For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*' recursive-files '*/zsh/*'
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>If the current directory is /home/pws/zsh/Src, then zle_tr&lt;TAB&gt; can be
completed to Zle/zle_tricky.c.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-regular_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>regular</p>
<p>This style is used by the _expand_alias completer and bindable command.
If set to true (the default), regular aliases will be expanded but
only in command position. If it is set to false, regular aliases will
never be expanded. If it is set to always, regular aliases will be
expanded even if not in command position.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-rehash_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>rehash</p>
2021-05-11 02:29:21 +02:00
<p>If this is set when completing external commands, the internal list
2022-08-24 15:22:41 +02:00
(hash) of commands will be updated for each search by issuing the rehash
command. There is a speed penalty for this which is only likely to be
noticeable when directories in the path have slow file access.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-remote_002daccess_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>remote-access</p>
2021-05-11 02:29:21 +02:00
<p>If set to false, certain commands will be prevented from making
Internet connections to retrieve remote information. This includes the
2022-08-24 15:22:41 +02:00
completion for the CVS command.</p>
2021-05-11 02:29:21 +02:00
<p>It is not always possible to know if connections are in fact to a remote
site, so some may be prevented unnecessarily.</p>
<p><span id="index-remove_002dall_002ddups_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>remove-all-dups</p>
<p>The _history_complete_word bindable command and the _history completer
use this to decide if all duplicate matches should be removed, rather
than just consecutive duplicates.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-select_002dprompt_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>select-prompt</p>
<p>If this is set for the default tag, its value will be displayed during
menu selection (see the menu style above) when the completion list does
not fit on the screen as a whole. The same escapes as for the
list-prompt style are understood, except that the numbers refer to the
2021-05-11 02:29:21 +02:00
match or line the mark is on. A default prompt is used when the value is
the empty string.</p>
<p><span id="index-select_002dscroll_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>select-scroll</p>
<p>This style is tested for the default tag and determines how a completion
list is scrolled during a menu selection (see the menu style above) when
the completion list does not fit on the screen as a whole. If the value
is 0 (zero), the list is scrolled by half-screenfuls; if it is a
positive integer, the list is scrolled by the given number of lines; if
it is a negative number, the list is scrolled by a screenful minus the
absolute value of the given number of lines. The default is to scroll by
single lines.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-separate_002dsections_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>separate-sections</p>
<p>This style is used with the manuals tag when completing names of manual
pages. If it is true, entries for different sections are added
separately using tag names of the form manuals.<code>X</code>, where <code>X</code> is the
section number. When the group-name style is also in effect, pages from
different sections will appear separately. This style is also used
similarly with the words style when completing words for the dict
2021-05-11 02:29:21 +02:00
command. It allows words from different dictionary databases to be added
2022-08-24 15:22:41 +02:00
separately. See also insert-sections.</p>
<p>The default for this style is false.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-show_002dambiguity_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>show-ambiguity</p>
<p>If the zsh/complist module is loaded, this style can be used to
2021-05-11 02:29:21 +02:00
highlight the first ambiguous character in completion lists. The value
2022-08-24 15:22:41 +02:00
is either a color indication such as those supported by the list-colors
style or, with a value of true, a default of underlining is selected.
The highlighting is only applied if the completion display strings
correspond to the actual matches.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-show_002dcompleter_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>show-completer</p>
2021-05-11 02:29:21 +02:00
<p>Tested whenever a new completer is tried. If it is true, the
completion system outputs a progress message in the listing area showing
what completer is being tried. The message will be overwritten by any
output when completions are found and is removed after completion is
finished.</p>
<p><span id="index-single_002dignored_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>single-ignored</p>
<p>This is used by the _ignored completer when there is only one match. If
its value is show, the single match will be displayed but not
inserted. If the value is menu, then the single match and the original
string are both added as matches and menu completion is started, making
it easy to select either of them.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-sort_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>sort</p>
2021-05-11 02:29:21 +02:00
<p>This allows the standard ordering of matches to be overridden.</p>
2022-08-24 15:22:41 +02:00
<p>If its value is true or false, sorting is enabled or disabled.
Additionally the values associated with the -o option to compadd can
also be listed: match, nosort, numeric, reverse. If it is not set for
the context, the standard behaviour of the calling widget is used.</p>
2021-05-11 02:29:21 +02:00
<p>The style is tested first against the full context including the tag,
and if that fails to produce a value against the context without the
tag.</p>
<p>In many cases where a calling widget explicitly selects a particular
2022-08-24 15:22:41 +02:00
ordering in lieu of the default, a value of true is not honoured. An
2021-05-11 02:29:21 +02:00
example of where this is not the case is for command history where the
default of sorting matches chronologically may be overridden by setting
the style to true.</p>
2022-08-24 15:22:41 +02:00
<p>In the _expand completer, if it is set to true, the expansions
generated will always be sorted. If it is set to menu, then the
2021-05-11 02:29:21 +02:00
expansions are only sorted when they are offered as single strings but
not in the string containing all possible expansions.</p>
<p><span id="index-special_002ddirs_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>special-dirs</p>
<p>Normally, the completion code will not produce the directory names .
and .. as possible completions. If this style is set to true, it
will add both . and .. as possible completions; if it is set to
.., only .. will be added.</p>
<p>The following example sets special-dirs to .. when the current prefix
is empty, is a single ., or consists only of a path beginning with
../. Otherwise the value is false.</p>
<div class="example">
<pre><code class="language-zsh">zstyle -e ':completion:*' special-dirs \
2021-05-11 02:29:21 +02:00
'[[ $PREFIX = (../)#(|.|..) ]] &amp;&amp; reply=(..)'
</code></pre>
</div>
<p><span id="index-squeeze_002dslashes_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>squeeze-slashes</p>
2021-05-11 02:29:21 +02:00
<p>If set to true, sequences of slashes in filename paths (for example in
2022-08-24 15:22:41 +02:00
foo//bar) will be treated as a single slash. This is the usual
2021-05-11 02:29:21 +02:00
behaviour of UNIX paths. However, by default the file completion
2022-08-24 15:22:41 +02:00
function behaves as if there were a * between the slashes.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-stop_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>stop</p>
<p>If set to true, the _history_complete_word bindable command will stop
once when reaching the beginning or end of the history. Invoking
_history_complete_word will then wrap around to the opposite end of the
history. If this style is set to false (the default),
_history_complete_word will loop immediately as in a menu completion.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-strip_002dcomments_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>strip-comments</p>
2021-05-11 02:29:21 +02:00
<p>If set to true, this style causes non-essential comment text to be
removed from completion matches. Currently it is only used when
completing e-mail addresses where it removes any display name from the
addresses, cutting them down to plain <code>user@host</code> form.</p>
<p><span id="index-subst_002dglobs_002donly_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>subst-globs-only</p>
<p>This is used by the _expand completer. If it is set to true, the
2021-05-11 02:29:21 +02:00
expansion will only be used if it resulted from globbing; hence, if
2022-08-24 15:22:41 +02:00
expansions resulted from the use of the substitute style described
2021-05-11 02:29:21 +02:00
below, but these were not further changed by globbing, the expansions
will be rejected.</p>
<p>The default for this style is false.</p>
<p><span id="index-substitute_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>substitute</p>
<p>This boolean style controls whether the _expand completer will first
try to expand all substitutions in the string (such as $(<code>...</code>) and
${<code>...</code>}).</p>
2021-05-11 02:29:21 +02:00
<p>The default is true.</p>
<p><span id="index-suffix_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>suffix</p>
<p>This is used by the _expand completer if the word starts with a tilde
2021-05-11 02:29:21 +02:00
or contains a parameter expansion. If it is set to true, the word will
only be expanded if it doesnt have a suffix, i.e. if it is something
2022-08-24 15:22:41 +02:00
like ~foo or $foo rather than ~foo/ or $foo/bar, unless that
suffix itself contains characters eligible for expansion. The default
for this style is true.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-tag_002dorder_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>tag-order</p>
2021-05-11 02:29:21 +02:00
<p>This provides a mechanism for sorting how the tags available in a
particular context will be used.</p>
<p>The values for the style are sets of space-separated lists of tags. The
tags in each value will be tried at the same time; if no match is found,
2022-08-24 15:22:41 +02:00
the next value is used. (See the file-patterns style for an exception to
this behavior.)</p>
2021-05-11 02:29:21 +02:00
<p>For example:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*:complete:-command-:*:*' tag-order \
2021-05-11 02:29:21 +02:00
'commands functions'
</code></pre>
</div>
<p>specifies that completion in command position first offers external
commands and shell functions. Remaining tags will be tried if no
completions are found.</p>
<p>In addition to tag names, each string in the value may take one of the
following forms:</p>
2022-08-24 15:22:41 +02:00
<p>-<br />
If any value consists of only a hyphen, then <em>only</em> the tags specified
in the other values are generated. Normally all tags not explicitly
selected are tried last if the specified tags fail to generate any
matches. This means that a single value consisting only of a single
hyphen turns off completion.</p>
<p>! <code>tags</code>...<br />
A string starting with an exclamation mark specifies names of tags that
are <em>not</em> to be used. The effect is the same as if all other possible
tags for the context had been listed.</p>
<p><code>tag</code>:<code>label</code> ...<br />
2021-05-11 02:29:21 +02:00
Here, <code>tag</code> is one of the standard tags and <code>label</code> is an arbitrary
2022-08-24 15:22:41 +02:00
name. Matches are generated as normal but the name <code>label</code> is used in
contexts instead of <code>tag</code>. This is not useful in words starting with !.</p>
2021-05-11 02:29:21 +02:00
<p>If the <code>label</code> starts with a hyphen, the <code>tag</code> is prepended to the
2022-08-24 15:22:41 +02:00
<code>label</code> to form the name used for lookup. This can be used to make the
completion system try a certain tag more than once, supplying different
style settings for each attempt; see below for an example.</p>
<p><code>tag</code>:<code>label</code>:<code>description</code><br />
As before, but description will replace the %d in the value of the
format style instead of the default description supplied by the
completion function. Spaces in the description must be quoted with a
backslash. A %d appearing in <code>description</code> is replaced with the
description given by the completion function.</p>
2021-05-11 02:29:21 +02:00
<p>In any of the forms above the tag may be a pattern or several patterns
2022-08-24 15:22:41 +02:00
in the form {<code>pat1</code>,<code>pat2...</code>}. In this case all matching tags will be
used except for any given explicitly in the same string.</p>
2021-05-11 02:29:21 +02:00
<p>One use of these features is to try one tag more than once, setting
other styles differently on each attempt, but still to use all the other
tags without having to repeat them all. For example, to make completion
of function names in command position ignore all the completion
functions starting with an underscore the first time completion is
tried:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*:*:-command-:*:*' tag-order \
2021-05-11 02:29:21 +02:00
'functions:-non-comp *' functions
zstyle ':completion:*:functions-non-comp' \
ignored-patterns '_*'
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>On the first attempt, all tags will be offered but the functions tag
will be replaced by functions-non-comp. The ignored-patterns style is
set for this tag to exclude functions starting with an underscore. If
there are no matches, the second value of the tag-order style is used
2021-05-11 02:29:21 +02:00
which completes functions using the default tag, this time presumably
including all function names.</p>
<p>The matches for one tag can be split into different groups. For example:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*' tag-order \
2021-05-11 02:29:21 +02:00
'options:-long:long\ options
options:-short:short\ options
options:-single-letter:single\ letter\ options'
zstyle ':completion:*:options-long' \
ignored-patterns '[-+](|-|[^-]*)'
zstyle ':completion:*:options-short' \
ignored-patterns '--*' '[-+]?'
zstyle ':completion:*:options-single-letter' \
ignored-patterns '???*'
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>With the group-names style set, options beginning with --, options
beginning with a single - or + but containing multiple characters,
and single-letter options will be displayed in separate groups with
different descriptions.</p>
2021-05-11 02:29:21 +02:00
<p>Another use of patterns is to try multiple match specifications one
2022-08-24 15:22:41 +02:00
after another. The matcher-list style offers something similar, but it
2021-05-11 02:29:21 +02:00
is tested very early in the completion system and hence cant be set for
single commands nor for more specific contexts. Here is how to try
normal completion without any match specification and, if that generates
no matches, try again with case-insensitive matching, restricting the
2022-08-24 15:22:41 +02:00
effect to arguments of the command foo:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*:*:foo:*:*' tag-order '*' '*:-case'
2021-05-11 02:29:21 +02:00
zstyle ':completion:*-case' matcher 'm:{a-z}={A-Z}'
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>First, all the tags offered when completing after foo are tried using
2021-05-11 02:29:21 +02:00
the normal tag name. If that generates no matches, the second value of
2022-08-24 15:22:41 +02:00
tag-order is used, which tries all tags again except that this time each
has -case appended to its name for lookup of styles. Hence this time the
value for the matcher style from the second call to zstyle in the
example is used to make completion case-insensitive.</p>
<p>It is possible to use the -e option of the zstyle builtin command to
2021-05-11 02:29:21 +02:00
specify conditions for the use of particular tags. For example:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle -e '*:-command-:*' tag-order '
2021-05-11 02:29:21 +02:00
if [[ -n $PREFIX$SUFFIX ]]; then
reply=( )
else
reply=( - )
fi'
</code></pre>
</div>
<p>Completion in command position will be attempted only if the string
2022-08-24 15:22:41 +02:00
typed so far is not empty. This is tested using the PREFIX special
2021-05-11 02:29:21 +02:00
parameter; see <a href="Completion-Widgets.html#Completion-Widgets">Completion
Widgets</a> for a description
2022-08-24 15:22:41 +02:00
of parameters which are special inside completion widgets. Setting reply
to an empty array provides the default behaviour of trying all tags at
once; setting it to an array containing only a hyphen disables the use
of all tags and hence of all completions.</p>
<p>If no tag-order style has been defined for a context, the strings
(|*-)argument-* (|*-)option-* values and options plus all tags
2021-05-11 02:29:21 +02:00
offered by the completion function will be used to provide a sensible
default behavior that causes arguments (whether normal command arguments
or arguments of options) to be completed before option names for most
commands.</p>
<p><span id="index-urls_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>urls</p>
<p>This is used together with the urls tag by functions completing URLs.</p>
2021-05-11 02:29:21 +02:00
<p>If the value consists of more than one string, or if the only string
does not name a file or directory, the strings are used as the URLs to
complete.</p>
<p>If the value contains only one string which is the name of a normal file
the URLs are taken from that file (where the URLs may be separated by
white space or newlines).</p>
<p>Finally, if the only string in the value names a directory, the
directory hierarchy rooted at this directory gives the completions. The
2022-08-24 15:22:41 +02:00
top level directory should be the file access method, such as http,
ftp, bookmark and so on. In many cases the next level of directories
will be a filename. The directory hierarchy can descend as deep as
necessary.</p>
2021-05-11 02:29:21 +02:00
<p>For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*' urls ~/.urls
2021-05-11 02:29:21 +02:00
mkdir -p ~/.urls/ftp/ftp.zsh.org/pub
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>allows completion of all the components of the URL netscape or lynx.
Note, however, that access methods and files are completed separately,
so if the hosts style is set hosts can be completed without reference to
the urls style.</p>
<p>See the description in the function _urls itself for more information
(e.g. more $^fpath/_urls(N)).</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-use_002dcache_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>use-cache</p>
2021-05-11 02:29:21 +02:00
<p>If this is set, the completion caching layer is activated for any
2022-08-24 15:22:41 +02:00
completions which use it (via the _store_cache, _retrieve_cache, and
_cache_invalid functions). The directory containing the cache files can
be changed with the cache-path style.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-use_002dcompctl_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>use-compctl</p>
<p>If this style is set to a string <em>not</em> equal to false, 0, no, and off,
the completion system may use any completion specifications defined with
the compctl builtin command. If the style is unset, this is done only if
the zsh/compctl module is loaded. The string may also contain the
substring first to use completions defined with compctl -T, and the
substring default to use the completion defined with compctl -D.</p>
<p>Note that this is only intended to smooth the transition from compctl to
the new completion system and may disappear in the future.</p>
<p>Note also that the definitions from compctl will only be used if there
2021-05-11 02:29:21 +02:00
is no specific completion function for the command in question. For
2022-08-24 15:22:41 +02:00
example, if there is a function _foo to complete arguments to the
command foo, compctl will never be invoked for foo. However, the compctl
version will be tried if foo only uses default completion.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-use_002dip_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>use-ip</p>
<p>By default, the function _hosts that completes host names strips IP
2021-05-11 02:29:21 +02:00
addresses from entries read from host databases such as NIS and ssh
files. If this style is true, the corresponding IP addresses can be
2022-08-24 15:22:41 +02:00
completed as well. This style is not use in any context where the hosts
style is set; note also it must be set before the cache of host names is
generated (typically the first completion attempt).</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-users_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>users</p>
2021-05-11 02:29:21 +02:00
<p>This may be set to a list of usernames to be completed. If it is not set
all usernames will be completed. Note that if it is set only that list
of users will be completed; this is because on some systems querying all
users can take a prohibitive amount of time.</p>
<p><span id="index-users_002dhosts_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>users-hosts</p>
<p>The values of this style should be of the form <code>user</code>@<code>host</code> or
<code>user</code>:<code>host</code>. It is used for commands that need pairs of user- and
hostnames. These commands will complete usernames from this style
2021-05-11 02:29:21 +02:00
(only), and will restrict subsequent hostname completion to hosts paired
with that user in one of the values of the style.</p>
<p>It is possible to group values for sets of commands which allow a remote
2022-08-24 15:22:41 +02:00
login, such as rlogin and ssh, by using the my-accounts tag. Similarly,
values for sets of commands which usually refer to the accounts of other
people, such as talk and finger, can be grouped by using the
other-accounts tag. More ambivalent commands may use the accounts tag.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-users_002dhosts_002dports_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>users-hosts-ports</p>
<p>Like users-hosts but used for commands like telnet and containing
strings of the form <code>user</code>@<code>host</code>:<code>port</code>.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-verbose_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>verbose</p>
2021-05-11 02:29:21 +02:00
<p>If set, as it is by default, the completion listing is more verbose. In
particular many commands show descriptions for options if this style is
true.</p>
<p><span id="index-word_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>word</p>
<p>This is used by the _list completer, which prevents the insertion of
2021-05-11 02:29:21 +02:00
completions until a second completion attempt when the line has not
changed. The normal way of finding out if the line has changed is to
compare its entire contents between the two occasions. If this style is
true, the comparison is instead performed only on the current word.
Hence if completion is performed on another word with the same contents,
completion will not be delayed.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Control-Functions"></span> <span
id="Control-Functions-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="204-control-functions"><a class="header" href="#204-control-functions">20.4 Control Functions</a></h2>
<p><span id="index-completion-system_002c-choosing-completers"></span></p>
2022-08-24 15:22:41 +02:00
<p>The initialization script compinit redefines all the widgets which
perform completion to call the supplied widget function _main_complete.
This function acts as a wrapper calling the so-called completer
functions that generate matches. If _main_complete is called with
arguments, these are taken as the names of completer functions to be
called in the order given. If no arguments are given, the set of
functions to try is taken from the completer style. For example, to use
normal completion and correction if that doesnt generate any matches:</p>
<div class="example">
<pre><code class="language-zsh">zstyle ':completion:*' completer _complete _correct
</code></pre>
</div>
<p>after calling compinit. The default value for this style is _complete
_ignored, i.e. normally only ordinary completion is tried, first with
the effect of the ignored-patterns style and then without it. The
_main_complete function uses the return status of the completer
functions to decide if other completers should be called. If the return
status is zero, no other completers are tried and the _main_complete
function returns.</p>
<p>If the first argument to _main_complete is a single hyphen, the
2021-05-11 02:29:21 +02:00
arguments will not be taken as names of completers. Instead, the second
argument gives a name to use in the <code>completer</code> field of the context and
the other arguments give a command name and arguments to call to
generate the matches.</p>
<p>The following completer functions are contained in the distribution,
although users may write their own. Note that in contexts the leading
underscore is stripped, for example basic completion is performed in the
2022-08-24 15:22:41 +02:00
context :completion::complete:<code>...</code>.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-completion-system_002c-completers"></span></p>
<p><span id="index-_005fall_005fmatches"></span></p>
2022-08-24 15:22:41 +02:00
<p>_all_matches</p>
2021-05-11 02:29:21 +02:00
<p>This completer can be used to add a string consisting of all other
matches. As it influences later completers it must appear as the first
completer in the list. The list of all matches is affected by the
2022-08-24 15:22:41 +02:00
avoid-completer and old-matches styles described above.</p>
<p>It may be useful to use the _generic function described below to bind
_all_matches to its own keystroke, for example:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zle -C all-matches complete-word _generic
2021-05-11 02:29:21 +02:00
bindkey '^Xa' all-matches
zstyle ':completion:all-matches:*' old-matches only
zstyle ':completion:all-matches::::' completer _all_matches
</code></pre>
</div>
<p>Note that this does not generate completions by itself: first use any of
2022-08-24 15:22:41 +02:00
the standard ways of generating a list of completions, then use ^Xa to
2021-05-11 02:29:21 +02:00
show all matches. It is possible instead to add a standard completer to
the list and request that the list of all matches should be directly
inserted:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:all-matches::::' completer \
2021-05-11 02:29:21 +02:00
_all_matches _complete
zstyle ':completion:all-matches:*' insert true
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>In this case the old-matches style should not be set.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fapproximate"></span></p>
2022-08-24 15:22:41 +02:00
<p>_approximate</p>
<p>This is similar to the basic _complete completer but allows the
2021-05-11 02:29:21 +02:00
completions to undergo corrections. The maximum number of errors can be
2022-08-24 15:22:41 +02:00
specified by the max-errors style; see the description of approximate
2021-05-11 02:29:21 +02:00
matching in <a href="Expansion.html#Filename-Generation">Filename Generation</a>
for how errors are counted. Normally this completer will only be tried
2022-08-24 15:22:41 +02:00
after the normal _complete completer:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*' completer _complete _approximate
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>This will give correcting completion if and only if normal completion
yields no possible completions. When corrected completions are found,
the completer will normally start menu completion allowing you to cycle
through these strings.</p>
2022-08-24 15:22:41 +02:00
<p>This completer uses the tags corrections and original when generating
the possible corrections and the original string. The format style for
the former may contain the additional sequences %e and %o which will
be replaced by the number of errors accepted to generate the corrections
and the original string, respectively.</p>
2021-05-11 02:29:21 +02:00
<p>The completer progressively increases the number of errors allowed up to
2022-08-24 15:22:41 +02:00
the limit by the max-errors style, hence if a completion is found with
2021-05-11 02:29:21 +02:00
one error, no completions with two errors will be shown, and so on. It
modifies the completer name in the context to indicate the number of
errors being tried: on the first try the completer field contains
2022-08-24 15:22:41 +02:00
approximate-1, on the second try approximate-2, and so on.</p>
<p>When _approximate is called from another function, the number of errors
to accept may be passed with the -a option. The argument is in the same
format as the max-errors style, all in one string.</p>
<p>Note that this completer (and the _correct completer mentioned below)
2021-05-11 02:29:21 +02:00
can be quite expensive to call, especially when a large number of errors
2022-08-24 15:22:41 +02:00
are allowed. One way to avoid this is to set up the completer style
using the -e option to zstyle so that some completers are only used when
completion is attempted a second time on the same string, e.g.:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle -e ':completion:*' completer '
2021-05-11 02:29:21 +02:00
if [[ $_last_try != &quot;$HISTNO$BUFFER$CURSOR&quot; ]]; then
_last_try=&quot;$HISTNO$BUFFER$CURSOR&quot;
reply=(_complete _match _prefix)
else
reply=(_ignored _correct _approximate)
fi'
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>This uses the HISTNO parameter and the BUFFER and CURSOR special
2021-05-11 02:29:21 +02:00
parameters that are available inside zle and completion widgets to find
out if the command line hasnt changed since the last time completion
2022-08-24 15:22:41 +02:00
was tried. Only then are the _ignored, _correct and _approximate
2021-05-11 02:29:21 +02:00
completers called.</p>
<p><span id="index-_005fcanonical_005fpaths"></span></p>
2022-08-24 15:22:41 +02:00
<p>_canonical_paths [ -A <code>var</code> ] [ -N ] [ -MJV12nfX ] <code>tag</code> <code>descr</code>
[ <code>paths</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>This completion function completes all paths given to it, and also tries
to offer completions which point to the same file as one of the paths
given (relative path when an absolute path is given, and vice versa;
2022-08-24 15:22:41 +02:00
when ..s are present in the word to be completed; and some paths got
2021-05-11 02:29:21 +02:00
from symlinks).</p>
2022-08-24 15:22:41 +02:00
<p>-A, if specified, takes the paths from the array variable specified.
Paths can also be specified on the command line as shown above. -N, if
2021-05-11 02:29:21 +02:00
specified, prevents canonicalizing the paths given before using them for
2022-08-24 15:22:41 +02:00
completion, in case they are already so. The options -M, -J, -V, -1, -2,
-n, -F, -X are passed to compadd.</p>
<p>See _description for a description of <code>tag</code> and <code>descr</code>.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fcmdambivalent"></span></p>
2022-08-24 15:22:41 +02:00
<p>_cmdambivalent</p>
2021-05-11 02:29:21 +02:00
<p>Completes the remaining positional arguments as an external command. The
external command and its arguments are completed as separate arguments
2022-08-24 15:22:41 +02:00
(in a manner appropriate for completing /usr/bin/env) if there are two
2021-05-11 02:29:21 +02:00
or more remaining positional arguments on the command line, and as a
2022-08-24 15:22:41 +02:00
quoted command string (in the manner of system(...)) otherwise. See also
_cmdstring and _precommand.</p>
2021-05-11 02:29:21 +02:00
<p>This function takes no arguments.</p>
<p><span id="index-_005fcmdstring"></span></p>
2022-08-24 15:22:41 +02:00
<p>_cmdstring</p>
<p>Completes an external command as a single argument, as for system(...).</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fcomplete"></span></p>
2022-08-24 15:22:41 +02:00
<p>_complete</p>
2021-05-11 02:29:21 +02:00
<p>This completer generates all possible completions in a context-sensitive
2022-08-24 15:22:41 +02:00
manner, i.e. using the settings defined with the compdef function
2021-05-11 02:29:21 +02:00
explained above and the current settings of all special parameters. This
gives the normal completion behaviour.</p>
2022-08-24 15:22:41 +02:00
<p>To complete arguments of commands, _complete uses the utility function
_normal, which is in turn responsible for finding the particular
2021-05-11 02:29:21 +02:00
function; it is described below. Various contexts of the form
2022-08-24 15:22:41 +02:00
-<code>context</code>- are handled specifically. These are all mentioned above as
possible arguments to the #compdef tag.</p>
<p>Before trying to find a function for a specific context, _complete
checks if the parameter compcontext is set. Setting compcontext
2021-05-11 02:29:21 +02:00
allows the usual completion dispatching to be overridden which is useful
2022-08-24 15:22:41 +02:00
in places such as a function that uses vared for input. If it is set to
an array, the elements are taken to be the possible matches which will
be completed using the tag values and the description value. If it
is set to an associative array, the keys are used as the possible
completions and the values (if non-empty) are used as descriptions for
the matches. If compcontext is set to a string containing colons, it
should be of the form <code>tag</code>:<code>descr</code>:<code>action</code>. In this case the <code>tag</code>
and <code>descr</code> give the tag and description to use and the <code>action</code>
indicates what should be completed in one of the forms accepted by the
_arguments utility function described below.</p>
<p>Finally, if compcontext is set to a string without colons, the value
2021-05-11 02:29:21 +02:00
is taken as the name of the context to use and the function defined for
that context will be called. For this purpose, there is a special
2022-08-24 15:22:41 +02:00
context named -command-line- that completes whole command lines
2021-05-11 02:29:21 +02:00
(commands and their arguments). This is not used by the completion
system itself but is nonetheless handled when explicitly called.</p>
<p><span id="index-_005fcorrect"></span></p>
2022-08-24 15:22:41 +02:00
<p>_correct</p>
2021-05-11 02:29:21 +02:00
<p>Generate corrections, but not completions, for the current word; this is
2022-08-24 15:22:41 +02:00
similar to _approximate but will not allow any number of extra
2021-05-11 02:29:21 +02:00
characters at the cursor as that completer does. The effect is similar
2022-08-24 15:22:41 +02:00
to spell-checking. It is based on _approximate, but the completer field
in the context name is correct.</p>
2021-05-11 02:29:21 +02:00
<p>For example, with:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:::::' completer \
2021-05-11 02:29:21 +02:00
_complete _correct _approximate
zstyle ':completion:*:correct:::' max-errors 2 not-numeric
zstyle ':completion:*:approximate:::' max-errors 3 numeric
</code></pre>
</div>
<p>correction will accept up to two errors. If a numeric argument is given,
correction will not be performed, but correcting completion will be, and
will accept as many errors as given by the numeric argument. Without a
numeric argument, first correction and then correcting completion will
be tried, with the first one accepting two errors and the second one
accepting three errors.</p>
2022-08-24 15:22:41 +02:00
<p>When _correct is called as a function, the number of errors to accept
may be given following the -a option. The argument is in the same form a
values to the accept style, all in one string.</p>
<p>This completer function is intended to be used without the _approximate
completer or, as in the example, just before it. Using it after the
_approximate completer is useless since _approximate will at least
generate the corrected strings generated by the _correct completer —
and probably more.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fexpand"></span></p>
2022-08-24 15:22:41 +02:00
<p>_expand</p>
2021-05-11 02:29:21 +02:00
<p>This completer function does not really perform completion, but instead
checks if the word on the command line is eligible for expansion and, if
it is, gives detailed control over how this expansion is done. For this
2022-08-24 15:22:41 +02:00
to happen, the completion system needs to be invoked with complete-word,
not expand-or-complete (the default binding for TAB), as otherwise the
string will be expanded by the shells internal mechanism before the
completion system is started. Note also this completer should be called
before the _complete completer function.</p>
<p>The tags used when generating expansions are all-expansions for the
string containing all possible expansions, expansions when adding the
possible expansions as single matches and original when adding the
2021-05-11 02:29:21 +02:00
original string from the line. The order in which these strings are
2022-08-24 15:22:41 +02:00
generated, if at all, can be controlled by the group-order and tag-order
styles, as usual.</p>
<p>The format string for all-expansions and for expansions may contain the
sequence %o which will be replaced by the original string from the
line.</p>
<p>The kind of expansion to be tried is controlled by the substitute, glob
and subst-globs-only styles.</p>
<p>It is also possible to call _expand as a function, in which case the
different modes may be selected with options: -s for substitute, -g for
glob and -o for subst-globs-only.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fexpand_005falias"></span></p>
2022-08-24 15:22:41 +02:00
<p>_expand_alias</p>
2021-05-11 02:29:21 +02:00
<p>If the word the cursor is on is an alias, it is expanded and no other
completers are called. The types of aliases which are to be expanded can
2022-08-24 15:22:41 +02:00
be controlled with the styles regular, global and disabled.</p>
2021-05-11 02:29:21 +02:00
<p>This function is also a bindable command, see <a href="Completion-System.html#Bindable-Commands">Bindable
Commands</a>.</p>
<p><span id="index-_005fextensions"></span></p>
2022-08-24 15:22:41 +02:00
<p>_extensions</p>
<p>If the cursor follows the string *., filename extensions are
2021-05-11 02:29:21 +02:00
completed. The extensions are taken from files in current directory or a
directory specified at the beginning of the current word. For exact
2022-08-24 15:22:41 +02:00
matches, completion continues to allow other completers such as _expand
to expand the pattern. The standard add-space and prefix-hidden styles
are observed.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fexternal_005fpwds"></span></p>
2022-08-24 15:22:41 +02:00
<p>_external_pwds</p>
2021-05-11 02:29:21 +02:00
<p>Completes current directories of other zsh processes belonging to the
current user.</p>
2022-08-24 15:22:41 +02:00
<p>This is intended to be used via _generic, bound to a custom key
2021-05-11 02:29:21 +02:00
combination. Note that pattern matching is enabled so matching is
2022-08-24 15:22:41 +02:00
performed similar to how it works with the _match completer.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fhistory"></span></p>
2022-08-24 15:22:41 +02:00
<p>_history</p>
2021-05-11 02:29:21 +02:00
<p>Complete words from the shells command history. This completer can be
2022-08-24 15:22:41 +02:00
controlled by the remove-all-dups, and sort styles as for the
_history_complete_word bindable command, see <a href="Completion-System.html#Bindable-Commands">Bindable
2021-05-11 02:29:21 +02:00
Commands</a> and <a href="Completion-System.html#Completion-System-Configuration">Completion System
Configuration</a>.</p>
<p><span id="index-_005fignored"></span></p>
2022-08-24 15:22:41 +02:00
<p>_ignored</p>
<p>The ignored-patterns style can be set to a list of patterns which are
2021-05-11 02:29:21 +02:00
compared against possible completions; matching ones are removed. With
this completer those matches can be reinstated, as if no
2022-08-24 15:22:41 +02:00
ignored-patterns style were set. The completer actually generates its
2021-05-11 02:29:21 +02:00
own list of matches; which completers are invoked is determined in the
2022-08-24 15:22:41 +02:00
same way as for the _prefix completer. The single-ignored style is also
available as described above.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005flist"></span></p>
2022-08-24 15:22:41 +02:00
<p>_list</p>
2021-05-11 02:29:21 +02:00
<p>This completer allows the insertion of matches to be delayed until
completion is attempted a second time without the word on the line being
changed. On the first attempt, only the list of matches will be shown.
2022-08-24 15:22:41 +02:00
It is affected by the styles condition and word, see <a href="Completion-System.html#Completion-System-Configuration">Completion System
Configuration</a>.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fmatch"></span></p>
2022-08-24 15:22:41 +02:00
<p>_match</p>
<p>This completer is intended to be used after the _complete completer. It
behaves similarly but the string on the command line may be a pattern to
match against trial completions. This gives the effect of the
GLOB_COMPLETE option.</p>
2021-05-11 02:29:21 +02:00
<p>Normally completion will be performed by taking the pattern from the
2022-08-24 15:22:41 +02:00
line, inserting a * at the cursor position and comparing the
2021-05-11 02:29:21 +02:00
resulting pattern with the possible completions generated. This can be
2022-08-24 15:22:41 +02:00
modified with the match-original style described above.</p>
2021-05-11 02:29:21 +02:00
<p>The generated matches will be offered in a menu completion unless the
2022-08-24 15:22:41 +02:00
insert-unambiguous style is set to true; see the description above for
other options for this style.</p>
2021-05-11 02:29:21 +02:00
<p>Note that matcher specifications defined globally or used by the
2022-08-24 15:22:41 +02:00
completion functions (the styles matcher-list and matcher) will not be
used.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fmenu"></span></p>
2022-08-24 15:22:41 +02:00
<p>_menu</p>
2021-05-11 02:29:21 +02:00
<p>This completer was written as simple example function to show how menu
2022-08-24 15:22:41 +02:00
effect of disabling menu selection which can be useful with _generic
2021-05-11 02:29:21 +02:00
based widgets. It should be used as the first completer in the list.
2022-08-24 15:22:41 +02:00
Note that this is independent of the setting of the MENU_COMPLETE option
and does not work with the other menu completion widgets such as
reverse-menu-complete, or accept-and-menu-complete.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005foldlist"></span></p>
2022-08-24 15:22:41 +02:00
<p>_oldlist</p>
2021-05-11 02:29:21 +02:00
<p>This completer controls how the standard completion widgets behave when
there is an existing list of completions which may have been generated
by a special completion (i.e. a separately-bound completion command). It
allows the ordinary completion keys to continue to use the list of
completions thus generated, instead of producing a new list of ordinary
contextual completions. It should appear in the list of completers
before any of the widgets which generate matches. It uses two styles:
2022-08-24 15:22:41 +02:00
old-list and old-menu, see <a href="Completion-System.html#Completion-System-Configuration">Completion System
2021-05-11 02:29:21 +02:00
Configuration</a>.</p>
<p><span id="index-_005fprecommand"></span></p>
2022-08-24 15:22:41 +02:00
<p>_precommand</p>
<p>Complete an external command in word-separated arguments, as for exec
and /usr/bin/env.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fprefix"></span></p>
2022-08-24 15:22:41 +02:00
<p>_prefix</p>
2021-05-11 02:29:21 +02:00
<p>This completer can be used to try completion with the suffix (everything
after the cursor) ignored. In other words, the suffix will not be
considered to be part of the word to complete. The effect is similar to
2022-08-24 15:22:41 +02:00
the expand-or-complete-prefix command.</p>
<p>The completer style is used to decide which other completers are to be
2021-05-11 02:29:21 +02:00
called to generate matches. If this style is unset, the list of
completers set for the current context is used — except, of course, the
2022-08-24 15:22:41 +02:00
_prefix completer itself. Furthermore, if this completer appears more
2021-05-11 02:29:21 +02:00
than once in the list of completers only those completers not already
2022-08-24 15:22:41 +02:00
tried by the last invocation of _prefix will be called.</p>
<p>For example, consider this global completer style:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*' completer \
2021-05-11 02:29:21 +02:00
_complete _prefix _correct _prefix:foo
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Here, the _prefix completer tries normal completion but ignoring the
2021-05-11 02:29:21 +02:00
suffix. If that doesnt generate any matches, and neither does the call
2022-08-24 15:22:41 +02:00
to the _correct completer after it, _prefix will be called a second
2021-05-11 02:29:21 +02:00
time and, now only trying correction with the suffix ignored. On the
2022-08-24 15:22:41 +02:00
second invocation the completer part of the context appears as foo.</p>
<p>To use _prefix as the last resort and try only normal completion when
2021-05-11 02:29:21 +02:00
it is invoked:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*' completer _complete ... _prefix
2021-05-11 02:29:21 +02:00
zstyle ':completion::prefix:*' completer _complete
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The add-space style is also respected. If it is set to true then
_prefix will insert a space between the matches generated (if any) and
2021-05-11 02:29:21 +02:00
the suffix.</p>
2022-08-24 15:22:41 +02:00
<p>Note that this completer is only useful if the COMPLETE_IN_WORD option
2021-05-11 02:29:21 +02:00
is set; otherwise, the cursor will be moved to the end of the current
word before the completion code is called and hence there will be no
suffix.</p>
<p><span id="index-_005fuser_005fexpand"></span></p>
2022-08-24 15:22:41 +02:00
<p>_user_expand</p>
<p>This completer behaves similarly to the _expand completer but instead
performs expansions defined by users. The styles add-space and sort
styles specific to the _expand completer are usable with _user_expand
in addition to other styles handled more generally by the completion
system. The tag all-expansions is also available.</p>
<p>The expansion depends on the array style user-expand being defined for
2021-05-11 02:29:21 +02:00
the current context; remember that the context for completers is less
specific than that for contextual completion as the full context has not
yet been determined. Elements of the array may have one of the following
forms:</p>
2022-08-24 15:22:41 +02:00
<p>$<code>hash</code><br />
2021-05-11 02:29:21 +02:00
<code>hash</code> is the name of an associative array. Note this is not a full
2022-08-24 15:22:41 +02:00
parameter expression, merely a $, suitably quoted to prevent immediate
expansion, followed by the name of an associative array. If the trial
expansion word matches a key in <code>hash</code>, the resulting expansion is the
corresponding value.</p>
2021-05-11 02:29:21 +02:00
<p><code>_func</code><br />
2022-08-24 15:22:41 +02:00
<code>_func</code> is the name of a shell function whose name must begin with _
but is not otherwise special to the completion system. The function is
called with the trial word as an argument. If the word is to be
expanded, the function should set the array reply to a list of
expansions. Optionally, it can set REPLY to a word that will be used as
a description for the set of expansions. The return status of the
function is irrelevant.</p>
<hr />
<p><span id="Bindable-Commands"></span> <span
id="Bindable-Commands-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="205-bindable-commands"><a class="header" href="#205-bindable-commands">20.5 Bindable Commands</a></h2>
<p><span id="index-completion-system_002c-bindable-commands"></span></p>
<p>In addition to the context-dependent completions provided, which are
expected to work in an intuitively obvious way, there are a few widgets
implementing special behaviour which can be bound separately to keys.
The following is a list of these and their default bindings.</p>
<p><span id="index-_005fbash_005fcompletions"></span></p>
2022-08-24 15:22:41 +02:00
<p>_bash_completions</p>
<p>This function is used by two widgets, _bash_complete-word and
_bash_list-choices. It exists to provide compatibility with completion
2021-05-11 02:29:21 +02:00
bindings in bash. The last character of the binding determines what is
2022-08-24 15:22:41 +02:00
completed: !, command names; $, environment variables; @, host
names; /, file names; ~ user names. In bash, the binding preceded
by \e gives completion, and preceded by ^X lists options. As some
of these bindings clash with standard zsh bindings, only \e~ and
^X~ are bound by default. To add the rest, the following should be
added to .zshrc after compinit has been run:</p>
<div class="example">
<pre><code class="language-zsh">for key in '!' '$' '@' '/' '~'; do
2021-05-11 02:29:21 +02:00
bindkey &quot;\e$key&quot; _bash_complete-word
bindkey &quot;^X$key&quot; _bash_list-choices
done
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>This includes the bindings for ~ in case they were already bound to
2021-05-11 02:29:21 +02:00
something else; the completion code does not override user bindings.</p>
<p><span id="index-_005fcorrect_005ffilename-_0028_005eXC_0029"></span></p>
2022-08-24 15:22:41 +02:00
<p>_correct_filename (^XC)</p>
2021-05-11 02:29:21 +02:00
<p>Correct the filename path at the cursor position. Allows up to six
errors in the name. Can also be called with an argument to correct a
filename path, independently of zle; the correction is printed on
standard output.</p>
<p><span id="index-_005fcorrect_005fword-_0028_005eXc_0029"></span></p>
2022-08-24 15:22:41 +02:00
<p>_correct_word (^Xc)</p>
2021-05-11 02:29:21 +02:00
<p>Performs correction of the current argument using the usual contextual
2022-08-24 15:22:41 +02:00
completions as possible choices. This stores the string correct-word
in the <code>function</code> field of the context name and then calls the _correct
completer.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fexpand_005falias-_0028_005eXa_0029"></span></p>
2022-08-24 15:22:41 +02:00
<p>_expand_alias (^Xa)</p>
2021-05-11 02:29:21 +02:00
<p>This function can be used as a completer and as a bindable command. It
expands the word the cursor is on if it is an alias. The types of alias
2022-08-24 15:22:41 +02:00
expanded can be controlled with the styles regular, global and disabled.</p>
2021-05-11 02:29:21 +02:00
<p>When used as a bindable command there is one additional feature that can
2022-08-24 15:22:41 +02:00
be selected by setting the complete style to true. In this case, if
the word is not the name of an alias, _expand_alias tries to complete
2021-05-11 02:29:21 +02:00
the word to a full alias name without expanding it. It leaves the cursor
2022-08-24 15:22:41 +02:00
directly after the completed word so that invoking _expand_alias once
2021-05-11 02:29:21 +02:00
more will expand the now-complete alias name.</p>
<p><span id="index-_005fexpand_005fword-_0028_005eXe_0029"></span></p>
2022-08-24 15:22:41 +02:00
<p>_expand_word (^Xe)</p>
2021-05-11 02:29:21 +02:00
<p>Performs expansion on the current word: equivalent to the standard
2022-08-24 15:22:41 +02:00
expand-word command, but using the _expand completer. Before calling
it, the <code>function</code> field of the context is set to expand-word.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fgeneric"></span></p>
2022-08-24 15:22:41 +02:00
<p>_generic</p>
2021-05-11 02:29:21 +02:00
<p>This function is not defined as a widget and not bound by default.
However, it can be used to define a widget and will then store the name
of the widget in the <code>function</code> field of the context and call the
completion system. This allows custom completion widgets with their own
set of style settings to be defined easily. For example, to define a
widget that performs normal completion and starts menu selection:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zle -C foo complete-word _generic
2021-05-11 02:29:21 +02:00
bindkey '...' foo
zstyle ':completion:foo:*' menu yes select=1
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Note in particular that the completer style may be set for the context
2021-05-11 02:29:21 +02:00
in order to change the set of functions used to generate possible
2022-08-24 15:22:41 +02:00
matches. If _generic is called with arguments, those are passed through
to _main_complete as the list of completers in place of those defined
by the completer style.</p>
<p><span
id="index-_005fhistory_005fcomplete_005fword-_0028_005ce_002f_0029"></span></p>
<p>_history_complete_word (\e/)</p>
<p>Complete words from the shells command history. This uses the list,
remove-all-dups, sort, and stop styles.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fmost_005frecent_005ffile-_0028_005eXm_0029"></span></p>
2022-08-24 15:22:41 +02:00
<p>_most_recent_file (^Xm)</p>
2021-05-11 02:29:21 +02:00
<p>Complete the name of the most recently modified file matching the
pattern on the command line (which may be blank). If given a numeric
argument <code>N</code>, complete the <code>N</code>th most recently modified file. Note the
completion, if any, is always unique.</p>
<p><span id="index-_005fnext_005ftags-_0028_005eXn_0029"></span></p>
2022-08-24 15:22:41 +02:00
<p>_next_tags (^Xn)</p>
2021-05-11 02:29:21 +02:00
<p>This command alters the set of matches used to that for the next tag, or
2022-08-24 15:22:41 +02:00
set of tags, either as given by the tag-order style or as set by
2021-05-11 02:29:21 +02:00
default; these matches would otherwise not be available. Successive
invocations of the command cycle through all possible sets of tags.</p>
<p><span id="index-_005fread_005fcomp-_0028_005eX_005eR_0029"></span></p>
2022-08-24 15:22:41 +02:00
<p>_read_comp (^X^R)</p>
2021-05-11 02:29:21 +02:00
<p>Prompt the user for a string, and use that to perform completion on the
current word. There are two possibilities for the string. First, it can
2022-08-24 15:22:41 +02:00
be a set of words beginning _, for example _files -/, in which
2021-05-11 02:29:21 +02:00
case the function with any arguments will be called to generate the
completions. Unambiguous parts of the function name will be completed
automatically (normal completion is not available at this point) until a
space is typed.</p>
2022-08-24 15:22:41 +02:00
<p>Second, any other string will be passed as a set of arguments to compadd
and should hence be an expression specifying what should be completed.</p>
2021-05-11 02:29:21 +02:00
<p>A very restricted set of editing commands is available when reading the
2022-08-24 15:22:41 +02:00
string: DEL and ^H delete the last character; ^U deletes the line,
and ^C and ^G abort the function, while RET accepts the
completion. Note the string is used verbatim as a command line, so
2021-05-11 02:29:21 +02:00
arguments must be quoted in accordance with standard shell rules.</p>
2022-08-24 15:22:41 +02:00
<p>Once a string has been read, the next call to _read_comp will use the
2021-05-11 02:29:21 +02:00
existing string instead of reading a new one. To force a new string to
2022-08-24 15:22:41 +02:00
be read, call _read_comp with a numeric argument.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fcomplete_005fdebug-_0028_005eX_003f_0029"></span></p>
2022-08-24 15:22:41 +02:00
<p>_complete_debug (^X?)</p>
2021-05-11 02:29:21 +02:00
<p>This widget performs ordinary completion, but captures in a temporary
file a trace of the shell commands executed by the completion system.
Each completion attempt gets its own file. A command to view each of
these files is pushed onto the editor buffer stack.</p>
<p><span id="index-_005fcomplete_005fhelp-_0028_005eXh_0029"></span></p>
2022-08-24 15:22:41 +02:00
<p>_complete_help (^Xh)</p>
2021-05-11 02:29:21 +02:00
<p>This widget displays information about the context names, the tags, and
the completion functions used when completing at the current cursor
2022-08-24 15:22:41 +02:00
position. If given a numeric argument other than 1 (as in ESC-2 ^Xh),
then the styles used and the contexts for which they are used will be
shown, too.</p>
2021-05-11 02:29:21 +02:00
<p>Note that the information about styles may be incomplete; it depends on
the information available from the completion functions called, which in
turn is determined by the users own styles and other settings.</p>
<p><span id="index-_005fcomplete_005fhelp_005fgeneric"></span></p>
2022-08-24 15:22:41 +02:00
<p>_complete_help_generic</p>
2021-05-11 02:29:21 +02:00
<p>Unlike other commands listed here, this must be created as a normal ZLE
2022-08-24 15:22:41 +02:00
widget rather than a completion widget (i.e. with zle -N). It is used
for generating help with a widget bound to the _generic widget that is
2021-05-11 02:29:21 +02:00
described above.</p>
<p>If this widget is created using the name of the function, as it is by
default, then when executed it will read a key sequence. This is
expected to be bound to a call to a completion function that uses the
2022-08-24 15:22:41 +02:00
_generic widget. That widget will be executed, and information provided
in the same format that the _complete_help widget displays for
2021-05-11 02:29:21 +02:00
contextual completion.</p>
2022-08-24 15:22:41 +02:00
<p>If the widgets name contains debug, for example if it is created as
zle -N _complete_debug_generic _complete_help_generic, it will read
and execute the keystring for a generic widget as before, but then
generate debugging information as done by _complete_debug for
contextual completion.</p>
<p>If the widgets name contains noread, it will not read a keystring but
2021-05-11 02:29:21 +02:00
instead arrange that the next use of a generic widget run in the same
shell will have the effect as described above.</p>
2022-08-24 15:22:41 +02:00
<p>The widget works by setting the shell parameter ZSH_TRACE_GENERIC_WIDGET
which is read by _generic. Unsetting the parameter cancels any pending
effect of the noread form.</p>
2021-05-11 02:29:21 +02:00
<p>For example, after executing the following:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zle -N _complete_debug_generic _complete_help_generic
2021-05-11 02:29:21 +02:00
bindkey '^x:' _complete_debug_generic
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>typing C-x : followed by the key sequence for a generic widget will
2021-05-11 02:29:21 +02:00
cause trace output for that widget to be saved to a file.</p>
<p><span id="index-_005fcomplete_005ftag-_0028_005eXt_0029"></span></p>
2022-08-24 15:22:41 +02:00
<p>_complete_tag (^Xt)</p>
<p>This widget completes symbol tags created by the etags or ctags
2021-05-11 02:29:21 +02:00
programmes (note there is no connection with the completion systems
2022-08-24 15:22:41 +02:00
tags) stored in a file TAGS, in the format used by etags, or tags, in
the format created by ctags. It will look back up the path hierarchy for
the first occurrence of either file; if both exist, the file TAGS is
preferred. You can specify the full path to a TAGS or tags file by
setting the parameter $TAGSFILE or $tagsfile respectively. The
corresponding completion tags used are etags and vtags, after emacs and
vi respectively.</p>
<hr />
<p><span id="Completion-Functions"></span> <span
id="Utility-Functions-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="206-utility-functions"><a class="header" href="#206-utility-functions">20.6 Utility Functions</a></h2>
<p><span id="index-completion-system_002c-utility-functions"></span></p>
<p>Descriptions follow for utility functions that may be useful when
writing completion functions. If functions are installed in
2022-08-24 15:22:41 +02:00
subdirectories, most of these reside in the Base subdirectory. Like the
example functions for commands in the distribution, the utility
2021-05-11 02:29:21 +02:00
functions generating matches all follow the convention of returning
status zero if they generated completions and non-zero if no matching
completions could be added.</p>
<p><span id="index-_005fabsolute_005fcommand_005fpaths"></span></p>
2022-08-24 15:22:41 +02:00
<p>_absolute_command_paths</p>
2021-05-11 02:29:21 +02:00
<p>This function completes external commands as absolute paths (unlike
2022-08-24 15:22:41 +02:00
_command_names -e which completes their basenames). It takes no
2021-05-11 02:29:21 +02:00
arguments.</p>
<p><span id="index-_005fall_005flabels"></span></p>
2022-08-24 15:22:41 +02:00
<p>_all_labels [ -x ] [ -12VJ ] <code>tag</code> <code>name</code> <code>descr</code> [ <code>command</code>
2021-05-11 02:29:21 +02:00
<code>arg</code> ... ]</p>
2022-08-24 15:22:41 +02:00
<p>This is a convenient interface to the _next_label function below,
implementing the loop shown in the _next_label example. The <code>command</code>
2021-05-11 02:29:21 +02:00
and its arguments are called to generate the matches. The options stored
in the parameter <code>name</code> will automatically be inserted into the <code>arg</code>s
passed to the <code>command</code>. Normally, they are put directly after the
<code>command</code>, but if one of the <code>arg</code>s is a single hyphen, they are
inserted directly before that. If the hyphen is the last argument, it
will be removed from the argument list before the <code>command</code> is called.
2022-08-24 15:22:41 +02:00
This allows _all_labels to be used in almost all cases where the
matches can be generated by a single call to the compadd builtin command
or by a call to one of the utility functions.</p>
2021-05-11 02:29:21 +02:00
<p>For example:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">local expl
2021-05-11 02:29:21 +02:00
...
if _requested foo; then
...
_all_labels foo expl '...' compadd ... - $matches
fi
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Will complete the strings from the matches parameter, using compadd with
additional options which will take precedence over those generated by
_all_labels.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005falternative"></span></p>
2022-08-24 15:22:41 +02:00
<p>_alternative [ -O <code>name</code> ] [ -C <code>name</code> ] <code>spec</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>This function is useful in simple cases where multiple tags are
available. Essentially it implements a loop like the one described for
2022-08-24 15:22:41 +02:00
the _tags function below.</p>
2021-05-11 02:29:21 +02:00
<p>The tags to use and the action to perform if a tag is requested are
described using the <code>spec</code>s which are of the form:
2022-08-24 15:22:41 +02:00
<code>tag</code>:<code>descr</code>:<code>action</code>. The <code>tag</code>s are offered using _tags and if the
tag is requested, the <code>action</code> is executed with the given description
<code>descr</code>. The <code>action</code>s are those accepted by the _arguments function
(described below), with the following exceptions:</p>
<ul>
<li>The -&gt;<code>state</code> and =<code>...</code> forms are not supported.</li>
<li>The ((a\:bar b\:baz)) form does not need the colon to be
escaped, since the <code>spec</code>s have no colon-separated fields after the
<code>action</code>.</li>
</ul>
2021-05-11 02:29:21 +02:00
<p>For example, the <code>action</code> may be a simple function call:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">_alternative \
2021-05-11 02:29:21 +02:00
'users:user:_users' \
'hosts:host:_hosts'
</code></pre>
</div>
<p>offers usernames and hostnames as possible matches, generated by the
2022-08-24 15:22:41 +02:00
_users and _hosts functions respectively.</p>
<p>Like _arguments, this function uses _all_labels to execute the
2021-05-11 02:29:21 +02:00
actions, which will loop over all sets of tags. Special handling is only
required if there is an additional valid tag, for example inside a
2022-08-24 15:22:41 +02:00
function called from _alternative.</p>
<p>The option -O <code>name</code> is used in the same way as by the _arguments
2021-05-11 02:29:21 +02:00
function. In other words, the elements of the <code>name</code> array will be
2022-08-24 15:22:41 +02:00
passed to compadd when executing an action.</p>
<p>Like _tags this function supports the -C option to give a different
2021-05-11 02:29:21 +02:00
name for the argument context field.</p>
<p><span id="index-_005farguments"></span></p>
2022-08-24 15:22:41 +02:00
<p>_arguments [ -nswWCRS ] [ -A <code>pat</code> ] [ -O <code>name</code> ] [ -M
<code>matchspec</code> ]</p>
<p>           [ : ] <code>spec</code> ...</p>
<p>_arguments [ <code>opt</code> ... ] -- [ -l ] [ -i <code>pats</code> ] [ -s <code>pair</code> ]</p>
<p>           [ <code>helpspec</code> ...]</p>
2021-05-11 02:29:21 +02:00
<p>This function can be used to give a complete specification for
completion for a command whose arguments follow standard UNIX option and
argument conventions.</p>
<p><em>Options Overview</em></p>
2022-08-24 15:22:41 +02:00
<p>Options to _arguments itself must be in separate words, i.e. -s -w, not
-sw. The options are followed by <code>spec</code>s that describe options and
2021-05-11 02:29:21 +02:00
arguments of the analyzed command. To avoid ambiguity, all options to
2022-08-24 15:22:41 +02:00
_arguments itself may be separated from the <code>spec</code> forms by a single
2021-05-11 02:29:21 +02:00
colon.</p>
2022-08-24 15:22:41 +02:00
<p>The -- form is used to intuit <code>spec</code> forms from the help output of the
command being analyzed, and is described in detail below. The <code>opts</code> for
the -- form are otherwise the same options as the first form. Note
that -s following -- has a distinct meaning from -s preceding
--, and both may appear.</p>
<p>The option switches -s, -S, -A, -w, and -W affect how _arguments parses
the analyzed command lines options. These switches are useful for
commands with standard argument parsing.</p>
<p>The options of _arguments have the following meanings:</p>
<p>-n<br />
With this option, _arguments sets the parameter NORMARG to the position
of the first normal argument in the $words array, i.e. the position
after the end of the options. If that argument has not been reached,
NORMARG is set to -1. The caller should declare integer NORMARG if the
-n option is passed; otherwise the parameter is not used.</p>
<p>-s<br />
2021-05-11 02:29:21 +02:00
Enable <em>option stacking</em> for single-letter options, whereby multiple
2022-08-24 15:22:41 +02:00
single-letter options may be combined into a single word. For example,
the two options -x and -y may be combined into a single word -xy.
By default, every word corresponds to a single option name (-xy is a
single option named xy).</p>
2021-05-11 02:29:21 +02:00
<p>Options beginning with a single hyphen or plus sign are eligible for
stacking; words beginning with two hyphens are not.</p>
2022-08-24 15:22:41 +02:00
<p>Note that -s after -- has a different meaning, which is documented in
the segment entitled Deriving <code>spec</code> forms from the help output.</p>
<p>-w<br />
In combination with -s, allow option stacking even if one or more of the
options take arguments. For example, if -x takes an argument, with no
-s, -xy is considered as a single (unhandled) option; with -s, -xy is
an option with the argument y; with both -s and -w, -xy is the option
-x and the option -y with arguments to -x (and to -y, if it takes
2021-05-11 02:29:21 +02:00
arguments) still to come in subsequent words.</p>
2022-08-24 15:22:41 +02:00
<p>-W<br />
This option takes -w a stage further: it is possible to complete
2021-05-11 02:29:21 +02:00
single-letter options even after an argument that occurs in the same
2022-08-24 15:22:41 +02:00
word. However, it depends on the action performed whether options will
really be completed at this point. For more control, use a utility
function like _guard as part of the action.</p>
<p>-C<br />
Modify the curcontext parameter for an action of the form -&gt;<code>state</code>.
This is discussed in detail below.</p>
<p>-R<br />
Return status 300 instead of zero when a $state is to be handled, in the
-&gt;<code>string</code> syntax.</p>
<p>-S<br />
Do not complete options after a -- appearing on the line, and ignore
the --. For example, with -S, in the line</p>
<div class="example">
<pre><code class="language-zsh">foobar -x -- -y
</code></pre>
</div>
<p>the -x is considered an option, the -y is considered an argument,
and the -- is considered to be neither.</p>
<p>-A <code>pat</code><br />
Do not complete options after the first non-option argument on the line.
<code>pat</code> is a pattern matching all strings which are not to be taken as
arguments. For example, to make _arguments stop completing options
after the first normal argument, but ignoring all strings starting with
a hyphen even if they are not described by one of the <code>optspec</code>s, the
form is -A &quot;-*&quot;.</p>
<p>-O <code>name</code><br />
Pass the elements of the array <code>name</code> as arguments to functions called
to execute <code>action</code>s. This is discussed in detail below.</p>
<p>-M <code>matchspec</code><br />
Use the match specification <code>matchspec</code> for completing option names and
values. The default <code>matchspec</code> allows partial word completion after
_ and -, such as completing -f-b to -foo-bar. The default
<code>matchspec</code> is:</p>
<div class="example">
<pre><code class="language-zsh">r:|[_-]=* r:|=*
</code></pre>
</div>
<p>-0<br />
When populating values of the opt_args associative array, dont
backslash-escape colons and backslashes and use NUL rather than colon
for joining multiple values. This option is described in more detail
below, under the heading <em><code>spec</code>s: actions</em>.</p>
2021-05-11 02:29:21 +02:00
<p><em><code>spec</code>s: overview</em></p>
<p>Each of the following forms is a <code>spec</code> describing individual sets of
options or arguments on the command line being analyzed.</p>
2022-08-24 15:22:41 +02:00
<p><code>n</code>:<code>message</code>:<code>action</code><br />
<code>n</code>::<code>message</code>:<code>action</code><br />
This describes the <code>n</code>th normal argument. The <code>message</code> will be printed
above the matches generated and the <code>action</code> indicates what can be
completed in this position (see below). If there are two colons before
the <code>message</code> the argument is optional. If the <code>message</code> contains only
white space, nothing will be printed above the matches unless the action
adds an explanation string itself.</p>
<p>:<code>message</code>:<code>action</code><br />
::<code>message</code>:<code>action</code><br />
Similar, but describes the <em>next</em> argument, whatever number that happens
to be. If all arguments are specified in this form in the correct order
the numbers are unnecessary.</p>
<p>*:<code>message</code>:<code>action</code><br />
*::<code>message</code>:<code>action</code><br />
*:::<code>message</code>:<code>action</code><br />
This describes how arguments (usually non-option arguments, those not
beginning with - or +) are to be completed when neither of the first two
forms was provided. Any number of arguments can be completed in this
fashion.</p>
<p>With two colons before the <code>message</code>, the words special array and the
CURRENT special parameter are modified to refer only to the normal
arguments when the <code>action</code> is executed or evaluated. With three colons
before the <code>message</code> they are modified to refer only to the normal
arguments covered by this description.</p>
2021-05-11 02:29:21 +02:00
<p><code>optspec</code><br />
2022-08-24 15:22:41 +02:00
<code>optspec</code>:<code>...</code><br />
This describes an option. The colon indicates handling for one or more
arguments to the option; if it is not present, the option is assumed to
take no arguments.</p>
<p>The following forms are available for the initial <code>optspec</code>, whether or
not the option has arguments.</p>
<p>*<code>optspec</code><br />
Here <code>optspec</code> is one of the remaining forms below. This indicates the
following <code>optspec</code> may be repeated. Otherwise if the corresponding
option is already present on the command line to the left of the cursor
it will not be offered again.</p>
<p>-<code>optname</code><br />
+<code>optname</code><br />
In the simplest form the <code>optspec</code> is just the option name beginning
with a minus or a plus sign, such as -foo. The first argument for the
option (if any) must follow as a <em>separate</em> word directly after the
option.</p>
<p>Either of -+<code>optname</code> and +-<code>optname</code> can be used to specify that
-<code>optname</code> and +<code>optname</code> are both valid.</p>
<p>In all the remaining forms, the leading - may be replaced by or paired
with + in this way.</p>
<p>-<code>optname</code>-<br />
The first argument of the option must come directly after the option
name <em>in the same word</em>. For example, -foo-:<code>...</code> specifies that the
completed option and argument will look like -foo<code>arg</code>.</p>
<p>-<code>optname</code>+<br />
The first argument may appear immediately after <code>optname</code> in the same
word, or may appear as a separate word after the option. For example,
-foo+:<code>...</code> specifies that the completed option and argument will look
like either -foo<code>arg</code> or -foo <code>arg</code>.</p>
<p>-<code>optname</code>=<br />
The argument may appear as the next word, or in same word as the option
name provided that it is separated from it by an equals sign, for
example -foo=<code>arg</code> or -foo <code>arg</code>.</p>
<p>-<code>optname</code>=-<br />
The argument to the option must appear after an equals sign in the same
word, and may not be given in the next argument.</p>
<p><code>optspec</code>[<code>explanation</code>]<br />
An explanation string may be appended to any of the preceding forms of
<code>optspec</code> by enclosing it in brackets, as in -q[query operation].</p>
<p>The verbose style is used to decide whether the explanation strings are
displayed with the option in a completion listing.</p>
<p>If no bracketed explanation string is given but the auto-description
style is set and only one argument is described for this <code>optspec</code>, the
value of the style is displayed, with any appearance of the sequence
%d in it replaced by the <code>message</code> of the first <code>optarg</code> that follows
the <code>optspec</code>; see below.</p>
<p>It is possible for options with a literal + or = to appear, but that
character must be quoted, for example -\+.</p>
2021-05-11 02:29:21 +02:00
<p>Each <code>optarg</code> following an <code>optspec</code> must take one of the following
forms:</p>
2022-08-24 15:22:41 +02:00
<p>:<code>message</code>:<code>action</code><br />
::<code>message</code>:<code>action</code><br />
An argument to the option; <code>message</code> and <code>action</code> are treated as for
ordinary arguments. In the first form, the argument is mandatory, and in
the second form it is optional.</p>
<p>This group may be repeated for options which take multiple arguments. In
other words, :<code>message1</code>:<code>action1</code>:<code>message2</code>:<code>action2</code> specifies that
the option takes two arguments.</p>
<p>:*<code>pattern</code>:<code>message</code>:<code>action</code><br />
:*<code>pattern</code>::<code>message</code>:<code>action</code><br />
:*<code>pattern</code>:::<code>message</code>:<code>action</code><br />
This describes multiple arguments. Only the last <code>optarg</code> for an option
taking multiple arguments may be given in this form. If the <code>pattern</code> is
empty (i.e. :*:), all the remaining words on the line are to be
completed as described by the <code>action</code>; otherwise, all the words up to
and including a word matching the <code>pattern</code> are to be completed using
the <code>action</code>.</p>
<p>Multiple colons are treated as for the *:<code>...</code> forms for ordinary
arguments: when the <code>message</code> is preceded by two colons, the words
special array and the CURRENT special parameter are modified during the
execution or evaluation of the <code>action</code> to refer only to the words after
the option. When preceded by three colons, they are modified to refer
only to the words covered by this description.</p>
2021-05-11 02:29:21 +02:00
<p>Any literal colon in an <code>optname</code>, <code>message</code>, or <code>action</code> must be
2022-08-24 15:22:41 +02:00
preceded by a backslash, \:.</p>
2021-05-11 02:29:21 +02:00
<p>Each of the forms above may be preceded by a list in parentheses of
option names and argument numbers. If the given option is on the command
line, the options and arguments indicated in parentheses will not be
2022-08-24 15:22:41 +02:00
offered. For example, (-two -three 1)-one:<code>...</code> completes the option
-one; if this appears on the command line, the options -two and -three
and the first ordinary argument will not be completed after it.
(-foo):<code>...</code> specifies an ordinary argument completion; -foo will not
be completed if that argument is already present.</p>
2021-05-11 02:29:21 +02:00
<p>Other items may appear in the list of excluded options to indicate
various other items that should not be applied when the current
2022-08-24 15:22:41 +02:00
specification is matched: a single star (*) for the rest arguments
(i.e. a specification of the form *:<code>...</code>); a colon (:) for all
normal (non-option-) arguments; and a hyphen (-) for all options. For
example, if (*) appears before an option and the option appears on
2021-05-11 02:29:21 +02:00
the command line, the list of remaining arguments completed.</p>
<p>To aid in reuse of specifications, it is possible to precede any of the
2022-08-24 15:22:41 +02:00
forms above with !; then the form will no longer be completed,
2021-05-11 02:29:21 +02:00
although if the option or argument appears on the command line they will
be skipped as normal. The main use for this is when the arguments are
2022-08-24 15:22:41 +02:00
given by an array, and _arguments is called repeatedly for more
specific contexts: on the first call _arguments $global_options is
used, and on subsequent calls _arguments !$^global_options.</p>
2021-05-11 02:29:21 +02:00
<p><em><code>spec</code>s: actions</em></p>
<p>In each of the forms above the <code>action</code> determines how completions
2022-08-24 15:22:41 +02:00
should be generated. Except for the -&gt;<code>string</code> form below, the
<code>action</code> will be executed by calling the _all_labels function to
2021-05-11 02:29:21 +02:00
process all tag labels. No special handling of tags is needed unless a
function call introduces a new one.</p>
<p>The functions called to execute <code>action</code>s will be called with the
2022-08-24 15:22:41 +02:00
elements of the array named by the -O <code>name</code> option as arguments. This
can be used, for example, to pass the same set of options for the
compadd builtin to all <code>action</code>s.</p>
2021-05-11 02:29:21 +02:00
<p>The forms for <code>action</code> are as follows.</p>
2022-08-24 15:22:41 +02:00
<p> (single unquoted space)<br />
This is useful where an argument is required but it is not possible or
desirable to generate matches for it. The <code>message</code> will be displayed
but no completions listed. Note that even in this case the colon at the
end of the <code>message</code> is needed; it may only be omitted when neither a
<code>message</code> nor an <code>action</code> is given.</p>
<p>(<code>item1</code> <code>item2</code> <code>...</code>)<br />
2021-05-11 02:29:21 +02:00
One of a list of possible matches, for example:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">:foo:(foo bar baz)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>((<code>item1</code>\:<code>desc1</code> <code>...</code>))<br />
2021-05-11 02:29:21 +02:00
Similar to the above, but with descriptions for each possible match.
Note the backslash before the colon. For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">:foo:((a\:bar b\:baz))
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>The matches will be listed together with their descriptions if the
2022-08-24 15:22:41 +02:00
description style is set with the values tag in the context.</p>
<p>-&gt;<code>string</code><br />
<span id="index-context_002c-use-of"></span> <span
id="index-line_002c-use-of"></span> <span
id="index-opt_005fargs_002c-use-of"></span></p>
<p>In this form, _arguments processes the arguments and options and then
returns control to the calling function with parameters set to indicate
the state of processing; the calling function then makes its own
arrangements for generating completions. For example, functions that
implement a state machine can use this type of action.</p>
<p>Where _arguments encounters <code>action</code> in the -&gt;<code>string</code> format, it
will strip all leading and trailing whitespace from <code>string</code> and set the
array state to the set of all <code>string</code>s for which an action is to be
performed. The elements of the array state_descr are assigned the
corresponding <code>message</code> field from each <code>optarg</code> containing such an
<code>action</code>.</p>
2021-05-11 02:29:21 +02:00
<p>By default and in common with all other well behaved completion
2022-08-24 15:22:41 +02:00
functions, _arguments returns status zero if it was able to add matches
and non-zero otherwise. However, if the -R option is given, _arguments
will instead return a status of 300 to indicate that $state is to be
handled.</p>
<p>In addition to $state and $state_descr, _arguments also sets the global
parameters context, line and opt_args as described below, and does
not reset any changes made to the special parameters such as PREFIX and
words. This gives the calling function the choice of resetting these
parameters or propagating changes in them.</p>
<p>A function calling _arguments with at least one action containing a
-&gt;<code>string</code> must therefore declare appropriate local parameters:</p>
<div class="example">
<pre><code class="language-zsh">local context state state_descr line
2021-05-11 02:29:21 +02:00
typeset -A opt_args
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>to prevent _arguments from altering the global environment.</p>
<p>{<code>eval-string</code>}<br />
2021-05-11 02:29:21 +02:00
<span id="index-expl_002c-use-of"></span></p>
2022-08-24 15:22:41 +02:00
<p>A string in braces is evaluated as shell code to generate matches. If
the <code>eval-string</code> itself does not begin with an opening parenthesis or
brace it is split into separate words before execution.</p>
<p>= <code>action</code><br />
If the <code>action</code> starts with = (an equals sign followed by a space),
_arguments will insert the contents of the <code>argument</code> field of the
current context as the new first element in the words special array and
increment the value of the CURRENT special parameter. This has the
effect of inserting a dummy word onto the completion command line while
not changing the point at which completion is taking place.</p>
<p>This is most useful with one of the specifiers that restrict the words
on the command line on which the <code>action</code> is to operate (the two- and
three-colon forms above). One particular use is when an <code>action</code> itself
causes _arguments on a restricted range; it is necessary to use this
trick to insert an appropriate command name into the range for the
second call to _arguments to be able to parse the line.</p>
2021-05-11 02:29:21 +02:00
<p><code> word...</code><br />
<code>word...</code><br />
This covers all forms other than those above. If the <code>action</code> starts
with a space, the remaining list of words will be invoked unchanged.</p>
2022-08-24 15:22:41 +02:00
<p>Otherwise it will be invoked with some extra strings placed after the
first word; these are to be passed down as options to the compadd
builtin. They ensure that the state specified by _arguments, in
particular the descriptions of options and arguments, is correctly
passed to the completion command. These additional arguments are taken
from the array parameter expl; this will be set up before executing
the <code>action</code> and hence may be referred to inside it, typically in an
expansion of the form $expl[@] which preserves empty elements of the
array.</p>
<p>During the performance of the action the array line will be set to the
normal arguments from the command line, i.e. the words from the command
line after the command name excluding all options and their arguments.
Options are stored in the associative array opt_args with option names
as keys and their arguments as the values. By default, all colons and
backslashes in the value are escaped with backslashes, and if an option
has multiple arguments (for example, when using an <code>optspec</code> of the form
*<code>optspec</code>), they are joined with (unescaped) colons. However, if the
-0 option was passed, no backslash escaping is performed, and multiple
values are joined with NUL bytes. For example, after zsh -o foo:foo -o
bar:bar -o &lt;TAB&gt;, the contents of opt_args would be</p>
<div class="example">
<pre><code class="language-zsh">typeset -A opt_args=( [-o]='foo\:foo:bar\:bar:' )
</code></pre>
</div>
<p>by default, and</p>
<div class="example">
<pre><code class="language-zsh">typeset -A opt_args=( [-o]=$'foo:foo\x00bar:bar\x00' )
</code></pre>
</div>
<p>if _arguments had been called with the -0 option.</p>
<p>The parameter context is set when returning to the calling function to
perform an action of the form -&gt;<code>string</code>. It is set to an array of
elements corresponding to the elements of $state. Each string of the
form option<code>-opt</code>-<code>n</code> for the <code>n</code>th argument of the option <code>-opt</code>, or
a string of the form argument-<code>n</code> for the <code>n</code>th argument. For rest
arguments, that is those in the list at the end not handled by position,
<code>n</code> is the string rest. For example, when completing the argument of
the -o option, the name is option-o-1, while for the second normal
(non-option-) argument it is argument-2.</p>
2021-05-11 02:29:21 +02:00
<p>Furthermore, during the evaluation of the <code>action</code> the context name in
2022-08-24 15:22:41 +02:00
the curcontext parameter is altered to append the same string that is
stored in the context parameter.</p>
<p>The option -C tells _arguments to modify the curcontext parameter for
an action of the form -&gt;<code>state</code>. This is the standard parameter used
to keep track of the current context. Here it (and not the context
array) should be made local to the calling function to avoid passing
back the modified value and should be initialised to the current value
at the start of the function:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">local curcontext=&quot;$curcontext&quot;
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>This is useful where it is not possible for multiple states to be valid
together.</p>
<p><em>Grouping Options</em></p>
<p>Options can be grouped to simplify exclusion lists. A group is
2022-08-24 15:22:41 +02:00
introduced with + followed by a name for the group in the subsequent
2021-05-11 02:29:21 +02:00
word. Whole groups can then be referenced in an exclusion list or a
group name can be used to disambiguate between two forms of the same
option. For example:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">_arguments \
2021-05-11 02:29:21 +02:00
'(group2--x)-a' \
+ group1 \
-m \
'(group2)-n' \
+ group2 \
-x -y
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>If the name of a group is specified in the form (<code>name</code>) then only one
value from that group will ever be completed; more formally, all
2021-05-11 02:29:21 +02:00
specifications are mutually exclusive to all other specifications in
that group. This is useful for defining options that are aliases for
each other. For example:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">_arguments \
2021-05-11 02:29:21 +02:00
-a -b \
+ '(operation)' \
{-c,--compress}'[compress]' \
{-d,--decompress}'[decompress]' \
{-l,--list}'[list]'
</code></pre>
</div>
<p>If an option in a group appears on the command line, it is stored in the
2022-08-24 15:22:41 +02:00
associative array opt_args with <code>group</code>-<code>option</code> as a key. In the
example above, a key operationc is used if the option -c is present
on the command line.</p>
2021-05-11 02:29:21 +02:00
<p><em>Specifying Multiple Sets of Arguments</em></p>
<p>It is possible to specify multiple sets of options and arguments with
the sets separated by single hyphens. This differs from groups in that
sets are considered to be mutually exclusive of each other.</p>
<p>Specifications before the first set and from any group are common to all
sets. For example:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">_arguments \
2021-05-11 02:29:21 +02:00
-a \
- set1 \
-c \
- set2 \
-d \
':arg:(x2 y2)'
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>This defines two sets. When the command line contains the option -c,
the -d option and the argument will not be considered possible
completions. When it contains -d or an argument, the option -c will
not be considered. However, after -a both sets will still be
2021-05-11 02:29:21 +02:00
considered valid.</p>
<p>As for groups, the name of a set may appear in exclusion lists, either
alone or preceding a normal option or argument specification.</p>
<p>The completion code has to parse the command line separately for each
set. This can be slow so sets should only be used when necessary. A
useful alternative is often an option specification with rest-arguments
2022-08-24 15:22:41 +02:00
(as in -foo:*:...); here the option -foo swallows up all remaining
2021-05-11 02:29:21 +02:00
arguments as described by the <code>optarg</code> definitions.</p>
<p><em>Deriving <code>spec</code> forms from the help output</em></p>
2022-08-24 15:22:41 +02:00
<p>The option -- allows _arguments to work out the names of long options
that support the --help option which is standard in many GNU commands.
The command word is called with the argument --help and the output
examined for option names. Clearly, it can be dangerous to pass this to
commands which may not support this option as the behaviour of the
command is unspecified.</p>
<p>In addition to options, _arguments -- will try to deduce the types of
arguments available for options when the form --<code>opt</code>=<code>val</code> is valid.
It is also possible to provide hints by examining the help text of the
command and adding <code>helpspec</code> of the form
<code>pattern</code>:<code>message</code>:<code>action</code>; note that other _arguments <code>spec</code> forms
are not used. The <code>pattern</code> is matched against the help text for an
option, and if it matches the <code>message</code> and <code>action</code> are used as for
other argument specifiers. The special case of *: means both
<code>message</code> and <code>action</code> are empty, which has the effect of causing
2021-05-11 02:29:21 +02:00
options having no description in the help output to be ordered in
listings ahead of options that have a description.</p>
<p>For example:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">_arguments -- '*\*:toggle:(yes no)' \
2021-05-11 02:29:21 +02:00
'*=FILE*:file:_files' \
'*=DIR*:directory:_files -/' \
'*=PATH*:directory:_files -/'
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Here, yes and no will be completed as the argument of options whose
description ends in a star; file names will be completed for options
that contain the substring =FILE in the description; and directories
will be completed for options whose description contains =DIR or
=PATH. The last three are in fact the default and so need not be given
explicitly, although it is possible to override the use of these
patterns. A typical help text which uses this feature is:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh"> -C, --directory=DIR change to directory DIR
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>so that the above specifications will cause directories to be completed
2022-08-24 15:22:41 +02:00
after --directory, though not after -C.</p>
<p>Note also that _arguments tries to find out automatically if the
2021-05-11 02:29:21 +02:00
argument for an option is optional. This can be specified explicitly by
doubling the colon before the <code>message</code>.</p>
2022-08-24 15:22:41 +02:00
<p>If the <code>pattern</code> ends in (-), this will be removed from the pattern
and the <code>action</code> will be used only directly after the =, not in the
2021-05-11 02:29:21 +02:00
next word. This is the behaviour of a normal specification defined with
2022-08-24 15:22:41 +02:00
the form =-.</p>
<p>By default, the command (with the option help) is run after resetting
all the locale categories (except for LC_CTYPE) to C. If the localized
help output is known to work, the option -l can be specified after the
_arguments -- so that the command is run in the current locale.</p>
<p>The _arguments -- can be followed by the option -i <code>patterns</code> to
give patterns for options which are not to be completed. The patterns
2021-05-11 02:29:21 +02:00
can be given as the name of an array parameter or as a literal list in
parentheses. For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">_arguments -- -i \
2021-05-11 02:29:21 +02:00
&quot;(--(en|dis)able-FEATURE*)&quot;
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>will cause completion to ignore the options --enable-FEATURE and
--disable-FEATURE (this example is useful with GNU configure).</p>
<p>The _arguments -- form can also be followed by the option -s <code>pair</code>
to describe option aliases. The <code>pair</code> consists of a list of alternating
patterns and corresponding replacements, enclosed in parens and quoted
so that it forms a single argument word in the _arguments call.</p>
<p>For example, some configure-script help output describes options only as
--enable-foo, but the script also accepts the negated form
--disable-foo. To allow completion of the second form:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">_arguments -- -s &quot;((#s)--enable- --disable-)&quot;
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p><em>Miscellaneous notes</em></p>
2022-08-24 15:22:41 +02:00
<p>Finally, note that _arguments generally expects to be the primary
2021-05-11 02:29:21 +02:00
function handling any completion for which it is used. It may have side
effects which change the treatment of any matches added by other
2022-08-24 15:22:41 +02:00
functions called after it. To combine _arguments with other functions,
those functions should be called either before _arguments, as an
<code>action</code> within a <code>spec</code>, or in handlers for -&gt;<code>state</code> actions.</p>
<p>Here is a more general example of the use of _arguments:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">_arguments '-l+:left border:' \
2021-05-11 02:29:21 +02:00
'-format:paper size:(letter A4)' \
'*-copy:output file:_files::resolution:(300 600)' \
':postscript file:_files -g \*.\(ps\|eps\)' \
'*:page number:'
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>This describes three options: -l, -format, and -copy. The first
takes one argument described as <code>left border</code> for which no completion
will be offered because of the empty action. Its argument may come
directly after the -l or it may be given as the next word on the line.</p>
<p>The -format option takes one argument in the next word, described as
<code>paper size</code> for which only the strings letter and A4 will be
2021-05-11 02:29:21 +02:00
completed.</p>
2022-08-24 15:22:41 +02:00
<p>The -copy option may appear more than once on the command line and
2021-05-11 02:29:21 +02:00
takes two arguments. The first is mandatory and will be completed as a
filename. The second is optional (because of the second colon before the
2022-08-24 15:22:41 +02:00
description <code>resolution</code>) and will be completed from the strings 300
and 600.</p>
2021-05-11 02:29:21 +02:00
<p>The last two descriptions say what should be completed as arguments. The
first describes the first argument as a <code>postscript file</code> and makes
2022-08-24 15:22:41 +02:00
files ending in ps or eps be completed. The last description gives
all other arguments the description <code>page number</code> but does not offer
completions.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fcache_005finvalid"></span></p>
2022-08-24 15:22:41 +02:00
<p>_cache_invalid <code>cache_identifier</code></p>
2021-05-11 02:29:21 +02:00
<p>This function returns status zero if the completions cache corresponding
to the given cache identifier needs rebuilding. It determines this by
2022-08-24 15:22:41 +02:00
looking up the cache-policy style for the current context. This should
2021-05-11 02:29:21 +02:00
provide a function name which is run with the full path to the relevant
cache file as the only argument.</p>
<p>Example:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">_example_caching_policy () {
2021-05-11 02:29:21 +02:00
# rebuild if cache is more than a week old
local -a oldp
oldp=( &quot;$1&quot;(Nm+7) )
(( $#oldp ))
}
</code></pre>
</div>
<p><span id="index-_005fcall_005ffunction"></span></p>
2022-08-24 15:22:41 +02:00
<p>_call_function <code>return</code> <code>name</code> [ <code>arg</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>If a function <code>name</code> exists, it is called with the arguments <code>arg</code>s. The
<code>return</code> argument gives the name of a parameter in which the return
status from the function <code>name</code> should be stored; if <code>return</code> is empty
or a single hyphen it is ignored.</p>
2022-08-24 15:22:41 +02:00
<p>The return status of _call_function itself is zero if the function
2021-05-11 02:29:21 +02:00
<code>name</code> exists and was called and non-zero otherwise.</p>
<p><span id="index-_005fcall_005fprogram"></span></p>
2022-08-24 15:22:41 +02:00
<p>_call_program [ -l ] [ -p ] <code>tag</code> <code>string</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>This function provides a mechanism for the user to override the use of
2022-08-24 15:22:41 +02:00
an external command. It looks up the command style with the supplied
2021-05-11 02:29:21 +02:00
<code>tag</code>. If the style is set, its value is used as the command to execute.
2022-08-24 15:22:41 +02:00
The <code>string</code>s from the call to _call_program, or from the style if set,
are concatenated with spaces between them and the resulting string is
evaluated. The return status is the return status of the command called.</p>
2021-05-11 02:29:21 +02:00
<p>By default, the command is run in an environment where all the locale
2022-08-24 15:22:41 +02:00
categories (except for LC_CTYPE) are reset to C by calling the utility
function _comp_locale (see below). If the option -l is given, the
command is run with the current locale.</p>
<p>If the option -p is supplied it indicates that the command output is
influenced by the permissions it is run with. If the gain-privileges
style is set to true, _call_program will make use of commands such as
sudo, if present on the command-line, to match the permissions to
2021-05-11 02:29:21 +02:00
whatever the final command is likely to run under. When looking up the
2022-08-24 15:22:41 +02:00
gain-privileges and command styles, the command component of the zstyle
context will end with a slash (/) followed by the command that would
be used to gain privileges.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fcombination"></span></p>
2022-08-24 15:22:41 +02:00
<p>_combination [ -s <code>pattern</code> ] <code>tag</code> <code>style</code> <code>spec</code> ... <code>field</code> <code>opts</code>
...</p>
2021-05-11 02:29:21 +02:00
<p>This function is used to complete combinations of values, for example
pairs of hostnames and usernames. The <code>style</code> argument gives the style
which defines the pairs; it is looked up in a context with the <code>tag</code>
specified.</p>
<p>The style name consists of field names separated by hyphens, for example
2022-08-24 15:22:41 +02:00
users-hosts-ports. For each field for a value is already known, a
<code>spec</code> of the form <code>field</code>=<code>pattern</code> is given. For example, if the
command line so far specifies a user pws, the argument users=pws
2021-05-11 02:29:21 +02:00
should appear.</p>
<p>The next argument with no equals sign is taken as the name of the field
for which completions should be generated (presumably not one of the
<code>field</code>s for which the value is known).</p>
<p>The matches generated will be taken from the value of the style. These
should contain the possible values for the combinations in the
appropriate order (users, hosts, ports in the example above). The values
for the different fields are separated by colons. This can be altered
2022-08-24 15:22:41 +02:00
with the option -s to _combination which specifies a pattern. Typically
this is a character class, as for example -s &quot;[:@]&quot; in the case of
the users-hosts style. Each <code>field</code>=<code>pattern</code> specification restricts
the completions which apply to elements of the style with appropriately
matching fields.</p>
2021-05-11 02:29:21 +02:00
<p>If no style with the given name is defined for the given tag, or if none
of the strings in styles value match, but a function name of the
required field preceded by an underscore is defined, that function will
be called to generate the matches. For example, if there is no
2022-08-24 15:22:41 +02:00
users-hosts-ports or no matching hostname when a host is required, the
function _hosts will automatically be called.</p>
2021-05-11 02:29:21 +02:00
<p>If the same name is used for more than one field, in both the
2022-08-24 15:22:41 +02:00
<code>field</code>=<code>pattern</code> and the argument that gives the name of the field to
be completed, the number of the field (starting with one) may be given
after the fieldname, separated from it by a colon.</p>
<p>All arguments after the required field name are passed to compadd when
2021-05-11 02:29:21 +02:00
generating matches from the style value, or to the functions for the
fields if they are called.</p>
<p><span id="index-_005fcommand_005fnames"></span></p>
2022-08-24 15:22:41 +02:00
<p>_command_names [ -e | - ]</p>
2021-05-11 02:29:21 +02:00
<p>This function completes words that are valid at command position: names
2022-08-24 15:22:41 +02:00
of aliases, builtins, hashed commands, functions, and so on. With the -e
flag, only hashed commands are completed. The - flag is ignored.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fcomp_005flocale"></span></p>
2022-08-24 15:22:41 +02:00
<p>_comp_locale</p>
<p>This function resets all the locale categories other than LC_CTYPE to
C so that the output from external commands can be easily analyzed by
the completion system. LC_CTYPE retains the current value (taking LC_ALL
and LANG into account), ensuring that non-ASCII characters in file names
are still handled properly.</p>
2021-05-11 02:29:21 +02:00
<p>This function should normally be run only in a subshell, because the new
locale is exported to the environment. Typical usage would be
2022-08-24 15:22:41 +02:00
$(_comp_locale; <code>command</code> ...).</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fcompleters"></span></p>
2022-08-24 15:22:41 +02:00
<p>_completers [ -p ]</p>
2021-05-11 02:29:21 +02:00
<p>This function completes names of completers.</p>
2022-08-24 15:22:41 +02:00
<p>-p<br />
Include the leading underscore (_) in the matches.</p>
<p><span id="index-_005fdefault"></span></p>
<p>_default</p>
<p>This function corresponds to the -default- special context which is
applied where no completion is defined. It is useful to call it under
certain error conditions such as completion after an unrecognised
subcommand. This applies the concept of graceful degradation to the
completion system, allowing it to fallback on basic completion of
commonly useful things like filenames.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fdescribe"></span></p>
2022-08-24 15:22:41 +02:00
<p>_describe [-12JVx] [ -oO | -t <code>tag</code> ] <code>descr</code> <code>name1</code> [ <code>name2</code>
] [ <code>opt</code> ... ]</p>
<p>          [ -- <code>name1</code> [ <code>name2</code> ] [ <code>opt</code> ... ] ... ]</p>
2021-05-11 02:29:21 +02:00
<p>This function associates completions with descriptions. Multiple groups
2022-08-24 15:22:41 +02:00
separated by -- can be supplied, potentially with different completion
options <code>opt</code>s.</p>
2021-05-11 02:29:21 +02:00
<p>The <code>descr</code> is taken as a string to display above the matches if the
2022-08-24 15:22:41 +02:00
format style for the descriptions tag is set. This is followed by one or
two names of arrays followed by options to pass to compadd. The array
<code>name1</code> contains the possible completions with their descriptions in the
form <code>completion</code>:<code>description</code>. Any literal colons in <code>completion</code>
must be quoted with a backslash. If a <code>name2</code> is given, it should have
the same number of elements as <code>name1</code>; in this case the corresponding
elements are added as possible completions instead of the <code>completion</code>
strings from <code>name1</code>. The completion list will retain the descriptions
from <code>name1</code>. Finally, a set of completion options can appear.</p>
<p>If the option -o appears before the first argument, the matches added
will be treated as names of command options (N.B. not shell options),
typically following a -, -- or + on the command line. In this case
_describe uses the prefix-hidden, prefix-needed and verbose styles to
find out if the strings should be added as completions and if the
descriptions should be shown. Without the -o option, only the verbose
style is used to decide how descriptions are shown. If -O is used
instead of -o, command options are completed as above but _describe
will not handle the prefix-needed style.</p>
<p>With the -t option a <code>tag</code> can be specified. The default is values or,
if the -o option is given, options.</p>
<p>The options -1, -2, -J, -V, -x are passed to _next_label.</p>
<p>If selected by the list-grouped style, strings with the same description
will appear together in the list.</p>
<p>_describe uses the _all_labels function to generate the matches, so it
does not need to appear inside a loop over tag labels.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fdescription"></span></p>
2022-08-24 15:22:41 +02:00
<p>_description [ -x ] [ -12VJ ] <code>tag</code> <code>name</code> <code>descr</code> [ <code>spec</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>This function is not to be confused with the previous one; it is used as
2022-08-24 15:22:41 +02:00
a helper function for creating options to compadd. It is buried inside
2021-05-11 02:29:21 +02:00
many of the higher level completion functions and so often does not need
to be called directly.</p>
<p>The styles listed below are tested in the current context using the
2022-08-24 15:22:41 +02:00
given <code>tag</code>. The resulting options for compadd are put into the array
named <code>name</code> (this is traditionally expl, but this convention is not
2021-05-11 02:29:21 +02:00
enforced). The description for the corresponding set of matches is
passed to the function in <code>descr</code>.</p>
2022-08-24 15:22:41 +02:00
<p>The styles tested are: format, hidden, matcher, ignore-line,
ignored-patterns, group-name and sort. The format style is first tested
for the given <code>tag</code> and then for the descriptions tag if no value was
found, while the remainder are only tested for the tag given as the
first argument. The function also calls _setup which tests some more
styles.</p>
<p>The string returned by the format style (if any) will be modified so
that the sequence %d is replaced by the <code>descr</code> given as the third
2021-05-11 02:29:21 +02:00
argument without any leading or trailing white space. If, after removing
the white space, the <code>descr</code> is the empty string, the format style will
not be used and the options put into the <code>name</code> array will not contain
an explanation string to be displayed above the matches.</p>
2022-08-24 15:22:41 +02:00
<p>If _description is called with more than three arguments, the
additional <code>spec</code>s should be of the form <code>char</code>:<code>str</code>. These supply
escape sequence replacements for the format style: every appearance of
%<code>char</code> will be replaced by <code>string</code>. If no additional <code>spec</code>s are
given but the description in <code>descr</code> conforms to a common form then
further escape sequences are set for elements of that description. These
elements correspond to a default (%r) and the remaining initial part
of the description (%h). The form the description takes consists of
specifying the units and range in parentheses and the default value in
square brackets, for example:</p>
<div class="example">
<pre><code class="language-zsh">_description times expl 'timeout (seconds) (0-60) [20]'
</code></pre>
</div>
<p>It is possible to use zformat conditional expressions when styling these
elements. So, for example, to add default: as a tag but only when
there is a default value to show, the format style might include
%(o.default: %o.).</p>
<p>If the -x option is given, the description will be passed to compadd
using the -x option instead of the default -X. This means that the
2021-05-11 02:29:21 +02:00
description will be displayed even if there are no corresponding
matches.</p>
2022-08-24 15:22:41 +02:00
<p>The options placed in the array <code>name</code> take account of the group-name
2021-05-11 02:29:21 +02:00
style, so matches are placed in a separate group where necessary. The
2022-08-24 15:22:41 +02:00
group normally has its elements sorted (by passing the option -J to
compadd), but if an option starting with -V, -J, -1, or -2 is
passed to _description, that option will be included in the array.
Hence it is possible for the completion group to be unsorted by giving
the option -V, -1V, or -2V.</p>
2021-05-11 02:29:21 +02:00
<p>In most cases, the function will be used like this:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">local expl
2021-05-11 02:29:21 +02:00
_description files expl file
compadd &quot;$expl[@]&quot; - &quot;$files[@]&quot;
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Note the use of the parameter expl, the hyphen, and the list of matches.
Almost all calls to compadd within the completion system use a similar
format; this ensures that user-specified styles are correctly passed
down to the builtins which implement the internals of completion.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fdir_005flist"></span></p>
2022-08-24 15:22:41 +02:00
<p>_dir_list [ -s <code>sep</code> ] [ -S ]</p>
2021-05-11 02:29:21 +02:00
<p>Complete a list of directory names separated by colons (the same format
2022-08-24 15:22:41 +02:00
as $PATH).</p>
<p>-s <code>sep</code><br />
Use <code>sep</code> as separator between items. <code>sep</code> defaults to a colon (:).</p>
<p>-S<br />
Add <code>sep</code> instead of slash (/) as an autoremoveable suffix.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fdispatch"></span></p>
2022-08-24 15:22:41 +02:00
<p>_dispatch <code>context string</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>This sets the current context to <code>context</code> and looks for completion
functions to handle this context by hunting through the list of command
2022-08-24 15:22:41 +02:00
names or special contexts (as described above for compdef) given as
2021-05-11 02:29:21 +02:00
<code>string</code>s. The first completion function to be defined for one of the
contexts in the list is used to generate matches. Typically, the last
2022-08-24 15:22:41 +02:00
<code>string</code> is -default- to cause the function for default completion to be
used as a fallback.</p>
<p>The function sets the parameter $service to the <code>string</code> being tried,
and sets the <code>context/command</code> field (the fourth) of the $curcontext
2021-05-11 02:29:21 +02:00
parameter to the <code>context</code> given as the first argument.</p>
<p><span id="index-_005femail_005faddresses"></span></p>
2022-08-24 15:22:41 +02:00
<p>_email_addresses [ -c ] [ -n <code>plugin</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>Complete email addresses. Addresses are provided by plugins.</p>
2022-08-24 15:22:41 +02:00
<p>-c<br />
Complete bare localhost@domain.tld addresses, without a name part or a
comment. Without this option, RFC822 <code>Firstname Lastname</code>
&lt;<code>address</code>&gt; strings are completed.</p>
<p>-n <code>plugin</code><br />
2021-05-11 02:29:21 +02:00
Complete aliases from <code>plugin</code>.</p>
2022-08-24 15:22:41 +02:00
<p>The following plugins are available by default: _email-ldap (see the
filter style), _email-local (completes <code>user</code>@<code>hostname</code> Unix
addresses), _email-mail (completes aliases from ~/.mailrc),
_email-mush, _email-mutt, and _email-pine.</p>
<p>Addresses from the _email-<code>foo</code> plugin are added under the tag
email-<code>foo</code>.</p>
2021-05-11 02:29:21 +02:00
<p><em>Writing plugins</em></p>
<p>Plugins are written as separate functions with names starting with
2022-08-24 15:22:41 +02:00
_email-. They are invoked with the -c option and compadd options.
They should either do their own completion or set the $reply array to a
list of <code>alias</code>:<code>address</code> elements and return 300. New plugins will be
picked up and run automatically.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005ffiles"></span></p>
2022-08-24 15:22:41 +02:00
<p>_files</p>
<p>The function _files is a wrapper around _path_files. It supports all
2021-05-11 02:29:21 +02:00
of the same functionality, with some enhancements — notably, it respects
2022-08-24 15:22:41 +02:00
the list-dirs-first style, and it allows users to override the behaviour
of the -g and -/ options with the file-patterns style. _files should
therefore be preferred over _path_files in most cases.</p>
<p>This function accepts the full set of options allowed by _path_files,
2021-05-11 02:29:21 +02:00
described below.</p>
<p><span id="index-_005fgnu_005fgeneric"></span></p>
2022-08-24 15:22:41 +02:00
<p>_gnu_generic</p>
<p>This function is a simple wrapper around the _arguments function
2021-05-11 02:29:21 +02:00
described above. It can be used to determine automatically the long
options understood by commands that produce a list when passed the
2022-08-24 15:22:41 +02:00
option --help. It is intended to be used as a top-level completion
2021-05-11 02:29:21 +02:00
function in its own right. For example, to enable option completion for
2022-08-24 15:22:41 +02:00
the commands foo and bar, use</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">compdef _gnu_generic foo bar
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>after the call to compinit.</p>
2021-05-11 02:29:21 +02:00
<p>The completion system as supplied is conservative in its use of this
function, since it is important to be sure the command understands the
2022-08-24 15:22:41 +02:00
option --help.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fguard"></span></p>
2022-08-24 15:22:41 +02:00
<p>_guard [ <code>options</code> ] <code>pattern descr</code></p>
2021-05-11 02:29:21 +02:00
<p>This function displays <code>descr</code> if <code>pattern</code> matches the string to be
completed. It is intended to be used in the <code>action</code> for the
2022-08-24 15:22:41 +02:00
specifications passed to _arguments and similar functions.</p>
2021-05-11 02:29:21 +02:00
<p>The return status is zero if the message was displayed and the word to
complete is not empty, and non-zero otherwise.</p>
<p>The <code>pattern</code> may be preceded by any of the options understood by
2022-08-24 15:22:41 +02:00
compadd that are passed down from _description, namely -M, -J, -V, -1,
-2, -n, -F and -X. All of these options will be ignored. This fits in
conveniently with the argument-passing conventions of actions for
_arguments.</p>
<p>As an example, consider a command taking the options -n and -none, where
-n must be followed by a numeric value in the same word. By using:</p>
<div class="example">
<pre><code class="language-zsh">_arguments '-n-: :_guard &quot;[0-9]#&quot; &quot;numeric value&quot;' '-none'
</code></pre>
</div>
<p>_arguments can be made to both display the message numeric value and
complete options after -n&lt;TAB&gt;. If the -n is already followed by
one or more digits (the pattern passed to _guard) only the message will
be displayed; if the -n is followed by another character, only options
are completed.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fmessage"></span></p>
2022-08-24 15:22:41 +02:00
<p>_message [ -r12 ] [ -VJ <code>group</code> ] <code>descr</code></p>
<p>_message -e [ <code>tag</code> ] <code>descr</code></p>
2021-05-11 02:29:21 +02:00
<p>The <code>descr</code> is used in the same way as the third argument to the
2022-08-24 15:22:41 +02:00
_description function, except that the resulting string will always be
2021-05-11 02:29:21 +02:00
shown whether or not matches were generated. This is useful for
displaying a help message in places where no completions can be
generated.</p>
2022-08-24 15:22:41 +02:00
<p>The format style is examined with the messages tag to find a message;
the usual tag, descriptions, is used only if the style is not set with
the former.</p>
<p>If the -r option is given, no style is used; the <code>descr</code> is taken
2021-05-11 02:29:21 +02:00
literally as the string to display. This is most useful when the <code>descr</code>
comes from a pre-processed argument list which already contains an
expanded description. Note that this option does not disable the
2022-08-24 15:22:41 +02:00
%-sequence parsing done by compadd.</p>
<p>The -12VJ options and the <code>group</code> are passed to compadd and hence
2021-05-11 02:29:21 +02:00
determine the group the message string is added to.</p>
2022-08-24 15:22:41 +02:00
<p>The second -e form gives a description for completions with the tag
2021-05-11 02:29:21 +02:00
<code>tag</code> to be shown even if there are no matches for that tag. This form
2022-08-24 15:22:41 +02:00
is called by _arguments in the event that there is no action for an
2021-05-11 02:29:21 +02:00
option specification. The tag can be omitted and if so the tag is taken
2022-08-24 15:22:41 +02:00
from the parameter $curtag; this is maintained by the completion system
and so is usually correct. Note that if there are no matches at the time
this function is called, compstate[insert] is cleared, so additional
matches generated later are not inserted on the command line.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fmulti_005fparts"></span></p>
2022-08-24 15:22:41 +02:00
<p>_multi_parts [ -i ] <code>sep</code> <code>array</code></p>
2021-05-11 02:29:21 +02:00
<p>The argument <code>sep</code> is a separator character. The <code>array</code> may be either
2022-08-24 15:22:41 +02:00
the name of an array parameter or a literal array in the form (foo
bar), a parenthesised list of words separated by whitespace. The
2021-05-11 02:29:21 +02:00
possible completions are the strings from the array. However, each chunk
2022-08-24 15:22:41 +02:00
delimited by <code>sep</code> will be completed separately. For example, the _tar
function uses _multi_parts / <code>patharray</code> to complete partial file
2021-05-11 02:29:21 +02:00
paths from the given array of complete file paths.</p>
2022-08-24 15:22:41 +02:00
<p>The -i option causes _multi_parts to insert a unique match even if that
requires multiple separators to be inserted. This is not usually the
expected behaviour with filenames, but certain other types of
2021-05-11 02:29:21 +02:00
completion, for example those with a fixed set of possibilities, may be
more suited to this form.</p>
2022-08-24 15:22:41 +02:00
<p>Like other utility functions, this function accepts the -V, -J,
-1, -2, -n, -f, -X, -M, -P, -S, -r, -R, and -q
options and passes them to the compadd builtin.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fnext_005flabel"></span></p>
2022-08-24 15:22:41 +02:00
<p>_next_label [ -x ] [ -12VJ ] <code>tag</code> <code>name</code> <code>descr</code> [ <code>option</code> ...
]</p>
2021-05-11 02:29:21 +02:00
<p>This function is used to implement the loop over different tag labels
2022-08-24 15:22:41 +02:00
for a particular tag as described above for the tag-order style. On each
call it checks to see if there are any more tag labels; if there is it
returns status zero, otherwise non-zero. As this function requires a
current tag to be set, it must always follow a call to _tags or
_requested.</p>
<p>The -x12VJ options and the first three arguments are passed to the
_description function. Where appropriate the <code>tag</code> will be replaced by
a tag label in this call. Any description given in the tag-order style
is preferred to the <code>descr</code> passed to _next_label.</p>
2021-05-11 02:29:21 +02:00
<p>The <code>option</code>s given after the <code>descr</code> are set in the parameter given by
2022-08-24 15:22:41 +02:00
<code>name</code>, and hence are to be passed to compadd or whatever function is
2021-05-11 02:29:21 +02:00
called to add the matches.</p>
2022-08-24 15:22:41 +02:00
<p>Here is a typical use of this function for the tag foo. The call to
_requested determines if tag foo is required at all; the loop over
_next_label handles any labels defined for the tag in the tag-order
2021-05-11 02:29:21 +02:00
style.</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">local expl ret=1
2021-05-11 02:29:21 +02:00
...
if _requested foo; then
...
while _next_label foo expl '...'; do
compadd &quot;$expl[@]&quot; ... &amp;&amp; ret=0
done
...
fi
return ret
</code></pre>
</div>
<p><span id="index-_005fnormal"></span></p>
2022-08-24 15:22:41 +02:00
<p>_normal [ -P | -p <code>precommand</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>This is the standard function called to handle completion outside any
2022-08-24 15:22:41 +02:00
special -<code>context</code>-. It is called both to complete the command word and
also the arguments for a command. In the second case, _normal looks for
a special completion for that command, and if there is none it uses the
completion for the -default- context.</p>
<p>A second use is to reexamine the command line specified by the $words
array and the $CURRENT parameter after those have been modified. For
example, the function _precommand, which completes after precommand
specifiers such as nohup, removes the first word from the words array,
decrements the CURRENT parameter, then calls _normal -p $service. The
effect is that nohup <code>cmd ...</code> is treated in the same way as
<code>cmd ...</code>.</p>
<p>-P<br />
Reset the list of precommands. This option should be used if completing
a command line which allows internal commands (e.g. builtins and
functions) regardless of prior precommands (e.g. zsh -c).</p>
<p>-p <code>precommand</code><br />
Append <code>precommand</code> to the list of precommands. This option should be
used in nearly all cases in which -P is not applicable.</p>
2021-05-11 02:29:21 +02:00
<p>If the command name matches one of the patterns given by one of the
2022-08-24 15:22:41 +02:00
options -p or -P to compdef, the corresponding completion function is
called and then the parameter _compskip is checked. If it is set
2021-05-11 02:29:21 +02:00
completion is terminated at that point even if no matches have been
2022-08-24 15:22:41 +02:00
found. This is the same effect as in the -first- context.</p>
<p><span id="index-_005fnumbers"></span></p>
<p>_numbers [ <code>option</code> ... ] [ <code>description</code> ] [ <code>suffix</code> ... ]</p>
<p>This can be used where a number is followed by a suffix to indicate the
units. The unit suffixes are completed and can also be included in the
description used when completion is invoked for the preceding number.</p>
<p>In addition to common compadd options, _numbers accepts the following
options:</p>
<p>-t <code>tag</code><br />
Specify a tag to use instead of the default of numbers.</p>
<p>-u <code>units</code><br />
Indicate the default units for the number, e.g. bytes.</p>
<p>-l <code>min</code><br />
Specify the lowest possible value for the number.</p>
<p>-m <code>max</code><br />
Specify the highest possible value for the number.</p>
<p>-d <code>default</code><br />
Specify the default value.</p>
<p>-N<br />
Allow negative numbers. This is implied if the range includes a
negative.</p>
<p>-f<br />
Allow decimal numbers.</p>
<p>Where a particular suffix represents the default units for a number, it
should be prefixed with a colon. Additionally, suffixes can be followed
by a colon and a description. So for example, the following allows the
age of something to be specified, either in seconds or with an optional
suffix with a longer unit of time:</p>
<div class="example">
<pre><code class="language-zsh">_numbers -u seconds age :s:seconds m:minutes h:hours d:days
</code></pre>
</div>
<p>It is typically helpful for units to be presented in order of magnitude
when completed. To facilitate this, the order in which they are given is
preserved.</p>
<p>When the format style is looked up with the descriptions tag or the tag
specified with -t, the list of suffixes is available as a %x escape
sequence. This is in addition to the usual sequences documented under
the format style. The form this list takes can also be configured. To
this end, the format style is first looked up with the tag
unit-suffixes. The retrieved format is applied to each suffix in turn
and the results are then concatenated to form the completed list. For
the unit-suffixes format, %x expands to the individual suffix and %X
to its description. %d indicates a default suffix and can be used in a
condition. The index and reverse index are set in %i and %r
respectively and are useful for text included only with the first and
last suffixes in the list. So for example, the following joins the
suffixes together as a comma-separated list:</p>
<div class="example">
<pre><code class="language-zsh">zstyle ':completion:*:unit-suffixes' format '%x%(r::,)'
</code></pre>
</div>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005foptions"></span></p>
2022-08-24 15:22:41 +02:00
<p>_options</p>
2021-05-11 02:29:21 +02:00
<p>This can be used to complete the names of shell options. It provides a
2022-08-24 15:22:41 +02:00
matcher specification that ignores a leading no, ignores underscores
2021-05-11 02:29:21 +02:00
and allows upper-case letters to match their lower-case counterparts
2022-08-24 15:22:41 +02:00
(for example, glob, noglob, NO_GLOB are all completed). Any
arguments are propagated to the compadd builtin.</p>
<p><span id="index-_005foptions_005fset"></span> <span
id="index-_005foptions_005funset"></span></p>
<p>_options_set and _options_unset</p>
2021-05-11 02:29:21 +02:00
<p>These functions complete only set or unset options, with the same
2022-08-24 15:22:41 +02:00
matching specification used in the _options function.</p>
<p>Note that you need to uncomment a few lines in the _main_complete
2021-05-11 02:29:21 +02:00
function for these functions to work properly. The lines in question are
used to store the option settings in effect before the completion widget
locally sets the options it needs. Hence these functions are not
generally used by the completion system.</p>
<p><span id="index-_005fparameters"></span></p>
2022-08-24 15:22:41 +02:00
<p>_parameters</p>
2021-05-11 02:29:21 +02:00
<p>This is used to complete the names of shell parameters.</p>
2022-08-24 15:22:41 +02:00
<p>The option -g <code>pattern</code> limits the completion to parameters whose type
matches the <code>pattern</code>. The type of a parameter is that shown by print
${(t)<code>param</code>}, hence judicious use of * in <code>pattern</code> is probably
necessary.</p>
<p>All other arguments are passed to the compadd builtin.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fpath_005ffiles"></span></p>
2022-08-24 15:22:41 +02:00
<p>_path_files</p>
2021-05-11 02:29:21 +02:00
<p>This function is used throughout the completion system to complete
filenames. It allows completion of partial paths. For example, the
2022-08-24 15:22:41 +02:00
string /u/i/s/sig may be completed to /usr/include/sys/signal.h.</p>
<p>The options accepted by both _path_files and _files are:</p>
<p>-f<br />
2021-05-11 02:29:21 +02:00
Complete all filenames. This is the default.</p>
2022-08-24 15:22:41 +02:00
<p>-/<br />
2021-05-11 02:29:21 +02:00
Specifies that only directories should be completed.</p>
2022-08-24 15:22:41 +02:00
<p>-g <code>pattern</code><br />
Specifies that only files matching the <code>pattern</code> should be completed.</p>
<p>-W <code>paths</code><br />
Specifies path prefixes that are to be prepended to the string from the
command line to generate the filenames but that should not be inserted
as completions nor shown in completion listings. Here, <code>paths</code> may be
the name of an array parameter, a literal list of paths enclosed in
parentheses or an absolute pathname.</p>
<p>-F <code>ignored-files</code><br />
This behaves as for the corresponding option to the compadd builtin. It
gives direct control over which filenames should be ignored. If the
option is not present, the ignored-patterns style is used.</p>
<p>Both _path_files and _files also accept the following options which
are passed to compadd: -J, -V, -1, -2, -n, -X, -M, -P,
-S, -q, -r, and -R.</p>
<p>Finally, the _path_files function uses the styles expand, ambiguous,
special-dirs, list-suffixes and file-sort described above.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fpick_005fvariant"></span></p>
2022-08-24 15:22:41 +02:00
<p>_pick_variant [ -b <code>builtin-label</code> ] [ -c <code>command</code> ] [ -r <code>name</code>
]</p>
<p>              <code>label</code>=<code>pattern</code> ... <code>label</code> [ <code>arg</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>This function is used to resolve situations where a single command name
requires more than one type of handling, either because it has more than
one variant or because there is a name clash between two different
commands.</p>
2022-08-24 15:22:41 +02:00
<p>The command to run is taken from the first element of the array words
unless this is overridden by the option -c. This command is run and its
output is compared with a series of patterns. Arguments to be passed to
the command can be specified at the end after all the other arguments.
The patterns to try in order are given by the arguments
<code>label</code>=<code>pattern</code>; if the output of <code>command</code> <code>arg</code> ... contains
2021-05-11 02:29:21 +02:00
<code>pattern</code>, then <code>label</code> is selected as the label for the command
variant. If none of the patterns match, the final command label is
selected and status 1 is returned.</p>
2022-08-24 15:22:41 +02:00
<p>If the -b <code>builtin-label</code> is given, the command is tested to see if it
is provided as a shell builtin, possibly autoloaded; if so, the label
2021-05-11 02:29:21 +02:00
<code>builtin-label</code> is selected as the label for the variant.</p>
2022-08-24 15:22:41 +02:00
<p>If the -r <code>name</code> is given, the <code>label</code> picked is stored in the
2021-05-11 02:29:21 +02:00
parameter named <code>name</code>.</p>
2022-08-24 15:22:41 +02:00
<p>The results are also cached in the _cmd_variant associative array
2021-05-11 02:29:21 +02:00
indexed by the name of the command run.</p>
<p><span id="index-_005fregex_005farguments"></span></p>
2022-08-24 15:22:41 +02:00
<p>_regex_arguments <code>name</code> <code>spec</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>This function generates a completion function <code>name</code> which matches the
specifications <code>spec</code>s, a set of regular expressions as described below.
2022-08-24 15:22:41 +02:00
After running _regex_arguments, the function <code>name</code> should be called as
a normal completion function. The pattern to be matched is given by the
contents of the words array up to the current cursor position joined
together with null characters; no quotation is applied.</p>
<p>The arguments are grouped as sets of alternatives separated by |,
2021-05-11 02:29:21 +02:00
which are tried one after the other until one matches. Each alternative
consists of a one or more specifications which are tried left to right,
with each pattern matched being stripped in turn from the command line
being tested, until all of the group succeeds or until one fails; in the
latter case, the next alternative is tried. This structure can be
repeated to arbitrary depth by using parentheses; matching proceeds from
inside to outside.</p>
<p>A special procedure is applied if no test succeeds but the remaining
command line string contains no null character (implying the remaining
word is the one for which completions are to be generated). The
completion target is restricted to the remaining word and any <code>action</code>s
for the corresponding patterns are executed. In this case, nothing is
stripped from the command line string. The order of evaluation of the
2022-08-24 15:22:41 +02:00
<code>action</code>s can be determined by the tag-order style; the various formats
supported by _alternative can be used in <code>action</code>. The <code>descr</code> is used
for setting up the array parameter expl.</p>
2021-05-11 02:29:21 +02:00
<p>Specification arguments take one of following forms, in which
2022-08-24 15:22:41 +02:00
metacharacters such as (, ), # and | should be quoted.</p>
<p>/<code>pattern</code>/ [%<code>lookahead</code>%] [-<code>guard</code>] [:<code>tag</code>:<code>descr</code>:<code>action</code>]<br />
2021-05-11 02:29:21 +02:00
This is a single primitive component. The function tests whether the
2022-08-24 15:22:41 +02:00
combined pattern (#b)((#B)<code>pattern</code>)<code>lookahead</code>* matches the command
line string. If so, <code>guard</code> is evaluated and its return status is
examined to determine if the test has succeeded. The <code>pattern</code> string
[] is guaranteed never to match. The <code>lookahead</code> is not stripped
from the command line before the next pattern is examined.</p>
<p>The argument starting with : is used in the same manner as an argument
to _alternative.</p>
2021-05-11 02:29:21 +02:00
<p>A component is used as follows: <code>pattern</code> is tested to see if the
2022-08-24 15:22:41 +02:00
component already exists on the command line. If it does, any following
specifications are examined to find something to complete. If a
component is reached but no such pattern exists yet on the command line,
the string containing the <code>action</code> is used to generate matches to insert
at that point.</p>
<p>/<code>pattern</code>/+ [%<code>lookahead</code>%] [-<code>guard</code>] [:<code>tag</code>:<code>descr</code>:<code>action</code>]<br />
This is similar to /<code>pattern</code>/ ... but the left part of the command
line string (i.e. the part already matched by previous patterns) is also
considered part of the completion target.</p>
<p>/<code>pattern</code>/- [%<code>lookahead</code>%] [-<code>guard</code>] [:<code>tag</code>:<code>descr</code>:<code>action</code>]<br />
This is similar to /<code>pattern</code>/ ... but the <code>action</code>s of the current
and previously matched patterns are ignored even if the following
<code>pattern</code> matches the empty string.</p>
<p>( <code>spec</code> )<br />
Parentheses may be used to groups <code>spec</code>s; note each parenthesis is a
single argument to _regex_arguments.</p>
<p><code>spec</code> #<br />
2021-05-11 02:29:21 +02:00
This allows any number of repetitions of <code>spec</code>.</p>
<p><code>spec</code> <code>spec</code><br />
The two <code>spec</code>s are to be matched one after the other as described
above.</p>
2022-08-24 15:22:41 +02:00
<p><code>spec</code> | <code>spec</code><br />
2021-05-11 02:29:21 +02:00
Either of the two <code>spec</code>s can be matched.</p>
2022-08-24 15:22:41 +02:00
<p>The function _regex_words can be used as a helper function to generate
2021-05-11 02:29:21 +02:00
matches for a set of alternative words possibly with their own arguments
as a command line argument.</p>
<p>Examples:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">_regex_arguments _tst /$'[^\0]#\0'/ \
2021-05-11 02:29:21 +02:00
/$'[^\0]#\0'/ :'compadd aaa'
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>This generates a function _tst that completes aaa as its only argument.
The <code>tag</code> and <code>description</code> for the action have been omitted for brevity
(this works but is not recommended in normal use). The first component
matches the command word, which is arbitrary; the second matches any
argument. As the argument is also arbitrary, any following component
would not depend on aaa being present.</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">_regex_arguments _tst /$'[^\0]#\0'/ \
2021-05-11 02:29:21 +02:00
/$'aaa\0'/ :'compadd aaa'
</code></pre>
</div>
<p>This is a more typical use; it is similar, but any following patterns
2022-08-24 15:22:41 +02:00
would only match if aaa was present as the first argument.</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">_regex_arguments _tst /$'[^\0]#\0'/ \( \
2021-05-11 02:29:21 +02:00
/$'aaa\0'/ :'compadd aaa' \
/$'bbb\0'/ :'compadd bbb' \) \#
</code></pre>
</div>
<p>In this example, an indefinite number of command arguments may be
2022-08-24 15:22:41 +02:00
completed. Odd arguments are completed as aaa and even arguments as bbb.
Completion fails unless the set of aaa and bbb arguments before the
current one is matched correctly.</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">_regex_arguments _tst /$'[^\0]#\0'/ \
2021-05-11 02:29:21 +02:00
\( /$'aaa\0'/ :'compadd aaa' \| \
/$'bbb\0'/ :'compadd bbb' \) \#
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>This is similar, but either aaa or bbb may be completed for any
argument. In this case _regex_words could be used to generate</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fregex_005fwords-_005b-_002dt-term-_005d"></span></p>
2022-08-24 15:22:41 +02:00
<p>_regex_words <code>tag</code> <code>description</code> <code>spec</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>This function can be used to generate arguments for the
2022-08-24 15:22:41 +02:00
_regex_arguments command which may be inserted at any point where a set
of rules is expected. The <code>tag</code> and <code>description</code> give a standard tag
and description pertaining to the current context. Each <code>spec</code> contains
two or three arguments separated by a colon: note that there is no
leading colon in this case.</p>
2021-05-11 02:29:21 +02:00
<p>Each <code>spec</code> gives one of a set of words that may be completed at this
point, together with arguments. It is thus roughly equivalent to the
2022-08-24 15:22:41 +02:00
_arguments function when used in normal (non-regex) completion.</p>
2021-05-11 02:29:21 +02:00
<p>The part of the <code>spec</code> before the first colon is the word to be
2022-08-24 15:22:41 +02:00
completed. This may contain a *; the entire word, before and after the
* is completed, but only the text before the * is required for the
2021-05-11 02:29:21 +02:00
context to be matched, so that further arguments may be completed after
the abbreviated form.</p>
<p>The second part of <code>spec</code> is a description for the word being completed.</p>
<p>The optional third part of the <code>spec</code> describes how words following the
one being completed are themselves to be completed. It will be evaluated
in order to avoid problems with quoting. This means that typically it
contains a reference to an array containing previously generated regex
arguments.</p>
2022-08-24 15:22:41 +02:00
<p>The option -t <code>term</code> specifies a terminator for the word instead of the
usual space. This is handled as an auto-removable suffix in the manner
of the option -s <code>sep</code> to _values.</p>
<p>The result of the processing by _regex_words is placed in the array
reply, which should be made local to the calling function. If the set of
words and arguments may be matched repeatedly, a # should be appended to
the generated array at that point.</p>
2021-05-11 02:29:21 +02:00
<p>For example:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">local -a reply
2021-05-11 02:29:21 +02:00
_regex_words mydb-commands 'mydb commands' \
'add:add an entry to mydb:$mydb_add_cmds' \
'show:show entries in mydb'
_regex_arguments _mydb &quot;$reply[@]&quot;
_mydb &quot;$@&quot;
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>This shows a completion function for a command mydb which takes two
command arguments, add and show. show takes no arguments, while the
arguments for add have already been prepared in an array mydb_add_cmds,
quite possibly by a previous call to _regex_words.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005frequested"></span></p>
2022-08-24 15:22:41 +02:00
<p>_requested [ -x ] [ -12VJ ] <code>tag</code> [ <code>name</code> <code>descr</code> [ <code>command</code> [
<code>arg</code> ... ] ]</p>
2021-05-11 02:29:21 +02:00
<p>This function is called to decide whether a tag already registered by a
2022-08-24 15:22:41 +02:00
call to _tags (see below) has been requested by the user and hence
2021-05-11 02:29:21 +02:00
completion should be performed for it. It returns status zero if the tag
is requested and non-zero otherwise. The function is typically used as
part of a loop over different tags as follows:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">_tags foo bar baz
2021-05-11 02:29:21 +02:00
while _tags; do
if _requested foo; then
... # perform completion for foo
fi
... # test the tags bar and baz in the same way
... # exit loop if matches were generated
done
</code></pre>
</div>
<p>Note that the test for whether matches were generated is not performed
2022-08-24 15:22:41 +02:00
until the end of the _tags loop. This is so that the user can set the
tag-order style to specify a set of tags to be completed at the same
2021-05-11 02:29:21 +02:00
time.</p>
2022-08-24 15:22:41 +02:00
<p>If <code>name</code> and <code>descr</code> are given, _requested calls the _description
2021-05-11 02:29:21 +02:00
function with these arguments together with the options passed to
2022-08-24 15:22:41 +02:00
_requested.</p>
<p>If <code>command</code> is given, the _all_labels function will be called
2021-05-11 02:29:21 +02:00
immediately with the same arguments. In simple cases this makes it
possible to perform the test for the tag and the matching in one go. For
example:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">local expl ret=1
2021-05-11 02:29:21 +02:00
_tags foo bar baz
while _tags; do
_requested foo expl 'description' \
compadd foobar foobaz &amp;&amp; ret=0
...
(( ret )) || break
done
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>If the <code>command</code> is not compadd, it must nevertheless be prepared to
2021-05-11 02:29:21 +02:00
handle the same options.</p>
<p><span id="index-_005fretrieve_005fcache"></span></p>
2022-08-24 15:22:41 +02:00
<p>_retrieve_cache <code>cache_identifier</code></p>
2021-05-11 02:29:21 +02:00
<p>This function retrieves completion information from the file given by
2022-08-24 15:22:41 +02:00
<code>cache_identifier</code>, stored in a directory specified by the cache-path
style which defaults to ~/.zcompcache. The return status is zero if
2021-05-11 02:29:21 +02:00
retrieval was successful. It will only attempt retrieval if the
2022-08-24 15:22:41 +02:00
use-cache style is set, so you can call this function without worrying
2021-05-11 02:29:21 +02:00
about whether the user wanted to use the caching layer.</p>
2022-08-24 15:22:41 +02:00
<p>See _store_cache below for more details.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fsep_005fparts"></span></p>
2022-08-24 15:22:41 +02:00
<p>_sep_parts</p>
2021-05-11 02:29:21 +02:00
<p>This function is passed alternating arrays and separators as arguments.
The arrays specify completions for parts of strings to be separated by
the separators. The arrays may be the names of array parameters or a
quoted list of words in parentheses. For example, with the array
2022-08-24 15:22:41 +02:00
hosts=(ftp news) the call _sep_parts (foo bar) @ hosts will
complete the string f to foo and the string b@n to bar@news.</p>
<p>This function accepts the compadd options -V, -J, -1, -2, -n,
-X, -M, -P, -S, -r, -R, and -q and passes them on to the
compadd builtin used to add the matches.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fsequence"></span></p>
2022-08-24 15:22:41 +02:00
<p>_sequence [ -s <code>sep</code> ] [ -n <code>max</code> ] [ -d ] <code>function</code> [ - ] ...</p>
2021-05-11 02:29:21 +02:00
<p>This function is a wrapper to other functions for completing items in a
separated list. The same function is used to complete each item in the
2022-08-24 15:22:41 +02:00
list. The separator is specified with the -s option. If -s is omitted it
will use ,. Duplicate values are not matched unless -d is specified.
If there is a fixed or maximum number of items in the list, this can be
specified with the -n option.</p>
<p>Common compadd options are passed on to the function. It is possible to
use compadd directly with _sequence, though _values may be more
2021-05-11 02:29:21 +02:00
appropriate in this situation.</p>
<p><span id="index-_005fsetup"></span></p>
2022-08-24 15:22:41 +02:00
<p>_setup <code>tag</code> [ <code>group</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>This function sets up the special parameters used by the completion
system appropriately for the <code>tag</code> given as the first argument. It uses
2022-08-24 15:22:41 +02:00
the styles list-colors, list-packed, list-rows-first, last-prompt,
accept-exact, menu and force-list.</p>
2021-05-11 02:29:21 +02:00
<p>The optional <code>group</code> supplies the name of the group in which the matches
will be placed. If it is not given, the <code>tag</code> is used as the group name.</p>
2022-08-24 15:22:41 +02:00
<p>This function is called automatically from _description and hence is
2021-05-11 02:29:21 +02:00
not normally called explicitly.</p>
<p><span id="index-_005fstore_005fcache"></span></p>
2022-08-24 15:22:41 +02:00
<p>_store_cache <code>cache_identifier</code> <code>param</code> ...</p>
<p>This function, together with _retrieve_cache and _cache_invalid,
2021-05-11 02:29:21 +02:00
implements a caching layer which can be used in any completion function.
Data obtained by costly operations are stored in parameters; this
function then dumps the values of those parameters to a file. The data
2022-08-24 15:22:41 +02:00
can then be retrieved quickly from that file via _retrieve_cache, even
2021-05-11 02:29:21 +02:00
in different instances of the shell.</p>
<p>The <code>cache_identifier</code> specifies the file which the data should be
2022-08-24 15:22:41 +02:00
dumped to. The file is stored in a directory specified by the cache-path
style which defaults to ~/.zcompcache. The remaining <code>param</code>s arguments
are the parameters to dump to the file.</p>
2021-05-11 02:29:21 +02:00
<p>The return status is zero if storage was successful. The function will
2022-08-24 15:22:41 +02:00
only attempt storage if the use-cache style is set, so you can call this
function without worrying about whether the user wanted to use the
2021-05-11 02:29:21 +02:00
caching layer.</p>
2022-08-24 15:22:41 +02:00
<p>The completion function may avoid calling _retrieve_cache when it
2021-05-11 02:29:21 +02:00
already has the completion data available as parameters. However, in
2022-08-24 15:22:41 +02:00
that case it should call _cache_invalid to check whether the data in
2021-05-11 02:29:21 +02:00
the parameters and in the cache are still valid.</p>
<p>See the _perl_modules completion function for a simple example of the
usage of the caching layer.</p>
<p><span id="index-_005ftags"></span></p>
2022-08-24 15:22:41 +02:00
<p>_tags [ [ -C <code>name</code> ] <code>tag</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>If called with arguments, these are taken to be the names of tags valid
for completions in the current context. These tags are stored internally
2022-08-24 15:22:41 +02:00
and sorted by using the tag-order style.</p>
<p>Next, _tags is called repeatedly without arguments from the same
2021-05-11 02:29:21 +02:00
completion function. This successively selects the first, second, etc.
set of tags requested by the user. The return status is zero if at least
one of the tags is requested and non-zero otherwise. To test if a
2022-08-24 15:22:41 +02:00
particular tag is to be tried, the _requested function should be called
(see above).</p>
<p>If -C <code>name</code> is given, <code>name</code> is temporarily stored in the <code>argument</code>
field (the fifth) of the context in the curcontext parameter during the
call to _tags; the field is restored on exit. This allows _tags to use
a more specific context without having to change and reset the
curcontext parameter (which has the same effect).</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005ftilde_005ffiles"></span></p>
2022-08-24 15:22:41 +02:00
<p>_tilde_files</p>
<p>Like _files, but resolve leading tildes according to the rules of
filename expansion, so the suggested completions dont start with a ~
even if the filename on the command-line does.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fvalues"></span></p>
2022-08-24 15:22:41 +02:00
<p>_values [ -O <code>name</code> ] [ -s <code>sep</code> ] [ -S <code>sep</code> ] [ -wC ] <code>desc</code>
<code>spec</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>This is used to complete arbitrary keywords (values) and their
arguments, or lists of such combinations.</p>
2022-08-24 15:22:41 +02:00
<p>If the first argument is the option -O <code>name</code>, it will be used in the
same way as by the _arguments function. In other words, the elements of
the <code>name</code> array will be passed to compadd when executing an action.</p>
<p>If the first argument (or the first argument after -O <code>name</code>) is -s,
the next argument is used as the character that separates multiple
values. This character is automatically added after each value in an
auto-removable fashion (see below); all values completed by _values
-s appear in the same word on the command line, unlike completion using
_arguments. If this option is not present, only a single value will be
completed per word.</p>
<p>Normally, _values will only use the current word to determine which
2021-05-11 02:29:21 +02:00
values are already present on the command line and hence are not to be
2022-08-24 15:22:41 +02:00
completed again. If the -w option is given, other arguments are examined
as well.</p>
2021-05-11 02:29:21 +02:00
<p>The first non-option argument, <code>desc</code>, is used as a string to print as a
description before listing the values.</p>
<p>All other arguments describe the possible values and their arguments in
2022-08-24 15:22:41 +02:00
the same format used for the description of options by the _arguments
2021-05-11 02:29:21 +02:00
function (see above). The only differences are that no minus or plus
sign is required at the beginning, values can have only one argument,
and the forms of action beginning with an equal sign are not supported.</p>
<p>The character separating a value from its argument can be set using the
2022-08-24 15:22:41 +02:00
option -S (like -s, followed by the character to use as the separator in
the next argument). By default the equals sign will be used as the
separator between values and arguments.</p>
2021-05-11 02:29:21 +02:00
<p>Example:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">_values -s , 'description' \
2021-05-11 02:29:21 +02:00
'*foo[bar]' \
'(two)*one[number]:first count:' \
'two[another number]::second count:(1 2 3)'
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>This describes three possible values: foo, one, and two. The first
is described as bar, takes no argument and may appear more than once.
The second is described as number, may appear more than once, and
takes one mandatory argument described as first count; no action is
specified, so it will not be completed. The (two) at the beginning
says that if the value one is on the line, the value two will no
longer be considered a possible completion. Finally, the last value
(two) is described as another number and takes an optional argument
described as second count for which the completions (to appear after
an =) are 1, 2, and 3. The _values function will complete lists
of these values separated by commas.</p>
<p>Like _arguments, this function temporarily adds another context name
2021-05-11 02:29:21 +02:00
component to the arguments element (the fifth) of the current context
while executing the <code>action</code>. Here this name is just the name of the
value for which the argument is completed.</p>
2022-08-24 15:22:41 +02:00
<p>The style verbose is used to decide if the descriptions for the values
2021-05-11 02:29:21 +02:00
(but not those for the arguments) should be printed.</p>
2022-08-24 15:22:41 +02:00
<p>The associative array val_args is used to report values and their
arguments; this works similarly to the opt_args associative array used
by _arguments. Hence the function calling _values should declare the
local parameters state, state_descr, line, context and val_args:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">local context state state_descr line
2021-05-11 02:29:21 +02:00
typeset -A val_args
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>when using an action of the form -&gt;<code>string</code>. With this function the
context parameter will be set to the name of the value whose argument is
to be completed. Note that for _values, the state and state_descr are
scalars rather than arrays. Only a single matching state is returned.</p>
<p>Note also that _values normally adds the character used as the
separator between values as an auto-removable suffix (similar to a /
after a directory). However, this is not possible for a -&gt;<code>string</code>
2021-05-11 02:29:21 +02:00
action as the matches for the argument are generated by the calling
function. To get the usual behaviour, the calling function can add the
2022-08-24 15:22:41 +02:00
separator <code>x</code> as a suffix by passing the options -qS <code>x</code> either
directly or indirectly to compadd.</p>
<p>The option -C is treated in the same way as it is by _arguments. In
that case the parameter curcontext should be made local instead of
context (as described above).</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fwanted"></span></p>
2022-08-24 15:22:41 +02:00
<p>_wanted [ -x ] [ -C <code>name</code> ] [ -12VJ ] <code>tag</code> <code>name</code> <code>descr</code>
<code>command</code> [ <code>arg</code> ...]</p>
2021-05-11 02:29:21 +02:00
<p>In many contexts, completion can only generate one particular set of
matches, usually corresponding to a single tag. However, it is still
necessary to decide whether the user requires matches of this type. This
function is useful in such a case.</p>
2022-08-24 15:22:41 +02:00
<p>The arguments to _wanted are the same as those to _requested, i.e.
arguments to be passed to _description. However, in this case the
2021-05-11 02:29:21 +02:00
<code>command</code> is not optional; all the processing of tags, including the
loop over both tags and tag labels and the generation of matches, is
2022-08-24 15:22:41 +02:00
carried out automatically by _wanted.</p>
2021-05-11 02:29:21 +02:00
<p>Hence to offer only one tag and immediately add the corresponding
matches with the given description:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">local expl
2021-05-11 02:29:21 +02:00
_wanted tag expl 'description' \
2022-08-24 15:22:41 +02:00
compadd -- match1 match2...
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>See also the use of _wanted in the example function in <a href="Expansion.html#Dynamic-named-directories">Dynamic named
directories</a>.</p>
<p>Note that, as for _requested, the <code>command</code> must be able to accept
options to be passed down to compadd.</p>
<p>Like _tags this function supports the -C option to give a different
name for the argument context field. The -x option has the same meaning
as for _description.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-_005fwidgets"></span></p>
2022-08-24 15:22:41 +02:00
<p>_widgets [ -g <code>pattern</code> ]</p>
<p>This function completes names of zle widgets (see <a href="Zsh-Line-Editor.html#Zle-Widgets">Zle
Widgets</a>). The <code>pattern</code>, if present,
is matched against values of the $widgets special parameter, documented
in <a href="Zsh-Modules.html#The-zsh_002fzleparameter-Module">The zsh/zleparameter
2021-05-11 02:29:21 +02:00
Module</a>.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Completion-System-Variables"></span> <span
id="Completion-System-Variables-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="207-completion-system-variables"><a class="header" href="#207-completion-system-variables">20.7 Completion System Variables</a></h2>
<p><span id="index-completion-system_002c-variables"></span></p>
2022-08-24 15:22:41 +02:00
<p>There are some standard variables, initialised by the _main_complete
2021-05-11 02:29:21 +02:00
function and then used from other functions.</p>
<p>The standard variables are:</p>
2022-08-24 15:22:41 +02:00
<p>_comp_caller_options<br />
The completion system uses setopt to set a number of options. This
allows functions to be written without concern for compatibility with
every possible combination of user options. However, sometimes
completion needs to know what the users option preferences are. These
are saved in the _comp_caller_options associative array. Option names,
spelled in lowercase without underscores, are mapped to one or other of
the strings on and off.</p>
<p>_comp_priv_prefix<br />
Completion functions such as _sudo can set the _comp_priv_prefix array
to a command prefix that may then be used by _call_program to match the
privileges when calling programs to generate matches.</p>
<p><span id="index-compprefuncs_002c-use-of"></span> <span
id="index-comppostfuncs_002c-use-of"></span></p>
<p>Two more features are offered by the _main_complete function. The
arrays compprefuncs and comppostfuncs may contain names of functions
2021-05-11 02:29:21 +02:00
that are to be called immediately before or after completion has been
tried. A function will only be called once unless it explicitly
reinserts itself into the array.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Completion-Directories"></span> <span
id="Completion-Directories-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="208-completion-directories"><a class="header" href="#208-completion-directories">20.8 Completion Directories</a></h2>
<p><span id="index-completion-system_002c-directory-structure"></span></p>
<p>In the source distribution, the files are contained in various
2022-08-24 15:22:41 +02:00
subdirectories of the Completion directory. They may have been installed
in the same structure, or into one single function directory. The
following is a description of the files found in the original directory
structure. If you wish to alter an installed file, you will need to copy
it to some directory which appears earlier in your fpath than the
standard directory where it appears.</p>
<p>Base<br />
The core functions and special completion widgets automatically bound to
keys. You will certainly need most of these, though will probably not
need to alter them. Many of these are documented above.</p>
<p>Zsh<br />
Functions for completing arguments of shell builtin commands and utility
functions for this. Some of these are also used by functions from the
Unix directory.</p>
<p>Unix<br />
Functions for completing arguments of external commands and suites of
commands. They may need modifying for your system, although in many
cases some attempt is made to decide which version of a command is
present. For example, completion for the mount command tries to
determine the system it is running on, while completion for many other
utilities try to decide whether the GNU version of the command is in
use, and hence whether the --help option is supported.</p>
<p>X, AIX, BSD, ...<br />
2021-05-11 02:29:21 +02:00
Completion and utility function for commands available only on some
2022-08-24 15:22:41 +02:00
systems. These are not arranged hierarchically, so, for example, both
the Linux and Debian directories, as well as the X directory, may be
useful on your system.</p>
<hr />
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="Completion-Using-compctl.html#21-completion-using-compctl">21 Completion Using compctl</a>
<ul>
<li><a href="Completion-Using-compctl.html#211-types-of-completion">21.1 Types of completion</a></li>
<li><a href="Completion-Using-compctl.html#212-description">21.2 Description</a></li>
<li><a href="Completion-Using-compctl.html#213-command-flags">21.3 Command Flags</a></li>
<li><a href="Completion-Using-compctl.html#214-option-flags">21.4 Option Flags</a>
<ul>
<li><a href="Completion-Using-compctl.html#2141-simple-flags">21.4.1 Simple Flags</a></li>
<li><a href="Completion-Using-compctl.html#2142-flags-with-arguments">21.4.2 Flags with Arguments</a></li>
<li><a href="Completion-Using-compctl.html#2143-control-flags">21.4.3 Control Flags</a></li>
</ul>
</li>
<li><a href="Completion-Using-compctl.html#215-alternative-completion">21.5 Alternative Completion</a></li>
<li><a href="Completion-Using-compctl.html#216-extended-completion">21.6 Extended Completion</a></li>
<li><a href="Completion-Using-compctl.html#217-example">21.7 Example</a></li>
</ul>
</li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2022-08-24 15:22:41 +02:00
<p><span id="Completion-Using-compctl"></span> <span
id="Completion-Using-compctl-1"></span></p>
2021-05-11 02:29:21 +02:00
<h1 id="21-completion-using-compctl"><a class="header" href="#21-completion-using-compctl">21 Completion Using compctl</a></h1>
2022-08-24 15:22:41 +02:00
<p><span id="index-completion_002c-programmable-2"></span> <span
id="index-completion_002c-controlling-2"></span></p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Types-of-completion"></span></p>
<h2 id="211-types-of-completion"><a class="header" href="#211-types-of-completion">21.1 Types of completion</a></h2>
<p>This version of zsh has two ways of performing completion of words on
the command line. New users of the shell may prefer to use the newer and
more powerful system based on shell functions; this is described in
<a href="Completion-System.html#Completion-System">Completion System</a>, and the
basic shell mechanisms which support it are described in <a href="Completion-Widgets.html#Completion-Widgets">Completion
Widgets</a>. This chapter
2022-08-24 15:22:41 +02:00
describes the older compctl command.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Description-5"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="212-description"><a class="header" href="#212-description">21.2 Description</a></h2>
<p><span id="index-compctl"></span></p>
2022-08-24 15:22:41 +02:00
<p>compctl [ -CDT ] <code>options</code> [ <code>command</code> ... ]</p>
<p>compctl [ -CDT ] <code>options</code> [ -x <code>pattern</code> <code>options</code> - ... -- ]</p>
<p>        [ + <code>options</code> [ -x ... -- ] ... [+] ] [ <code>command</code> ... ]</p>
<p>compctl -M <code>match-specs</code> ...</p>
<p>compctl -L [ -CDTM ] [ <code>command</code> ... ]</p>
<p>compctl + <code>command</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>Control the editors completion behavior according to the supplied set
2022-08-24 15:22:41 +02:00
of <code>options</code>. Various editing commands, notably expand-or-complete-word,
usually bound to tab, will attempt to complete a word typed by the user,
while others, notably delete-char-or-list, usually bound to ^D in EMACS
editing mode, list the possibilities; compctl controls what those
possibilities are. They may for example be filenames (the most common
case, and hence the default), shell variables, or words from a
user-specified list.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Command-Flags"></span> <span id="Command-Flags-1"></span></p>
<h2 id="213-command-flags"><a class="header" href="#213-command-flags">21.3 Command Flags</a></h2>
<p>Completion of the arguments of a command may be different for each
command or may use the default. The behavior when completing the command
word itself may also be separately specified. These correspond to the
2022-08-24 15:22:41 +02:00
following flags and arguments, all of which (except for -L) may be
2021-05-11 02:29:21 +02:00
combined with any combination of the <code>options</code> described subsequently in
<a href="Completion-Using-compctl.html#Option-Flags">Option Flags</a>:</p>
<p><code>command</code> ...<br />
2022-08-24 15:22:41 +02:00
controls completion for the named commands, which must be listed last on
the command line. If completion is attempted for a command with a
pathname containing slashes and no completion definition is found, the
search is retried with the last pathname component. If the command
starts with a =, completion is tried with the pathname of the command.</p>
<p>Any of the <code>command</code> strings may be patterns of the form normally used
for filename generation. These should be quoted to protect them from
immediate expansion; for example the command string foo* arranges for
completion of the words of any command beginning with foo. When
completion is attempted, all pattern completions are tried in the
reverse order of their definition until one matches. By default,
completion then proceeds as normal, i.e. the shell will try to generate
more matches for the specific command on the command line; this can be
overridden by including -tn in the flags for the pattern completion.</p>
2021-05-11 02:29:21 +02:00
<p>Note that aliases are expanded before the command name is determined
2022-08-24 15:22:41 +02:00
unless the COMPLETE_ALIASES option is set. Commands may not be combined
with the -C, -D or -T flags.</p>
<p>-C<br />
controls completion when the command word itself is being completed. If
no compctl -C command has been issued, the names of any as aliases or
functions) are completed.</p>
<p>-D<br />
controls default completion behavior for the arguments of commands not
assigned any special behavior. If no compctl -D command has been issued,
filenames are completed.</p>
<p>-T<br />
2021-05-11 02:29:21 +02:00
supplies completion flags to be used before any other processing is
2022-08-24 15:22:41 +02:00
done, even before processing for compctls defined for specific commands.
This is especially useful when combined with extended completion (the -x
flag, see <a href="Completion-Using-compctl.html#Extended-Completion">Extended Completion</a> below). Using this
flag you can define default behavior which will apply to all commands
without exception, or you can alter the standard behavior for all
commands. For example, if your access to the user database is too slow
and/or it contains too many users (so that completion after ~ is too
2021-05-11 02:29:21 +02:00
slow to be usable), you can use</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">compctl -T -x 's[~] C[0,[^/]#]' -k friends -S/ -tn
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>to complete the strings in the array friends after a ~. The
C[<code>...</code>] argument is necessary so that this form of ~-completion is
not tried after the directory name is finished.</p>
<p>-L<br />
2021-05-11 02:29:21 +02:00
<em>no argument</em><br />
2022-08-24 15:22:41 +02:00
If no argument is given, compctl lists all defined completions in an
abbreviated form; with a list of <code>options</code>, all completions with those
flags set (not counting extended completion) are listed.</p>
<p>If the + flag is alone and followed immediately by the <code>command</code> list,
2021-05-11 02:29:21 +02:00
the completion behavior for all the commands in the list is reset to the
default. In other words, completion will subsequently use the options
2022-08-24 15:22:41 +02:00
specified by the -D flag.</p>
<p>The form with -M as the first and only option defines global matching
2021-05-11 02:29:21 +02:00
specifications (see <a href="Completion-Widgets.html#Completion-Matching-Control">Completion Matching
Control</a>). The
match specifications given will be used for every completion attempt
2022-08-24 15:22:41 +02:00
(only when using compctl, not with the new completion system) and are
2021-05-11 02:29:21 +02:00
tried in the order in which they are defined until one generates at
least one match. E.g.:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">compctl -M '' 'm:{a-zA-Z}={A-Za-z}'
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>This will first try completion without any global match specifications
(the empty string) and, if that generates no matches, will try case
insensitive completion.</p>
<hr />
<p><span id="Option-Flags"></span> <span id="Option-Flags-1"></span></p>
<h2 id="214-option-flags"><a class="header" href="#214-option-flags">21.4 Option Flags</a></h2>
2022-08-24 15:22:41 +02:00
<p>[ -fcFBdeaRGovNAIOPZEnbjrzu/12 ]</p>
<p>[ -k <code>array</code> ] [ -g <code>globstring</code> ] [ -s <code>subststring</code> ]</p>
<p>[ -K <code>function</code> ]</p>
<p>[ -Q ] [ -P <code>prefix</code> ] [ -S <code>suffix</code> ]</p>
<p>[ -W <code>file-prefix</code> ] [ -H <code>num pattern</code> ]</p>
<p>[ -q ] [ -X <code>explanation</code> ] [ -Y <code>explanation</code> ]</p>
<p>[ -y <code>func-or-var</code> ] [ -l <code>cmd</code> ] [ -h <code>cmd</code> ] [ -U ]</p>
<p>[ -t <code>continue</code> ] [ -J <code>name</code> ] [ -V <code>name</code> ]</p>
<p>[ -M <code>match-spec</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>The remaining <code>options</code> specify the type of command arguments to look
for during completion. Any combination of these flags may be specified;
the result is a sorted list of all the possibilities. The options are as
follows.</p>
<hr />
<p><span id="Simple-Flags"></span> <span id="Simple-Flags-1"></span></p>
<h3 id="2141-simple-flags"><a class="header" href="#2141-simple-flags">21.4.1 Simple Flags</a></h3>
<p>These produce completion lists made up by the shell itself:</p>
2022-08-24 15:22:41 +02:00
<p>-f<br />
2021-05-11 02:29:21 +02:00
Filenames and file system paths.</p>
2022-08-24 15:22:41 +02:00
<p>-/<br />
2021-05-11 02:29:21 +02:00
Just file system paths.</p>
2022-08-24 15:22:41 +02:00
<p>-c<br />
Command names, including aliases, shell functions, builtins and reserved
words.</p>
<p>-F<br />
2021-05-11 02:29:21 +02:00
Function names.</p>
2022-08-24 15:22:41 +02:00
<p>-B<br />
2021-05-11 02:29:21 +02:00
Names of builtin commands.</p>
2022-08-24 15:22:41 +02:00
<p>-m<br />
2021-05-11 02:29:21 +02:00
Names of external commands.</p>
2022-08-24 15:22:41 +02:00
<p>-w<br />
2021-05-11 02:29:21 +02:00
Reserved words.</p>
2022-08-24 15:22:41 +02:00
<p>-a<br />
2021-05-11 02:29:21 +02:00
Alias names.</p>
2022-08-24 15:22:41 +02:00
<p>-R<br />
2021-05-11 02:29:21 +02:00
Names of regular (non-global) aliases.</p>
2022-08-24 15:22:41 +02:00
<p>-G<br />
2021-05-11 02:29:21 +02:00
Names of global aliases.</p>
2022-08-24 15:22:41 +02:00
<p>-d<br />
This can be combined with -F, -B, -w, -a, -R and -G to get names of
disabled functions, builtins, reserved words or aliases.</p>
<p>-e<br />
This option (to show enabled commands) is in effect by default, but may
be combined with -d; -de in combination with -F, -B, -w, -a, -R and -G
will complete names of functions, builtins, reserved words or aliases
whether or not they are disabled.</p>
<p>-o<br />
2021-05-11 02:29:21 +02:00
Names of shell options (see <a href="Options.html#Options">Options</a>).</p>
2022-08-24 15:22:41 +02:00
<p>-v<br />
2021-05-11 02:29:21 +02:00
Names of any variable defined in the shell.</p>
2022-08-24 15:22:41 +02:00
<p>-N<br />
2021-05-11 02:29:21 +02:00
Names of scalar (non-array) parameters.</p>
2022-08-24 15:22:41 +02:00
<p>-A<br />
2021-05-11 02:29:21 +02:00
Array names.</p>
2022-08-24 15:22:41 +02:00
<p>-I<br />
2021-05-11 02:29:21 +02:00
Names of integer variables.</p>
2022-08-24 15:22:41 +02:00
<p>-O<br />
2021-05-11 02:29:21 +02:00
Names of read-only variables.</p>
2022-08-24 15:22:41 +02:00
<p>-p<br />
Names of parameters used by the shell (including special parameters).</p>
<p>-Z<br />
2021-05-11 02:29:21 +02:00
Names of shell special parameters.</p>
2022-08-24 15:22:41 +02:00
<p>-E<br />
2021-05-11 02:29:21 +02:00
Names of environment variables.</p>
2022-08-24 15:22:41 +02:00
<p>-n<br />
2021-05-11 02:29:21 +02:00
Named directories.</p>
2022-08-24 15:22:41 +02:00
<p>-b<br />
2021-05-11 02:29:21 +02:00
Key binding names.</p>
2022-08-24 15:22:41 +02:00
<p>-j<br />
2021-05-11 02:29:21 +02:00
Job names: the first word of the job leaders command line. This is
2022-08-24 15:22:41 +02:00
useful with the kill builtin.</p>
<p>-r<br />
2021-05-11 02:29:21 +02:00
Names of running jobs.</p>
2022-08-24 15:22:41 +02:00
<p>-z<br />
2021-05-11 02:29:21 +02:00
Names of suspended jobs.</p>
2022-08-24 15:22:41 +02:00
<p>-u<br />
2021-05-11 02:29:21 +02:00
User names.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Flags-with-Arguments"></span> <span
id="Flags-with-Arguments-1"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="2142-flags-with-arguments"><a class="header" href="#2142-flags-with-arguments">21.4.2 Flags with Arguments</a></h3>
<p>These have user supplied arguments to determine how the list of
completions is to be made up:</p>
2022-08-24 15:22:41 +02:00
<p>-k <code>array</code><br />
Names taken from the elements of $<code>array</code> (note that the $ does not
appear on the command line). Alternatively, the argument <code>array</code> itself
may be a set of space- or comma-separated values in parentheses, in
which any delimiter may be escaped with a backslash; in this case the
argument should be quoted. For example,</p>
<div class="example">
<pre><code class="language-zsh">compctl -k &quot;(cputime filesize datasize stacksize
2021-05-11 02:29:21 +02:00
coredumpsize resident descriptors)&quot; limit
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>-g <code>globstring</code><br />
2021-05-11 02:29:21 +02:00
The <code>globstring</code> is expanded using filename globbing; it should be
2022-08-24 15:22:41 +02:00
quoted to protect it from immediate expansion. The resulting filenames
are taken as the possible completions. Use *(/) instead of */ for
directories. The fignore special parameter is not applied to the
resulting files. More than one pattern may be given separated by blanks.
(Note that brace expansion is <em>not</em> part of globbing. Use the syntax
(either|or) to match alternatives.)</p>
<p>-s <code>subststring</code><br />
The <code>subststring</code> is split into words and these words are than expanded
using all shell expansion mechanisms (see
<a href="Expansion.html#Expansion">Expansion</a>). The resulting words are taken as
possible completions. The fignore special parameter is not applied to
the resulting files. Note that -g is faster for filenames.</p>
<p>-K <code>function</code><br />
2021-05-11 02:29:21 +02:00
<span id="index-reply_002c-use-of-2"></span></p>
2022-08-24 15:22:41 +02:00
<p>Call the given function to get the completions. Unless the name starts
with an underscore, the function is passed two arguments: the prefix and
the suffix of the word on which completion is to be attempted, in other
words those characters before the cursor position, and those from the
cursor position onwards. The whole command line can be accessed with the
-c and -l flags of the read builtin. The function should set the
variable reply to an array containing the completions (one completion
per element); note that reply should not be made local to the function.
From such a function the command line can be accessed with the -c and -l
flags to the read builtin. For example,</p>
<div class="example">
<pre><code class="language-zsh">function whoson { reply=(`users`); }
2021-05-11 02:29:21 +02:00
compctl -K whoson talk
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>completes only logged-on users after talk. Note that whoson must
return an array, so reply=users would be incorrect.</p>
<p>-H <code>num pattern</code><br />
The possible completions are taken from the last <code>num</code> history lines.
Only words matching <code>pattern</code> are taken. If <code>num</code> is zero or negative
the whole history is searched and if <code>pattern</code> is the empty string all
words are taken (as with *). A typical use is</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">compctl -D -f + -H 0 ''
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>which forces completion to look back in the history list for a word if
no filename matches.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Control-Flags"></span> <span id="Control-Flags-1"></span></p>
<h3 id="2143-control-flags"><a class="header" href="#2143-control-flags">21.4.3 Control Flags</a></h3>
<p>These do not directly specify types of name to be completed, but
manipulate the options that do:</p>
2022-08-24 15:22:41 +02:00
<p>-Q<br />
This instructs the shell not to quote any metacharacters in the possible
completions. Normally the results of a completion are inserted into the
command line with any metacharacters quoted so that they are interpreted
as normal characters. This is appropriate for filenames and ordinary
strings. However, for special effects, such as inserting a backquoted
expression from a completion array (-k) so that the expression will not
be evaluated until the complete line is executed, this option must be
used.</p>
<p>-P <code>prefix</code><br />
The <code>prefix</code> is inserted just before the completed string; any initial
part already typed will be completed and the whole <code>prefix</code> ignored for
completion purposes. For example,</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">compctl -j -P &quot;%&quot; kill
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>inserts a % after the kill command and then completes job names.</p>
2022-08-24 15:22:41 +02:00
<p>-S <code>suffix</code><br />
When a completion is found the <code>suffix</code> is inserted after the completed
string. In the case of menu completion the suffix is inserted
immediately, but it is still possible to cycle through the list of
completions by repeatedly hitting the same key.</p>
<p>-W <code>file-prefix</code><br />
With directory <code>file-prefix</code>: for command, file, directory and globbing
completion (options -c, -f, -/, -g), the file prefix is implicitly added
in front of the completion. For example,</p>
<div class="example">
<pre><code class="language-zsh">compctl -/ -W ~/Mail maildirs
</code></pre>
</div>
<p>completes any subdirectories to any depth beneath the directory ~/Mail,
although that prefix does not appear on the command line. The
<code>file-prefix</code> may also be of the form accepted by the -k flag, i.e. the
name of an array or a literal list in parenthesis. In this case all the
directories in the list will be searched for possible completions.</p>
<p>-q<br />
If used with a suffix as specified by the -S option, this causes the
suffix to be removed if the next character typed is a blank or does not
insert anything or if the suffix consists of only one character and the
next character typed is the same character; this the same rule used for
the AUTO_REMOVE_SLASH option. The option is most useful for list
separators (comma, colon, etc.).</p>
<p>-l <code>cmd</code><br />
2021-05-11 02:29:21 +02:00
This option restricts the range of command line words that are
considered to be arguments. If combined with one of the extended
2022-08-24 15:22:41 +02:00
completion patterns p[...], r[...], or R[...] (see <a href="Completion-Using-compctl.html#Extended-Completion">Extended
Completion</a> below) the range is restricted to the
range of arguments specified in the brackets. Completion is then
performed as if these had been given as arguments to the <code>cmd</code> supplied
with the option. If the <code>cmd</code> string is empty the first word in the
range is instead taken as the command name, and command name completion
performed on the first word in the range. For example,</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">compctl -x 'r[-exec,;]' -l '' -- find
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>completes arguments between -exec and the following ; (or the end of
the command line if there is no such string) as if they were a separate
command line.</p>
<p>-h <code>cmd</code><br />
2021-05-11 02:29:21 +02:00
Normally zsh completes quoted strings as a whole. With this option,
2022-08-24 15:22:41 +02:00
completion can be done separately on different parts of such strings. It
works like the -l option but makes the completion code work on the parts
of the current word that are separated by spaces. These parts are
completed as if they were arguments to the given <code>cmd</code>. If <code>cmd</code> is the
empty string, the first part is completed as a command name, as with -l.</p>
<p>-U<br />
Use the whole list of possible completions, whether or not they actually
match the word on the command line. The word typed so far will be
deleted. This is most useful with a function (given by the -K option)
which can examine the word components passed to it (or via the read
builtins -c and -l flags) and use its own criteria to decide what
matches. If there is no completion, the original word is retained. Since
the produced possible completions seldom have interesting common
prefixes and suffixes, menu completion is started immediately if
AUTO_MENU is set and this flag is used.</p>
<p>-y <code>func-or-var</code><br />
2021-05-11 02:29:21 +02:00
<span id="index-reply_002c-use-of-3"></span></p>
2022-08-24 15:22:41 +02:00
<p>The list provided by <code>func-or-var</code> is displayed instead of the list of
completions whenever a listing is required; the actual completions to be
inserted are not affected. It can be provided in two ways. Firstly, if
<code>func-or-var</code> begins with a $ it defines a variable, or if it begins
with a left parenthesis a literal array, which contains the list. A
variable may have been set by a call to a function using the -K option.
Otherwise it contains the name of a function which will be executed to
create the list. The function will be passed as an argument list all
matching completions, including prefixes and suffixes expanded in full,
and should set the array reply to the result. In both cases, the display
list will only be retrieved after a complete list of matches has been
created.</p>
<p>Note that the returned list does not have to correspond, even in length,
to the original set of matches, and may be passed as a scalar instead of
an array. No special formatting of characters is performed on the output
in this case; in particular, newlines are printed literally and if they
appear output in columns is suppressed.</p>
<p>-X <code>explanation</code><br />
2021-05-11 02:29:21 +02:00
Print <code>explanation</code> when trying completion on the current set of
2022-08-24 15:22:41 +02:00
options. A %n in this string is replaced by the number of matches that
were added for this explanation string. The explanation only appears if
completion was tried and there was no unique match, or when listing
completions. Explanation strings will be listed together with the
matches of the group specified together with the -X option (using the -J
or -V option). If the same explanation string is given to multiple -X
options, the string appears only once (for each group) and the number of
matches shown for the %n is the total number of all matches for each
of these uses. In any case, the explanation string will only be shown if
there was at least one match added for the explanation string.</p>
<p>The sequences %B, %b, %S, %s, %U, and %u specify output attributes
(bold, standout, and underline), %F, %f, %K, %k specify foreground and
background colours, and %{<code>...</code>%} can be used to include literal escape
sequences as in prompts.</p>
<p>-Y <code>explanation</code><br />
Identical to -X, except that the <code>explanation</code> first undergoes expansion
following the usual rules for strings in double quotes. The expansion
will be carried out after any functions are called for the -K or -y
options, allowing them to set variables.</p>
<p>-t <code>continue</code><br />
The <code>continue</code>-string contains a character that specifies which set of
completion flags should be used next. It is useful:</p>
<p>(i) With -T, or when trying a list of pattern completions, when
compctl would usually continue with ordinary processing after finding
matches; this can be suppressed with -tn.</p>
<p>(ii) With a list of alternatives separated by +, when compctl would
normally stop when one of the alternatives generates matches. It can be
forced to consider the next set of completions by adding -t+ to the
flags of the alternative before the +.</p>
<p>(iii) In an extended completion list (see below), when compctl would
normally continue until a set of conditions succeeded, then use only the
immediately following flags. With -t-, compctl will continue trying
extended completions after the next -; with -tx it will attempt
completion with the default flags, in other words those before the -x.</p>
<p>-J <code>name</code><br />
This gives the name of the group the matches should be placed in. Groups
are listed and sorted separately; likewise, menu completion will offer
the matches in the groups in the order in which the groups were defined.
If no group name is explicitly given, the matches are stored in a group
named default. The first time a group name is encountered, a group with
that name is created. After that all matches with the same group name
are stored in that group.</p>
2021-05-11 02:29:21 +02:00
<p>This can be useful with non-exclusive alternative completions. For
example, in</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">compctl -f -J files -t+ + -v -J variables foo
</code></pre>
</div>
<p>both files and variables are possible completions, as the -t+ forces
both sets of alternatives before and after the + to be considered at
once. Because of the -J options, however, all files are listed before
all variables.</p>
<p>-V <code>name</code><br />
Like -J, but matches within the group will not be sorted in listings nor
in menu completion. These unsorted groups are in a different name space
from the sorted ones, so groups defined as -J files and -V files are
distinct.</p>
<p>-1<br />
If given together with the -V option, makes only consecutive duplicates
in the group be removed. Note that groups with and without this flag are
in different name spaces.</p>
<p>-2<br />
If given together with the -J or -V option, makes all duplicates be
kept. Again, groups with and without this flag are in different name
spaces.</p>
<p>-M <code>match-spec</code><br />
This defines additional matching control specifications that should be
used only when testing words for the list of flags this flag appears in.
The format of the <code>match-spec</code> string is described in <a href="Completion-Widgets.html#Completion-Matching-Control">Completion
Matching Control</a>.</p>
<hr />
<p><span id="Alternative-Completion"></span> <span
id="Alternative-Completion-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="215-alternative-completion"><a class="header" href="#215-alternative-completion">21.5 Alternative Completion</a></h2>
2022-08-24 15:22:41 +02:00
<p>compctl [ -CDT ] <code>options</code> + <code>options</code> [ + ... ] [ + ] <code>command</code>
...</p>
<p>The form with + specifies alternative options. Completion is tried
with the options before the first +. If this produces no matches
completion is tried with the flags after the + and so on. If there are
no flags after the last + and a match has not been found up to that
point, default completion is tried. If the list of flags contains a -t
with a + character, the next list of flags is used even if the current
list produced matches.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Extended-Completion"></span></p>
<p>Additional options are available that restrict completion to some part
of the command line; this is referred to as extended completion.</p>
<p><span id="Extended-Completion-1"></span></p>
<h2 id="216-extended-completion"><a class="header" href="#216-extended-completion">21.6 Extended Completion</a></h2>
2022-08-24 15:22:41 +02:00
<p>compctl [ -CDT ] <code>options</code> -x <code>pattern</code> <code>options</code> - ... --</p>
<p>        [ <code>command</code> ... ]</p>
<p>compctl [ -CDT ] <code>options</code> [ -x <code>pattern</code> <code>options</code> - ... -- ]</p>
<p>        [ + <code>options</code> [ -x ... -- ] ... [+] ] [ <code>command</code> ... ]</p>
<p>The form with -x specifies extended completion for the commands given;
as shown, it may be combined with alternative completion using +. Each
<code>pattern</code> is examined in turn; when a match is found, the corresponding
<code>options</code>, as described in <a href="Completion-Using-compctl.html#Option-Flags">Option Flags</a> above, are used
to generate possible completions. If no <code>pattern</code> matches, the <code>options</code>
given before the -x are used.</p>
2021-05-11 02:29:21 +02:00
<p>Note that each pattern should be supplied as a single argument and
should be quoted to prevent expansion of metacharacters by the shell.</p>
<p>A <code>pattern</code> is built of sub-patterns separated by commas; it matches if
at least one of these sub-patterns matches (they are ored). These
sub-patterns are in turn composed of other sub-patterns separated by
white spaces which match if all of the sub-patterns match (they are
anded). An element of the sub-patterns is of the form
2022-08-24 15:22:41 +02:00
<code>c</code>[...][...], where the pairs of brackets may be repeated as
2021-05-11 02:29:21 +02:00
often as necessary, and matches if any of the sets of brackets match (an
or). The example below makes this clearer.</p>
<p>The elements may be any of the following:</p>
2022-08-24 15:22:41 +02:00
<p>s[<code>string</code>]...<br />
Matches if the current word on the command line starts with one of the
strings given in brackets. The <code>string</code> is not removed and is not part
of the completion.</p>
<p>S[<code>string</code>]...<br />
Like s[<code>string</code>] except that the <code>string</code> is part of the completion.</p>
<p>p[<code>from</code>,<code>to</code>]...<br />
Matches if the number of the current word is between one of the <code>from</code>
and <code>to</code> pairs inclusive. The comma and <code>to</code> are optional; <code>to</code> defaults
to the same value as <code>from</code>. The numbers may be negative: -<code>n</code> refers to
the <code>n</code>th last word on the line.</p>
<p>c[<code>offset</code>,<code>string</code>]...<br />
2021-05-11 02:29:21 +02:00
Matches if the <code>string</code> matches the word offset by <code>offset</code> from the
current word position. Usually <code>offset</code> will be negative.</p>
2022-08-24 15:22:41 +02:00
<p>C[<code>offset</code>,<code>pattern</code>]...<br />
Like c but using pattern matching instead.</p>
<p>w[<code>index</code>,<code>string</code>]...<br />
Matches if the word in position <code>index</code> is equal to the corresponding
<code>string</code>. Note that the word count is made after any alias expansion.</p>
<p>W[<code>index</code>,<code>pattern</code>]...<br />
Like w but using pattern matching instead.</p>
<p>n[<code>index</code>,<code>string</code>]...<br />
2021-05-11 02:29:21 +02:00
Matches if the current word contains <code>string</code>. Anything up to and
2022-08-24 15:22:41 +02:00
including the <code>index</code>th occurrence of this string will not be considered
part of the completion, but the rest will. <code>index</code> may be negative to
count from the end: in most cases, <code>index</code> will be 1 or -1. For example,</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">compctl -s '`users`' -x 'n[1,@]' -k hosts -- talk
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>will usually complete usernames, but if you insert an @ after the name,
names from the array <code>hosts</code> (assumed to contain hostnames, though you
must make the array yourself) will be completed. Other commands such as
rcp can be handled similarly.</p>
<p>N[<code>index</code>,<code>string</code>]...<br />
Like n except that the string will be taken as a character class.
2021-05-11 02:29:21 +02:00
Anything up to and including the <code>index</code>th occurrence of any of the
2022-08-24 15:22:41 +02:00
characters in <code>string</code> will not be considered part of the completion.</p>
<p>m[<code>min</code>,<code>max</code>]...<br />
2021-05-11 02:29:21 +02:00
Matches if the total number of words lies between <code>min</code> and <code>max</code>
inclusive.</p>
2022-08-24 15:22:41 +02:00
<p>r[<code>str1</code>,<code>str2</code>]...<br />
Matches if the cursor is after a word with prefix <code>str1</code>. If there is
also a word with prefix <code>str2</code> on the command line after the one matched
by <code>str1</code> it matches only if the cursor is before this word. If the
comma and <code>str2</code> are omitted, it matches if the cursor is after a word
with prefix <code>str1</code>.</p>
<p>R[<code>str1</code>,<code>str2</code>]...<br />
Like r but using pattern matching instead.</p>
<p>q[<code>str</code>]...<br />
Matches the word currently being completed is in single quotes and the
<code>str</code> begins with the letter s, or if completion is done in double
quotes and <code>str</code> starts with the letter d, or if completion is done in
backticks and <code>str</code> starts with a b.</p>
<hr />
<p><span id="Example"></span> <span id="Example-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="217-example"><a class="header" href="#217-example">21.7 Example</a></h2>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">compctl -u -x 's[+] c[-1,-f],s[-f+]' \
2021-05-11 02:29:21 +02:00
-g '~/Mail/*(:t)' - 's[-f],c[-1,-f]' -f -- mail
</code></pre>
</div>
<p>This is to be interpreted as follows:</p>
2022-08-24 15:22:41 +02:00
<p>If the current command is mail, then</p>
2021-05-11 02:29:21 +02:00
<blockquote>
2022-08-24 15:22:41 +02:00
<p>if ((the current word begins with + and the previous word is -f) or
(the current word begins with -f+)), then complete the non-directory
part (the :t glob modifier) of files in the directory ~/Mail; else</p>
<p>if the current word begins with -f or the previous word was -f, then
complete any file; else</p>
2021-05-11 02:29:21 +02:00
<p>complete user names.</p>
</blockquote>
<hr />
2022-08-24 15:22:41 +02:00
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="Zsh-Modules.html#22-zsh-modules">22 Zsh Modules</a>
<ul>
<li><a href="Zsh-Modules.html#221-description">22.1 Description</a></li>
<li><a href="Zsh-Modules.html#222-the-zshattr-module">22.2 The zsh/attr Module</a></li>
<li><a href="Zsh-Modules.html#223-the-zshcap-module">22.3 The zsh/cap Module</a></li>
<li><a href="Zsh-Modules.html#224-the-zshclone-module">22.4 The zsh/clone Module</a></li>
<li><a href="Zsh-Modules.html#225-the-zshcompctl-module">22.5 The zsh/compctl Module</a></li>
<li><a href="Zsh-Modules.html#226-the-zshcomplete-module">22.6 The zsh/complete Module</a></li>
<li><a href="Zsh-Modules.html#227-the-zshcomplist-module">22.7 The zsh/complist Module</a>
<ul>
<li><a href="Zsh-Modules.html#2271-colored-completion-listings">22.7.1 Colored completion listings</a></li>
<li><a href="Zsh-Modules.html#2272-scrolling-in-completion-listings">22.7.2 Scrolling in completion listings</a></li>
<li><a href="Zsh-Modules.html#2273-menu-selection">22.7.3 Menu selection</a></li>
</ul>
</li>
<li><a href="Zsh-Modules.html#228-the-zshcomputil-module">22.8 The zsh/computil Module</a></li>
<li><a href="Zsh-Modules.html#229-the-zshcurses-module">22.9 The zsh/curses Module</a>
<ul>
<li><a href="Zsh-Modules.html#2291-builtin">22.9.1 Builtin</a></li>
<li><a href="Zsh-Modules.html#2292-parameters">22.9.2 Parameters</a></li>
</ul>
</li>
<li><a href="Zsh-Modules.html#2210-the-zshdatetime-module">22.10 The zsh/datetime Module</a></li>
<li><a href="Zsh-Modules.html#2211-the-zshdbgdbm-module">22.11 The zsh/db/gdbm Module</a></li>
<li><a href="Zsh-Modules.html#2212-the-zshdeltochar-module">22.12 The zsh/deltochar Module</a></li>
<li><a href="Zsh-Modules.html#2213-the-zshexample-module">22.13 The zsh/example Module</a></li>
<li><a href="Zsh-Modules.html#2214-the-zshfiles-module">22.14 The zsh/files Module</a></li>
<li><a href="Zsh-Modules.html#2215-the-zshlanginfo-module">22.15 The zsh/langinfo Module</a></li>
<li><a href="Zsh-Modules.html#2216-the-zshmapfile-module">22.16 The zsh/mapfile Module</a>
<ul>
<li><a href="Zsh-Modules.html#22161-limitations">22.16.1 Limitations</a></li>
</ul>
</li>
<li><a href="Zsh-Modules.html#2217-the-zshmathfunc-module">22.17 The zsh/mathfunc Module</a></li>
<li><a href="Zsh-Modules.html#2218-the-zshnearcolor-module">22.18 The zsh/nearcolor Module</a></li>
<li><a href="Zsh-Modules.html#2219-the-zshnewuser-module">22.19 The zsh/newuser Module</a></li>
<li><a href="Zsh-Modules.html#2220-the-zshparameter-module">22.20 The zsh/parameter Module</a></li>
<li><a href="Zsh-Modules.html#2221-the-zshpcre-module">22.21 The zsh/pcre Module</a></li>
<li><a href="Zsh-Modules.html#2222-the-zshparamprivate-module">22.22 The zsh/param/private Module</a></li>
<li><a href="Zsh-Modules.html#2223-the-zshregex-module">22.23 The zsh/regex Module</a></li>
<li><a href="Zsh-Modules.html#2224-the-zshsched-module">22.24 The zsh/sched Module</a></li>
<li><a href="Zsh-Modules.html#2225-the-zshnetsocket-module">22.25 The zsh/net/socket Module</a>
<ul>
<li><a href="Zsh-Modules.html#22251-outbound-connections">22.25.1 Outbound Connections</a></li>
<li><a href="Zsh-Modules.html#22252-inbound-connections">22.25.2 Inbound Connections</a></li>
</ul>
</li>
<li><a href="Zsh-Modules.html#2226-the-zshstat-module">22.26 The zsh/stat Module</a></li>
<li><a href="Zsh-Modules.html#2227-the-zshsystem-module">22.27 The zsh/system Module</a>
<ul>
<li><a href="Zsh-Modules.html#22271-builtins">22.27.1 Builtins</a></li>
<li><a href="Zsh-Modules.html#22272-math-functions">22.27.2 Math Functions</a></li>
<li><a href="Zsh-Modules.html#22273-parameters">22.27.3 Parameters</a></li>
</ul>
</li>
<li><a href="Zsh-Modules.html#2228-the-zshnettcp-module">22.28 The zsh/net/tcp Module</a>
<ul>
<li><a href="Zsh-Modules.html#22281-outbound-connections">22.28.1 Outbound Connections</a></li>
<li><a href="Zsh-Modules.html#22282-inbound-connections">22.28.2 Inbound Connections</a></li>
<li><a href="Zsh-Modules.html#22283-closing-connections">22.28.3 Closing Connections</a></li>
<li><a href="Zsh-Modules.html#22284-example">22.28.4 Example</a></li>
</ul>
</li>
<li><a href="Zsh-Modules.html#2229-the-zshtermcap-module">22.29 The zsh/termcap Module</a></li>
<li><a href="Zsh-Modules.html#2230-the-zshterminfo-module">22.30 The zsh/terminfo Module</a></li>
2022-08-24 15:22:41 +02:00
<li><a href="Zsh-Modules.html#2231-the-zshwatch-module">22.31 The zsh/watch Module</a></li>
<li><a href="Zsh-Modules.html#2232-the-zshzftp-module">22.32 The zsh/zftp Module</a>
2021-05-11 02:29:21 +02:00
<ul>
2022-08-24 15:22:41 +02:00
<li><a href="Zsh-Modules.html#22321-subcommands">22.32.1 Subcommands</a></li>
<li><a href="Zsh-Modules.html#22322-parameters">22.32.2 Parameters</a></li>
<li><a href="Zsh-Modules.html#22323-functions">22.32.3 Functions</a></li>
<li><a href="Zsh-Modules.html#22324-problems">22.32.4 Problems</a></li>
2021-05-11 02:29:21 +02:00
</ul>
</li>
2022-08-24 15:22:41 +02:00
<li><a href="Zsh-Modules.html#2233-the-zshzle-module">22.33 The zsh/zle Module</a></li>
<li><a href="Zsh-Modules.html#2234-the-zshzleparameter-module">22.34 The zsh/zleparameter Module</a></li>
<li><a href="Zsh-Modules.html#2235-the-zshzprof-module">22.35 The zsh/zprof Module</a></li>
<li><a href="Zsh-Modules.html#2236-the-zshzpty-module">22.36 The zsh/zpty Module</a></li>
<li><a href="Zsh-Modules.html#2237-the-zshzselect-module">22.37 The zsh/zselect Module</a></li>
<li><a href="Zsh-Modules.html#2238-the-zshzutil-module">22.38 The zsh/zutil Module</a></li>
2021-05-11 02:29:21 +02:00
</ul>
</li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<p><span id="Zsh-Modules"></span> <span id="Zsh-Modules-1"></span></p>
<h1 id="22-zsh-modules"><a class="header" href="#22-zsh-modules">22 Zsh Modules</a></h1>
<p><span id="index-modules"></span></p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Description-4"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="221-description"><a class="header" href="#221-description">22.1 Description</a></h2>
<p>Some optional parts of zsh are in modules, separate from the core of the
shell. Each of these modules may be linked in to the shell at build
time, or can be dynamically linked while the shell is running if the
installation supports this feature. Modules are linked at runtime with
2022-08-24 15:22:41 +02:00
the zmodload command, see <a href="Shell-Builtin-Commands.html#Shell-Builtin-Commands">Shell Builtin
2021-05-11 02:29:21 +02:00
Commands</a>.</p>
<p>The modules that are bundled with the zsh distribution are:</p>
2022-08-24 15:22:41 +02:00
<p>zsh/attr<br />
2021-05-11 02:29:21 +02:00
Builtins for manipulating extended attributes (xattr).</p>
2022-08-24 15:22:41 +02:00
<p>zsh/cap<br />
2021-05-11 02:29:21 +02:00
Builtins for manipulating POSIX.1e (POSIX.6) capability (privilege)
sets.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/clone<br />
2021-05-11 02:29:21 +02:00
A builtin that can clone a running shell onto another terminal.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/compctl<br />
The compctl builtin for controlling completion.</p>
<p>zsh/complete<br />
2021-05-11 02:29:21 +02:00
The basic completion code.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/complist<br />
2021-05-11 02:29:21 +02:00
Completion listing extensions.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/computil<br />
2021-05-11 02:29:21 +02:00
A module with utility builtins needed for the shell function based
completion system.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/curses<br />
2021-05-11 02:29:21 +02:00
curses windowing commands</p>
2022-08-24 15:22:41 +02:00
<p>zsh/datetime<br />
2021-05-11 02:29:21 +02:00
Some date/time commands and parameters.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/db/gdbm<br />
2021-05-11 02:29:21 +02:00
Builtins for managing associative array parameters tied to GDBM
databases.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/deltochar<br />
A ZLE function duplicating EMACS zap-to-char.</p>
<p>zsh/example<br />
2021-05-11 02:29:21 +02:00
An example of how to write a module.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/files<br />
2021-05-11 02:29:21 +02:00
Some basic file manipulation commands as builtins.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/langinfo<br />
2021-05-11 02:29:21 +02:00
Interface to locale information.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/mapfile<br />
2021-05-11 02:29:21 +02:00
Access to external files via a special associative array.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/mathfunc<br />
2021-05-11 02:29:21 +02:00
Standard scientific functions for use in mathematical evaluations.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/nearcolor<br />
2021-05-11 02:29:21 +02:00
Map colours to the nearest colour in the available palette.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/newuser<br />
2021-05-11 02:29:21 +02:00
Arrange for files for new users to be installed.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/parameter<br />
zsh/pcre<br />
2021-05-11 02:29:21 +02:00
Interface to the PCRE library.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/param/private<br />
2021-05-11 02:29:21 +02:00
Builtins for managing private-scoped parameters in function context.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/regex<br />
2021-05-11 02:29:21 +02:00
Interface to the POSIX regex library.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/sched<br />
2021-05-11 02:29:21 +02:00
A builtin that provides a timed execution facility within the shell.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/net/socket<br />
2021-05-11 02:29:21 +02:00
Manipulation of Unix domain sockets</p>
2022-08-24 15:22:41 +02:00
<p>zsh/stat<br />
A builtin command interface to the stat system call.</p>
<p>zsh/system<br />
2021-05-11 02:29:21 +02:00
A builtin interface to various low-level system features.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/net/tcp<br />
2021-05-11 02:29:21 +02:00
Manipulation of TCP sockets</p>
2022-08-24 15:22:41 +02:00
<p>zsh/termcap<br />
2021-05-11 02:29:21 +02:00
Interface to the termcap database.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/terminfo<br />
2021-05-11 02:29:21 +02:00
Interface to the terminfo database.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/watch<br />
Reporting of login and logout events.</p>
<p>zsh/zftp<br />
2021-05-11 02:29:21 +02:00
A builtin FTP client.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/zle<br />
The Zsh Line Editor, including the bindkey and vared builtins.</p>
<p>zsh/zleparameter<br />
2021-05-11 02:29:21 +02:00
Access to internals of the Zsh Line Editor via parameters.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/zprof<br />
2021-05-11 02:29:21 +02:00
A module allowing profiling for shell functions.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/zpty<br />
2021-05-11 02:29:21 +02:00
A builtin for starting a command in a pseudo-terminal.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/zselect<br />
2021-05-11 02:29:21 +02:00
Block and return when file descriptors are ready.</p>
2022-08-24 15:22:41 +02:00
<p>zsh/zutil<br />
2021-05-11 02:29:21 +02:00
Some utility builtins, e.g. the one for supporting configuration via
styles.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fattr-Module"></span> <span
id="The-zsh_002fattr-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="222-the-zshattr-module"><a class="header" href="#222-the-zshattr-module">22.2 The zsh/attr Module</a></h2>
2022-08-24 15:22:41 +02:00
<p>The zsh/attr module is used for manipulating extended attributes. The -h
option causes all commands to operate on symbolic links instead of their
targets. The builtins in this module are:</p>
<p><span id="index-zgetattr"></span> <span
id="index-extended-attributes_002c-xattr_002c-getting-from-files"></span></p>
<p>zgetattr [ -h ] <code>filename</code> <code>attribute</code> [ <code>parameter</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>Get the extended attribute <code>attribute</code> from the specified <code>filename</code>. If
the optional argument <code>parameter</code> is given, the attribute is set on that
parameter instead of being printed to stdout.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-zsetattr"></span> <span
id="index-extended-attributes_002c-xattr_002c-setting-on-files"></span></p>
<p>zsetattr [ -h ] <code>filename</code> <code>attribute</code> <code>value</code></p>
2021-05-11 02:29:21 +02:00
<p>Set the extended attribute <code>attribute</code> on the specified <code>filename</code> to
<code>value</code>.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-zdelattr"></span> <span
id="index-extended-attributes_002c-xattr_002c-removing_002c-deleting"></span></p>
<p>zdelattr [ -h ] <code>filename</code> <code>attribute</code></p>
2021-05-11 02:29:21 +02:00
<p>Remove the extended attribute <code>attribute</code> from the specified <code>filename</code>.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-zlistattr"></span> <span
id="index-extended-attributes_002c-xattr_002c-listing"></span></p>
<p>zlistattr [ -h ] <code>filename</code> [ <code>parameter</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>List the extended attributes currently set on the specified <code>filename</code>.
If the optional argument <code>parameter</code> is given, the list of attributes is
set on that parameter instead of being printed to stdout.</p>
2022-08-24 15:22:41 +02:00
<p>zgetattr and zlistattr allocate memory dynamically. If the attribute or
list of attributes grows between the allocation and the call to get
2021-05-11 02:29:21 +02:00
them, they return 2. On all other errors, 1 is returned. This allows the
calling function to check for this case and retry.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fcap-Module"></span> <span
id="The-zsh_002fcap-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="223-the-zshcap-module"><a class="header" href="#223-the-zshcap-module">22.3 The zsh/cap Module</a></h2>
2022-08-24 15:22:41 +02:00
<p>The zsh/cap module is used for manipulating POSIX.1e (POSIX.6)
2021-05-11 02:29:21 +02:00
capability sets. If the operating system does not support this
interface, the builtins defined by this module will do nothing. The
builtins in this module are:</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-cap"></span> <span
id="index-capabilities_002c-setting"></span></p>
<p>cap [ <code>capabilities</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>Change the shells process capability sets to the specified
<code>capabilities</code>, otherwise display the shells current capabilities.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-getcap"></span> <span
id="index-capabilities_002c-getting-from-files"></span></p>
<p>getcap <code>filename</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>This is a built-in implementation of the POSIX standard utility. It
displays the capability sets on each specified <code>filename</code>.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-setcap"></span> <span
id="index-capabilities_002c-setting-on-files"></span></p>
<p>setcap <code>capabilities</code> <code>filename</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>This is a built-in implementation of the POSIX standard utility. It sets
the capability sets on each specified <code>filename</code> to the specified
<code>capabilities</code>.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fclone-Module"></span> <span
id="The-zsh_002fclone-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="224-the-zshclone-module"><a class="header" href="#224-the-zshclone-module">22.4 The zsh/clone Module</a></h2>
2022-08-24 15:22:41 +02:00
<p>The zsh/clone module makes available one builtin command:</p>
<p><span id="index-clone"></span> <span
id="index-shell_002c-cloning"></span> <span
id="index-cloning-the-shell"></span> <span id="index-terminal"></span></p>
<p>clone <code>tty</code></p>
2021-05-11 02:29:21 +02:00
<p>Creates a forked instance of the current shell, attached to the
2022-08-24 15:22:41 +02:00
specified <code>tty</code>. In the new shell, the PID, PPID and TTY special
parameters are changed appropriately. $! is set to zero in the new
2021-05-11 02:29:21 +02:00
shell, and to the new shells PID in the original shell.</p>
<p>The return status of the builtin is zero in both shells if successful,
and non-zero on error.</p>
2022-08-24 15:22:41 +02:00
<p>The target of clone should be an unused terminal, such as an unused
2021-05-11 02:29:21 +02:00
virtual console or a virtual terminal created by</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">xterm -e sh -c 'trap : INT QUIT TSTP; tty;
2021-05-11 02:29:21 +02:00
while :; do sleep 100000000; done'
</code></pre>
</div>
<p>Some words of explanation are warranted about this long xterm command
line: when doing clone on a pseudo-terminal, some other session
(&quot;session&quot; meant as a unix session group, or SID) is already owning the
terminal. Hence the cloned zsh cannot acquire the pseudo-terminal as a
controlling tty. That means two things:</p>
<ul>
<li>the job control signals will go to the sh-started-by-xterm process
group (thats why we disable INT QUIT and TSTP with trap; otherwise
the while loop could get suspended or killed)</li>
<li>the cloned shell will have job control disabled, and the job control
keys (control-C, control-\ and control-Z) will not work.</li>
</ul>
<p>This does not apply when cloning to an <em>unused</em> vc.</p>
<p>Cloning to a used (and unprepared) terminal will result in two processes
reading simultaneously from the same terminal, with input bytes going
randomly to either process.</p>
2022-08-24 15:22:41 +02:00
<p>clone is mostly useful as a shell built-in replacement for openvt.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fcompctl-Module"></span> <span
id="The-zsh_002fcompctl-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="225-the-zshcompctl-module"><a class="header" href="#225-the-zshcompctl-module">22.5 The zsh/compctl Module</a></h2>
2022-08-24 15:22:41 +02:00
<p>The zsh/compctl module makes available two builtin commands. compctl, is
the old, deprecated way to control completions for ZLE. See <a href="Completion-Using-compctl.html#Completion-Using-compctl">Completion
Using compctl</a>.
The other builtin command, compcall can be used in user-defined
completion widgets, see <a href="Completion-Widgets.html#Completion-Widgets">Completion
2021-05-11 02:29:21 +02:00
Widgets</a>.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fcomplete-Module"></span> <span
id="The-zsh_002fcomplete-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="226-the-zshcomplete-module"><a class="header" href="#226-the-zshcomplete-module">22.6 The zsh/complete Module</a></h2>
2022-08-24 15:22:41 +02:00
<p>The zsh/complete module makes available several builtin commands which
2021-05-11 02:29:21 +02:00
can be used in user-defined completion widgets, see <a href="Completion-Widgets.html#Completion-Widgets">Completion
Widgets</a>.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fcomplist-Module"></span> <span
id="The-zsh_002fcomplist-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="227-the-zshcomplist-module"><a class="header" href="#227-the-zshcomplist-module">22.7 The zsh/complist Module</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-completion_002c-listing-1"></span> <span
id="index-completion_002c-coloured-listings"></span> <span
id="index-completion_002c-scroll-listings"></span></p>
<p>The zsh/complist module offers three extensions to completion listings:
the ability to highlight matches in such a list, the ability to scroll
through long lists and a different style of menu completion.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Colored-completion-listings"></span></p>
<h3 id="2271-colored-completion-listings"><a class="header" href="#2271-colored-completion-listings">22.7.1 Colored completion listings</a></h3>
2022-08-24 15:22:41 +02:00
<p>Whenever one of the parameters ZLS_COLORS or ZLS_COLOURS is set and the
zsh/complist module is loaded or linked into the shell, completion lists
will be colored. Note, however, that complist will not automatically be
loaded if it is not linked in: on systems with dynamic loading,
zmodload zsh/complist is required.</p>
<p><span id="index-ZLS_005fCOLORS"></span> <span
id="index-ZLS_005fCOLOURS"></span></p>
<p>The parameters ZLS_COLORS and ZLS_COLOURS describe how matches are
2021-05-11 02:29:21 +02:00
highlighted. To turn on highlighting an empty value suffices, in which
case all the default values given below will be used. The format of the
value of these parameters is the same as used by the GNU version of the
2022-08-24 15:22:41 +02:00
ls command: a colon-separated list of specifications of the form
<code>name</code>=<code>value</code>. The <code>name</code> may be one of the following strings, most
of which specify file types for which the <code>value</code> will be used. The
2021-05-11 02:29:21 +02:00
strings and their default values are:</p>
2022-08-24 15:22:41 +02:00
<p>no 0<br />
2021-05-11 02:29:21 +02:00
for normal text (i.e. when displaying something other than a matched
file)</p>
2022-08-24 15:22:41 +02:00
<p>fi 0<br />
2021-05-11 02:29:21 +02:00
for regular files</p>
2022-08-24 15:22:41 +02:00
<p>di 32<br />
2021-05-11 02:29:21 +02:00
for directories</p>
2022-08-24 15:22:41 +02:00
<p>ln 36<br />
for symbolic links. If this has the special value target, symbolic links
are dereferenced and the target file used to determine the display
format.</p>
<p>pi 31<br />
2021-05-11 02:29:21 +02:00
for named pipes (FIFOs)</p>
2022-08-24 15:22:41 +02:00
<p>so 33<br />
2021-05-11 02:29:21 +02:00
for sockets</p>
2022-08-24 15:22:41 +02:00
<p>bd 44;37<br />
2021-05-11 02:29:21 +02:00
for block devices</p>
2022-08-24 15:22:41 +02:00
<p>cd 44;37<br />
2021-05-11 02:29:21 +02:00
for character devices</p>
2022-08-24 15:22:41 +02:00
<p>or <code>none</code><br />
for a symlink to nonexistent file (default is the value defined for ln)</p>
<p>mi <code>none</code><br />
for a non-existent file (default is the value defined for fi); this code
is currently not used</p>
<p>su 37;41<br />
2021-05-11 02:29:21 +02:00
for files with setuid bit set</p>
2022-08-24 15:22:41 +02:00
<p>sg 30;43<br />
2021-05-11 02:29:21 +02:00
for files with setgid bit set</p>
2022-08-24 15:22:41 +02:00
<p>tw 30;42<br />
ow 34;43<br />
sa <code>none</code><br />
2021-05-11 02:29:21 +02:00
for files with an associated suffix alias; this is only tested after
specific suffixes, as described below</p>
2022-08-24 15:22:41 +02:00
<p>st 37;44<br />
ex 35<br />
lc \e[<br />
2021-05-11 02:29:21 +02:00
for the left code (see below)</p>
2022-08-24 15:22:41 +02:00
<p>rc m<br />
2021-05-11 02:29:21 +02:00
for the right code</p>
2022-08-24 15:22:41 +02:00
<p>tc 0<br />
for the character indicating the file type printed after filenames if
the LIST_TYPES option is set</p>
<p>sp 0<br />
2021-05-11 02:29:21 +02:00
for the spaces printed after matches to align the next column</p>
2022-08-24 15:22:41 +02:00
<p>ec <code>none</code><br />
2021-05-11 02:29:21 +02:00
for the end code</p>
2022-08-24 15:22:41 +02:00
<p>Apart from these strings, the <code>name</code> may also be an asterisk (*)
2021-05-11 02:29:21 +02:00
followed by any string. The <code>value</code> given for such a string will be used
for all files whose name ends with the string. The <code>name</code> may also be an
2022-08-24 15:22:41 +02:00
equals sign (=) followed by a pattern; the EXTENDED_GLOB option will
be turned on for evaluation of the pattern. The <code>value</code> given for this
pattern will be used for all matches (not just filenames) whose display
string are matched by the pattern. Definitions for the form with the
leading equal sign take precedence over the values defined for file
2021-05-11 02:29:21 +02:00
types, which in turn take precedence over the form with the leading
asterisk (file extensions).</p>
<p>The leading-equals form also allows different parts of the displayed
strings to be colored differently. For this, the pattern has to use the
2022-08-24 15:22:41 +02:00
(#b) globbing flag and pairs of parentheses surrounding the parts of
the strings that are to be colored differently. In this case the <code>value</code>
may consist of more than one color code separated by equal signs. The
first code will be used for all parts for which no explicit code is
specified and the following codes will be used for the parts matched by
the sub-patterns in parentheses. For example, the specification
=(#b)(?)*(?)=0=3=7 will be used for all matches which are at least
two characters long and will use the code 3 for the first character,
7 for the last character and 0 for the rest.</p>
2021-05-11 02:29:21 +02:00
<p>All three forms of <code>name</code> may be preceded by a pattern in parentheses.
If this is given, the <code>value</code> will be used only for matches in groups
whose names are matched by the pattern given in the parentheses. For
2022-08-24 15:22:41 +02:00
example, (g*)m*=43 highlights all matches beginning with m in
groups whose names begin with g using the color code 43. In case of
the lc, rc, and ec codes, the group pattern is ignored.</p>
2021-05-11 02:29:21 +02:00
<p>Note also that all patterns are tried in the order in which they appear
in the parameter value until the first one matches which is then used.
Patterns may be matched against completions, descriptions (possibly with
spaces appended for padding), or lines consisting of a completion
followed by a description. For consistent coloring it may be necessary
to use more than one pattern or a pattern with backreferences.</p>
2022-08-24 15:22:41 +02:00
<p>When printing a match, the code prints the value of lc, the value for
the file-type or the last matching specification with a *, the value
of rc, the string to display for the match itself, and then the value of
ec if that is defined or the values of lc, no, and rc if ec is not
defined.</p>
2021-05-11 02:29:21 +02:00
<p>The default values are ISO 6429 (ANSI) compliant and can be used on
2022-08-24 15:22:41 +02:00
vt100 compatible terminals such as xterms. On monochrome terminals the
default values will have no visible effect. The colors function from the
contribution can be used to get associative arrays containing the codes
for ANSI terminals (see <a href="User-Contributions.html#Other-Functions">Other
2021-05-11 02:29:21 +02:00
Functions</a>). For example, after
2022-08-24 15:22:41 +02:00
loading colors, one could use $color[red] to get the code for
foreground color red and $color[bg-green] for the code for
2021-05-11 02:29:21 +02:00
background color green.</p>
<p>If the completion system invoked by compinit is used, these parameters
should not be set directly because the system controls them itself.
2022-08-24 15:22:41 +02:00
Instead, the list-colors style should be used (see <a href="Completion-System.html#Completion-System-Configuration">Completion System
2021-05-11 02:29:21 +02:00
Configuration</a>).</p>
<hr />
<p><span id="Scrolling-in-completion-listings"></span></p>
<h3 id="2272-scrolling-in-completion-listings"><a class="header" href="#2272-scrolling-in-completion-listings">22.7.2 Scrolling in completion listings</a></h3>
2022-08-24 15:22:41 +02:00
<p>To enable scrolling through a completion list, the LISTPROMPT parameter
must be set. Its value will be used as the prompt; if it is the empty
string, a default prompt will be used. The value may contain escapes of
the form %x. It supports the escapes %B, %b, %S, %s, %U,
%u, %F, %f, %K, %k and %{<code>...</code>%} used also in shell prompts
as well as three pairs of additional sequences: a %l or %L is
replaced by the number of the last line shown and the total number of
lines in the form <code>number</code>/<code>total</code>; a %m or %M is replaced with
the number of the last match shown and the total number of matches; and
%p or %P is replaced with Top, Bottom or the position of the
2021-05-11 02:29:21 +02:00
first line shown in percent of the total number of lines, respectively.
In each of these cases the form with the uppercase letter will be
replaced with a string of fixed width, padded to the right with spaces,
while the lowercase form will not be padded.</p>
2022-08-24 15:22:41 +02:00
<p>If the parameter LISTPROMPT is set, the completion code will not ask if
the list should be shown. Instead it immediately starts displaying the
list, stopping after the first screenful, showing the prompt at the
2021-05-11 02:29:21 +02:00
bottom, waiting for a keypress after temporarily switching to the
2022-08-24 15:22:41 +02:00
listscroll keymap. Some of the zle functions have a special meaning
2021-05-11 02:29:21 +02:00
while scrolling lists:</p>
2022-08-24 15:22:41 +02:00
<p>send-break<br />
2021-05-11 02:29:21 +02:00
stops listing discarding the key pressed</p>
2022-08-24 15:22:41 +02:00
<p>accept-line, down-history, down-line-or-history<br />
down-line-or-search, vi-down-line-or-history<br />
2021-05-11 02:29:21 +02:00
scrolls forward one line</p>
2022-08-24 15:22:41 +02:00
<p>complete-word, menu-complete, expand-or-complete<br />
expand-or-complete-prefix, menu-complete-or-expand<br />
2021-05-11 02:29:21 +02:00
scrolls forward one screenful</p>
2022-08-24 15:22:41 +02:00
<p>accept-search<br />
2021-05-11 02:29:21 +02:00
stop listing but take no other action</p>
<p>Every other character stops listing and immediately processes the key as
2022-08-24 15:22:41 +02:00
usual. Any key that is not bound in the listscroll keymap or that is
bound to undefined-key is looked up in the keymap currently selected.</p>
<p>As for the ZLS_COLORS and ZLS_COLOURS parameters, LISTPROMPT should not
be set directly when using the shell function based completion system.
Instead, the list-prompt style should be used.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Menu-selection"></span></p>
<h3 id="2273-menu-selection"><a class="header" href="#2273-menu-selection">22.7.3 Menu selection</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-completion_002c-selecting-by-cursor"></span> <span
id="index-MENUSELECT"></span> <span id="index-menu_002dselect"></span></p>
<p>The zsh/complist module also offers an alternative style of selecting
2021-05-11 02:29:21 +02:00
matches from a list, called menu selection, which can be used if the
shell is set up to return to the last prompt after showing a completion
2022-08-24 15:22:41 +02:00
list (see the ALWAYS_LAST_PROMPT option in
2021-05-11 02:29:21 +02:00
<a href="Options.html#Options">Options</a>).</p>
2022-08-24 15:22:41 +02:00
<p>Menu selection can be invoked directly by the widget menu-select defined
by this module. This is a standard ZLE widget that can be bound to a key
in the usual way as described in <a href="Zsh-Line-Editor.html#Zsh-Line-Editor">Zsh Line
2021-05-11 02:29:21 +02:00
Editor</a>.</p>
2022-08-24 15:22:41 +02:00
<p>Alternatively, the parameter MENUSELECT can be set to an integer, which
gives the minimum number of matches that must be present before menu
selection is automatically turned on. This second method requires that
menu completion be started, either directly from a widget such as
menu-complete, or due to one of the options MENU_COMPLETE or AUTO_MENU
being set. If MENUSELECT is set, but is 0, 1 or empty, menu selection
will always be started during an ambiguous menu completion.</p>
2021-05-11 02:29:21 +02:00
<p>When using the completion system based on shell functions, the
2022-08-24 15:22:41 +02:00
MENUSELECT parameter should not be used (like the ZLS_COLORS and
ZLS_COLOURS parameters described above). Instead, the menu style should
be used with the select=<code>...</code> keyword.</p>
2021-05-11 02:29:21 +02:00
<p>After menu selection is started, the matches will be listed. If there
are more matches than fit on the screen, only the first screenful is
shown. The matches to insert into the command line can be selected from
2022-08-24 15:22:41 +02:00
this list. In the list one match is highlighted using the value for ma
from the ZLS_COLORS or ZLS_COLOURS parameter. The default value for this
is 7 which forces the selected match to be highlighted using standout
mode on a vt100-compatible terminal. If neither ZLS_COLORS nor
ZLS_COLOURS is set, the same terminal control sequence as for the %S
escape in prompts is used.</p>
2021-05-11 02:29:21 +02:00
<p>If there are more matches than fit on the screen and the parameter
2022-08-24 15:22:41 +02:00
MENUPROMPT is set, its value will be shown below the matches. It
supports the same escape sequences as LISTPROMPT, but the number of the
match or line shown will be that of the one where the mark is placed. If
its value is the empty string, a default prompt will be used.</p>
<p>The MENUSCROLL parameter can be used to specify how the list is
2021-05-11 02:29:21 +02:00
scrolled. If the parameter is unset, this is done line by line, if it is
2022-08-24 15:22:41 +02:00
set to 0 (zero), the list will scroll half the number of lines of the
screen. If the value is positive, it gives the number of lines to scroll
and if it is negative, the list will be scrolled the number of lines of
the screen minus the (absolute) value.</p>
<p>As for the ZLS_COLORS, ZLS_COLOURS and LISTPROMPT parameters, neither
MENUPROMPT nor MENUSCROLL should be set directly when using the shell
function based completion system. Instead, the select-prompt and
select-scroll styles should be used.</p>
2021-05-11 02:29:21 +02:00
<p>The completion code sometimes decides not to show all of the matches in
the list. These hidden matches are either matches for which the
completion function which added them explicitly requested that they not
2022-08-24 15:22:41 +02:00
appear in the list (using the -n option of the compadd builtin command)
or they are matches which duplicate a string already in the list
(because they differ only in things like prefixes or suffixes that are
not displayed). In the list used for menu selection, however, even these
matches are shown so that it is possible to select them. To highlight
such matches the hi and du capabilities in the ZLS_COLORS and
ZLS_COLOURS parameters are supported for hidden matches of the first and
second kind, respectively.</p>
2021-05-11 02:29:21 +02:00
<p>Selecting matches is done by moving the mark around using the zle
movement functions. When not all matches can be shown on the screen at
the same time, the list will scroll up and down when crossing the top or
bottom line. The following zle functions have special meaning during
menu selection. Note that the following always perform the same task
within the menu selection map and cannot be replaced by user defined
widgets, nor can the set of functions be extended:</p>
2022-08-24 15:22:41 +02:00
<p>accept-line, accept-search<br />
accept the current match and leave menu selection (but do not cause the
command line to be accepted)</p>
<p>send-break<br />
leaves menu selection and restores the previous contents of the command
line</p>
<p>redisplay, clear-screen<br />
2021-05-11 02:29:21 +02:00
execute their normal function without leaving menu selection</p>
2022-08-24 15:22:41 +02:00
<p>accept-and-hold, accept-and-menu-complete<br />
accept the currently inserted match and continue selection allowing to
select the next match to insert into the line</p>
<p>accept-and-infer-next-history<br />
accepts the current match and then tries completion with menu selection
again; in the case of files this allows one to select a directory and
immediately attempt to complete files in it; if there are no matches, a
message is shown and one can use undo to go back to completion on the
previous level, every other key leaves menu selection (including the
other zle functions which are otherwise special during menu selection)</p>
<p>undo<br />
removes matches inserted during the menu selection by one of the three
functions before</p>
<p>down-history, down-line-or-history<br />
vi-down-line-or-history, down-line-or-search<br />
2021-05-11 02:29:21 +02:00
moves the mark one line down</p>
2022-08-24 15:22:41 +02:00
<p>up-history, up-line-or-history<br />
vi-up-line-or-history, up-line-or-search<br />
2021-05-11 02:29:21 +02:00
moves the mark one line up</p>
2022-08-24 15:22:41 +02:00
<p>forward-char, vi-forward-char<br />
2021-05-11 02:29:21 +02:00
moves the mark one column right</p>
2022-08-24 15:22:41 +02:00
<p>backward-char, vi-backward-char<br />
2021-05-11 02:29:21 +02:00
moves the mark one column left</p>
2022-08-24 15:22:41 +02:00
<p>forward-word, vi-forward-word<br />
vi-forward-word-end, emacs-forward-word<br />
2021-05-11 02:29:21 +02:00
moves the mark one screenful down</p>
2022-08-24 15:22:41 +02:00
<p>backward-word, vi-backward-word, emacs-backward-word<br />
2021-05-11 02:29:21 +02:00
moves the mark one screenful up</p>
2022-08-24 15:22:41 +02:00
<p>vi-forward-blank-word, vi-forward-blank-word-end<br />
2021-05-11 02:29:21 +02:00
moves the mark to the first line of the next group of matches</p>
2022-08-24 15:22:41 +02:00
<p>vi-backward-blank-word<br />
2021-05-11 02:29:21 +02:00
moves the mark to the last line of the previous group of matches</p>
2022-08-24 15:22:41 +02:00
<p>beginning-of-history<br />
2021-05-11 02:29:21 +02:00
moves the mark to the first line</p>
2022-08-24 15:22:41 +02:00
<p>end-of-history<br />
2021-05-11 02:29:21 +02:00
moves the mark to the last line</p>
2022-08-24 15:22:41 +02:00
<p>beginning-of-buffer-or-history, beginning-of-line<br />
beginning-of-line-hist, vi-beginning-of-line<br />
2021-05-11 02:29:21 +02:00
moves the mark to the leftmost column</p>
2022-08-24 15:22:41 +02:00
<p>end-of-buffer-or-history, end-of-line<br />
end-of-line-hist, vi-end-of-line<br />
2021-05-11 02:29:21 +02:00
moves the mark to the rightmost column</p>
2022-08-24 15:22:41 +02:00
<p>complete-word, menu-complete, expand-or-complete<br />
expand-or-complete-prefix, menu-expand-or-complete<br />
2021-05-11 02:29:21 +02:00
moves the mark to the next match</p>
2022-08-24 15:22:41 +02:00
<p>reverse-menu-complete<br />
2021-05-11 02:29:21 +02:00
moves the mark to the previous match</p>
2022-08-24 15:22:41 +02:00
<p>vi-insert<br />
this toggles between normal and interactive mode; in interactive mode
the keys bound to self-insert and self-insert-unmeta insert into the
command line as in normal editing mode but without leaving menu
selection; after each character completion is tried again and the list
changes to contain only the new matches; the completion widgets make the
longest unambiguous string be inserted in the command line and undo and
backward-delete-char go back to the previous set of matches</p>
<p>history-incremental-search-forward<br />
history-incremental-search-backward<br />
this starts incremental searches in the list of completions displayed;
in this mode, accept-line only leaves incremental search, going back to
the normal menu selection mode</p>
2021-05-11 02:29:21 +02:00
<p>All movement functions wrap around at the edges; any other zle function
not listed leaves menu selection and executes that function. It is
possible to make widgets in the above list do the same by using the form
2022-08-24 15:22:41 +02:00
of the widget with a . in front. For example, the widget
.accept-line has the effect of leaving menu selection and accepting
the entire command line.</p>
<p>During this selection the widget uses the keymap menuselect. Any key
that is not defined in this keymap or that is bound to undefined-key is
looked up in the keymap currently selected. This is used to ensure that
the most important keys used during selection (namely the cursor keys,
return, and TAB) have sensible defaults. However, keys in the menuselect
keymap can be modified directly using the bindkey builtin command (see
<a href="Zsh-Modules.html#The-zsh_002fzle-Module">The zsh/zle Module</a>). For example, to make the
return key leave menu selection without accepting the match currently
selected one could call</p>
<div class="example">
<pre><code class="language-zsh">bindkey -M menuselect '^M' send-break
</code></pre>
</div>
<p>after loading the zsh/complist module.</p>
<hr />
<p><span id="The-zsh_002fcomputil-Module"></span> <span
id="The-zsh_002fcomputil-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="228-the-zshcomputil-module"><a class="header" href="#228-the-zshcomputil-module">22.8 The zsh/computil Module</a></h2>
<p><span id="index-completion_002c-utility"></span></p>
2022-08-24 15:22:41 +02:00
<p>The zsh/computil module adds several builtin commands that are used by
2021-05-11 02:29:21 +02:00
some of the completion functions in the completion system based on shell
functions (see <a href="Completion-System.html#Completion-System">Completion
System</a> ). Except for
2022-08-24 15:22:41 +02:00
compquote these builtin commands are very specialised and thus not very
interesting when writing your own completion functions. In summary,
2021-05-11 02:29:21 +02:00
these builtin commands are:</p>
<p><span id="index-comparguments"></span></p>
2022-08-24 15:22:41 +02:00
<p>comparguments</p>
<p>This is used by the _arguments function to do the argument and command
line parsing. Like compdescribe it has an option -i to do the parsing
and initialize some internal state and various options to access the
state information to decide what should be completed.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-compdescribe"></span></p>
2022-08-24 15:22:41 +02:00
<p>compdescribe</p>
<p>This is used by the _describe function to build the displays for the
2021-05-11 02:29:21 +02:00
matches and to get the strings to add as matches with their options. On
2022-08-24 15:22:41 +02:00
the first call one of the options -i or -I should be supplied as the
2021-05-11 02:29:21 +02:00
first argument. In the first case, display strings without the
descriptions will be generated, in the second case, the string used to
separate the matches from their descriptions must be given as the second
argument and the descriptions (if any) will be shown. All other
2022-08-24 15:22:41 +02:00
arguments are like the definition arguments to _describe itself.</p>
<p>Once compdescribe has been called with either the -i or the -I option,
it can be repeatedly called with the -g option and the names of four
parameters as its arguments. This will step through the different sets
of matches and store the value of compstate[list] in the first scalar,
the options for compadd in the second array, the matches in the third
array, and the strings to be displayed in the completion listing in the
fourth array. The arrays may then be directly given to compadd to
register the matches with the completion code.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-compfiles"></span></p>
2022-08-24 15:22:41 +02:00
<p>compfiles</p>
<p>Used by the _path_files function to optimize complex recursive filename
generation (globbing). It does three things. With the -p and -P options
it builds the glob patterns to use, including the paths already handled
and trying to optimize the patterns with respect to the prefix and
suffix from the line and the match specification currently used. The -i
option does the directory tests for the ignore-parents style and the -r
option tests if a component for some of the matches are equal to the
string on the line and removes all other matches if that is true.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-compgroups"></span></p>
2022-08-24 15:22:41 +02:00
<p>compgroups</p>
<p>Used by the _tags function to implement the internals of the
group-order style. This only takes its arguments as names of completion
groups and creates the groups for it (all six types: sorted and
unsorted, both without removing duplicates, with removing all duplicates
and with removing consecutive duplicates).</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-compquote"></span></p>
2022-08-24 15:22:41 +02:00
<p>compquote [ -p ] <code>names</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>There may be reasons to write completion functions that have to add the
2022-08-24 15:22:41 +02:00
matches using the -Q option to compadd and perform quoting themselves.
Instead of interpreting the first character of the all_quotes key of the
compstate special association and using the q flag for parameter
expansions, one can use this builtin command. The arguments are the
names of scalar or array parameters and the values of these parameters
are quoted as needed for the innermost quoting level. If the -p option
is given, quoting is done as if there is some prefix before the values
of the parameters, so that a leading equal sign will not be quoted.</p>
2021-05-11 02:29:21 +02:00
<p>The return status is non-zero in case of an error and zero otherwise.</p>
<p><span id="index-comptags"></span> <span id="index-comptry"></span></p>
2022-08-24 15:22:41 +02:00
<p>comptags</p>
<p>comptry</p>
2021-05-11 02:29:21 +02:00
<p>These implement the internals of the tags mechanism.</p>
<p><span id="index-compvalues"></span></p>
2022-08-24 15:22:41 +02:00
<p>compvalues</p>
<p>Like comparguments, but for the _values function.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fcurses-Module"></span> <span
id="The-zsh_002fcurses-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="229-the-zshcurses-module"><a class="header" href="#229-the-zshcurses-module">22.9 The zsh/curses Module</a></h2>
2022-08-24 15:22:41 +02:00
<p>The zsh/curses module makes available one builtin command and various
2021-05-11 02:29:21 +02:00
parameters.</p>
<hr />
<p><span id="Builtin"></span></p>
<h3 id="2291-builtin"><a class="header" href="#2291-builtin">22.9.1 Builtin</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-zcurses"></span> <span
id="index-windows_002c-curses"></span></p>
<p>zcurses init</p>
<p>zcurses end</p>
<p>zcurses addwin <code>targetwin</code> <code>nlines</code> <code>ncols</code> <code>begin_y</code> <code>begin_x</code> [
2021-05-11 02:29:21 +02:00
<code>parentwin</code> ]</p>
2022-08-24 15:22:41 +02:00
<p>zcurses delwin <code>targetwin</code></p>
<p>zcurses refresh [ <code>targetwin</code> ... ]</p>
<p>zcurses touch <code>targetwin</code> ...</p>
<p>zcurses move <code>targetwin</code> <code>new_y</code> <code>new_x</code></p>
<p>zcurses clear <code>targetwin</code> [ redraw | eol | bot ]</p>
<p>zcurses position <code>targetwin</code> <code>array</code></p>
<p>zcurses char <code>targetwin</code> <code>character</code></p>
<p>zcurses string <code>targetwin</code> <code>string</code></p>
<p>zcurses border <code>targetwin</code> <code>border</code></p>
<p>zcurses attr <code>targetwin</code> [ [+|-]<code>attribute</code> | <code>fg_col</code>/<code>bg_col</code> ]
[...]</p>
<p>zcurses bg <code>targetwin</code> [ [+|-]<code>attribute</code> | <code>fg_col</code>/<code>bg_col</code> |
@<code>char</code> ] [...]</p>
<p>zcurses scroll <code>targetwin</code> [ on | off | [+|-]<code>lines</code> ]</p>
<p>zcurses input <code>targetwin</code> [ <code>param</code> [ <code>kparam</code> [ <code>mparam</code> ] ] ]</p>
<p>zcurses mouse [ delay <code>num</code> | [+|-]motion ]</p>
<p>zcurses timeout <code>targetwin</code> <code>intval</code></p>
<p>zcurses querychar <code>targetwin</code> [ <code>param</code> ]</p>
<p>zcurses resize <code>height</code> <code>width</code> [ endwin | nosave | endwin_nosave ]</p>
2021-05-11 02:29:21 +02:00
<p>Manipulate curses windows. All uses of this command should be bracketed
2022-08-24 15:22:41 +02:00
by zcurses init to initialise use of curses, and zcurses end to end
it; omitting zcurses end can cause the terminal to be in an unwanted
state.</p>
<p>The subcommand addwin creates a window with <code>nlines</code> lines and <code>ncols</code>
2021-05-11 02:29:21 +02:00
columns. Its upper left corner will be placed at row <code>begin_y</code> and
column <code>begin_x</code> of the screen. <code>targetwin</code> is a string and refers to
the name of a window that is not currently assigned. Note in particular
the curses convention that vertical values appear before horizontal
values.</p>
2022-08-24 15:22:41 +02:00
<p>If addwin is given an existing window as the final argument, the new
2021-05-11 02:29:21 +02:00
window is created as a subwindow of <code>parentwin</code>. This differs from an
ordinary new window in that the memory of the window contents is shared
with the parents memory. Subwindows must be deleted before their
parent. Note that the coordinates of subwindows are relative to the
screen, not the parent, as with other windows.</p>
2022-08-24 15:22:41 +02:00
<p>Use the subcommand delwin to delete a window created with addwin. Note
that end does <em>not</em> implicitly delete windows, and that delwin does not
erase the screen image of the window.</p>
<p>The window corresponding to the full visible screen is called stdscr; it
always exists after zcurses init and cannot be delete with delwin.</p>
<p>The subcommand refresh will refresh window <code>targetwin</code>; this is
2021-05-11 02:29:21 +02:00
necessary to make any pending changes (such as characters you have
2022-08-24 15:22:41 +02:00
prepared for output with char) visible on the screen. refresh without an
argument causes the screen to be cleared and redrawn. If multiple
windows are given, the screen is updated once at the end.</p>
<p>The subcommand touch marks the <code>targetwin</code>s listed as changed. This is
necessary before refreshing windows if a window that was in front of
another window (which may be stdscr) is deleted.</p>
<p>The subcommand move moves the cursor position in <code>targetwin</code> to new
coordinates <code>new_y</code> and <code>new_x</code>. Note that the subcommand string (but
not the subcommand char) advances the cursor position over the
2021-05-11 02:29:21 +02:00
characters added.</p>
2022-08-24 15:22:41 +02:00
<p>The subcommand clear erases the contents of <code>targetwin</code>. One (and no
2021-05-11 02:29:21 +02:00
more than one) of three options may be specified. With the option
2022-08-24 15:22:41 +02:00
redraw, in addition the next refresh of <code>targetwin</code> will cause the
screen to be cleared and repainted. With the option eol, <code>targetwin</code> is
only cleared to the end of the current cursor line. With the option bot,
<code>targetwin</code> is cleared to the end of the window, i.e everything to the
right and below the cursor is cleared.</p>
<p>The subcommand position writes various positions associated with
2021-05-11 02:29:21 +02:00
<code>targetwin</code> into the array named <code>array</code>. These are, in order:</p>
<p>-<br />
The y and x coordinates of the cursor relative to the top left of
<code>targetwin</code></p>
<p>-<br />
The y and x coordinates of the top left of <code>targetwin</code> on the screen</p>
<p>-<br />
The size of <code>targetwin</code> in y and x dimensions.</p>
2022-08-24 15:22:41 +02:00
<p>Outputting characters and strings are achieved by char and string
2021-05-11 02:29:21 +02:00
respectively.</p>
2022-08-24 15:22:41 +02:00
<p>To draw a border around window <code>targetwin</code>, use border. Note that the
2021-05-11 02:29:21 +02:00
border is not subsequently handled specially: in other words, the border
is simply a set of characters output at the edge of the window. Hence it
can be overwritten, can scroll off the window, etc.</p>
2022-08-24 15:22:41 +02:00
<p>The subcommand attr will set <code>targetwin</code>s attributes or
2021-05-11 02:29:21 +02:00
foreground/background color pair for any successive character output.
2022-08-24 15:22:41 +02:00
Each <code>attribute</code> given on the line may be prepended by a + to set or a -
to unset that attribute; + is assumed if absent. The attributes
supported are blink, bold, dim, reverse, standout, and underline.</p>
<p>Each <code>fg_col</code>/<code>bg_col</code> attribute (to be read as <code>fg_col</code> on <code>bg_col</code>)
sets the foreground and background color for character output. The color
default is sometimes available (in particular if the library is
ncurses), specifying the foreground or background color with which the
terminal started. The color pair default/default is always available. To
use more than the 8 named colors (red, green, etc.) construct the
<code>fg_col</code>/<code>bg_col</code> pairs where <code>fg_col</code> and <code>bg_col</code> are decimal
integers, e.g 128/200. The maximum color value is 254 if the terminal
supports 256 colors.</p>
<p>bg overrides the color and other attributes of all characters in the
2021-05-11 02:29:21 +02:00
window. Its usual use is to set the background initially, but it will
overwrite the attributes of any characters at the time when it is
2022-08-24 15:22:41 +02:00
called. In addition to the arguments allowed with attr, an argument
@<code>char</code> specifies a character to be shown in otherwise blank areas of
2021-05-11 02:29:21 +02:00
the window. Owing to limitations of curses this cannot be a multibyte
character (use of ASCII characters only is recommended). As the
specified set of attributes override the existing background, turning
attributes off in the arguments is not useful, though this does not
cause an error.</p>
2022-08-24 15:22:41 +02:00
<p>The subcommand scroll can be used with on or off to enabled or disable
scrolling of a window when the cursor would otherwise move below the
window due to typing or output. It can also be used with a positive or
negative integer to scroll the window up or down the given number of
2021-05-11 02:29:21 +02:00
lines without changing the current cursor position (which therefore
appears to move in the opposite direction relative to the window). In
2022-08-24 15:22:41 +02:00
the second case, if scrolling is off it is temporarily turned on to
2021-05-11 02:29:21 +02:00
allow the window to be scrolled.</p>
2022-08-24 15:22:41 +02:00
<p>The subcommand input reads a single character from the window without
2021-05-11 02:29:21 +02:00
echoing it back. If <code>param</code> is supplied the character is assigned to the
2022-08-24 15:22:41 +02:00
parameter <code>param</code>, else it is assigned to the parameter REPLY.</p>
2021-05-11 02:29:21 +02:00
<p>If both <code>param</code> and <code>kparam</code> are supplied, the key is read in keypad
mode. In this mode special keys such as function keys and arrow keys
return the name of the key in the parameter <code>kparam</code>. The key names are
2022-08-24 15:22:41 +02:00
the macros defined in the curses.h or ncurses.h with the prefix KEY_
removed; see also the description of the parameter zcurses_keycodes
below. Other keys cause a value to be set in <code>param</code> as before. On a
successful return only one of <code>param</code> or <code>kparam</code> contains a non-empty
string; the other is set to an empty string.</p>
<p>If <code>mparam</code> is also supplied, input attempts to handle mouse input. This
is only available with the ncurses library; mouse handling can be
detected by checking for the exit status of zcurses mouse with no
2021-05-11 02:29:21 +02:00
arguments. If a mouse button is clicked (or double- or triple-clicked,
or pressed or released with a configurable delay from being clicked)
2022-08-24 15:22:41 +02:00
then <code>kparam</code> is set to the string MOUSE, and <code>mparam</code> is set to an
2021-05-11 02:29:21 +02:00
array consisting of the following elements:</p>
<p>-<br />
An identifier to discriminate different input devices; this is only
rarely useful.</p>
<p>-<br />
The x, y and z coordinates of the mouse click relative to the full
screen, as three elements in that order (i.e. the y coordinate is,
2022-08-24 15:22:41 +02:00
unusually, after the x coordinate). The z coordinate is only available
for a few unusual input devices and is otherwise set to zero.</p>
2021-05-11 02:29:21 +02:00
<p>-<br />
2022-08-24 15:22:41 +02:00
Any events that occurred as separate items; usually there will be just
one. An event consists of PRESSED, RELEASED, CLICKED, DOUBLE_CLICKED or
TRIPLE_CLICKED followed immediately (in the same element) by the number
of the button.</p>
2021-05-11 02:29:21 +02:00
<p>-<br />
2022-08-24 15:22:41 +02:00
If the shift key was pressed, the string SHIFT.</p>
2021-05-11 02:29:21 +02:00
<p>-<br />
2022-08-24 15:22:41 +02:00
If the control key was pressed, the string CTRL.</p>
2021-05-11 02:29:21 +02:00
<p>-<br />
2022-08-24 15:22:41 +02:00
If the alt key was pressed, the string ALT.</p>
2021-05-11 02:29:21 +02:00
<p>Not all mouse events may be passed through to the terminal window; most
terminal emulators handle some mouse events themselves. Note that the
ncurses manual implies that using input both with and without mouse
handling may cause the mouse cursor to appear and disappear.</p>
2022-08-24 15:22:41 +02:00
<p>The subcommand mouse can be used to configure the use of the mouse.
There is no window argument; mouse options are global. zcurses mouse
2021-05-11 02:29:21 +02:00
with no arguments returns status 0 if mouse handling is possible, else
status 1. Otherwise, the possible arguments (which may be combined on
2022-08-24 15:22:41 +02:00
the same command line) are as follows. delay <code>num</code> sets the maximum
2021-05-11 02:29:21 +02:00
delay in milliseconds between press and release events to be considered
as a click; the value 0 disables click resolution, and the default is
2022-08-24 15:22:41 +02:00
one sixth of a second. motion proceeded by an optional + (the default)
or - turns on or off reporting of mouse motion in addition to clicks,
presses and releases, which are always reported. However, it appears
reports for mouse motion are not currently implemented.</p>
<p>The subcommand timeout specifies a timeout value for input from
<code>targetwin</code>. If <code>intval</code> is negative, zcurses input waits indefinitely
for a character to be typed; this is the default. If <code>intval</code> is zero,
zcurses input returns immediately; if there is typeahead it is
returned, else no input is done and status 1 is returned. If <code>intval</code> is
positive, zcurses input waits <code>intval</code> milliseconds for input and if
there is none at the end of that period returns status 1.</p>
<p>The subcommand querychar queries the character at the current cursor
2021-05-11 02:29:21 +02:00
position. The return values are stored in the array named <code>param</code> if
2022-08-24 15:22:41 +02:00
supplied, else in the array reply. The first value is the character
2021-05-11 02:29:21 +02:00
(which may be a multibyte character if the system supports them); the
2022-08-24 15:22:41 +02:00
second is the color pair in the usual <code>fg_col</code>/<code>bg_col</code> notation, or 0
if color is not supported. Any attributes other than color that apply to
the character, as set with the subcommand attr, appear as additional
elements.</p>
<p>The subcommand resize resizes stdscr and all windows to given dimensions
(windows that stick out from the new dimensions are resized down). The
underlying curses extension (resize_term call) can be unavailable. To
verify, zeroes can be used for <code>height</code> and <code>width</code>. If the result of
the subcommand is 0, resize_term is available (2 otherwise). Tests show
that resizing can be normally accomplished by calling zcurses end and
zcurses refresh. The resize subcommand is provided for versatility.
Multiple system configurations have been checked and zcurses end and
zcurses refresh are still needed for correct terminal state after
resize. To invoke them with resize, use <code>endwin</code> argument. Using
<code>nosave</code> argument will cause new terminal state to not be saved
internally by zcurses. This is also provided for versatility and should
normally be not needed.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Parameters-2"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="2292-parameters"><a class="header" href="#2292-parameters">22.9.2 Parameters</a></h3>
<p><span id="index-ZCURSES_005fCOLORS"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZCURSES_COLORS</p>
2021-05-11 02:29:21 +02:00
<p>Readonly integer. The maximum number of colors the terminal supports.
This value is initialised by the curses library and is not available
2022-08-24 15:22:41 +02:00
until the first time zcurses init is run.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-ZCURSES_005fCOLOR_005fPAIRS"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZCURSES_COLOR_PAIRS</p>
<p>Readonly integer. The maximum number of color pairs <code>fg_col</code>/<code>bg_col</code>
that may be defined in zcurses attr commands; note this limit applies
to all color pairs that have been used whether or not they are currently
active. This value is initialised by the curses library and is not
available until the first time zcurses init is run.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zcurses_005fattrs"></span></p>
2022-08-24 15:22:41 +02:00
<p>zcurses_attrs</p>
<p>Readonly array. The attributes supported by zsh/curses; available as
2021-05-11 02:29:21 +02:00
soon as the module is loaded.</p>
<p><span id="index-zcurses_005fcolors"></span></p>
2022-08-24 15:22:41 +02:00
<p>zcurses_colors</p>
<p>Readonly array. The colors supported by zsh/curses; available as soon as
the module is loaded.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zcurses_005fkeycodes"></span></p>
2022-08-24 15:22:41 +02:00
<p>zcurses_keycodes</p>
2021-05-11 02:29:21 +02:00
<p>Readonly array. The values that may be returned in the second parameter
2022-08-24 15:22:41 +02:00
supplied to zcurses input in the order in which they are defined
internally by curses. Not all function keys are listed, only F0; curses
reserves space for F0 up to F63.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zcurses_005fwindows"></span></p>
2022-08-24 15:22:41 +02:00
<p>zcurses_windows</p>
2021-05-11 02:29:21 +02:00
<p>Readonly array. The current list of windows, i.e. all windows that have
2022-08-24 15:22:41 +02:00
been created with zcurses addwin and not removed with zcurses
delwin.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fdatetime-Module"></span> <span
id="The-zsh_002fdatetime-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="2210-the-zshdatetime-module"><a class="header" href="#2210-the-zshdatetime-module">22.10 The zsh/datetime Module</a></h2>
2022-08-24 15:22:41 +02:00
<p>The zsh/datetime module makes available one builtin command:</p>
<p><span id="index-strftime"></span> <span
id="index-date-string_002c-printing"></span></p>
<p>strftime [ -s <code>scalar</code> | -n ] <code>format</code> [ <code>epochtime</code> [
<code>nanoseconds</code> ] ]</p>
<p>strftime -r [ -q ] [ -s <code>scalar</code> | -n ] <code>format</code> <code>timestring</code></p>
2021-05-11 02:29:21 +02:00
<p>Output the date in the <code>format</code> specified. With no <code>epochtime</code>, the
current system date/time is used; optionally, <code>epochtime</code> may be used to
specify the number of seconds since the epoch, and <code>nanoseconds</code> may
additionally be used to specify the number of nanoseconds past the
2022-08-24 15:22:41 +02:00
second (otherwise that number is assumed to be 0). See strftime(3) for
details. The zsh extensions described in <a href="Prompt-Expansion.html#Prompt-Expansion">Prompt
2021-05-11 02:29:21 +02:00
Expansion</a> are also available.</p>
2022-08-24 15:22:41 +02:00
<p>-n<br />
Suppress printing a newline after the formatted string.</p>
<p>-q<br />
Run quietly; suppress printing of all error messages described below.
Errors for invalid <code>epochtime</code> values are always printed.</p>
<p>-r<br />
With the option -r (reverse), use <code>format</code> to parse the input string
<code>timestring</code> and output the number of seconds since the epoch at which
the time occurred. The parsing is implemented by the system function
strptime; see strptime(3). This means that zsh format extensions are not
available, but for reverse lookup they are not required.</p>
<p>In most implementations of strftime any timezone in the <code>timestring</code> is
ignored and the local timezone declared by the TZ environment variable
is used; other parameters are set to zero if not present.</p>
<p>If <code>timestring</code> does not match <code>format</code> the command returns status 1 and
prints an error message. If <code>timestring</code> matches <code>format</code> but not all
characters in <code>timestring</code> were used, the conversion succeeds but also
prints an error message.</p>
<p>If either of the system functions strptime or mktime is not available,
status 2 is returned and an error message is printed.</p>
<p>-s <code>scalar</code><br />
Assign the date string (or epoch time in seconds if -r is given) to
<code>scalar</code> instead of printing it.</p>
2021-05-11 02:29:21 +02:00
<p>Note that depending on the systems declared integral time type,
2022-08-24 15:22:41 +02:00
strftime may produce incorrect results for epoch times greater than
2021-05-11 02:29:21 +02:00
2147483647 which corresponds to 2038-01-19 03:14:07 +0000.</p>
2022-08-24 15:22:41 +02:00
<p>The zsh/datetime module makes available several parameters; all are
2021-05-11 02:29:21 +02:00
readonly:</p>
<p><span id="index-EPOCHREALTIME"></span></p>
2022-08-24 15:22:41 +02:00
<p>EPOCHREALTIME</p>
2021-05-11 02:29:21 +02:00
<p>A floating point value representing the number of seconds since the
2022-08-24 15:22:41 +02:00
epoch. The notional accuracy is to nanoseconds if the clock_gettime call
is available and to microseconds otherwise, but in practice the range of
double precision floating point and shell scheduling latencies may be
significant effects.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-EPOCHSECONDS"></span></p>
2022-08-24 15:22:41 +02:00
<p>EPOCHSECONDS</p>
2021-05-11 02:29:21 +02:00
<p>An integer value representing the number of seconds since the epoch.</p>
<p><span id="index-epochtime"></span></p>
2022-08-24 15:22:41 +02:00
<p>epochtime</p>
2021-05-11 02:29:21 +02:00
<p>An array value containing the number of seconds since the epoch in the
first element and the remainder of the time since the epoch in
nanoseconds in the second element. To ensure the two elements are
consistent the array should be copied or otherwise referenced as a
single substitution before the values are used. The following idiom may
be used:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">for secs nsecs in $epochtime; do
2021-05-11 02:29:21 +02:00
...
done
</code></pre>
</div>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fdb_002fgdbm-Module"></span> <span
id="The-zsh_002fdb_002fgdbm-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="2211-the-zshdbgdbm-module"><a class="header" href="#2211-the-zshdbgdbm-module">22.11 The zsh/db/gdbm Module</a></h2>
2022-08-24 15:22:41 +02:00
<p>The zsh/db/gdbm module is used to create &quot;tied&quot; associative arrays that
interface to database files. If the GDBM interface is not available, the
builtins defined by this module will report an error. This module is
also intended as a prototype for creating additional database
interfaces, so the ztie builtin may move to a more generic module in the
future.</p>
2021-05-11 02:29:21 +02:00
<p>The builtins in this module are:</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-ztie"></span> <span
id="index-database-tied-array_002c-creating"></span></p>
<p>ztie -d db/gdbm -f <code>filename</code> [ -r ] <code>arrayname</code></p>
2021-05-11 02:29:21 +02:00
<p>Open the GDBM database identified by <code>filename</code> and, if successful,
create the associative array <code>arrayname</code> linked to the file. To create a
local tied array, the parameter must first be declared, so commands
similar to the following would be executed inside a function scope:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">local -A sampledb
2021-05-11 02:29:21 +02:00
ztie -d db/gdbm -f sample.gdbm sampledb
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The -r option opens the database file for reading only, creating a
parameter with the readonly attribute. Without this option, using ztie
on a file for which the user does not have write permission is changed
in <code>arrayname</code> are immediately written to <code>filename</code>.</p>
2021-05-11 02:29:21 +02:00
<p>Changes to the file modes <code>filename</code> after it has been opened do not
2022-08-24 15:22:41 +02:00
alter the state of <code>arrayname</code>, but typeset -r <code>arrayname</code> works as
2021-05-11 02:29:21 +02:00
expected.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-zuntie"></span> <span
id="index-database-tied-array_002c-destroying"></span></p>
<p>zuntie [ -u ] <code>arrayname</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>Close the GDBM database associated with each <code>arrayname</code> and then unset
2022-08-24 15:22:41 +02:00
the parameter. The -u option forces an unset of parameters made readonly
with ztie -r.</p>
2021-05-11 02:29:21 +02:00
<p>This happens automatically if the parameter is explicitly unset or its
local scope (function) ends. Note that a readonly parameter may not be
explicitly unset, so the only way to unset a global parameter created
2022-08-24 15:22:41 +02:00
with ztie -r is to use zuntie -u.</p>
<p><span id="index-zgdbmpath"></span> <span
id="index-database-file-path_002c-reading"></span></p>
<p>zgdbmpath <code>parametername</code></p>
<p>Put path to database file assigned to <code>parametername</code> into REPLY scalar.</p>
<p><span id="index-zgdbm_005ftied"></span> <span
id="index-database-tied-arrays_002c-enumerating"></span></p>
<p>zgdbm_tied</p>
2021-05-11 02:29:21 +02:00
<p>Array holding names of all tied parameters.</p>
<p>The fields of an associative array tied to GDBM are neither cached nor
otherwise stored in memory, they are read from or written to the
database on each reference. Thus, for example, the values in a readonly
array may be changed by a second writer of the same database file.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fdeltochar-Module"></span> <span
id="The-zsh_002fdeltochar-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="2212-the-zshdeltochar-module"><a class="header" href="#2212-the-zshdeltochar-module">22.12 The zsh/deltochar Module</a></h2>
2022-08-24 15:22:41 +02:00
<p>The zsh/deltochar module makes available two ZLE functions:</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-delete_002dto_002dchar"></span></p>
2022-08-24 15:22:41 +02:00
<p>delete-to-char</p>
2021-05-11 02:29:21 +02:00
<p>Read a character from the keyboard, and delete from the cursor position
up to and including the next (or, with repeat count <code>n</code>, the <code>n</code>th)
instance of that character. Negative repeat counts mean delete
backwards.</p>
<p><span id="index-zap_002dto_002dchar"></span></p>
2022-08-24 15:22:41 +02:00
<p>zap-to-char</p>
<p>This behaves like delete-to-char, except that the final occurrence of
2021-05-11 02:29:21 +02:00
the character itself is not deleted.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fexample-Module"></span> <span
id="The-zsh_002fexample-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="2213-the-zshexample-module"><a class="header" href="#2213-the-zshexample-module">22.13 The zsh/example Module</a></h2>
2022-08-24 15:22:41 +02:00
<p>The zsh/example module makes available one builtin command:</p>
<p><span id="index-example"></span> <span
id="index-modules_002c-example"></span> <span
id="index-modules_002c-writing"></span> <span
id="index-writing-modules"></span></p>
<p>example [ -flags ] [ <code>args</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>Displays the flags and arguments it is invoked with.</p>
<p>The purpose of the module is to serve as an example of how to write a
module.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002ffiles-Module"></span> <span
id="The-zsh_002ffiles-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="2214-the-zshfiles-module"><a class="header" href="#2214-the-zshfiles-module">22.14 The zsh/files Module</a></h2>
<p><span id="index-files_002c-manipulating"></span></p>
2022-08-24 15:22:41 +02:00
<p>The zsh/files module makes available some common commands for file
2021-05-11 02:29:21 +02:00
manipulation as builtins; these commands are probably not needed for
many normal situations but can be useful in emergency recovery
situations with constrained resources. The commands do not implement all
features now required by relevant standards committees.</p>
2022-08-24 15:22:41 +02:00
<p>For all commands, a variant beginning zf_ is also available and loaded
2021-05-11 02:29:21 +02:00
automatically. Using the features capability of zmodload will let you
load only those names you want. Note that its possible to load only the
builtins with zsh-specific names using the following command:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zmodload -m -F zsh/files b:zf_\*
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>The commands loaded by default are:</p>
<p><span id="index-chgrp"></span></p>
2022-08-24 15:22:41 +02:00
<p>chgrp [ -hRs ] <code>group</code> <code>filename</code> ...</p>
<p>Changes group of files specified. This is equivalent to chown with a
<code>user-spec</code> argument of :<code>group</code>.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-chmod"></span></p>
2022-08-24 15:22:41 +02:00
<p>chmod [ -Rs ] <code>mode</code> <code>filename</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>Changes mode of files specified.</p>
<p>The specified <code>mode</code> must be in octal.</p>
2022-08-24 15:22:41 +02:00
<p>The -R option causes chmod to recursively descend into directories,
2021-05-11 02:29:21 +02:00
changing the mode of all files in the directory after changing the mode
of the directory itself.</p>
2022-08-24 15:22:41 +02:00
<p>The -s option is a zsh extension to chmod functionality. It enables
2021-05-11 02:29:21 +02:00
paranoid behaviour, intended to avoid security problems involving a
2022-08-24 15:22:41 +02:00
chmod being tricked into affecting files other than the ones intended.
It will refuse to follow symbolic links, so that (for example) chmod
600 /tmp/foo/passwd cant accidentally chmod /etc/passwd if /tmp/foo
happens to be a link to /etc. It will also check where it is after
leaving directories, so that a recursive chmod of a deep directory tree
cant end up recursively chmoding /usr as a result of directories being
moved up the tree.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-chown"></span></p>
2022-08-24 15:22:41 +02:00
<p>chown [ -hRs ] <code>user-spec</code> <code>filename</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>Changes ownership and group of files specified.</p>
<p>The <code>user-spec</code> can be in four forms:</p>
<p><code>user</code><br />
change owner to <code>user</code>; do not change group</p>
2022-08-24 15:22:41 +02:00
<p><code>user</code>::<br />
2021-05-11 02:29:21 +02:00
change owner to <code>user</code>; do not change group</p>
2022-08-24 15:22:41 +02:00
<p><code>user</code>:<br />
2021-05-11 02:29:21 +02:00
change owner to <code>user</code>; change group to <code>user</code>s primary group</p>
2022-08-24 15:22:41 +02:00
<p><code>user</code>:<code>group</code><br />
2021-05-11 02:29:21 +02:00
change owner to <code>user</code>; change group to <code>group</code></p>
2022-08-24 15:22:41 +02:00
<p>:<code>group</code><br />
2021-05-11 02:29:21 +02:00
do not change owner; change group to <code>group</code></p>
2022-08-24 15:22:41 +02:00
<p>In each case, the : may instead be a .. The rule is that if there is
a : then the separator is :, otherwise if there is a . then the
separator is ., otherwise there is no separator.</p>
2021-05-11 02:29:21 +02:00
<p>Each of <code>user</code> and <code>group</code> may be either a username (or group name, as
appropriate) or a decimal user ID (group ID). Interpretation as a name
takes precedence, if there is an all-numeric username (or group name).</p>
2022-08-24 15:22:41 +02:00
<p>If the target is a symbolic link, the -h option causes chown to set the
ownership of the link instead of its target.</p>
<p>The -R option causes chown to recursively descend into directories,
2021-05-11 02:29:21 +02:00
changing the ownership of all files in the directory after changing the
ownership of the directory itself.</p>
2022-08-24 15:22:41 +02:00
<p>The -s option is a zsh extension to chown functionality. It enables
2021-05-11 02:29:21 +02:00
paranoid behaviour, intended to avoid security problems involving a
2022-08-24 15:22:41 +02:00
chown being tricked into affecting files other than the ones intended.
It will refuse to follow symbolic links, so that (for example) chown
luser /tmp/foo/passwd cant accidentally chown /etc/passwd if /tmp/foo
happens to be a link to /etc. It will also check where it is after
leaving directories, so that a recursive chown of a deep directory tree
cant end up recursively chowning /usr as a result of directories being
moved up the tree.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-ln"></span></p>
2022-08-24 15:22:41 +02:00
<p>ln [ -dfhins ] <code>filename</code> <code>dest</code></p>
<p>ln [ -dfhins ] <code>filename</code> ... <code>dir</code></p>
<p>Creates hard (or, with -s, symbolic) links. In the first form, the
2021-05-11 02:29:21 +02:00
specified <code>dest</code>ination is created, as a link to the specified
<code>filename</code>. In the second form, each of the <code>filename</code>s is taken in
turn, and linked to a pathname in the specified <code>dir</code>ectory that has the
same last pathname component.</p>
2022-08-24 15:22:41 +02:00
<p>Normally, ln will not attempt to create hard links to directories. This
check can be overridden using the -d option. Typically only the
2021-05-11 02:29:21 +02:00
super-user can actually succeed in creating hard links to directories.
This does not apply to symbolic links in any case.</p>
2022-08-24 15:22:41 +02:00
<p>By default, existing files cannot be replaced by links. The -i option
causes the user to be queried about replacing existing files. The -f
2021-05-11 02:29:21 +02:00
option causes existing files to be silently deleted, without querying.
2022-08-24 15:22:41 +02:00
-f takes precedence.</p>
<p>The -h and -n options are identical and both exist for compatibility;
either one indicates that if the target is a symlink then it should not
be dereferenced. Typically this is used in combination with -sf so that
if an existing link points to a directory then it will be removed,
instead of followed. If this option is used with multiple filenames and
the target is a symbolic link pointing to a directory then the result is
an error.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-mkdir"></span></p>
2022-08-24 15:22:41 +02:00
<p>mkdir [ -p ] [ -m <code>mode</code> ] <code>dir</code> ...</p>
<p>Creates directories. With the -p option, non-existing parent directories
are first created if necessary, and there will be no complaint if the
directory already exists. The -m option can be used to specify (in
octal) a set of file permissions for the created directories, otherwise
mode 777 modified by the current umask (see umask(2)) is used.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-mv"></span></p>
2022-08-24 15:22:41 +02:00
<p>mv [ -fi ] <code>filename</code> <code>dest</code></p>
<p>mv [ -fi ] <code>filename</code> ... <code>dir</code></p>
2021-05-11 02:29:21 +02:00
<p>Moves files. In the first form, the specified <code>filename</code> is moved to the
specified <code>dest</code>ination. In the second form, each of the <code>filename</code>s is
taken in turn, and moved to a pathname in the specified <code>dir</code>ectory that
has the same last pathname component.</p>
<p>By default, the user will be queried before replacing any file removed.
2022-08-24 15:22:41 +02:00
The -i option causes the user to be queried about replacing any existing
files. The -f option causes any existing files to be silently deleted,
without querying. -f takes precedence.</p>
<p>Note that this mv will not move files across devices. Historical
versions of mv, when actual renaming is impossible, fall back on copying
and removing files; if this behaviour is desired, use cp and rm
manually. This may change in a future version.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-rm"></span></p>
2022-08-24 15:22:41 +02:00
<p>rm [ -dfiRrs ] <code>filename</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>Removes files and directories specified.</p>
2022-08-24 15:22:41 +02:00
<p>Normally, rm will not remove directories (except with the -R or -r
options). The -d option causes rm to try removing directories with
unlink (see unlink(2)), the same method used for files. Typically only
the super-user can actually succeed in unlinking directories in this
way. -d takes precedence over -R and -r.</p>
2021-05-11 02:29:21 +02:00
<p>By default, the user will be queried before removing any file removed.
2022-08-24 15:22:41 +02:00
The -i option causes the user to be queried about removing any files.
The -f option causes files to be silently deleted, without querying, and
suppresses all error indications. -f takes precedence.</p>
<p>The -R and -r options cause rm to recursively descend into directories,
deleting all files in the directory before removing the directory with
the rmdir system call (see rmdir(2)).</p>
<p>The -s option is a zsh extension to rm functionality. It enables
2021-05-11 02:29:21 +02:00
paranoid behaviour, intended to avoid common security problems involving
2022-08-24 15:22:41 +02:00
a root-run rm being tricked into removing files other than the ones
2021-05-11 02:29:21 +02:00
intended. It will refuse to follow symbolic links, so that (for example)
2022-08-24 15:22:41 +02:00
rm /tmp/foo/passwd cant accidentally remove /etc/passwd if /tmp/foo
happens to be a link to /etc. It will also check where it is after
leaving directories, so that a recursive removal of a deep directory
tree cant end up recursively removing /usr as a result of directories
being moved up the tree.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-rmdir"></span></p>
2022-08-24 15:22:41 +02:00
<p>rmdir <code>dir</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>Removes empty directories specified.</p>
<p><span id="index-sync"></span></p>
2022-08-24 15:22:41 +02:00
<p>sync</p>
<p>Calls the system call of the same name (see sync(2)), which flushes
dirty buffers to disk. It might return before the I/O has actually been
completed.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002flanginfo-Module"></span> <span
id="The-zsh_002flanginfo-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="2215-the-zshlanginfo-module"><a class="header" href="#2215-the-zshlanginfo-module">22.15 The zsh/langinfo Module</a></h2>
2022-08-24 15:22:41 +02:00
<p>The zsh/langinfo module makes available one parameter:</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-langinfo"></span></p>
2022-08-24 15:22:41 +02:00
<p>langinfo</p>
2021-05-11 02:29:21 +02:00
<p>An associative array that maps langinfo elements to their values.</p>
<p>Your implementation may support a number of the following keys:</p>
2022-08-24 15:22:41 +02:00
<p>CODESET, D_T_FMT, D_FMT, T_FMT, RADIXCHAR, THOUSEP, YESEXPR, NOEXPR,
CRNCYSTR, ABDAY_{1..7}, DAY_{1..7}, ABMON_{1..12}, MON_{1..12},
T_FMT_AMPM, AM_STR, PM_STR, ERA, ERA_D_FMT, ERA_D_T_FMT, ERA_T_FMT,
ALT_DIGITS</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fmapfile-Module"></span> <span
id="The-zsh_002fmapfile-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="2216-the-zshmapfile-module"><a class="header" href="#2216-the-zshmapfile-module">22.16 The zsh/mapfile Module</a></h2>
<p><span id="index-parameter_002c-file-access-via"></span></p>
2022-08-24 15:22:41 +02:00
<p>The zsh/mapfile module provides one special associative array parameter
of the same name.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-mapfile"></span></p>
2022-08-24 15:22:41 +02:00
<p>mapfile</p>
2021-05-11 02:29:21 +02:00
<p>This associative array takes as keys the names of files; the resulting
value is the content of the file. The value is treated identically to
any other text coming from a parameter. The value may also be assigned
to, in which case the file in question is written (whether or not it
originally existed); or an element may be unset, which will delete the
2022-08-24 15:22:41 +02:00
file in question. For example, vared mapfile[myfile] works as
expected, editing the file myfile.</p>
2021-05-11 02:29:21 +02:00
<p>When the array is accessed as a whole, the keys are the names of files
in the current directory, and the values are empty (to save a huge
2022-08-24 15:22:41 +02:00
overhead in memory). Thus ${(k)mapfile} has the same effect as the glob
operator *(D), since files beginning with a dot are not special. Care
must be taken with expressions such as rm ${(k)mapfile}, which will
delete every file in the current directory without the usual rm *
test.</p>
<p>The parameter mapfile may be made read-only; in that case, files
2021-05-11 02:29:21 +02:00
referenced may not be written or deleted.</p>
<p>A file may conveniently be read into an array as one line per element
2022-08-24 15:22:41 +02:00
with the form <code>array</code>=(&quot;${(f@)mapfile[<code>filename</code>]}&quot;). The double
quotes and the @ are necessary to prevent empty lines from being
2021-05-11 02:29:21 +02:00
removed. Note that if the file ends with a newline, the shell will split
on the final newline, generating an additional empty field; this can be
suppressed by using
2022-08-24 15:22:41 +02:00
<code>array</code>=(&quot;${(f@)${mapfile[<code>filename</code>]%$\n}}&quot;).</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Limitations"></span></p>
<h3 id="22161-limitations"><a class="header" href="#22161-limitations">22.16.1 Limitations</a></h3>
<p>Although reading and writing of the file in question is efficiently
handled, zshs internal memory management may be arbitrarily baroque;
2022-08-24 15:22:41 +02:00
however, mapfile is usually very much more efficient than anything
2021-05-11 02:29:21 +02:00
involving a loop. Note in particular that the whole contents of the file
will always reside physically in memory when accessed (possibly multiple
times, due to standard parameter substitution operations). In
particular, this means handling of sufficiently long files (greater than
the machines swap space, or than the range of the pointer type) will be
incorrect.</p>
<p>No errors are printed or flagged for non-existent, unreadable, or
execution hierarchy to make this convenient.</p>
<p>It is unfortunate that the mechanism for loading modules does not yet
allow the user to specify the name of the shell parameter to be given
the special behaviour.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fmathfunc-Module"></span> <span
id="The-zsh_002fmathfunc-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="2217-the-zshmathfunc-module"><a class="header" href="#2217-the-zshmathfunc-module">22.17 The zsh/mathfunc Module</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-functions_002c-mathematical"></span> <span
id="index-mathematical-functions"></span></p>
<p>The zsh/mathfunc module provides standard mathematical functions for use
when evaluating mathematical formulae. The syntax agrees with normal C
and FORTRAN conventions, for example,</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">(( f = sin(0.3) ))
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>assigns the sine of 0.3 to the parameter f.</p>
<p>Most functions take floating point arguments and return a floating point
value. However, any necessary conversions from or to integer type will
2022-08-24 15:22:41 +02:00
be performed automatically by the shell. Apart from atan with a second
argument and the abs, int and float functions, all functions behave as
noted in the manual page for the corresponding C function, except that
any arguments out of range for the function in question will be detected
by the shell and an error reported.</p>
<p>The following functions take a single floating point argument: acos,
acosh, asin, asinh, atan, atanh, cbrt, ceil, cos, cosh, erf, erfc, exp,
expm1, fabs, floor, gamma, j0, j1, lgamma, log, log10, log1p, log2,
logb, sin, sinh, sqrt, tan, tanh, y0, y1. The atan function can
optionally take a second argument, in which case it behaves like the C
function atan2. The ilogb function takes a single floating point
argument, but returns an integer.</p>
<p>The function signgam takes no arguments, and returns an integer, which
is the C variable of the same name, as described in gamma(3). Note that
it is therefore only useful immediately after a call to gamma or lgamma.
Note also that signgam() and signgam are distinct expressions.</p>
<p>The functions min, max, and sum are defined not in this module but in
the zmathfunc autoloadable function, described in <a href="User-Contributions.html#Mathematical-Functions">Mathematical
2021-05-11 02:29:21 +02:00
Functions</a>.</p>
2022-08-24 15:22:41 +02:00
<p>The following functions take two floating point arguments: copysign,
fmod, hypot, nextafter.</p>
2021-05-11 02:29:21 +02:00
<p>The following take an integer first argument and a floating point second
2022-08-24 15:22:41 +02:00
argument: jn, yn.</p>
2021-05-11 02:29:21 +02:00
<p>The following take a floating point first argument and an integer second
2022-08-24 15:22:41 +02:00
argument: ldexp, scalb.</p>
<p>The function abs does not convert the type of its single argument; it
2021-05-11 02:29:21 +02:00
returns the absolute value of either a floating point number or an
2022-08-24 15:22:41 +02:00
integer. The functions float and int convert their arguments into a
2021-05-11 02:29:21 +02:00
floating point or integer value (by truncation) respectively.</p>
2022-08-24 15:22:41 +02:00
<p>Note that the C pow function is available in ordinary math evaluation as
the ** operator and is not provided here.</p>
<p>The function rand48 is available if your systems mathematical library
has the function erand48(3). It returns a pseudo-random floating point
2021-05-11 02:29:21 +02:00
number between 0 and 1. It takes a single string optional argument.</p>
<p>If the argument is not present, the random number seed is initialised by
2022-08-24 15:22:41 +02:00
three calls to the rand(3) function — this produces the same random
numbers as the next three values of $RANDOM.</p>
2021-05-11 02:29:21 +02:00
<p>If the argument is present, it gives the name of a scalar parameter
where the current random number seed will be stored. On the first call,
the value must contain at least twelve hexadecimal digits (the remainder
of the string is ignored), or the seed will be initialised in the same
2022-08-24 15:22:41 +02:00
manner as for a call to rand48 with no argument. Subsequent calls to
rand48(<code>param</code>) will then maintain the seed in the parameter <code>param</code> as
a string of twelve hexadecimal digits, with no base signifier. The
2021-05-11 02:29:21 +02:00
random number sequences for different parameters are completely
2022-08-24 15:22:41 +02:00
independent, and are also independent from that used by calls to rand48
with no argument.</p>
2021-05-11 02:29:21 +02:00
<p>For example, consider</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">print $(( rand48(seed) ))
2021-05-11 02:29:21 +02:00
print $(( rand48() ))
print $(( rand48(seed) ))
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Assuming $seed does not exist, it will be initialised by the first call.
In the second call, the default seed is initialised; note, however, that
because of the properties of rand() there is a correlation between the
seeds used for the two initialisations, so for more secure uses, you
should generate your own 12-byte seed. The third call returns to the
same sequence of random numbers used in the first call, unaffected by
the intervening rand48().</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fnearcolor-Module"></span> <span
id="The-zsh_002fnearcolor-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="2218-the-zshnearcolor-module"><a class="header" href="#2218-the-zshnearcolor-module">22.18 The zsh/nearcolor Module</a></h2>
2022-08-24 15:22:41 +02:00
<p>The zsh/nearcolor module replaces colours specified as hex triplets with
the nearest colour in the 88 or 256 colour palettes that are widely used
by terminal emulators. By default, 24-bit true colour escape codes are
generated when colours are specified using hex triplets. These are not
supported by all terminals. The purpose of this module is to make it
2021-05-11 02:29:21 +02:00
easier to define colour preferences in a form that can work across a
range of terminal emulators.</p>
<p>Aside from the default colour, the ANSI standard for terminal escape
codes provides for eight colours. The bright attribute brings this to
sixteen. These basic colours are commonly used in terminal applications
due to being widely supported. Expanded 88 and 256 colour palettes are
also common and, while the first sixteen colours vary somewhat between
terminals and configurations, these add a generally consistent and</p>
2022-08-24 15:22:41 +02:00
<p>In order to use the zsh/nearcolor module, it only needs to be loaded.
2021-05-11 02:29:21 +02:00
Thereafter, whenever a colour is specified using a hex triplet, it will
be compared against each of the available colours and the closest will
be selected. The first sixteen colours are never matched in</p>
<p>It isnt possible to reliably detect support for true colour in the
terminal emulator. It is therefore recommended to be selective in
2022-08-24 15:22:41 +02:00
loading the zsh/nearcolor module. For example, the following checks the
COLORTERM environment variable:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">[[ $COLORTERM = *(24bit|truecolor)* ]] || zmodload zsh/nearcolor
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>Note that some terminals accept the true color escape codes but map them
internally to a more limited palette in a similar manner to the
2022-08-24 15:22:41 +02:00
zsh/nearcolor module.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fnewuser-Module"></span> <span
id="The-zsh_002fnewuser-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="2219-the-zshnewuser-module"><a class="header" href="#2219-the-zshnewuser-module">22.19 The zsh/newuser Module</a></h2>
2022-08-24 15:22:41 +02:00
<p>The zsh/newuser module is loaded at boot if it is available, the RCS
option is set, and the PRIVILEGED option is not set (all three are true
by default). This takes place immediately after commands in the global
zshenv file (typically /etc/zshenv), if any, have been executed. If the
module is not available it is silently ignored by the shell; the module
may safely be removed from $MODULE_PATH by the administrator if it is
not required.</p>
<p>On loading, the module tests if any of the start-up files .zshenv,
.zprofile, .zshrc or .zlogin exist in the directory given by the
environment variable ZDOTDIR, or the users home directory if that is
2021-05-11 02:29:21 +02:00
not set. The test is not performed and the module halts processing if
the shell was in an emulation mode (i.e. had been invoked as some other
shell than zsh).</p>
<p>If none of the start-up files were found, the module then looks for the
2022-08-24 15:22:41 +02:00
file newuser first in a sitewide directory, usually the parent directory
of the site-functions directory, and if that is not found the module
searches in a version-specific directory, usually the parent of the
functions directory containing version-specific functions. (These
directories can be configured when zsh is built using the
enable-site-scriptdir=<code>dir</code> and enable-scriptdir=<code>dir</code> flags to
configure, respectively; the defaults are <code>prefix</code>/share/zsh and
<code>prefix</code>/share/zsh/$ZSH_VERSION where the default <code>prefix</code> is
/usr/local.)</p>
<p>If the file newuser is found, it is then sourced in the same manner as a
start-up file. The file is expected to contain code to install start-up
files for the user, however any valid shell code will be executed.</p>
<p>The zsh/newuser module is then unconditionally unloaded.</p>
2021-05-11 02:29:21 +02:00
<p>Note that it is possible to achieve exactly the same effect as the
2022-08-24 15:22:41 +02:00
zsh/newuser module by adding code to /etc/zshenv. The module exists
2021-05-11 02:29:21 +02:00
simply to allow the shell to make arrangements for new users without the
need for intervention by package maintainers and system administrators.</p>
<p>The script supplied with the module invokes the shell function
2022-08-24 15:22:41 +02:00
zsh-newuser-install. This may be invoked directly by the user even if
the zsh/newuser module is disabled. Note, however, that if the module is
not installed the function will not be installed either. The function is
documented in <a href="User-Contributions.html#User-Configuration-Functions">User Configuration
2021-05-11 02:29:21 +02:00
Functions</a>.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fparameter-Module"></span> <span
id="The-zsh_002fparameter-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="2220-the-zshparameter-module"><a class="header" href="#2220-the-zshparameter-module">22.20 The zsh/parameter Module</a></h2>
<p><span id="index-parameters_002c-special-1"></span></p>
2022-08-24 15:22:41 +02:00
<p>The zsh/parameter module gives access to some of the internal hash</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-options-1"></span></p>
2022-08-24 15:22:41 +02:00
<p>options</p>
2021-05-11 02:29:21 +02:00
<p>The keys for this associative array are the names of the options that
2022-08-24 15:22:41 +02:00
can be set and unset using the setopt and unsetopt builtins. The value
of each key is either the string on if the option is currently set, or
the string off if the option is unset. Setting a key to one of these
strings is like setting or unsetting the option, respectively. Unsetting
a key in this array is like setting it to the value off.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-commands"></span></p>
2022-08-24 15:22:41 +02:00
<p>commands</p>
2021-05-11 02:29:21 +02:00
<p>names of external commands, the values are the pathnames of the files
that would be executed when the command would be invoked. Setting a with
2022-08-24 15:22:41 +02:00
the hash builtin. Unsetting a key as in unset &quot;commands[foo]&quot;
2021-05-11 02:29:21 +02:00
removes the entry for the given key from the command</p>
<p><span id="index-functions-2"></span></p>
2022-08-24 15:22:41 +02:00
<p>functions</p>
2021-05-11 02:29:21 +02:00
<p>This associative array maps names of enabled functions to their
definitions. Setting a key in it is like defining a function with the
name given by the key and the body given by the value. Unsetting a key
removes the definition for the function named by the key.</p>
<p><span id="index-dis_005ffunctions"></span></p>
2022-08-24 15:22:41 +02:00
<p>dis_functions</p>
<p>Like functions but for disabled functions.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-functions_005fsource"></span></p>
2022-08-24 15:22:41 +02:00
<p>functions_source</p>
2021-05-11 02:29:21 +02:00
<p>This readonly associative array maps names of enabled functions to the
name of the file containing the source of the function.</p>
<p>For an autoloaded function that has already been loaded, or marked for
autoload with an absolute path, or that has had its path resolved with
2022-08-24 15:22:41 +02:00
functions -r, this is the file found for autoloading, resolved to an
absolute path.</p>
2021-05-11 02:29:21 +02:00
<p>For a function defined within the body of a script or sourced file, this
is the name of that file. In this case, this is the exact path
originally used to that file, which may be a relative path.</p>
<p>For any other function, including any defined at an interactive prompt
or an autoload function whose path has not yet been resolved, this is
the empty string. However, the hash element is reported as defined just
so long as the function is present: the keys to this hash are the same
2022-08-24 15:22:41 +02:00
as those to $functions.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-dis_005ffunctions_005fsource"></span></p>
2022-08-24 15:22:41 +02:00
<p>dis_functions_source</p>
<p>Like functions_source but for disabled functions.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-builtins"></span></p>
2022-08-24 15:22:41 +02:00
<p>builtins</p>
2021-05-11 02:29:21 +02:00
<p>This associative array gives information about the builtin commands
currently enabled. The keys are the names of the builtin commands and
2022-08-24 15:22:41 +02:00
the values are either undefined for builtin commands that will
automatically be loaded from a module if invoked or defined for
2021-05-11 02:29:21 +02:00
builtin commands that are already loaded.</p>
<p><span id="index-dis_005fbuiltins"></span></p>
2022-08-24 15:22:41 +02:00
<p>dis_builtins</p>
<p>Like builtins but for disabled builtin commands.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-reswords"></span></p>
2022-08-24 15:22:41 +02:00
<p>reswords</p>
2021-05-11 02:29:21 +02:00
<p>This array contains the enabled reserved words.</p>
<p><span id="index-dis_005freswords"></span></p>
2022-08-24 15:22:41 +02:00
<p>dis_reswords</p>
<p>Like reswords but for disabled reserved words.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-patchars"></span></p>
2022-08-24 15:22:41 +02:00
<p>patchars</p>
2021-05-11 02:29:21 +02:00
<p>This array contains the enabled pattern characters.</p>
<p><span id="index-dis_005fpatchars"></span></p>
2022-08-24 15:22:41 +02:00
<p>dis_patchars</p>
<p>Like patchars but for disabled pattern characters.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-aliases"></span></p>
2022-08-24 15:22:41 +02:00
<p>aliases</p>
2021-05-11 02:29:21 +02:00
<p>This maps the names of the regular aliases currently enabled to their
expansions.</p>
<p><span id="index-dis_005faliases"></span></p>
2022-08-24 15:22:41 +02:00
<p>dis_aliases</p>
<p>Like aliases but for disabled regular aliases.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-galiases"></span></p>
2022-08-24 15:22:41 +02:00
<p>galiases</p>
<p>Like aliases, but for global aliases.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-dis_005fgaliases"></span></p>
2022-08-24 15:22:41 +02:00
<p>dis_galiases</p>
<p>Like galiases but for disabled global aliases.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-saliases"></span></p>
2022-08-24 15:22:41 +02:00
<p>saliases</p>
<p>Like raliases, but for suffix aliases.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-dis_005fsaliases"></span></p>
2022-08-24 15:22:41 +02:00
<p>dis_saliases</p>
<p>Like saliases but for disabled suffix aliases.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-parameters-1"></span></p>
2022-08-24 15:22:41 +02:00
<p>parameters</p>
2021-05-11 02:29:21 +02:00
<p>The keys in this associative array are the names of the parameters
currently defined. The values are strings describing the type of the
2022-08-24 15:22:41 +02:00
parameter, in the same format used by the t parameter flag, see
2021-05-11 02:29:21 +02:00
<a href="Expansion.html#Parameter-Expansion">Parameter Expansion</a> . Setting or
unsetting keys in this array is not possible.</p>
<p><span id="index-modules-1"></span></p>
2022-08-24 15:22:41 +02:00
<p>modules</p>
2021-05-11 02:29:21 +02:00
<p>An associative array giving information about modules. The keys are the
names of the modules loaded, registered to be autoloaded, or aliased.
The value says which state the named module is in and is one of the
2022-08-24 15:22:41 +02:00
strings loaded, autoloaded, or alias:<code>name</code>, where <code>name</code> is the
name the module is aliased to.</p>
2021-05-11 02:29:21 +02:00
<p>Setting or unsetting keys in this array is not possible.</p>
<p><span id="index-dirstack"></span></p>
2022-08-24 15:22:41 +02:00
<p>dirstack</p>
2021-05-11 02:29:21 +02:00
<p>A normal array holding the elements of the directory stack. Note that
2022-08-24 15:22:41 +02:00
the output of the dirs builtin command includes one more directory, the
current working directory.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-history-2"></span></p>
2022-08-24 15:22:41 +02:00
<p>history</p>
2021-05-11 02:29:21 +02:00
<p>This associative array maps history event numbers to the full history
lines. Although it is presented as an associative array, the array of
2022-08-24 15:22:41 +02:00
all values (${history[@]}) is guaranteed to be returned in order from
2021-05-11 02:29:21 +02:00
most recent to oldest history event, that is, by decreasing history
event number.</p>
<p><span id="index-historywords"></span></p>
2022-08-24 15:22:41 +02:00
<p>historywords</p>
2021-05-11 02:29:21 +02:00
<p>A special array containing the words stored in the history. These also
appear in most to least recent order.</p>
<p><span id="index-jobdirs"></span></p>
2022-08-24 15:22:41 +02:00
<p>jobdirs</p>
2021-05-11 02:29:21 +02:00
<p>This associative array maps job numbers to the directories from which
the job was started (which may not be the current directory of the job).</p>
<p>The keys of the associative arrays are usually valid job numbers, and
2022-08-24 15:22:41 +02:00
these are the values output with, for example, ${(k)jobdirs}.
2021-05-11 02:29:21 +02:00
Non-numeric job references may be used when looking up a value; for
2022-08-24 15:22:41 +02:00
example, ${jobdirs[%+]} refers to the current job.</p>
<p>See the jobs builtin for how job information is provided in a subshell.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-jobtexts"></span></p>
2022-08-24 15:22:41 +02:00
<p>jobtexts</p>
2021-05-11 02:29:21 +02:00
<p>This associative array maps job numbers to the texts of the command
lines that were used to start the jobs.</p>
<p>Handling of the keys of the associative array is as described for
2022-08-24 15:22:41 +02:00
jobdirs above.</p>
<p>See the jobs builtin for how job information is provided in a subshell.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-jobstates"></span></p>
2022-08-24 15:22:41 +02:00
<p>jobstates</p>
2021-05-11 02:29:21 +02:00
<p>This associative array gives information about the states of the jobs
currently known. The keys are the job numbers and the values are strings
2022-08-24 15:22:41 +02:00
of the form <code>job-state</code>:<code>mark</code>:<code>pid</code>=<code>state</code>.... The <code>job-state</code> gives
the state the whole job is currently in, one of running, suspended,
or done. The <code>mark</code> is + for the current job, - for the previous
job and empty otherwise. This is followed by one :<code>pid</code>=<code>state</code> for
every process in the job. The <code>pid</code>s are, of course, the process IDs and
the <code>state</code> describes the state of that process.</p>
2021-05-11 02:29:21 +02:00
<p>Handling of the keys of the associative array is as described for
2022-08-24 15:22:41 +02:00
jobdirs above.</p>
<p>See the jobs builtin for how job information is provided in a subshell.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-nameddirs"></span></p>
2022-08-24 15:22:41 +02:00
<p>nameddirs</p>
2021-05-11 02:29:21 +02:00
<p>This associative array maps the names of named directories to the
pathnames they stand for.</p>
<p><span id="index-userdirs"></span></p>
2022-08-24 15:22:41 +02:00
<p>userdirs</p>
2021-05-11 02:29:21 +02:00
<p>This associative array maps user names to the pathnames of their home
directories.</p>
<p><span id="index-usergroups"></span></p>
2022-08-24 15:22:41 +02:00
<p>usergroups</p>
2021-05-11 02:29:21 +02:00
<p>This associative array maps names of system groups of which the current
user is a member to the corresponding group identifiers. The contents
2022-08-24 15:22:41 +02:00
are the same as the groups output by the id command.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-funcfiletrace"></span></p>
2022-08-24 15:22:41 +02:00
<p>funcfiletrace</p>
2021-05-11 02:29:21 +02:00
<p>This array contains the absolute line numbers and corresponding file
names for the point where the current function, sourced file, or (if
2022-08-24 15:22:41 +02:00
EVAL_LINENO is set) eval command was called. The array is of the same
length as funcsourcetrace and functrace, but differs from
funcsourcetrace in that the line and file are the point of call, not the
point of definition, and differs from functrace in that all values are
absolute line numbers in files, rather than relative to the start of a
function, if any.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-funcsourcetrace"></span></p>
2022-08-24 15:22:41 +02:00
<p>funcsourcetrace</p>
2021-05-11 02:29:21 +02:00
<p>This array contains the file names and line numbers of the points where
2022-08-24 15:22:41 +02:00
the functions, sourced files, and (if EVAL_LINENO is set) eval commands
currently being executed were defined. The line number is the line where
the function <code>name</code> or <code>name</code> () started. In the case of an
autoloaded function the line number is reported as zero. The format of
each element is <code>filename</code>:<code>lineno</code>.</p>
2021-05-11 02:29:21 +02:00
<p>For functions autoloaded from a file in native zsh format, where only
the body of the function occurs in the file, or for files that have been
2022-08-24 15:22:41 +02:00
executed by the source or . builtins, the trace information is shown
as <code>filename</code>:<code>0</code>, since the entire file is the definition. The source
file name is resolved to an absolute path when the function is loaded or
the path to it otherwise resolved.</p>
<p>Most users will be interested in the information in the funcfiletrace
2021-05-11 02:29:21 +02:00
array instead.</p>
<p><span id="index-funcstack"></span></p>
2022-08-24 15:22:41 +02:00
<p>funcstack</p>
2021-05-11 02:29:21 +02:00
<p>This array contains the names of the functions, sourced files, and (if
2022-08-24 15:22:41 +02:00
EVAL_LINENO is set) eval commands. currently being executed. The first
element is the name of the function using the parameter.</p>
<p>The standard shell array zsh_eval_context can be used to determine the
2021-05-11 02:29:21 +02:00
type of shell construct being executed at each depth: note, however,
that is in the opposite order, with the most recent item last, and it is
2022-08-24 15:22:41 +02:00
more detailed, for example including an entry for toplevel, the main
2021-05-11 02:29:21 +02:00
shell code being executed either interactively or from a script, which
2022-08-24 15:22:41 +02:00
is not present in $funcstack.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-functrace"></span></p>
2022-08-24 15:22:41 +02:00
<p>functrace</p>
2021-05-11 02:29:21 +02:00
<p>This array contains the names and line numbers of the callers
corresponding to the functions currently being executed. The format of
2022-08-24 15:22:41 +02:00
each element is <code>name</code>:<code>lineno</code>. Callers are also shown for sourced
files; the caller is the point where the source or . command was
2021-05-11 02:29:21 +02:00
executed.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fpcre-Module"></span> <span
id="The-zsh_002fpcre-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="2221-the-zshpcre-module"><a class="header" href="#2221-the-zshpcre-module">22.21 The zsh/pcre Module</a></h2>
<p><span id="index-regular-expressions_002c-perl_002dcompatible"></span></p>
2022-08-24 15:22:41 +02:00
<p>The zsh/pcre module makes some commands available as builtins:</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-pcre_005fcompile"></span></p>
2022-08-24 15:22:41 +02:00
<p>pcre_compile [ -aimxs ] <code>PCRE</code></p>
2021-05-11 02:29:21 +02:00
<p>Compiles a perl-compatible regular expression.</p>
2022-08-24 15:22:41 +02:00
<p>Option -a will force the pattern to be anchored. Option -i will compile
a case-insensitive pattern. Option -m will compile a multi-line pattern;
that is, ^ and $ will match newlines within the pattern. Option -x will
compile an extended pattern, wherein whitespace and # comments are
ignored. Option -s makes the dot metacharacter match all characters,
including those that indicate newline.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-pcre_005fstudy"></span></p>
2022-08-24 15:22:41 +02:00
<p>pcre_study</p>
2021-05-11 02:29:21 +02:00
<p>Studies the previously-compiled PCRE which may result in faster
matching.</p>
<p><span id="index-pcre_005fmatch"></span></p>
2022-08-24 15:22:41 +02:00
<p>pcre_match [ -v <code>var</code> ] [ -a <code>arr</code> ] [ -n <code>offset</code> ] [ -b ]
<code>string</code></p>
<p>Returns successfully if string matches the previously-compiled PCRE.</p>
2021-05-11 02:29:21 +02:00
<p>Upon successful match, if the expression captures substrings within
2022-08-24 15:22:41 +02:00
parentheses, pcre_match will set the array match to those substrings,
unless the -a option is given, in which case it will set the array
<code>arr</code>. Similarly, the variable MATCH will be set to the entire matched
portion of the string, unless the -v option is given, in which case the
variable <code>var</code> will be set. No variables are altered if there is no
successful match. A -n option starts searching for a match from the byte
<code>offset</code> position in <code>string</code>. If the -b option is given, the variable
ZPCRE_OP will be set to an offset pair string, representing the byte
offset positions of the entire matched portion within the <code>string</code>. For
example, a ZPCRE_OP set to &quot;32 45&quot; indicates that the matched portion
began on byte offset 32 and ended on byte offset 44. Here, byte offset
position 45 is the position directly after the matched portion. Keep in
mind that the byte position isnt necessarily the same as the character
position when UTF-8 characters are involved. Consequently, the byte
offset positions are only to be relied on in the context of using them
for subsequent searches on <code>string</code>, using an offset position as an
argument to the -n option. This is mostly used to implement the &quot;find
all non-overlapping matches&quot; functionality.</p>
2021-05-11 02:29:21 +02:00
<p>A simple example of &quot;find all non-overlapping matches&quot;:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">string=&quot;The following zip codes: 78884 90210 99513&quot;
2021-05-11 02:29:21 +02:00
pcre_compile -m &quot;\d{5}&quot;
accum=()
pcre_match -b -- $string
while [[ $? -eq 0 ]] do
b=($=ZPCRE_OP)
accum+=$MATCH
pcre_match -b -n $b[2] -- $string
done
print -l $accum
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The zsh/pcre module makes available the following test condition:</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-pcre_002dmatch"></span></p>
2022-08-24 15:22:41 +02:00
<p><code>expr</code> -pcre-match <code>pcre</code></p>
2021-05-11 02:29:21 +02:00
<p>Matches a string against a perl-compatible regular expression.</p>
<p>For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">[[ &quot;$text&quot; -pcre-match ^d+$ ]] &amp;&amp;
2021-05-11 02:29:21 +02:00
print text variable contains only &quot;d's&quot;.
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p><span id="index-REMATCH_005fPCRE-1"></span> <span
id="index-NO_005fCASE_005fMATCH-1"></span></p>
<p>If the REMATCH_PCRE option is set, the =~ operator is equivalent to
-pcre-match, and the NO_CASE_MATCH option may be used. Note that
NO_CASE_MATCH never applies to the pcre_match builtin, instead use the
-i switch of pcre_compile.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fparam_002fprivate-Module"></span> <span
id="The-zsh_002fparam_002fprivate-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="2222-the-zshparamprivate-module"><a class="header" href="#2222-the-zshparamprivate-module">22.22 The zsh/param/private Module</a></h2>
2022-08-24 15:22:41 +02:00
<p>The zsh/param/private module is used to create parameters whose scope is
limited to the current function body, and <em>not</em> to other functions
2021-05-11 02:29:21 +02:00
called by the current function.</p>
<p>This module provides a single autoloaded builtin:</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-private"></span> <span
id="index-private-parameter_002c-creating"></span></p>
<p>private [ {+|-}AHUahlmrtux ] [ {+|-}EFLRZi [ <code>n</code> ] ] [
<code>name</code>[=<code>value</code>] ... ]</p>
<p>The private builtin accepts all the same options and arguments as local
(<a href="Shell-Builtin-Commands.html#Shell-Builtin-Commands">Shell Builtin
2021-05-11 02:29:21 +02:00
Commands</a>) except
2022-08-24 15:22:41 +02:00
for the -T option. Tied parameters may not be made private.</p>
<p>The -p option is presently a no-op because the state of private
parameters cannot reliably be reloaded. This also applies to printing
private parameters with typeset -p.</p>
<p>If used at the top level (outside a function scope), private creates a
normal parameter in the same manner as declare or typeset. A warning
about this is printed if WARN_CREATE_GLOBAL is set
(<a href="Options.html#Options">Options</a>). Used inside a function scope, private
creates a local parameter similar to one declared with local, except
having special properties noted below.</p>
2021-05-11 02:29:21 +02:00
<p>Special parameters which expose or manipulate internal shell state, such
2022-08-24 15:22:41 +02:00
as ARGC, argv, COLUMNS, LINES, UID, EUID, IFS, PROMPT, RANDOM, SECONDS,
etc., cannot be made private unless the -h option is used to hide the
special meaning of the parameter. This may change in the future.</p>
<p>As with other typeset equivalents, private is both a builtin and a
2021-05-11 02:29:21 +02:00
reserved word, so arrays may be assigned with parenthesized word list
2022-08-24 15:22:41 +02:00
<code>name</code>=(<code>value</code>...) syntax. However, the reserved word private is not
available until zsh/param/private is loaded, so care must be taken with
order of execution and parsing for function definitions which use
private. To compensate for this, the module also adds the option -P to
the local builtin to declare private parameters.</p>
<p>For example, this construction fails if zsh/param/private has not yet
been loaded when bad_declaration is defined:</p>
<div class="example">
<pre><code class="language-zsh">bad_declaration() {
2021-05-11 02:29:21 +02:00
zmodload zsh/param/private
private array=( one two three )
}
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>This construction works because local is already a keyword, and the
2021-05-11 02:29:21 +02:00
module is loaded before the statement is executed:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">good_declaration() {
2021-05-11 02:29:21 +02:00
zmodload zsh/param/private
local -P array=( one two three )
}
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The following is usable in scripts but may have trouble with autoload:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zmodload zsh/param/private
2021-05-11 02:29:21 +02:00
iffy_declaration() {
private array=( one two three )
}
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The private builtin may always be used with scalar assignments and for
2021-05-11 02:29:21 +02:00
declarations without assignments.</p>
2022-08-24 15:22:41 +02:00
<p>Parameters declared with private have the following properties:</p>
2021-05-11 02:29:21 +02:00
<ul>
<li>Within the function body where it is declared, the parameter behaves
as a local, except as noted above for tied or special parameters.</li>
<li>The type of a parameter declared private cannot be changed in the
scope where it was declared, even if the parameter is unset. Thus an
array cannot be assigned to a private scalar, etc.</li>
<li>Within any other function called by the declaring function, the
private parameter does <em>NOT</em> hide other parameters of the same name,
so for example a global parameter of the same name is visible and
may be assigned or unset. This includes calls to anonymous
2022-08-24 15:22:41 +02:00
functions, although that may also change in the future. However, the
private name may not be created outside the local scope when it was
not previously declared.</li>
2021-05-11 02:29:21 +02:00
<li>An exported private remains in the environment of inner scopes but
appears unset for the current shell in those scopes. Generally,
exporting private parameters should be avoided.</li>
</ul>
<p>Note that this differs from the static scope defined by compiled
languages derived from C, in that the a new call to the same function
creates a new scope, i.e., the parameter is still associated with the
call stack rather than with the function definition. It differs from ksh
2022-08-24 15:22:41 +02:00
typeset -S because the syntax used to define the function has no
2021-05-11 02:29:21 +02:00
bearing on whether the parameter scope is respected.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fregex-Module"></span> <span
id="The-zsh_002fregex-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="2223-the-zshregex-module"><a class="header" href="#2223-the-zshregex-module">22.23 The zsh/regex Module</a></h2>
2022-08-24 15:22:41 +02:00
<p><span id="index-regular-expressions"></span> <span
id="index-regex"></span></p>
<p>The zsh/regex module makes available the following test condition:</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-regex_002dmatch"></span></p>
2022-08-24 15:22:41 +02:00
<p><code>expr</code> -regex-match <code>regex</code></p>
2021-05-11 02:29:21 +02:00
<p>Matches a string against a POSIX extended regular expression. On
successful match, matched portion of the string will normally be placed
2022-08-24 15:22:41 +02:00
in the MATCH variable. If there are any capturing parentheses within the
regex, then the match array variable will contain those. If the match is
not successful, then the variables will not be altered.</p>
2021-05-11 02:29:21 +02:00
<p>For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">[[ alphabetical -regex-match ^a([^a]+)a([^a]+)a ]] &amp;&amp;
2021-05-11 02:29:21 +02:00
print -l $MATCH X $match
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>If the option REMATCH_PCRE is not set, then the =~ operator will
2021-05-11 02:29:21 +02:00
automatically load this module as needed and will invoke the
2022-08-24 15:22:41 +02:00
-regex-match operator.</p>
<p>If BASH_REMATCH is set, then the array BASH_REMATCH will be set instead
of MATCH and match.</p>
<p>Note that the zsh/regex module logic relies on the host system. The same
<code>expr</code> and <code>regex</code> pair could produce different results on different
platforms if a <code>regex</code> with non-standard syntax is given.</p>
<p>For example, no syntax for matching a word boundary is defined in the
POSIX extended regular expression standard. GNU libc and BSD libc both
provide such syntaxes as extensions (\b and [[:&lt;:]]/[[:&gt;:]]
respectively), but neither of these syntaxes is supported by both of
these implementations.</p>
<p>Refer to the regcomp(3) and re_format(7) manual pages on your system for
locally-supported syntax.</p>
<hr />
<p><span id="The-zsh_002fsched-Module"></span> <span
id="The-zsh_002fsched-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="2224-the-zshsched-module"><a class="header" href="#2224-the-zshsched-module">22.24 The zsh/sched Module</a></h2>
2022-08-24 15:22:41 +02:00
<p>The zsh/sched module makes available one builtin command and one
2021-05-11 02:29:21 +02:00
parameter.</p>
<p><span id="index-sched"></span> <span id="index-timed-execution"></span>
<span id="index-execution_002c-timed"></span></p>
2022-08-24 15:22:41 +02:00
<p>sched [-o] [+]<code>hh</code>:<code>mm</code>[:<code>ss</code>] <code>command</code> ...</p>
<p>sched [-o] [+]<code>seconds</code> <code>command</code> ...</p>
<p>sched [ -<code>item</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>Make an entry in the scheduled list of commands to execute. The time may
be specified in either absolute or relative time, and either as hours,
minutes and (optionally) seconds separated by a colon, or seconds alone.
An absolute number of seconds indicates the time since the epoch
(1970/01/01 00:00); this is useful in combination with the features in
2022-08-24 15:22:41 +02:00
the zsh/datetime module, see <a href="Zsh-Modules.html#The-zsh_002fdatetime-Module">The zsh/datetime
2021-05-11 02:29:21 +02:00
Module</a>.</p>
<p>With no arguments, prints the list of scheduled commands. If the
2022-08-24 15:22:41 +02:00
scheduled command has the -o flag set, this is shown at the start of the
command.</p>
<p>With the argument -<code>item</code>, removes the given item from the list. The
2021-05-11 02:29:21 +02:00
numbering of the list is continuous and entries are in time order, so
the numbering can change when entries are added or deleted.</p>
<p>Commands are executed either immediately before a prompt, or while the
shells line editor is waiting for input. In the latter case it is
useful to be able to produce output that does not interfere with the
2022-08-24 15:22:41 +02:00
line being edited. Providing the option -o causes the shell to clear the
command line before the event and redraw it afterwards. This should be
used with any scheduled event that produces visible output to the
2021-05-11 02:29:21 +02:00
terminal; it is not needed, for example, with output that updates a
terminal emulators title bar.</p>
<p>To effect changes to the editor buffer when an event executes, use the
2022-08-24 15:22:41 +02:00
zle command with no arguments to test whether the editor is active,
and if it is, then use zle <code>widget</code> to access the editor via the named
<code>widget</code>.</p>
<p>The sched builtin is not made available by default when the shell starts
in a mode emulating another shell. It can be made available with the
command zmodload -F zsh/sched b:sched.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zsh_005fscheduled_005fevents"></span></p>
2022-08-24 15:22:41 +02:00
<p>zsh_scheduled_events</p>
<p>A readonly array corresponding to the events scheduled by the sched
2021-05-11 02:29:21 +02:00
builtin. The indices of the array correspond to the numbers shown when
2022-08-24 15:22:41 +02:00
sched is run with no arguments (provided that the KSH_ARRAYS option is
not set). The value of the array consists of the scheduled time in
2021-05-11 02:29:21 +02:00
seconds since the epoch (see <a href="Zsh-Modules.html#The-zsh_002fdatetime-Module">The zsh/datetime
Module</a> for facilities for using this
number), followed by a colon, followed by any options (which may be
2022-08-24 15:22:41 +02:00
empty but will be preceded by a - otherwise), followed by a colon,
2021-05-11 02:29:21 +02:00
followed by the command to be executed.</p>
2022-08-24 15:22:41 +02:00
<p>The sched builtin should be used for manipulating the events. Note that
this will have an immediate effect on the contents of the array, so that
indices may become invalid.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fnet_002fsocket-Module"></span> <span
id="The-zsh_002fnet_002fsocket-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="2225-the-zshnetsocket-module"><a class="header" href="#2225-the-zshnetsocket-module">22.25 The zsh/net/socket Module</a></h2>
2022-08-24 15:22:41 +02:00
<p>The zsh/net/socket module makes available one builtin command:</p>
<p><span id="index-zsocket"></span> <span id="index-sockets"></span> <span
id="index-sockets_002c-Unix-domain"></span></p>
<p>zsocket [ -altv ] [ -d <code>fd</code> ] [ <code>args</code> ]</p>
<p>zsocket is implemented as a builtin to allow full use of shell command
2021-05-11 02:29:21 +02:00
line editing, file I/O, and job control mechanisms.</p>
<hr />
<p><span id="Outbound-Connections-1"></span></p>
<h3 id="22251-outbound-connections"><a class="header" href="#22251-outbound-connections">22.25.1 Outbound Connections</a></h3>
<p><span id="index-sockets_002c-outbound-Unix-domain"></span></p>
2022-08-24 15:22:41 +02:00
<p>zsocket [ -v ] [ -d <code>fd</code> ] <code>filename</code><br />
2021-05-11 02:29:21 +02:00
Open a new Unix domain connection to <code>filename</code>. The shell parameter
2022-08-24 15:22:41 +02:00
REPLY will be set to the file descriptor associated with that
2021-05-11 02:29:21 +02:00
connection. Currently, only stream connections are supported.</p>
2022-08-24 15:22:41 +02:00
<p>If -d is specified, its argument will be taken as the target file
2021-05-11 02:29:21 +02:00
descriptor for the connection.</p>
2022-08-24 15:22:41 +02:00
<p>In order to elicit more verbose output, use -v.</p>
<p>File descriptors can be closed with normal shell syntax when no longer
needed, for example:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">exec {REPLY}&gt;&amp;-
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<hr />
<p><span id="Inbound-Connections"></span></p>
<h3 id="22252-inbound-connections"><a class="header" href="#22252-inbound-connections">22.25.2 Inbound Connections</a></h3>
<p><span id="index-sockets_002c-inbound-Unix-domain"></span></p>
2022-08-24 15:22:41 +02:00
<p>zsocket -l [ -v ] [ -d <code>fd</code> ] <code>filename</code><br />
zsocket -l will open a socket listening on <code>filename</code>. The shell
parameter REPLY will be set to the file descriptor associated with that
listener. The file descriptor remains open in subshells</p>
<p>If -d is specified, its argument will be taken as the target file
2021-05-11 02:29:21 +02:00
descriptor for the connection.</p>
2022-08-24 15:22:41 +02:00
<p>In order to elicit more verbose output, use -v.</p>
<p>zsocket -a [ -tv ] [ -d <code>targetfd</code> ] <code>listenfd</code><br />
zsocket -a will accept an incoming connection to the socket associated
with <code>listenfd</code>. The shell parameter REPLY will be set to the file
descriptor associated with the inbound connection. The file descriptor
remains open in subshells</p>
<p>If -d is specified, its argument will be taken as the target file
2021-05-11 02:29:21 +02:00
descriptor for the connection.</p>
2022-08-24 15:22:41 +02:00
<p>If -t is specified, zsocket will return if no incoming connection is
pending. Otherwise it will wait for one.</p>
<p>In order to elicit more verbose output, use -v.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fstat-Module"></span> <span
id="The-zsh_002fstat-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="2226-the-zshstat-module"><a class="header" href="#2226-the-zshstat-module">22.26 The zsh/stat Module</a></h2>
2022-08-24 15:22:41 +02:00
<p>The zsh/stat module makes available one builtin command under two
2021-05-11 02:29:21 +02:00
possible names:</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-zstat"></span> <span id="index-stat"></span> <span
id="index-files_002c-listing"></span> <span
id="index-files_002c-examining"></span></p>
<p>zstat [ -gnNolLtTrs ] [ -f <code>fd</code> ] [ -H <code>hash</code> ] [ -A <code>array</code> ]
[ -F <code>fmt</code> ]</p>
<p>      [ +<code>element</code> ] [ <code>file</code> ... ]</p>
<p>stat <code>...</code></p>
<p>The command acts as a front end to the stat system call (see stat(2)).
The same command is provided with two names; as the name stat is often
used by an external command it is recommended that only the zstat form
of the command is used. This can be arranged by loading the module with
the command zmodload -F zsh/stat b:zstat.</p>
<p>If the stat call fails, the appropriate system error message printed and
status 1 is returned. The fields of struct stat give information about
the files provided as arguments to the command. In addition to those
available from the stat call, an extra element link is provided. These
elements are:</p>
<p>device<br />
2021-05-11 02:29:21 +02:00
The number of the device on which the file resides.</p>
2022-08-24 15:22:41 +02:00
<p>inode<br />
2021-05-11 02:29:21 +02:00
The unique number of the file on this device (<em>inode</em> number).</p>
2022-08-24 15:22:41 +02:00
<p>mode<br />
The mode of the file; that is, the files type and access permissions.
With the -s option, this will be returned as a string corresponding to
the first column in the display of the ls -l command.</p>
<p>nlink<br />
2021-05-11 02:29:21 +02:00
The number of hard links to the file.</p>
2022-08-24 15:22:41 +02:00
<p>uid<br />
The user ID of the owner of the file. With the -s option, this is
2021-05-11 02:29:21 +02:00
displayed as a user name.</p>
2022-08-24 15:22:41 +02:00
<p>gid<br />
The group ID of the file. With the -s option, this is displayed as a
group name.</p>
<p>rdev<br />
2021-05-11 02:29:21 +02:00
The raw device number. This is only useful for special devices.</p>
2022-08-24 15:22:41 +02:00
<p>size<br />
2021-05-11 02:29:21 +02:00
The size of the file in bytes.</p>
2022-08-24 15:22:41 +02:00
<p>atime<br />
mtime<br />
ctime<br />
2021-05-11 02:29:21 +02:00
The last access, modification and inode change times of the file,
respectively, as the number of seconds since midnight GMT on 1st
2022-08-24 15:22:41 +02:00
January, 1970. With the -s option, these are printed as strings for the
local time zone; the format can be altered with the -F option, and with
the -g option the times are in GMT.</p>
<p>blksize<br />
The number of bytes in one allocation block on the device on which the
file resides.</p>
<p>block<br />
2021-05-11 02:29:21 +02:00
The number of disk blocks used by the file.</p>
2022-08-24 15:22:41 +02:00
<p>link<br />
If the file is a link and the -L option is in effect, this contains the
name of the file linked to, otherwise it is empty. Note that if this
element is selected (zstat +link) then the -L option is
automatically used.</p>
2021-05-11 02:29:21 +02:00
<p>A particular element may be selected by including its name preceded by a
2022-08-24 15:22:41 +02:00
+ in the option list; only one element is allowed. The element may be
shortened to any unique set of leading characters. Otherwise, all
2021-05-11 02:29:21 +02:00
elements will be shown for all files.</p>
<p>Options:</p>
2022-08-24 15:22:41 +02:00
<p>-A <code>array</code><br />
Instead of displaying the results on standard output, assign them to an
<code>array</code>, one struct stat element per array element for each file in
order. In this case neither the name of the element nor the name of the
files appears in <code>array</code> unless the -t or -n options were given,
respectively. If -t is given, the element name appears as a prefix to
the appropriate array element; if -n is given, the file name appears as
a separate array element preceding all the others. Other formatting
options are respected.</p>
<p>-H <code>hash</code><br />
Similar to -A, but instead assign the values to <code>hash</code>. The keys are the
elements listed above. If the -n option is provided then the name of the
file is included in the hash with key name.</p>
<p>-f <code>fd</code><br />
Use the file on file descriptor <code>fd</code> instead of named files; no list of
file names is allowed in this case.</p>
<p>-F <code>fmt</code><br />
Supplies a strftime (see strftime(3)) string for the formatting of the
time elements. The format string supports all of the zsh extensions
described in <a href="Prompt-Expansion.html#Prompt-Expansion">Prompt Expansion</a>.
In particular, -F %s.%N can be used to show timestamps with nanosecond
precision if supported by the system. The -s option is implied.</p>
<p>-g<br />
Show the time elements in the GMT time zone. The -s option is implied.</p>
<p>-l<br />
List the names of the type elements (to standard output or an array as
appropriate) and return immediately; arguments, and options other than
-A, are ignored.</p>
<p>-L<br />
Perform an lstat (see lstat(2)) rather than a stat system call. In this
case, if the file is a link, information about the link itself rather
than the target file is returned. This option is required to make the
link element useful. Its important to note that this is the exact
opposite from ls(1), etc.</p>
<p>-n<br />
Always show the names of files. Usually these are only shown when output
is to standard output and there is more than one file in the list.</p>
<p>-N<br />
2021-05-11 02:29:21 +02:00
Never show the names of files.</p>
2022-08-24 15:22:41 +02:00
<p>-o<br />
If a raw file mode is printed, show it in octal, which is more useful
for human consumption than the default of decimal. A leading zero will
be printed in this case. Note that this does not affect whether a raw or
formatted file mode is shown, which is controlled by the -r and -s
options, nor whether a mode is shown at all.</p>
<p>-r<br />
Print raw data (the default format) alongside string data (the -s
2021-05-11 02:29:21 +02:00
format); the string data appears in parentheses after the raw data.</p>
2022-08-24 15:22:41 +02:00
<p>-s<br />
Print mode, uid, gid and the three time elements as strings instead of
numbers. In each case the format is like that of ls -l.</p>
<p>-t<br />
Always show the type names for the elements of struct stat. Usually
these are only shown when output is to standard output and no individual
element has been selected.</p>
<p>-T<br />
Never show the type names of the struct stat elements.</p>
<hr />
<p><span id="The-zsh_002fsystem-Module"></span> <span
id="The-zsh_002fsystem-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="2227-the-zshsystem-module"><a class="header" href="#2227-the-zshsystem-module">22.27 The zsh/system Module</a></h2>
2022-08-24 15:22:41 +02:00
<p>The zsh/system module makes available various builtin commands and
2021-05-11 02:29:21 +02:00
parameters.</p>
<hr />
<p><span id="Builtins"></span></p>
<h3 id="22271-builtins"><a class="header" href="#22271-builtins">22.27.1 Builtins</a></h3>
<p><span id="index-syserror"></span></p>
2022-08-24 15:22:41 +02:00
<p>syserror [ -e <code>errvar</code> ] [ -p <code>prefix</code> ] [ <code>errno</code> | <code>errname</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>This command prints out the error message associated with <code>errno</code>, a
system error number, followed by a newline to standard error.</p>
2022-08-24 15:22:41 +02:00
<p>Instead of the error number, a name <code>errname</code>, for example ENOENT, may
2021-05-11 02:29:21 +02:00
be used. The set of names is the same as the contents of the array
2022-08-24 15:22:41 +02:00
errnos, see below.</p>
2021-05-11 02:29:21 +02:00
<p>If the string <code>prefix</code> is given, it is printed in front of the error
message, with no intervening space.</p>
<p>If <code>errvar</code> is supplied, the entire message, without a newline, is
assigned to the parameter names <code>errvar</code> and nothing is output.</p>
<p>A return status of 0 indicates the message was successfully printed
(although it may not be useful if the error number was out of the
systems range), a return status of 1 indicates an error in the
parameters, and a return status of 2 indicates the error name was not
recognised (no message is printed for this).</p>
<p><span id="index-sysopen"></span></p>
2022-08-24 15:22:41 +02:00
<p>sysopen [ -arw ] [ -m <code>permissions</code> ] [ -o <code>options</code> ]</p>
<p>        -u <code>fd</code> <code>file</code></p>
<p>This command opens a file. The -r, -w and -a flags indicate whether the
file should be opened for reading, writing and appending, respectively.
The -m option allows the initial permissions to use when creating a file
to be specified in octal form. The file descriptor is specified with -u.
Either an explicit file descriptor in the range 0 to 9 can be specified
or a variable name can be given to which the file descriptor number will
be assigned.</p>
<p>The -o option allows various system specific options to be specified as
a comma-separated list. The following is a list of possible options.
2021-05-11 02:29:21 +02:00
Note that, depending on the system, some may not be available.</p>
2022-08-24 15:22:41 +02:00
<p>cloexec<br />
mark file to be closed when other programs are executed (else the file
descriptor remains open in subshells and forked external</p>
<p>create<br />
creat<br />
2021-05-11 02:29:21 +02:00
create file if it does not exist</p>
2022-08-24 15:22:41 +02:00
<p>excl<br />
2021-05-11 02:29:21 +02:00
create file, error if it already exists</p>
2022-08-24 15:22:41 +02:00
<p>noatime<br />
2021-05-11 02:29:21 +02:00
suppress updating of the file atime</p>
2022-08-24 15:22:41 +02:00
<p>nofollow<br />
2021-05-11 02:29:21 +02:00
fail if <code>file</code> is a symbolic link</p>
2022-08-24 15:22:41 +02:00
<p>nonblock<br />
the file is opened in nonblocking mode</p>
<p>sync<br />
2021-05-11 02:29:21 +02:00
request that writes wait until data has been physically written</p>
2022-08-24 15:22:41 +02:00
<p>truncate<br />
trunc<br />
2021-05-11 02:29:21 +02:00
truncate file to size 0</p>
<p>To close the file, use one of the following:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">exec {fd}&lt;&amp;-
2021-05-11 02:29:21 +02:00
exec {fd}&gt;&amp;-
</code></pre>
</div>
<p><span id="index-sysread"></span></p>
2022-08-24 15:22:41 +02:00
<p>sysread [ -c <code>countvar</code> ] [ -i <code>infd</code> ] [ -o <code>outfd</code> ]</p>
<p>        [ -s <code>bufsize</code> ] [ -t <code>timeout</code> ] [ <code>param</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>Perform a single system read from file descriptor <code>infd</code>, or zero if
2022-08-24 15:22:41 +02:00
that is not given. The result of the read is stored in <code>param</code> or REPLY
if that is not given. If <code>countvar</code> is given, the number of bytes read
is assigned to the parameter named by <code>countvar</code>.</p>
2021-05-11 02:29:21 +02:00
<p>The maximum number of bytes read is <code>bufsize</code> or 8192 if that is not
given, however the command returns as soon as any number of bytes was
successfully read.</p>
<p>If <code>timeout</code> is given, it specifies a timeout in seconds, which may be
2022-08-24 15:22:41 +02:00
zero to poll the file descriptor. This is handled by the poll system
call if available, otherwise the select system call if available.</p>
2021-05-11 02:29:21 +02:00
<p>If <code>outfd</code> is given, an attempt is made to write all the bytes just read
to the file descriptor <code>outfd</code>. If this fails, because of a system error
2022-08-24 15:22:41 +02:00
other than EINTR or because of an internal zsh error during an
2021-05-11 02:29:21 +02:00
interrupt, the bytes read but not written are stored in the parameter
named by <code>param</code> if supplied (no default is used in this case), and the
number of bytes read but not written is stored in the parameter named by
<code>countvar</code> if that is supplied. If it was successful, <code>countvar</code>
contains the full number of bytes transferred, as usual, and <code>param</code> is
not set.</p>
2022-08-24 15:22:41 +02:00
<p>The error EINTR (interrupted system call) is handled internally so that
shell interrupts are transparent to the caller. Any other error causes a
return.</p>
2021-05-11 02:29:21 +02:00
<p>The possible return statuses are</p>
<p>0<br />
At least one byte of data was successfully read and, if appropriate,
written.</p>
<p>1<br />
2022-08-24 15:22:41 +02:00
There was an error in the parameters to the command. This is the only
error for which a message is printed to standard error.</p>
2021-05-11 02:29:21 +02:00
<p>2<br />
2022-08-24 15:22:41 +02:00
There was an error on the read, or on polling the input file descriptor
for a timeout. The parameter ERRNO gives the error.</p>
2021-05-11 02:29:21 +02:00
<p>3<br />
Data were successfully read, but there was an error writing them to
2022-08-24 15:22:41 +02:00
<code>outfd</code>. The parameter ERRNO gives the error.</p>
2021-05-11 02:29:21 +02:00
<p>4<br />
2022-08-24 15:22:41 +02:00
The attempt to read timed out. Note this does not set ERRNO as this is
not a system error.</p>
2021-05-11 02:29:21 +02:00
<p>5<br />
No system error occurred, but zero bytes were read. This usually
indicates end of file. The parameters are set according to the usual
rules; no write to <code>outfd</code> is attempted.</p>
2022-08-24 15:22:41 +02:00
<p>sysseek [ -u <code>fd</code> ] [ -w start|end|current ] <code>offset</code></p>
2021-05-11 02:29:21 +02:00
<p>The current file position at which future reads and writes will take
place is adjusted to the specified byte offset. The <code>offset</code> is
2022-08-24 15:22:41 +02:00
evaluated as a math expression. The -u option allows the file descriptor
to be specified. By default the offset is specified relative to the
start or the file but, with the -w option, it is possible to specify
that the offset should be relative to the current position or the end of
the file.</p>
<p>syswrite [ -c <code>countvar</code> ] [ -o <code>outfd</code> ] <code>data</code></p>
2021-05-11 02:29:21 +02:00
<p>The data (a single string of bytes) are written to the file descriptor
2022-08-24 15:22:41 +02:00
<code>outfd</code>, or 1 if that is not given, using the write system call.
2021-05-11 02:29:21 +02:00
Multiple write operations may be used if the first does not write all
the data.</p>
<p>If <code>countvar</code> is given, the number of byte written is stored in the
parameter named by <code>countvar</code>; this may not be the full length of <code>data</code>
if an error occurred.</p>
2022-08-24 15:22:41 +02:00
<p>The error EINTR (interrupted system call) is handled internally by
2021-05-11 02:29:21 +02:00
retrying; otherwise an error causes the command to return. For example,
2022-08-24 15:22:41 +02:00
if the file descriptor is set to non-blocking output, an error EAGAIN
(on some systems, EWOULDBLOCK) may result in the command returning
2021-05-11 02:29:21 +02:00
early.</p>
<p>The return status may be 0 for success, 1 for an error in the parameters
to the command, or 2 for an error on the write; no error message is
2022-08-24 15:22:41 +02:00
printed in the last case, but the parameter ERRNO will reflect the error
that occurred.</p>
<p>zsystem flock [ -t <code>timeout</code> ] [ -i <code>interval</code> ] [ -f <code>var</code> ]
[-er] <code>file</code></p>
<p>zsystem flock -u <code>fd_expr</code></p>
<p>The builtin zsystems subcommand flock performs advisory file locking
(via the fcntl(2) system call) over the entire contents of the given
file. This form of locking requires the processes accessing the file to
cooperate; its most obvious use is between two instances of the shell
itself.</p>
2021-05-11 02:29:21 +02:00
<p>In the first form the named <code>file</code>, which must already exist, is locked
by opening a file descriptor to the file and applying a lock to the file
descriptor. The lock terminates when the shell process that created the
lock exits; it is therefore often convenient to create file locks within
subshells, since the lock is automatically released when the subshell
2022-08-24 15:22:41 +02:00
exits. Note that use of the print builtin with the -u option will, as a
side effect, release the lock, as will redirection to the file in the
shell holding the lock. To work around this use a subshell, e.g. (print
message) &gt;&gt; <code>file</code>. Status 0 is returned if the lock succeeds, else
status 1.</p>
2021-05-11 02:29:21 +02:00
<p>In the second form the file descriptor given by the arithmetic
expression <code>fd_expr</code> is closed, releasing a lock. The file descriptor
2022-08-24 15:22:41 +02:00
can be queried by using the -f <code>var</code> form during the lock; on a
2021-05-11 02:29:21 +02:00
successful lock, the shell variable <code>var</code> is set to the file descriptor
used for locking. The lock will be released if the file descriptor is
2022-08-24 15:22:41 +02:00
closed by any other means, for example using exec {<code>var</code>}&gt;&amp;-; however,
the form described here performs a safety check that the file descriptor
is in use for file locking.</p>
2021-05-11 02:29:21 +02:00
<p>By default the shell waits indefinitely for the lock to succeed. The
2022-08-24 15:22:41 +02:00
option -t <code>timeout</code> specifies a timeout for the lock in seconds;
fractional seconds are allowed. During this period, the shell will
attempt to lock the file every <code>interval</code> seconds if the -i <code>interval</code>
option is given, otherwise once a second. (This <code>interval</code> is shortened
before the last attempt if needed, so that the shell waits only until
the <code>timeout</code> and not longer.) If the attempt times out, status 2 is
returned.</p>
<p>(Note: <code>timeout</code> is limited to 2^30-1 seconds (about 34 years), and
<code>interval</code> to 0.999 * LONG_MAX microseconds (only about 35 minutes on
32-bit systems).)</p>
<p>If the option -e is given, the file descriptor for the lock is preserved
when the shell uses exec to start a new process; otherwise it is closed
at that point and the lock released.</p>
<p>If the option -r is given, the lock is only for reading, otherwise it is
for reading and writing. The file descriptor is opened accordingly.</p>
<p>zsystem supports <code>subcommand</code></p>
<p>The builtin zsystems subcommand supports tests whether a given
2021-05-11 02:29:21 +02:00
subcommand is supported. It returns status 0 if so, else status 1. It
operates silently unless there was a syntax error (i.e. the wrong number
of arguments), in which case status 255 is returned. Status 1 can
indicate one of two things: <code>subcommand</code> is known but not supported by
the current operating system, or <code>subcommand</code> is not known (possibly
because this is an older version of the shell before it was
implemented).</p>
<hr />
<p><span id="Math-Functions"></span></p>
<h3 id="22272-math-functions"><a class="header" href="#22272-math-functions">22.27.2 Math Functions</a></h3>
2022-08-24 15:22:41 +02:00
<p>systell(<code>fd</code>)<br />
The systell math function returns the current file position for the file
descriptor passed as an argument.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Parameters-1"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="22273-parameters"><a class="header" href="#22273-parameters">22.27.3 Parameters</a></h3>
<p><span id="index-errnos"></span></p>
2022-08-24 15:22:41 +02:00
<p>errnos</p>
2021-05-11 02:29:21 +02:00
<p>A readonly array of the names of errors defined on the system. These are
typically macros defined in C by including the system header file
2022-08-24 15:22:41 +02:00
errno.h. The index of each name (assuming the option KSH_ARRAYS is
2021-05-11 02:29:21 +02:00
unset) corresponds to the error number. Error numbers <code>num</code> before the
2022-08-24 15:22:41 +02:00
last known error which have no name are given the name E<code>num</code> in the
2021-05-11 02:29:21 +02:00
array.</p>
<p>Note that aliases for errors are not handled; only the canonical name is
used.</p>
<p><span id="index-sysparams"></span></p>
2022-08-24 15:22:41 +02:00
<p>sysparams</p>
2021-05-11 02:29:21 +02:00
<p>A readonly associative array. The keys are:</p>
2022-08-24 15:22:41 +02:00
<p>pid<br />
2021-05-11 02:29:21 +02:00
<span id="index-pid_002c-sysparams"></span></p>
<p>Returns the process ID of the current process, even in subshells.
2022-08-24 15:22:41 +02:00
Compare $$, which returns the process ID of the main shell process.</p>
<p>ppid<br />
2021-05-11 02:29:21 +02:00
<span id="index-ppid_002c-sysparams"></span></p>
2022-08-24 15:22:41 +02:00
<p>Returns the current process ID of the parent of the current process,
even in subshells. Compare $PPID, which returns the process ID of the
initial parent of the main shell process.</p>
<p>procsubstpid<br />
2021-05-11 02:29:21 +02:00
Returns the process ID of the last process started for process
2022-08-24 15:22:41 +02:00
substitution, i.e. the &lt;(<code>...</code>) and &gt;(<code>...</code>) expansions.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fnet_002ftcp-Module"></span> <span
id="The-zsh_002fnet_002ftcp-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="2228-the-zshnettcp-module"><a class="header" href="#2228-the-zshnettcp-module">22.28 The zsh/net/tcp Module</a></h2>
2022-08-24 15:22:41 +02:00
<p>The zsh/net/tcp module makes available one builtin command:</p>
<p><span id="index-ztcp"></span> <span id="index-TCP"></span> <span
id="index-sockets_002c-TCP"></span></p>
<p>ztcp [ -acflLtv ] [ -d <code>fd</code> ] [ <code>args</code> ]</p>
<p>ztcp is implemented as a builtin to allow full use of shell command line
editing, file I/O, and job control mechanisms.</p>
<p>If ztcp is run with no options, it will output</p>
<p>If it is run with only the option -L, it will output the contents of is
ignored if given with a command to open or close a session. The output
consists of a set of lines, one per session, each containing the
2021-05-11 02:29:21 +02:00
following elements separated by spaces:</p>
<p>File descriptor<br />
2022-08-24 15:22:41 +02:00
The file descriptor in use for the connection. For normal inbound (I)
and outbound (O) connections this may be read and written by the usual
shell mechanisms. However, it should only be close with ztcp -c.</p>
2021-05-11 02:29:21 +02:00
<p>Connection type<br />
A letter indicating how the session was created:</p>
2022-08-24 15:22:41 +02:00
<p>Z<br />
A session created with the zftp command.</p>
<p>L<br />
A connection opened for listening with ztcp -l.</p>
<p>I<br />
An inbound connection accepted with ztcp -a.</p>
<p>O<br />
An outbound connection created with ztcp <code>host</code> <code>...</code>.</p>
2021-05-11 02:29:21 +02:00
<p>The local host<br />
This is usually set to an all-zero IP address as the address of the
localhost is irrelevant.</p>
<p>The local port<br />
This is likely to be zero unless the connection is for listening.</p>
<p>The remote host<br />
2022-08-24 15:22:41 +02:00
This is the fully qualified domain name of the peer, if available, else
an IP address. It is an all-zero IP address for a session opened for
listening.</p>
2021-05-11 02:29:21 +02:00
<p>The remote port<br />
This is zero for a connection opened for listening.</p>
<hr />
<p><span id="Outbound-Connections"></span></p>
<h3 id="22281-outbound-connections"><a class="header" href="#22281-outbound-connections">22.28.1 Outbound Connections</a></h3>
<p><span id="index-sockets_002c-outbound-TCP"></span></p>
2022-08-24 15:22:41 +02:00
<p>ztcp [ -v ] [ -d <code>fd</code> ] <code>host</code> [ <code>port</code> ]<br />
Open a new TCP connection to <code>host</code>. If the <code>port</code> is omitted, it will
default to port 23. The connection will REPLY will be set to the file
descriptor associated with that connection.</p>
<p>If -d is specified, its argument will be taken as the target file
2021-05-11 02:29:21 +02:00
descriptor for the connection.</p>
2022-08-24 15:22:41 +02:00
<p>In order to elicit more verbose output, use -v.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Inbound-Connections-1"></span></p>
<h3 id="22282-inbound-connections"><a class="header" href="#22282-inbound-connections">22.28.2 Inbound Connections</a></h3>
<p><span id="index-sockets_002c-inbound-TCP"></span></p>
2022-08-24 15:22:41 +02:00
<p>ztcp -l [ -v ] [ -d <code>fd</code> ] <code>port</code><br />
ztcp -l will open a socket listening on TCP <code>port</code>. The socket will be
added to the will be set to the file descriptor associated with that
listener.</p>
<p>If -d is specified, its argument will be taken as the target file
2021-05-11 02:29:21 +02:00
descriptor for the connection.</p>
2022-08-24 15:22:41 +02:00
<p>In order to elicit more verbose output, use -v.</p>
<p>ztcp -a [ -tv ] [ -d <code>targetfd</code> ] <code>listenfd</code><br />
ztcp -a will accept an incoming connection to the port associated with
<code>listenfd</code>. The connection will be added to the session be set to the
file descriptor associated with the inbound connection.</p>
<p>If -d is specified, its argument will be taken as the target file
2021-05-11 02:29:21 +02:00
descriptor for the connection.</p>
2022-08-24 15:22:41 +02:00
<p>If -t is specified, ztcp will return if no incoming connection is
pending. Otherwise it will wait for one.</p>
<p>In order to elicit more verbose output, use -v.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Closing-Connections"></span></p>
<h3 id="22283-closing-connections"><a class="header" href="#22283-closing-connections">22.28.3 Closing Connections</a></h3>
<p><span id="index-sockets_002c-closing-TCP"></span></p>
2022-08-24 15:22:41 +02:00
<p>ztcp -cf [ -v ] [ <code>fd</code> ]<br />
ztcp -c [ -v ] [ <code>fd</code> ]<br />
ztcp -c will close the socket associated with <code>fd</code>. The socket will be
removed from the</p>
2021-05-11 02:29:21 +02:00
<p>Normally, sockets registered by zftp (see <a href="Zsh-Modules.html#The-zsh_002fzftp-Module">The zsh/zftp
2022-08-24 15:22:41 +02:00
Module</a> ) cannot be closed this way. In order
to force such a socket closed, use -f.</p>
<p>In order to elicit more verbose output, use -v.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Example-2"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="22284-example"><a class="header" href="#22284-example">22.28.4 Example</a></h3>
<p><span id="index-TCP_002c-example"></span></p>
<p>Here is how to create a TCP connection between two instances of zsh. We
need to pick an unassigned port; here we use the randomly chosen 5123.</p>
2022-08-24 15:22:41 +02:00
<p>On host1,</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zmodload zsh/net/tcp
2021-05-11 02:29:21 +02:00
ztcp -l 5123
listenfd=$REPLY
ztcp -a $listenfd
fd=$REPLY
</code></pre>
</div>
<p>The second from last command blocks until there is an incoming
connection.</p>
2022-08-24 15:22:41 +02:00
<p>Now create a connection from host2 (which may, of course, be the same
2021-05-11 02:29:21 +02:00
machine):</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zmodload zsh/net/tcp
2021-05-11 02:29:21 +02:00
ztcp host1 5123
fd=$REPLY
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Now on each host, $fd contains a file descriptor for talking to the
other. For example, on host1:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">print This is a message &gt;&amp;$fd
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>and on host2:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">read -r line &lt;&amp;$fd; print -r - $line
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>prints This is a message.</p>
<p>To tidy up, on host1:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">ztcp -c $listenfd
2021-05-11 02:29:21 +02:00
ztcp -c $fd
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>and on host2</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">ztcp -c $fd
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002ftermcap-Module"></span> <span
id="The-zsh_002ftermcap-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="2229-the-zshtermcap-module"><a class="header" href="#2229-the-zshtermcap-module">22.29 The zsh/termcap Module</a></h2>
2022-08-24 15:22:41 +02:00
<p>The zsh/termcap module makes available one builtin command:</p>
<p><span id="index-echotc"></span> <span
id="index-termcap-value_002c-printing"></span></p>
<p>echotc <code>cap</code> [ <code>arg</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>Output the termcap value corresponding to the capability <code>cap</code>, with
optional arguments.</p>
2022-08-24 15:22:41 +02:00
<p>The zsh/termcap module makes available one parameter:</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-termcap"></span></p>
2022-08-24 15:22:41 +02:00
<p>termcap</p>
2021-05-11 02:29:21 +02:00
<p>An associative array that maps termcap capability codes to their values.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fterminfo-Module"></span> <span
id="The-zsh_002fterminfo-Module-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="2230-the-zshterminfo-module"><a class="header" href="#2230-the-zshterminfo-module">22.30 The zsh/terminfo Module</a></h2>
2022-08-24 15:22:41 +02:00
<p>The zsh/terminfo module makes available one builtin command:</p>
<p><span id="index-echoti"></span> <span
id="index-terminfo-value_002c-printing"></span></p>
<p>echoti <code>cap</code> [ <code>arg</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>Output the terminfo value corresponding to the capability <code>cap</code>,
instantiated with <code>arg</code> if applicable.</p>
2022-08-24 15:22:41 +02:00
<p>The zsh/terminfo module makes available one parameter:</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-terminfo"></span></p>
2022-08-24 15:22:41 +02:00
<p>terminfo</p>
2021-05-11 02:29:21 +02:00
<p>An associative array that maps terminfo capability names to their
values.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fwatch-Module"></span> <span
id="The-zsh_002fwatch-Module-1"></span></p>
<h2 id="2231-the-zshwatch-module"><a class="header" href="#2231-the-zshwatch-module">22.31 The zsh/watch Module</a></h2>
<p>The zsh/watch module can be used to report when specific users log in or
out. This is controlled via the following parameters.</p>
<p><span id="index-LOGCHECK"></span></p>
<p>LOGCHECK</p>
<p>The interval in seconds between checks for login/logout activity using
the watch parameter.</p>
<p><span id="index-watch"></span> <span id="index-WATCH"></span></p>
<p>watch &lt;S&gt; &lt;Z&gt; (WATCH &lt;S&gt;)</p>
<p>An array (colon-separated list) of login/logout events to report.</p>
<p>If it contains the single word all, then all login/logout events are
reported. If it contains the single word notme, then all events are
reported as with all except $USERNAME.</p>
<p>An entry in this list may consist of a username, an @ followed by a
remote hostname, and a % followed by a line (tty). Any of these may be
a pattern (be sure to quote this during the assignment to watch so that
it does not immediately perform file generation); the setting of the
EXTENDED_GLOB option is respected. Any or all of these components may be
present in an entry; if a login/logout event matches all of them, it is
reported.</p>
<p>For example, with the EXTENDED_GLOB option set, the following:</p>
<div class="example">
<pre><code class="language-zsh">watch=('^(pws|barts)')
</code></pre>
</div>
<p>causes reports for activity associated with any user other than pws or
barts.</p>
<p><span id="index-WATCHFMT"></span></p>
<p>WATCHFMT</p>
<p>The format of login/logout reports if the watch parameter is set.
Default is %n has %a %l from %m. Recognizes the following escape
sequences:</p>
<p>%n<br />
The name of the user that logged in/out.</p>
<p>%a<br />
The observed action, i.e. &quot;logged on&quot; or &quot;logged off&quot;.</p>
<p>%l<br />
The line (tty) the user is logged in on.</p>
<p>%M<br />
The full hostname of the remote host.</p>
<p>%m<br />
The hostname up to the first .. If only the IP address is available or
the utmp field contains the name of an X-windows display, the whole name
is printed.</p>
<p><em>NOTE:</em> The %m and %M escapes will work only if there is a host name
field in the utmp on your machine. Otherwise they are treated as
ordinary strings.</p>
<p>%F{<code>color</code>} (%f)<br />
Start (stop) using a different foreground color.</p>
<p>%K{<code>color</code>} (%k)<br />
Start (stop) using a different background color.</p>
<p>%S (%s)<br />
Start (stop) standout mode.</p>
<p>%U (%u)<br />
Start (stop) underline mode.</p>
<p>%B (%b)<br />
Start (stop) boldface mode.</p>
<p>%t<br />
%@<br />
The time, in 12-hour, am/pm format.</p>
<p>%T<br />
The time, in 24-hour format.</p>
<p>%w<br />
The date in <code>day</code>-<code>dd</code> format.</p>
<p>%W<br />
The date in <code>mm</code>/<code>dd</code>/<code>yy</code> format.</p>
<p>%D<br />
The date in <code>yy</code>-<code>mm</code>-<code>dd</code> format.</p>
<p>%D{<code>string</code>}<br />
The date formatted as <code>string</code> using the strftime function, with zsh
extensions as described by <a href="Prompt-Expansion.html#Prompt-Expansion">Prompt
Expansion</a>.</p>
<p>%(<code>x</code>:<code>true-text</code>:<code>false-text</code>)<br />
Specifies a ternary expression. The character following the <code>x</code> is
arbitrary; the same character is used to separate the text for the
&quot;true&quot; result from that for the &quot;false&quot; result. Both the separator and
the right parenthesis may be escaped with a backslash. Ternary
expressions may be nested.</p>
<p>The test character <code>x</code> may be any one of l, n, m or M, which
indicate a true result if the corresponding escape sequence would
return a non-empty value; or it may be a, which indicates a true
result if the watched user has logged in, or false if he has logged
out. Other characters evaluate to neither true nor false; the entire
expression is omitted in this case.</p>
<p>If the result is true, then the <code>true-text</code> is formatted according to
the rules above and printed, and the <code>false-text</code> is skipped. If
false, the <code>true-text</code> is skipped and the <code>false-text</code> is formatted
and printed. Either or both of the branches may be empty, but both
separators must be present in any case.</p>
<p>Furthermore, the zsh/watch module makes available one builtin command:</p>
<p><span id="index-log"></span> <span id="index-watch_002c-use-of"></span>
<span id="index-watching-users"></span> <span
id="index-users_002c-watching"></span></p>
<p>log</p>
<p>List all users currently logged in who are affected by the current
setting of the watch parameter.</p>
<hr />
<p><span id="The-zsh_002fzftp-Module"></span> <span
id="The-zsh_002fzftp-Module-1"></span></p>
<h2 id="2232-the-zshzftp-module"><a class="header" href="#2232-the-zshzftp-module">22.32 The zsh/zftp Module</a></h2>
<p>The zsh/zftp module makes available one builtin command:</p>
<p><span id="index-zftp"></span> <span id="index-FTP"></span> <span
id="index-files_002c-transferring"></span></p>
<p>zftp <code>subcommand</code> [ <code>args</code> ]</p>
<p>The zsh/zftp module is a client for FTP (file transfer protocol). It is
implemented as a builtin to allow full use of shell command line
2021-05-11 02:29:21 +02:00
editing, file I/O, and job control mechanisms. Often, users will access
it via shell functions providing a more powerful interface; a set is
2022-08-24 15:22:41 +02:00
provided with the zsh distribution and is described in <a href="Zftp-Function-System.html#Zftp-Function-System">Zftp Function
2021-05-11 02:29:21 +02:00
System</a>. However, the
2022-08-24 15:22:41 +02:00
zftp command is entirely usable in its own right.</p>
<p>All commands consist of the command name zftp followed by the name of a
subcommand. These are listed below. The return status of each subcommand
is supposed to reflect the success or failure of the remote operation.
See a description of the variable ZFTP_VERBOSE for more information on
how responses from the server may be printed.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Subcommands"></span></p>
2022-08-24 15:22:41 +02:00
<h3 id="22321-subcommands"><a class="header" href="#22321-subcommands">22.32.1 Subcommands</a></h3>
2021-05-11 02:29:21 +02:00
<p><span id="index-zftp_002c-subcommands"></span></p>
<p><span id="index-FTP_002c-starting-a-session"></span></p>
2022-08-24 15:22:41 +02:00
<p>open <code>host</code>[:<code>port</code>] [ <code>user</code> [ <code>password</code> [ <code>account</code> ] ] ]</p>
2021-05-11 02:29:21 +02:00
<p>Open a new FTP session to <code>host</code>, which may be the name of a TCP/IP
connected host or an IP number in the standard dot notation. If the
2022-08-24 15:22:41 +02:00
argument is in the form <code>host</code>:<code>port</code>, open a connection to TCP port
2021-05-11 02:29:21 +02:00
<code>port</code> instead of the standard FTP port 21. This may be the name of a
2022-08-24 15:22:41 +02:00
TCP service or a number: see the description of ZFTP_PORT below for more
information.</p>
2021-05-11 02:29:21 +02:00
<p>If IPv6 addresses in colon format are used, the <code>host</code> should be
surrounded by quoted square brackets to distinguish it from the <code>port</code>,
2022-08-24 15:22:41 +02:00
for example [fe80::203:baff:fe02:8b56]. For consistency this is
2021-05-11 02:29:21 +02:00
allowed with all forms of <code>host</code>.</p>
2022-08-24 15:22:41 +02:00
<p>Remaining arguments are passed to the login subcommand. Note that if no
arguments beyond <code>host</code> are supplied, open will <em>not</em> automatically call
login. If no arguments at all are supplied, open will use the parameters
set by the params subcommand.</p>
<p>After a successful open, the shell variables ZFTP_HOST, ZFTP_PORT,
ZFTP_IP and ZFTP_SYSTEM are available; see Variables below.</p>
<p>login [ <code>name</code> [ <code>password</code> [ <code>account</code> ] ] ]</p>
<p>user [ <code>name</code> [ <code>password</code> [ <code>account</code> ] ] ]</p>
2021-05-11 02:29:21 +02:00
<p>Login the user <code>name</code> with parameters <code>password</code> and <code>account</code>. Any of
the parameters can be omitted, and will be read from standard input if
needed (<code>name</code> is always needed). If standard input is a terminal, a
prompt for each one will be printed on standard error and <code>password</code>
will not be echoed. If any of the parameters are not used, a warning
message is printed.</p>
2022-08-24 15:22:41 +02:00
<p>After a successful login, the shell variables ZFTP_USER, ZFTP_ACCOUNT
and ZFTP_PWD are available; see Variables below.</p>
2021-05-11 02:29:21 +02:00
<p>This command may be re-issued when a user is already logged in, and the
server will first be reinitialized for a new user.</p>
2022-08-24 15:22:41 +02:00
<p>params [ <code>host</code> [ <code>user</code> [ <code>password</code> [ <code>account</code> ] ] ] ]</p>
<p>params -</p>
<p>Store the given parameters for a later open command with no arguments.
2021-05-11 02:29:21 +02:00
Only those given on the command line will be remembered. If no arguments
are given, the parameters currently set are printed, although the
password will appear as a line of stars; the return status is one if no
parameters were set, zero otherwise.</p>
2022-08-24 15:22:41 +02:00
<p>Any of the parameters may be specified as a ?, which may need to be
2021-05-11 02:29:21 +02:00
quoted to protect it from shell expansion. In this case, the appropriate
2022-08-24 15:22:41 +02:00
parameter will be read from stdin as with the login subcommand,
including special handling of <code>password</code>. If the ? is followed by a
2021-05-11 02:29:21 +02:00
string, that is used as the prompt for reading the parameter instead of
the default message (any necessary punctuation and whitespace should be
included at the end of the prompt). The first letter of the parameter
2022-08-24 15:22:41 +02:00
(only) may be quoted with a \; hence an argument &quot;\\$word&quot;
guarantees that the string from the shell parameter $word will be
treated literally, whether or not it begins with a ?.</p>
<p>If instead a single - is given, the existing parameters, if any, are
deleted. In that case, calling open with no arguments will cause an
2021-05-11 02:29:21 +02:00
error.</p>
2022-08-24 15:22:41 +02:00
<p>The list of parameters is not deleted after a close, however it will be
deleted if the zsh/zftp module is unloaded.</p>
2021-05-11 02:29:21 +02:00
<p>For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zftp params ftp.elsewhere.xx juser '?Password for juser: '
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>will store the host ftp.elsewhere.xx and the user juser and then prompt
the user for the corresponding password with the given prompt.</p>
<p>test</p>
2021-05-11 02:29:21 +02:00
<p>Test the connection; if the server has reported that it has closed the
connection (maybe due to a timeout), return status 2; if no connection
2022-08-24 15:22:41 +02:00
was open anyway, return status 1; else return status 0. The test
subcommand is silent, apart from messages printed by the $ZFTP_VERBOSE
2021-05-11 02:29:21 +02:00
mechanism, or error messages if the connection closes. There is no
network overhead for this test.</p>
2022-08-24 15:22:41 +02:00
<p>The test is only supported on systems with either the select(2) or
poll(2) system calls; otherwise the message not supported on this
system is printed instead.</p>
<p>The test subcommand will automatically be called at the start of any
2021-05-11 02:29:21 +02:00
other subcommand for the current session when a connection is open.</p>
2022-08-24 15:22:41 +02:00
<p>cd <code>directory</code></p>
2021-05-11 02:29:21 +02:00
<p>Change the remote directory to <code>directory</code>. Also alters the shell
2022-08-24 15:22:41 +02:00
variable ZFTP_PWD.</p>
<p>cdup</p>
2021-05-11 02:29:21 +02:00
<p>Change the remote directory to the one higher in the directory tree.
2022-08-24 15:22:41 +02:00
Note that cd .. will also work correctly on non-UNIX systems.</p>
<p>dir [ <code>arg</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>Give a (verbose) listing of the remote directory. The <code>arg</code>s are passed
directly to the server. The commands behaviour is implementation
dependent, but a UNIX server will typically interpret <code>arg</code>s as
2022-08-24 15:22:41 +02:00
arguments to the ls command and with no arguments return the result of
ls -l. The directory is listed to standard output.</p>
<p>ls [ <code>arg</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>Give a (short) listing of the remote directory. With no <code>arg</code>, produces
a raw list of the files in the directory, one per line. Otherwise, up to
2022-08-24 15:22:41 +02:00
vagaries of the server implementation, behaves similar to dir.</p>
<p>type [ <code>type</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>Change the type for the transfer to <code>type</code>, or print the current type if
2022-08-24 15:22:41 +02:00
<code>type</code> is absent. The allowed values are A (ASCII), I (Image, i.e.
binary), or B (a synonym for I).</p>
<p>The FTP default for a transfer is ASCII. However, if zftp finds that the
remote host is a UNIX machine with 8-bit byes, it will automatically
switch to using binary for file transfers upon open. This can
2021-05-11 02:29:21 +02:00
subsequently be overridden.</p>
<p>The transfer type is only passed to the remote host when a data
connection is established; this command involves no network overhead.</p>
2022-08-24 15:22:41 +02:00
<p>ascii</p>
<p>The same as type A.</p>
<p>binary</p>
<p>The same as type I.</p>
<p>mode [ S | B ]</p>
<p>Set the mode type to stream (S) or block (B). Stream mode is the
2021-05-11 02:29:21 +02:00
default; block mode is not widely supported.</p>
2022-08-24 15:22:41 +02:00
<p>remote <code>file</code> ...</p>
<p>local [ <code>file</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>Print the size and last modification time of the remote or local files.
If there is more than one item on the list, the name of the file is
printed first. The first number is the file size, the second is the last
2022-08-24 15:22:41 +02:00
modification time of the file in the format CCYYMMDDhhmmSS consisting of
year, month, date, hour, minutes and seconds in GMT. Note that this
2021-05-11 02:29:21 +02:00
format, including the length, is guaranteed, so that time strings can be
2022-08-24 15:22:41 +02:00
directly compared via the [[ builtins &lt; and &gt; operators, even if
2021-05-11 02:29:21 +02:00
they are too long to be represented as integers.</p>
<p>Not all servers support the commands for retrieving this information. In
2022-08-24 15:22:41 +02:00
that case, the remote command will print nothing and return status 2,
2021-05-11 02:29:21 +02:00
compared with status 1 for a file not found.</p>
2022-08-24 15:22:41 +02:00
<p>The local command (but not remote) may be used with no arguments, in
2021-05-11 02:29:21 +02:00
which case the information comes from examining file descriptor zero.
2022-08-24 15:22:41 +02:00
This is the same file as seen by a put command with no further
2021-05-11 02:29:21 +02:00
redirection.</p>
2022-08-24 15:22:41 +02:00
<p>get <code>file</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>Retrieve all <code>file</code>s from the server, concatenating them and sending
them to standard output.</p>
2022-08-24 15:22:41 +02:00
<p>put <code>file</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>For each <code>file</code>, read a file from standard input and send that to the
remote host with the given name.</p>
2022-08-24 15:22:41 +02:00
<p>append <code>file</code> ...</p>
<p>As put, but if the remote <code>file</code> already exists, data is appended to it
instead of overwriting it.</p>
<p>getat <code>file</code> <code>point</code></p>
<p>putat <code>file</code> <code>point</code></p>
<p>appendat <code>file</code> <code>point</code></p>
<p>Versions of get, put and append which will start the transfer at the
given <code>point</code> in the remote <code>file</code>. This is useful for appending to an
incomplete local file. However, note that this ability is not
2021-05-11 02:29:21 +02:00
universally supported by servers (and is not quite the behaviour
specified by the standard).</p>
2022-08-24 15:22:41 +02:00
<p>delete <code>file</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>Delete the list of files on the server.</p>
2022-08-24 15:22:41 +02:00
<p>mkdir <code>directory</code></p>
2021-05-11 02:29:21 +02:00
<p>Create a new directory <code>directory</code> on the server.</p>
2022-08-24 15:22:41 +02:00
<p>rmdir <code>directory</code></p>
2021-05-11 02:29:21 +02:00
<p>Delete the directory <code>directory</code> on the server.</p>
2022-08-24 15:22:41 +02:00
<p>rename <code>old-name</code> <code>new-name</code></p>
2021-05-11 02:29:21 +02:00
<p>Rename file <code>old-name</code> to <code>new-name</code> on the server.</p>
2022-08-24 15:22:41 +02:00
<p>site <code>arg</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>Send a host-specific command to the server. You will probably only need
this if instructed by the server to use it.</p>
2022-08-24 15:22:41 +02:00
<p>quote <code>arg</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>Send the raw FTP command sequence to the server. You should be familiar
with the FTP command set as defined in RFC959 before doing this. Useful
2022-08-24 15:22:41 +02:00
commands may include STAT and HELP. Note also the mechanism for
returning messages as described for the variable ZFTP_VERBOSE below, in
particular that all messages from the control connection are sent to
2021-05-11 02:29:21 +02:00
standard error.</p>
2022-08-24 15:22:41 +02:00
<p>close</p>
<p>quit</p>
2021-05-11 02:29:21 +02:00
<p>Close the current data connection. This unsets the shell parameters
2022-08-24 15:22:41 +02:00
ZFTP_HOST, ZFTP_PORT, ZFTP_IP, ZFTP_SYSTEM, ZFTP_USER, ZFTP_ACCOUNT,
ZFTP_PWD, ZFTP_TYPE and ZFTP_MODE.</p>
<p>session [ <code>sessname</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>Allows multiple FTP sessions to be used at once. The name of the session
is an arbitrary string of characters; the default session is called
2022-08-24 15:22:41 +02:00
default. If this command is called without an argument, it will list
all the current sessions; with an argument, it will either switch to the
existing session called <code>sessname</code>, or create a new session of that
name.</p>
2021-05-11 02:29:21 +02:00
<p>Each session remembers the status of the connection, the set of
connection-specific shell parameters (the same set as are unset when a
2022-08-24 15:22:41 +02:00
connection closes, as given in the description of close), and any user
parameters specified with the params subcommand. Changing to a previous
session restores those values; changing to a new session initialises
them in the same way as if zftp had just been loaded. The name of the
current session is given by the parameter ZFTP_SESSION.</p>
<p>rmsession [ <code>sessname</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>Delete a session; if a name is not given, the current session is
deleted. If the current session is deleted, the earliest existing
session becomes the new current session, otherwise the current session
is not changed. If the session being deleted is the only one, a new
2022-08-24 15:22:41 +02:00
session called default is created and becomes the current session;
2021-05-11 02:29:21 +02:00
note that this is a new session even if the session being deleted is
2022-08-24 15:22:41 +02:00
also called default. It is recommended that sessions not be deleted
while background commands which use zftp are still active.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Parameters-4"></span></p>
<h3 id="22322-parameters"><a class="header" href="#22322-parameters">22.32.2 Parameters</a></h3>
2021-05-11 02:29:21 +02:00
<p><span id="index-zftp_002c-parameters"></span></p>
2022-08-24 15:22:41 +02:00
<p>The following shell parameters are used by zftp. Currently none of them
are special.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-ZFTP_005fTMOUT"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZFTP_TMOUT</p>
2021-05-11 02:29:21 +02:00
<p>Integer. The time in seconds to wait for a network operation to complete
before returning an error. If this is not set when the module is loaded,
it will be given the default value 60. A value of zero turns off
timeouts. If a timeout occurs on the control connection it will be
closed. Use a larger value if this occurs too frequently.</p>
<p><span id="index-ZFTP_005fIP"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZFTP_IP</p>
2021-05-11 02:29:21 +02:00
<p>Readonly. The IP address of the current connection in dot notation.</p>
<p><span id="index-ZFTP_005fHOST"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZFTP_HOST</p>
2021-05-11 02:29:21 +02:00
<p>Readonly. The hostname of the current remote server. If the host was
2022-08-24 15:22:41 +02:00
opened as an IP number, ZFTP_HOST contains that instead; this saves the
overhead for a name lookup, as IP numbers are most commonly used when a
nameserver is unavailable.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-ZFTP_005fPORT"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZFTP_PORT</p>
2021-05-11 02:29:21 +02:00
<p>Readonly. The number of the remote TCP port to which the connection is
open (even if the port was originally specified as a named service).
Usually this is the standard FTP port, 21.</p>
<p>In the unlikely event that your system does not have the appropriate
conversion functions, this appears in network byte order. If your system
is little-endian, the port then consists of two swapped bytes and the
standard port will be reported as 5376. In that case, numeric ports
2022-08-24 15:22:41 +02:00
passed to zftp open will also need to be in this format.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-ZFTP_005fSYSTEM"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZFTP_SYSTEM</p>
2021-05-11 02:29:21 +02:00
<p>Readonly. The system type string returned by the server in response to
2022-08-24 15:22:41 +02:00
an FTP SYST request. The most interesting case is a string beginning
&quot;UNIX Type: L8&quot;, which ensures maximum compatibility with a local UNIX
2021-05-11 02:29:21 +02:00
host.</p>
<p><span id="index-ZFTP_005fTYPE"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZFTP_TYPE</p>
<p>Readonly. The type to be used for data transfers , either A or I.
Use the type subcommand to change this.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-ZFTP_005fUSER"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZFTP_USER</p>
2021-05-11 02:29:21 +02:00
<p>Readonly. The username currently logged in, if any.</p>
<p><span id="index-ZFTP_005fACCOUNT"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZFTP_ACCOUNT</p>
2021-05-11 02:29:21 +02:00
<p>Readonly. The account name of the current user, if any. Most servers do
not require an account name.</p>
<p><span id="index-ZFTP_005fPWD"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZFTP_PWD</p>
2021-05-11 02:29:21 +02:00
<p>Readonly. The current directory on the server.</p>
<p><span id="index-ZFTP_005fCODE"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZFTP_CODE</p>
2021-05-11 02:29:21 +02:00
<p>Readonly. The three digit code of the last FTP reply from the server as
a string. This can still be read after the connection is closed, and is
not changed when the current session changes.</p>
<p><span id="index-ZFTP_005fREPLY"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZFTP_REPLY</p>
2021-05-11 02:29:21 +02:00
<p>Readonly. The last line of the last reply sent by the server. This can
still be read after the connection is closed, and is not changed when
the current session changes.</p>
<p><span id="index-ZFTP_005fSESSION"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZFTP_SESSION</p>
2021-05-11 02:29:21 +02:00
<p>Readonly. The name of the current FTP session; see the description of
2022-08-24 15:22:41 +02:00
the session subcommand.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-ZFTP_005fPREFS"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZFTP_PREFS</p>
<p>A string of preferences for altering aspects of zftps behaviour. Each
2021-05-11 02:29:21 +02:00
preference is a single character. The following are defined:</p>
2022-08-24 15:22:41 +02:00
<p>P<br />
Passive: attempt to make the remote server initiate data transfers. This
is slightly more efficient than sendport mode. If the letter S occurs
later in the string, zftp will use sendport mode if passive mode is not
available.</p>
<p>S<br />
Sendport: initiate transfers by the FTP PORT command. If this occurs
before any P in the string, passive mode will never be attempted.</p>
<p>D<br />
2021-05-11 02:29:21 +02:00
Dumb: use only the bare minimum of FTP commands. This prevents the
2022-08-24 15:22:41 +02:00
variables ZFTP_SYSTEM and ZFTP_PWD from being set, and will mean all
connections default to ASCII type. It may prevent ZFTP_SIZE from being
set during a transfer if the server does not send it anyway (many
servers do).</p>
<p>If ZFTP_PREFS is not set when zftp is loaded, it will be set to a
default of PS, i.e. use passive mode if available, otherwise fall back
to sendport mode.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-ZFTP_005fVERBOSE"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZFTP_VERBOSE</p>
2021-05-11 02:29:21 +02:00
<p>A string of digits between 0 and 5 inclusive, specifying which responses
from the server should be printed. All responses go to standard error.
If any of the numbers 1 to 5 appear in the string, raw responses from
the server with reply codes beginning with that digit will be printed to
standard error. The first digit of the three digit reply code is defined
by RFC959 to correspond to:</p>
<p>1.<br />
A positive preliminary reply.</p>
<p>2.<br />
A positive completion reply.</p>
<p>3.<br />
A positive intermediate reply.</p>
<p>4.<br />
A transient negative completion reply.</p>
<p>5.<br />
A permanent negative completion reply.</p>
<p>It should be noted that, for unknown reasons, the reply Service not
available, which forces termination of a connection, is classified as
421, i.e. transient negative, an interesting interpretation of the
word transient.</p>
<p>The code 0 is special: it indicates that all but the last line of
multiline replies read from the server will be printed to standard error
in a processed format. By convention, servers use this mechanism for
sending information for the user to read. The appropriate reply code, if
it matches the same response, takes priority.</p>
2022-08-24 15:22:41 +02:00
<p>If ZFTP_VERBOSE is not set when zftp is loaded, it will be set to the
default value 450, i.e., messages destined for the user and all errors
will be printed. A null string is valid and specifies that no messages
should be printed.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Functions-1"></span></p>
2022-08-24 15:22:41 +02:00
<h3 id="22323-functions"><a class="header" href="#22323-functions">22.32.3 Functions</a></h3>
2021-05-11 02:29:21 +02:00
<p><span id="index-zftp_002c-functions"></span></p>
<p><span id="index-zftp_005fchpwd_002c-specification"></span></p>
2022-08-24 15:22:41 +02:00
<p>zftp_chpwd</p>
2021-05-11 02:29:21 +02:00
<p>If this function is set by the user, it is called every time the
directory changes on the server, including when a user is logged in, or
2022-08-24 15:22:41 +02:00
when a connection is closed. In the last case, $ZFTP_PWD will be unset;
otherwise it will reflect the new directory.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zftp_005fprogress_002c-specification"></span></p>
2022-08-24 15:22:41 +02:00
<p>zftp_progress</p>
<p>If this function is set by the user, it will be called during a get, put
or append operation each time sufficient data has been received from the
host. During a get, the data is sent to standard output, so it is vital
that this function should write to standard error or directly to the
terminal, <em>not</em> to standard output.</p>
2021-05-11 02:29:21 +02:00
<p>When it is called with a transfer in progress, the following additional
shell parameters are set:</p>
<p><span id="index-ZFTP_005fFILE"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZFTP_FILE</p>
2021-05-11 02:29:21 +02:00
<p>The name of the remote file being transferred from or to.</p>
<p><span id="index-ZFTP_005fTRANSFER"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZFTP_TRANSFER</p>
<p>A G for a get operation and a P for a put operation.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-ZFTP_005fSIZE"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZFTP_SIZE</p>
2021-05-11 02:29:21 +02:00
<p>The total size of the complete file being transferred: the same as the
2022-08-24 15:22:41 +02:00
first value provided by the remote and local subcommands for a
2021-05-11 02:29:21 +02:00
particular file. If the server cannot supply this value for a remote
file being retrieved, it will not be set. If input is from a pipe the
value may be incorrect and correspond simply to a full pipe buffer.</p>
<p><span id="index-ZFTP_005fCOUNT"></span></p>
2022-08-24 15:22:41 +02:00
<p>ZFTP_COUNT</p>
2021-05-11 02:29:21 +02:00
<p>The amount of data so far transferred; a number between zero and
2022-08-24 15:22:41 +02:00
$ZFTP_SIZE, if that is set. This number is always available.</p>
<p>The function is initially called with ZFTP_TRANSFER set appropriately
and ZFTP_COUNT set to zero. After the transfer is finished, the function
will be called one more time with ZFTP_TRANSFER set to GF or PF, in case
it wishes to tidy up. It is otherwise never called twice with the same
value of ZFTP_COUNT.</p>
2021-05-11 02:29:21 +02:00
<p>Sometimes the progress meter may cause disruption. It is up to the user
2022-08-24 15:22:41 +02:00
to decide whether the function should be defined and to use unfunction
2021-05-11 02:29:21 +02:00
when necessary.</p>
<hr />
<p><span id="Problems"></span></p>
2022-08-24 15:22:41 +02:00
<h3 id="22324-problems"><a class="header" href="#22324-problems">22.32.4 Problems</a></h3>
2021-05-11 02:29:21 +02:00
<p><span id="index-zftp_002c-problems"></span></p>
<p>A connection may not be opened in the left hand side of a pipe as this
occurs in a subshell and the file information is not updated in the main
shell. In the case of type or mode changes or closing the connection in
a subshell, the information is returned but variables are not updated
2022-08-24 15:22:41 +02:00
until the next call to zftp. Other status changes in subshells will not
be reflected by changes to the variables (but should be otherwise
2021-05-11 02:29:21 +02:00
harmless).</p>
2022-08-24 15:22:41 +02:00
<p>Deleting sessions while a zftp command is active in the background can
2021-05-11 02:29:21 +02:00
have unexpected effects, even if it does not use the session being
deleted. This is because all shell subprocesses share information on the
state of all connections, and deleting a session changes the ordering of
that information.</p>
<p>On some operating systems, the control connection is not valid after a
fork(), so that operations in subshells, on the left hand side of a
pipeline, or in the background are not possible, as they should be. This
is presumably a bug in the operating system.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fzle-Module"></span> <span
id="The-zsh_002fzle-Module-1"></span></p>
<h2 id="2233-the-zshzle-module"><a class="header" href="#2233-the-zshzle-module">22.33 The zsh/zle Module</a></h2>
<p>The zsh/zle module contains the Zsh Line Editor. See <a href="Zsh-Line-Editor.html#Zsh-Line-Editor">Zsh Line
2021-05-11 02:29:21 +02:00
Editor</a>.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fzleparameter-Module"></span> <span
id="The-zsh_002fzleparameter-Module-1"></span></p>
<h2 id="2234-the-zshzleparameter-module"><a class="header" href="#2234-the-zshzleparameter-module">22.34 The zsh/zleparameter Module</a></h2>
2021-05-11 02:29:21 +02:00
<p><span id="index-parameters_002c-special-2"></span></p>
2022-08-24 15:22:41 +02:00
<p>The zsh/zleparameter module defines two special parameters that can be
2021-05-11 02:29:21 +02:00
used to access internal information of the Zsh Line Editor (see <a href="Zsh-Line-Editor.html#Zsh-Line-Editor">Zsh
Line Editor</a>).</p>
<p><span id="index-keymaps-2"></span></p>
2022-08-24 15:22:41 +02:00
<p>keymaps</p>
2021-05-11 02:29:21 +02:00
<p>This array contains the names of the keymaps currently defined.</p>
<p><span id="index-widgets-1"></span></p>
2022-08-24 15:22:41 +02:00
<p>widgets</p>
2021-05-11 02:29:21 +02:00
<p>This associative array contains one entry per widget. The name of the
widget is the key and the value gives information about the widget. It
2022-08-24 15:22:41 +02:00
is either the string builtin for builtin widgets, a string of the form
user:<code>name</code> for user-defined widgets, where <code>name</code> is the name of the
shell function implementing the widget, a string of the form
completion:<code>type</code>:<code>name</code> for completion widgets, or a null value if
the widget is not yet fully defined. In the penultimate case, <code>type</code> is
the name of the builtin widget the completion widget imitates in its
2021-05-11 02:29:21 +02:00
behavior and <code>name</code> is the name of the shell function implementing the
completion widget.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fzprof-Module"></span> <span
id="The-zsh_002fzprof-Module-1"></span></p>
<h2 id="2235-the-zshzprof-module"><a class="header" href="#2235-the-zshzprof-module">22.35 The zsh/zprof Module</a></h2>
2021-05-11 02:29:21 +02:00
<p><span id="index-functions_002c-profiling"></span></p>
2022-08-24 15:22:41 +02:00
<p>When loaded, the zsh/zprof causes shell functions to be profiled. The
profiling results can be obtained with the zprof builtin command made
2021-05-11 02:29:21 +02:00
available by this module. There is no way to turn profiling off other
than unloading the module.</p>
<p><span id="index-zprof"></span></p>
2022-08-24 15:22:41 +02:00
<p>zprof [ -c ]</p>
<p>Without the -c option, zprof lists profiling results to standard output.
The format is comparable to that of commands like gprof.</p>
2021-05-11 02:29:21 +02:00
<p>At the top there is a summary listing all functions that were called at
least once. This summary is sorted in decreasing order of the amount of
time spent in each. The lines contain the number of the function in
order, which is used in other parts of the list in suffixes of the form
2022-08-24 15:22:41 +02:00
[<code>num</code>], then the number of calls made to the function. The next
2021-05-11 02:29:21 +02:00
three columns list the time in milliseconds spent in the function and
its descendants, the average time in milliseconds spent in the function
and its descendants per call and the percentage of time spent in all
shell functions used in this function and its descendants. The following
three columns give the same information, but counting only the time
spent in the function itself. The final column shows the name of the
function.</p>
<p>After the summary, detailed information about every function that was
invoked is listed, sorted in decreasing order of the amount of time
spent in each function and its descendants. Each of these entries
consists of descriptions for the functions that called the function
described, the function itself, and the functions that were called from
it. The description for the function itself has the same format as in
the summary (and shows the same information). The other lines dont show
the number of the function at the beginning and have their function
named indented to make it easier to distinguish the line showing the
function described in the section from the surrounding lines.</p>
<p>The information shown in this case is almost the same as in the summary,
but only refers to the call hierarchy being displayed. For example, for
a calling function the column showing the total running time lists the
time spent in the described function and its descendants only for the
times when it was called from that particular calling function.
Likewise, for a called function, this columns lists the total time spent
in the called function and its descendants only for the times when it
was called from the function described.</p>
<p>Also in this case, the column showing the number of calls to a function
also shows a slash and then the total number of invocations made to the
called function.</p>
2022-08-24 15:22:41 +02:00
<p>As long as the zsh/zprof module is loaded, profiling will be done and
multiple invocations of the zprof builtin command will show the times
and numbers of calls since the module was loaded. With the -c option,
the zprof builtin command will reset its internal counters and will not
show the listing.</p>
<hr />
<p><span id="The-zsh_002fzpty-Module"></span> <span
id="The-zsh_002fzpty-Module-1"></span></p>
<h2 id="2236-the-zshzpty-module"><a class="header" href="#2236-the-zshzpty-module">22.36 The zsh/zpty Module</a></h2>
<p>The zsh/zpty module offers one builtin:</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zpty"></span></p>
2022-08-24 15:22:41 +02:00
<p>zpty [ -e ] [ -b ] <code>name</code> [ <code>arg</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>The arguments following <code>name</code> are concatenated with spaces between,
2022-08-24 15:22:41 +02:00
then executed as a command, as if passed to the eval builtin. The
2021-05-11 02:29:21 +02:00
command runs under a newly assigned pseudo-terminal; this is useful for
running commands non-interactively which expect an interactive
environment. The <code>name</code> is not part of the command, but is used to refer
2022-08-24 15:22:41 +02:00
to this command in later calls to zpty.</p>
<p>With the -e option, the pseudo-terminal is set up so that input
2021-05-11 02:29:21 +02:00
characters are echoed.</p>
2022-08-24 15:22:41 +02:00
<p>With the -b option, input to and output from the pseudo-terminal are
2021-05-11 02:29:21 +02:00
made non-blocking.</p>
2022-08-24 15:22:41 +02:00
<p>The shell parameter REPLY is set to the file descriptor assigned to the
master side of the pseudo-terminal. This allows the terminal to be
2021-05-11 02:29:21 +02:00
monitored with ZLE descriptor handlers (see <a href="Zsh-Line-Editor.html#Zle-Builtins">Zle
Builtins</a>) or manipulated with
2022-08-24 15:22:41 +02:00
sysread and syswrite (see <a href="Zsh-Modules.html#The-zsh_002fsystem-Module">The zsh/system
Module</a>). <em>Warning</em>: Use of sysread and
syswrite is <em>not</em> recommended; use zpty -r and zpty -w unless you know
exactly what you are doing.</p>
<p>zpty -d [ <code>name</code> ... ]</p>
<p>The second form, with the -d option, is used to delete commands
2021-05-11 02:29:21 +02:00
previously started, by supplying a list of their <code>name</code>s. If no <code>name</code>
is given, all commands are deleted. Deleting a command causes the HUP
signal to be sent to the corresponding process.</p>
2022-08-24 15:22:41 +02:00
<p>zpty -w [ -n ] <code>name</code> [ <code>string</code> ... ]</p>
<p>The -w option can be used to send the to command <code>name</code> the given
<code>string</code>s as input (separated by spaces). If the -n option is <em>not</em>
2021-05-11 02:29:21 +02:00
given, a newline is added at the end.</p>
<p>If no <code>string</code> is provided, the standard input is copied to the
pseudo-terminal; this may stop before copying the full input if the
pseudo-terminal is non-blocking. The exact input is always copied: the
2022-08-24 15:22:41 +02:00
-n option is not applied.</p>
2021-05-11 02:29:21 +02:00
<p>Note that the command under the pseudo-terminal sees this input as if it
were typed, so beware when sending special tty driver characters such as
word-erase, line-kill, and end-of-file.</p>
2022-08-24 15:22:41 +02:00
<p>zpty -r [ -mt ] <code>name</code> [ <code>param</code> [ <code>pattern</code> ] ]</p>
<p>The -r option can be used to read the output of the command <code>name</code>. With
only a <code>name</code> argument, the output read is copied to the standard
2021-05-11 02:29:21 +02:00
output. Unless the pseudo-terminal is non-blocking, copying continues
until the command under the pseudo-terminal exits; when non-blocking,
only as much output as is immediately available is copied. The return
status is zero if any output is copied.</p>
<p>When also given a <code>param</code> argument, at most one line is read and stored
in the parameter named <code>param</code>. Less than a full line may be read if the
pseudo-terminal is non-blocking. The return status is zero if at least
one character is stored in <code>param</code>.</p>
<p>If a <code>pattern</code> is given as well, output is read until the whole string
read matches the <code>pattern</code>, even in the non-blocking case. The return
status is zero if the string read matches the pattern, or if the command
has exited but at least one character could still be read. If the option
2022-08-24 15:22:41 +02:00
-m is present, the return status is zero only if the pattern matches. As
of this writing, a maximum of one megabyte of output can be consumed
2021-05-11 02:29:21 +02:00
this way; if a full megabyte is read without matching the pattern, the
return status is non-zero.</p>
<p>In all cases, the return status is non-zero if nothing could be read,
2022-08-24 15:22:41 +02:00
and is 2 if this is because the command has finished.</p>
<p>If the -r option is combined with the -t option, zpty tests whether
output is available before trying to read. If no output is available,
zpty immediately returns the status 1. When used with a <code>pattern</code>, the
behaviour on a failed poll is similar to when the command has exited:
the return value is zero if at least one character could still be read
even if the pattern failed to match.</p>
<p>zpty -t <code>name</code></p>
<p>The -t option without the -r option can be used to test whether the
2021-05-11 02:29:21 +02:00
command <code>name</code> is still running. It returns a zero status if the command
is running and a non-zero value otherwise.</p>
2022-08-24 15:22:41 +02:00
<p>zpty [ -L ]</p>
2021-05-11 02:29:21 +02:00
<p>The last form, without any arguments, is used to list the commands
2022-08-24 15:22:41 +02:00
currently defined. If the -L option is given, this is done in the form
of calls to the zpty builtin.</p>
<hr />
<p><span id="The-zsh_002fzselect-Module"></span> <span
id="The-zsh_002fzselect-Module-1"></span></p>
<h2 id="2237-the-zshzselect-module"><a class="header" href="#2237-the-zshzselect-module">22.37 The zsh/zselect Module</a></h2>
<p>The zsh/zselect module makes available one builtin command:</p>
<p><span id="index-zselect"></span> <span
id="index-select_002c-system-call"></span> <span
id="index-file-descriptors_002c-waiting-for"></span></p>
<p>zselect [ -rwe ] [ -t <code>timeout</code> ] [ -a <code>array</code> ] [ -A <code>assoc</code> ]
[ <code>fd</code> ... ]</p>
<p>The zselect builtin is a front-end to the select system call, which
2021-05-11 02:29:21 +02:00
blocks until a file descriptor is ready for reading or writing, or has
an error condition, with an optional timeout. If this is not available
on your system, the command prints an error message and returns status 2
2022-08-24 15:22:41 +02:00
(normal errors return status 1). For more information, see your systems
documentation for select(3). Note there is no connection with the shell
builtin of the same name.</p>
2021-05-11 02:29:21 +02:00
<p>Arguments and options may be intermingled in any order. Non-option
arguments are file descriptors, which must be decimal integers. By
2022-08-24 15:22:41 +02:00
default, file descriptors are to be tested for reading, i.e. zselect
2021-05-11 02:29:21 +02:00
will return when data is available to be read from the file descriptor,
or more precisely, when a read operation from the file descriptor will
2022-08-24 15:22:41 +02:00
not block. After a -r, -w and -e, the given file descriptors are to be
tested for reading, writing, or error conditions. These options and an
arbitrary list of file descriptors may be given in any order.</p>
2021-05-11 02:29:21 +02:00
<p>(The presence of an error condition is not well defined in the
documentation for many implementations of the select system call.
According to recent versions of the POSIX specification, it is really an
<em>exception</em> condition, of which the only standard example is out-of-band
2022-08-24 15:22:41 +02:00
data received on a socket. So zsh users are unlikely to find the -e
2021-05-11 02:29:21 +02:00
option useful.)</p>
2022-08-24 15:22:41 +02:00
<p>The option -t <code>timeout</code> specifies a timeout in hundredths of a second.
This may be zero, in which case the file descriptors will simply be
polled and zselect will return immediately. It is possible to call
2021-05-11 02:29:21 +02:00
zselect with no file descriptors and a non-zero timeout for use as a
finer-grained replacement for sleep; note, however, the return status
is always 1 for a timeout.</p>
2022-08-24 15:22:41 +02:00
<p>The option -a <code>array</code> indicates that <code>array</code> should be set to indicate
the file descriptor(s) which are ready. If the option is not given, the
array reply will be used for this purpose. The array will contain a
string similar to the arguments for zselect. For example,</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zselect -t 0 -r 0 -w 1
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>might return immediately with status 0 and $reply containing -r 0 -w 1
to show that both file descriptors are ready for the requested
2021-05-11 02:29:21 +02:00
operations.</p>
2022-08-24 15:22:41 +02:00
<p>The option -A <code>assoc</code> indicates that the associative array <code>assoc</code>
2021-05-11 02:29:21 +02:00
should be set to indicate the file descriptor(s) which are ready. This
2022-08-24 15:22:41 +02:00
option overrides the option -a, nor will reply be modified. The keys of
assoc are the file descriptors, and the corresponding values are any of
the characters rwe to indicate the condition.</p>
2021-05-11 02:29:21 +02:00
<p>The command returns status 0 if some file descriptors are ready for
reading. If the operation timed out, or a timeout of 0 was given and no
file descriptors were ready, or there was an error, it returns status 1
and the array will not be set (nor modified in any way). If there was an
error in the select operation the appropriate error message is printed.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="The-zsh_002fzutil-Module"></span> <span
id="The-zsh_002fzutil-Module-1"></span></p>
<h2 id="2238-the-zshzutil-module"><a class="header" href="#2238-the-zshzutil-module">22.38 The zsh/zutil Module</a></h2>
2021-05-11 02:29:21 +02:00
<p><span id="index-builtins_002c-utility"></span></p>
2022-08-24 15:22:41 +02:00
<p>The zsh/zutil module only adds some builtins:</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zstyle"></span></p>
2022-08-24 15:22:41 +02:00
<p>zstyle [ -L [ <code>metapattern</code> [ <code>style</code> ] ] ]</p>
<p>zstyle [ -e | - | -- ] <code>pattern</code> <code>style</code> <code>string</code> ...</p>
<p>zstyle -d [ <code>pattern</code> [ <code>style</code> ... ] ]</p>
<p>zstyle -g <code>name</code> [ <code>pattern</code> [ <code>style</code> ] ]</p>
<p>zstyle -{a|b|s} <code>context</code> <code>style</code> <code>name</code> [ <code>sep</code> ]</p>
<p>zstyle -{T|t} <code>context</code> <code>style</code> [ <code>string</code> ... ]</p>
<p>zstyle -m <code>context</code> <code>style</code> <code>pattern</code></p>
2021-05-11 02:29:21 +02:00
<p>This builtin command is used to define and lookup styles. Styles are
pairs of names and values, where the values consist of any number of
strings. They are stored together with patterns and lookup is done by
giving a string, called the <em>context</em>, which is matched against the
patterns. The definition stored for the most specific pattern that
matches will be returned.</p>
<p>A pattern is considered to be more specific than another if it contains
more components (substrings separated by colons) or if the patterns for
the components are more specific, where simple strings are considered to
be more specific than patterns and complex patterns are considered to be
2022-08-24 15:22:41 +02:00
more specific than the pattern *. A * in the pattern will match
2021-05-11 02:29:21 +02:00
zero or more characters in the context; colons are not treated specially
in this regard. If two patterns are equally specific, the tie is broken
in favour of the pattern that was defined first.</p>
2022-08-24 15:22:41 +02:00
<p><em>Example</em> <span
id="index-preferred_002dprecipitation_002c-example-style"></span> <span
id="index-weather_002c-example-function"></span></p>
<p>For example, a fictional weather plugin might state in its
documentation that it looks up the preferred-precipitation style under
the :weather:<code>continent</code>:<code>day-of-the-week</code>:<code>phase-of-the-moon</code>
context. According to this, you might set the following in your zshrc:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':weather:europe:*' preferred-precipitation rain
zstyle ':weather:*:Sunday:*' preferred-precipitation snow
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Then the plugin would run under the hood a command such as</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle -s &quot;:weather:${continent}:${day_of_week}:${moon_phase}&quot; preferred-precipitation REPLY
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>in order to retrieve your preference into the scalar variable $REPLY. On
Sundays $REPLY would be set to snow; in Europe it would be set to
rain; and on Sundays in Europe it would be set to snow again,
because the patterns :weather:europe:* and :weather:*:Sunday:*
both match the <code>context</code> argument to zstyle -s, are equally specific,
and the latter is more specific (because it has more colon-separated
components).</p>
2021-05-11 02:29:21 +02:00
<p><em>Usage</em></p>
<p>The forms that operate on patterns are the following.</p>
2022-08-24 15:22:41 +02:00
<p>zstyle [ -L [ <code>metapattern</code> [ <code>style</code> ] ] ]<br />
2021-05-11 02:29:21 +02:00
Without arguments, lists style definitions. Styles are shown in
2022-08-24 15:22:41 +02:00
alphabetic order and patterns are shown in the order zstyle will test
them.</p>
<p>If the -L option is given, listing is done in the form of calls to
zstyle. The optional first argument, <code>metapattern</code>, is a pattern which
will be matched against the string supplied as <code>pattern</code> when the style
was defined. Note: this means, for example, zstyle -L &quot;:completion:*&quot;
will match any supplied pattern beginning :completion:, not just
&quot;:completion:*&quot;: use :completion:\* to match that. The optional
second argument limits the output to a specific <code>style</code> (not a pattern).
-L is not compatible with any other options.</p>
<p>zstyle [ - | -- | -e ] <code>pattern</code> <code>style</code> <code>string</code> ...<br />
2021-05-11 02:29:21 +02:00
<span id="index-reply_002c-use-of-4"></span></p>
2022-08-24 15:22:41 +02:00
<p>Defines the given <code>style</code> for the <code>pattern</code> with the <code>string</code>s as the
value. If the -e option is given, the <code>string</code>s will be concatenated
(separated by spaces) and the resulting string will be evaluated (in the
same way as it is done by the eval builtin command) when the style is
looked up. In this case the parameter reply must be assigned to set
the strings returned after the evaluation. Before evaluating the value,
reply is unset, and if it is still unset after the evaluation, the style
is treated as if it were not set.</p>
<p>zstyle -d [ <code>pattern</code> [ <code>style</code> ... ] ]<br />
Delete style definitions. Without arguments all definitions are deleted,
with a <code>pattern</code> all definitions for that pattern are deleted and if any
<code>style</code>s are given, then only those styles are deleted for the
<code>pattern</code>.</p>
<p>zstyle -g <code>name</code> [ <code>pattern</code> [ <code>style</code> ] ]<br />
Retrieve a style definition. The <code>name</code> is used as the name of an array
in which the results are stored. Without any further arguments, all
patterns defined are returned. With a <code>pattern</code> the styles defined for
that pattern are returned and with both a <code>pattern</code> and a <code>style</code>, the
value strings of that combination is returned.</p>
2021-05-11 02:29:21 +02:00
<p>The other forms can be used to look up or test styles for a given
context.</p>
2022-08-24 15:22:41 +02:00
<p>zstyle -s <code>context</code> <code>style</code> <code>name</code> [ <code>sep</code> ]<br />
The parameter <code>name</code> is set to the value of the style interpreted as a
string. If the value contains several strings they are concatenated with
spaces (or with the <code>sep</code> string if that is given) between them.</p>
<p>Return 0 if the style is set, 1 otherwise.</p>
<p>zstyle -b <code>context</code> <code>style</code> <code>name</code><br />
The value is stored in <code>name</code> as a boolean, i.e. as the string yes if
the value has only one string and that string is equal to one of yes,
true, on, or 1. If the value is any other string or has more than
one string, the parameter is set to no.</p>
<p>Return 0 if <code>name</code> is set to yes, 1 otherwise.</p>
<p>zstyle -a <code>context</code> <code>style</code> <code>name</code><br />
The value is stored in <code>name</code> as an array. If <code>name</code> is declared as an
associative array, the first, third, etc. strings are used as the keys
and the other strings are used as the values.</p>
<p>Return 0 if the style is set, 1 otherwise.</p>
<p>zstyle -t <code>context</code> <code>style</code> [ <code>string</code> ... ]<br />
zstyle -T <code>context</code> <code>style</code> [ <code>string</code> ... ]<br />
Test the value of a style, i.e. the -t option only returns a status
(sets $?). Without any <code>string</code> the return status is zero if the style
is defined for at least one matching pattern, has only one string in its
value, and that is equal to one of true, yes, on or 1. If any
<code>string</code>s are given the status is zero if and only if at least one of
the <code>string</code>s is equal to at least one of the strings in the value. If
the style is defined but doesnt match, the return status is 1. If the
style is not defined, the status is 2.</p>
<p>The -T option tests the values of the style like -t, but it returns
status zero (rather than 2) if the style is not defined for any matching
pattern.</p>
<p>zstyle -m <code>context</code> <code>style</code> <code>pattern</code><br />
Match a value. Returns status zero if the <code>pattern</code> matches at least one
of the strings in the value.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zformat"></span></p>
2022-08-24 15:22:41 +02:00
<p>zformat -f <code>param</code> <code>format</code> <code>spec</code> ...</p>
<p>zformat -F <code>param</code> <code>format</code> <code>spec</code> ...</p>
<p>zformat -a <code>array</code> <code>sep</code> <code>spec</code> ...</p>
<p>This builtin provides different forms of formatting. The first form is
selected with the -f option. In this case the <code>format</code> string will be
modified by replacing sequences starting with a percent sign in it with
strings from the <code>spec</code>s. Each <code>spec</code> should be of the form
<code>char</code>:<code>string</code> which will cause every appearance of the sequence
%<code>char</code> in <code>format</code> to be replaced by the <code>string</code>. The % sequence
may also contain optional minimum and maximum field width specifications
between the % and the <code>char</code> in the form %<code>min</code>.<code>max</code>c, i.e. the
minimum field width is given first and if the maximum field width is
used, it has to be preceded by a dot. Specifying a minimum field width
makes the result be padded with spaces to the right if the <code>string</code> is
shorter than the requested width. Padding to the left can be achieved by
giving a negative minimum field width. If a maximum field width is
specified, the <code>string</code> will be truncated after that many characters.
After all % sequences for the given <code>spec</code>s have been processed, the
resulting string is stored in the parameter <code>param</code>.</p>
<p>The %-escapes also understand ternary expressions in the form used by
prompts. The % is followed by a ( and then an ordinary format
2021-05-11 02:29:21 +02:00
specifier character as described above. There may be a set of digits
2022-08-24 15:22:41 +02:00
either before or after the (; these specify a test number, which
2021-05-11 02:29:21 +02:00
defaults to zero. Negative numbers are also allowed. An arbitrary
delimiter character follows the format specifier, which is followed by a
piece of true text, the delimiter character again, a piece of false
text, and a closing parenthesis. The complete expression (without the
2022-08-24 15:22:41 +02:00
digits) thus looks like %(<code>X</code>.<code>text1</code>.<code>text2</code>), except that the .
character is arbitrary. The value given for the format specifier in the
<code>char</code>:<code>string</code> expressions is evaluated as a mathematical expression,
and compared with the test number. If they are the same, <code>text1</code> is
output, else <code>text2</code> is output. A parenthesis may be escaped in <code>text2</code>
as %). Either of <code>text1</code> or <code>text2</code> may contain nested %-escapes.</p>
2021-05-11 02:29:21 +02:00
<p>For example:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zformat -f REPLY &quot;The answer is '%3(c.yes.no)'.&quot; c:3
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>outputs &quot;The answer is yes.&quot; to REPLY since the value for the format
specifier c is 3, agreeing with the digit argument to the ternary
2021-05-11 02:29:21 +02:00
expression.</p>
2022-08-24 15:22:41 +02:00
<p>With -F instead of -f, ternary expressions choose between the true or
false text on the basis of whether the format specifier is present and
non-empty. A test number indicates a minimum width for the value given
in the format specifier. Negative numbers reverse this, so the test is
for whether the value exceeds a maximum width.</p>
<p>The form, using the -a option, can be used for aligning strings. Here,
the <code>spec</code>s are of the form <code>left</code>:<code>right</code> where <code>left</code> and
<code>right</code> are arbitrary strings. These strings are modified by replacing
the colons by the <code>sep</code> string and padding the <code>left</code> strings with
spaces to the right so that the <code>sep</code> strings in the result (and hence
the <code>right</code> strings after them) are all aligned if the strings are
printed below each other. All strings without a colon are left unchanged
and all strings with an empty <code>right</code> string have the trailing colon
removed. In both cases the lengths of the strings are not used to
determine how the other strings are to be aligned. A colon in the <code>left</code>
string can be escaped with a backslash. The resulting strings are stored
in the <code>array</code>.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zregexparse"></span></p>
2022-08-24 15:22:41 +02:00
<p>zregexparse</p>
<p>This implements some internals of the _regex_arguments function.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zparseopts"></span></p>
2022-08-24 15:22:41 +02:00
<p>zparseopts [ -D -E -F -K -M ] [ -a <code>array</code> ] [ -A <code>assoc</code> ] [ -
] <code>spec</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>This builtin simplifies the parsing of options in positional parameters,
2022-08-24 15:22:41 +02:00
i.e. the set of arguments given by $*. Each <code>spec</code> describes one option
and must be of the form <code>opt</code>[=<code>array</code>]. If an option described by
<code>opt</code> is found in the positional parameters it is copied into the
<code>array</code> specified with the -a option; if the optional =<code>array</code> is
given, it is instead copied into that array, which should be declared as
a normal array and never as an associative array.</p>
<p>Note that it is an error to give any <code>spec</code> without an =<code>array</code> unless
one of the -a or -A options is used.</p>
<p>Unless the -E option is given, parsing stops at the first string that
isnt described by one of the <code>spec</code>s. Even with -E, parsing always
stops at a positional parameter equal to - or --. See also -F.</p>
2021-05-11 02:29:21 +02:00
<p>The <code>opt</code> description must be one of the following. Any of the special
characters can appear in the option name provided it is preceded by a
backslash.</p>
<p><code>name</code><br />
2022-08-24 15:22:41 +02:00
<code>name</code>+<br />
The <code>name</code> is the name of the option without the leading -. To specify
a GNU-style long option, one of the usual two leading - must be
included in <code>name</code>; for example, a --file option is represented by a
<code>name</code> of -file.</p>
<p>If a + appears after <code>name</code>, the option is appended to <code>array</code> each
time it is found in the positional parameters; without the + only the
<em>last</em> occurrence of the option is preserved.</p>
<p>If one of these forms is used, the option takes no argument, so parsing
stops if the next positional parameter does not also begin with -
(unless the -E option is used).</p>
<p><code>name</code>:<br />
<code>name</code>:-<br />
<code>name</code>::<br />
If one or two colons are given, the option takes an argument; with one
colon, the argument is mandatory and with two colons it is optional. The
argument is appended to the <code>array</code> after the option itself.</p>
<p>An optional argument is put into the same array element as the option
name (note that this makes empty strings as arguments
indistinguishable). A mandatory argument is added as a separate element
unless the :- form is used, in which case the argument is put into the
same element.</p>
<p>A + as described above may appear between the <code>name</code> and the first
colon.</p>
2021-05-11 02:29:21 +02:00
<p>In all cases, option-arguments must appear either immediately following
the option in the same positional parameter or in the next one. Even an
optional argument may appear in the next parameter, unless it begins
2022-08-24 15:22:41 +02:00
with a -. There is no special handling of = as with GNU-style
argument parsers; given the <code>spec</code> -foo:, the positional parameter
--foo=bar is parsed as --foo with an argument of =bar.</p>
2021-05-11 02:29:21 +02:00
<p>When the names of two options that take no arguments overlap, the
2022-08-24 15:22:41 +02:00
longest one wins, so that parsing for the <code>spec</code>s -foo -foobar (for
2021-05-11 02:29:21 +02:00
example) is unambiguous. However, due to the aforementioned handling of
option-arguments, ambiguities may arise when at least one overlapping
2022-08-24 15:22:41 +02:00
<code>spec</code> takes an argument, as in -foo: -foobar. In that case, the last
matching <code>spec</code> wins.</p>
<p>The options of zparseopts itself cannot be stacked because, for example,
the stack -DEK is indistinguishable from a <code>spec</code> for the GNU-style
long option --DEK. The options of zparseopts itself are:</p>
<p>-a <code>array</code><br />
As described above, this names the default array in which to store the
recognised options.</p>
<p>-A <code>assoc</code><br />
2021-05-11 02:29:21 +02:00
If this is given, the options and their values are also put into an
2022-08-24 15:22:41 +02:00
associative array with the option names as keys and the arguments (if
any) as the values.</p>
<p>-D<br />
2021-05-11 02:29:21 +02:00
If this option is given, all options found are removed from the
2022-08-24 15:22:41 +02:00
positional parameters of the calling shell or shell function, up to but
not including any not described by the <code>spec</code>s. If the first such
parameter is - or --, it is removed as well. This is similar to
using the shift builtin.</p>
<p>-E<br />
This changes the parsing rules to <em>not</em> stop at the first string that
isnt described by one of the <code>spec</code>s. It can be used to test for or (if
used together with -D) extract options and their arguments, ignoring all
other options and arguments that may be in the positional parameters. As
indicated above, parsing still stops at the first - or -- not
described by a <code>spec</code>, but it is not removed when used with -D.</p>
<p>-F<br />
If this option is given, zparseopts immediately stops at the first
2021-05-11 02:29:21 +02:00
option-like parameter not described by one of the <code>spec</code>s, prints an
2022-08-24 15:22:41 +02:00
error message, and returns status 1. Removal (-D) and extraction (-E)
are not performed, and option arrays are not updated. This provides
basic validation for the given options.</p>
2021-05-11 02:29:21 +02:00
<p>Note that the appearance in the positional parameters of an option
2022-08-24 15:22:41 +02:00
without its required argument always aborts parsing and returns an error
as described above regardless of whether this option is used.</p>
<p>-K<br />
With this option, the arrays specified with the -a option and with the
=<code>array</code> forms are kept unchanged when none of the <code>spec</code>s for them is
used. Otherwise the entire array is replaced when any of the <code>spec</code>s is
used. Individual elements of associative arrays specified with the -A
option are preserved by -K. This allows assignment of default values to
arrays before calling zparseopts.</p>
<p>-M<br />
This changes the assignment rules to implement a map among equivalent
option names. If any <code>spec</code> uses the =<code>array</code> form, the string <code>array</code>
is interpreted as the name of another <code>spec</code>, which is used to choose
where to store the values. If no other <code>spec</code> is found, the values are
stored as usual. This changes only the way the values are stored, not
the way $* is parsed, so results may be</p>
2021-05-11 02:29:21 +02:00
<p>For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">set -- -a -bx -c y -cz baz -cend
2021-05-11 02:29:21 +02:00
zparseopts a=foo b:=bar c+:=bar
</code></pre>
</div>
<p>will have the effect of</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">foo=(-a)
2021-05-11 02:29:21 +02:00
bar=(-b x -c y -c z)
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The arguments from baz on will not be used.</p>
<p>As an example for the -E option, consider:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">set -- -a x -b y -c z arg1 arg2
2021-05-11 02:29:21 +02:00
zparseopts -E -D b:=bar
</code></pre>
</div>
<p>will have the effect of</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">bar=(-b y)
2021-05-11 02:29:21 +02:00
set -- -a x -c z arg1 arg2
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>I.e., the option -b and its arguments are taken from the positional
parameters and put into the array bar.</p>
<p>The -M option can be used like this:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">set -- -a -bx -c y -cz baz -cend
2021-05-11 02:29:21 +02:00
zparseopts -A bar -M a=foo b+: c:=b
</code></pre>
</div>
<p>to have the effect of</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">foo=(-a)
2021-05-11 02:29:21 +02:00
bar=(-a '' -b xyz)
</code></pre>
</div>
<hr />
2022-08-24 15:22:41 +02:00
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="Calendar-Function-System.html#23-calendar-function-system">23 Calendar Function System</a>
<ul>
<li><a href="Calendar-Function-System.html#231-description">23.1 Description</a></li>
<li><a href="Calendar-Function-System.html#232-file-and-date-formats">23.2 File and Date Formats</a>
<ul>
<li><a href="Calendar-Function-System.html#2321-calendar-file-format">23.2.1 Calendar File Format</a></li>
<li><a href="Calendar-Function-System.html#2322-date-format">23.2.2 Date Format</a></li>
<li><a href="Calendar-Function-System.html#2323-relative-time-format">23.2.3 Relative Time Format</a></li>
<li><a href="Calendar-Function-System.html#2324-example">23.2.4 Example</a></li>
</ul>
</li>
<li><a href="Calendar-Function-System.html#233-user-functions">23.3 User Functions</a>
<ul>
<li><a href="Calendar-Function-System.html#2331-calendar-system-functions">23.3.1 Calendar system functions</a></li>
<li><a href="Calendar-Function-System.html#2332-glob-qualifiers">23.3.2 Glob qualifiers</a></li>
</ul>
</li>
<li><a href="Calendar-Function-System.html#234-styles">23.4 Styles</a></li>
<li><a href="Calendar-Function-System.html#235-utility-functions">23.5 Utility functions</a></li>
<li><a href="Calendar-Function-System.html#236-bugs">23.6 Bugs</a></li>
</ul>
</li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2022-08-24 15:22:41 +02:00
<p><span id="Calendar-Function-System"></span> <span
id="Calendar-Function-System-1"></span></p>
2021-05-11 02:29:21 +02:00
<h1 id="23-calendar-function-system"><a class="header" href="#23-calendar-function-system">23 Calendar Function System</a></h1>
2022-08-24 15:22:41 +02:00
<p><span id="index-calendar-function-system"></span> <span
id="index-zsh_002fdatetime_002c-function-system-based-on"></span></p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Description-3"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="231-description"><a class="header" href="#231-description">23.1 Description</a></h2>
<p>The shell is supplied with a series of functions to replace and enhance
2022-08-24 15:22:41 +02:00
the traditional Unix calendar programme, which warns the user of
2021-05-11 02:29:21 +02:00
imminent or future events, details of which are stored in a text file
2022-08-24 15:22:41 +02:00
(typically calendar in the users home directory). The version provided
here includes a mechanism for alerting the user when an event is due.</p>
<p>In addition functions age, before and after are provided that can be
used in a glob qualifier; they allow files to be selected based on their
modification times.</p>
<p>The format of the calendar file and the dates used there in and in the
age function are described first, then the functions that can be called
to examine and modify the calendar file.</p>
<p>The functions here depend on the availability of the zsh/datetime module
which is usually installed with the shell. The library function
strptime() must be available; it is present on most recent operating
2021-05-11 02:29:21 +02:00
systems.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Calendar-File-and-Date-Formats"></span> <span
id="File-and-Date-Formats"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="232-file-and-date-formats"><a class="header" href="#232-file-and-date-formats">23.2 File and Date Formats</a></h2>
<hr />
<p><span id="Calendar-File-Format"></span></p>
<h3 id="2321-calendar-file-format"><a class="header" href="#2321-calendar-file-format">23.2.1 Calendar File Format</a></h3>
2022-08-24 15:22:41 +02:00
<p>The calendar file is by default ~/calendar. This can be configured by
the calendar-file style, see <a href="Calendar-Function-System.html#Calendar-Styles">Styles</a>. The basic
2021-05-11 02:29:21 +02:00
format consists of a series of separate lines, with no indentation, each
including a date and time specification followed by a description of the
event.</p>
<p>Various enhancements to this format are supported, based on the syntax
of Emacs calendar mode. An indented line indicates a continuation line
that continues the description of the event from the preceding line
(note the date may not be continued in this way). An initial ampersand
2022-08-24 15:22:41 +02:00
(&amp;) is ignored for compatibility.</p>
<p>An indented line on which the first non-whitespace character is # is not
displayed with the calendar entry, but is still scanned for information.
This can be used to hide information useful to the calendar system but
not to the user, such as the unique identifier used by calendar_add.</p>
2021-05-11 02:29:21 +02:00
<p>The Emacs extension that a date with no description may refer to a
number of succeeding events at different times is not supported.</p>
2022-08-24 15:22:41 +02:00
<p>Unless the done-file style has been altered, any events which have been
processed are appended to the file with the same name as the calendar
file with the suffix .done, hence ~/calendar.done by default.</p>
2021-05-11 02:29:21 +02:00
<p>An example is shown below.</p>
<hr />
<p><span id="Date-Format"></span></p>
<h3 id="2322-date-format"><a class="header" href="#2322-date-format">23.2.2 Date Format</a></h3>
<p>The format of the date and time is designed to allow flexibility without
admitting ambiguity. (The words date and time are both used in the
documentation below; except where specifically noted this implies a
string that may include both a date and a time specification.) Note that
there is no localization support; month and day names must be in English
and separator characters are fixed. Matching is case insensitive, and
only the first three letters of the names are significant, although as a
special case a form beginning &quot;month&quot; does not match &quot;Monday&quot;.
Furthermore, time zones are not handled; all times are assumed to be
local.</p>
<p>It is recommended that, rather than exploring the intricacies of the
system, users find a date format that is natural to them and stick to
it. This will avoid unexpected effects. Various key facts should be
noted.</p>
<ul>
2022-08-24 15:22:41 +02:00
<li>In particular, note the confusion between <code>month</code>/<code>day</code>/<code>year</code> and
<code>day</code>/<code>month</code>/<code>year</code> when the month is numeric; these formats should
be avoided if at all possible. Many alternatives are available.</li>
2021-05-11 02:29:21 +02:00
<li>The year must be given in full to avoid confusion, and only years
from 1900 to 2099 inclusive are matched.</li>
</ul>
<p>The following give some obvious examples; users finding here a format
they like and not subject to vagaries of style may skip the full
description. As dates and times are matched separately (even though the
time may be embedded in the date), any date format may be mixed with any
format for the time of day provide the separators are clear (whitespace,
colons, commas).</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">2007/04/03 13:13
2021-05-11 02:29:21 +02:00
2007/04/03:13:13
2007/04/03 1:13 pm
3rd April 2007, 13:13
April 3rd 2007 1:13 p.m.
Apr 3, 2007 13:13
Tue Apr 03 13:13:00 2007
13:13 2007/apr/3
</code></pre>
</div>
<p>More detailed rules follow.</p>
<p>Times are parsed and extracted before dates. They must use colons to
separate hours and minutes, though a dot is allowed before seconds if
they are present. This limits time formats to the following:</p>
<ul>
2022-08-24 15:22:41 +02:00
<li><code>HH</code>:<code>MM</code>[:<code>SS</code>[.<code>FFFFF</code>]] [am|pm|a.m.|p.m.]</li>
<li><code>HH</code>:<code>MM</code>.<code>SS</code>[.<code>FFFFF</code>] [am|pm|a.m.|p.m.]</li>
2021-05-11 02:29:21 +02:00
</ul>
<p>Here, square brackets indicate optional elements, possibly with
alternatives. Fractions of a second are recognised but ignored. For
2022-08-24 15:22:41 +02:00
absolute times (the normal format require by the calendar file and the
age, before and after functions) a date is mandatory but a time of day
is not; the time returned is at the start of the date. One variation is
allowed: if a.m. or p.m. or one of their variants is present, an hour
without a minute is allowed, e.g. 3 p.m..</p>
2021-05-11 02:29:21 +02:00
<p>Time zones are not handled, though if one is matched following a time
specification it will be removed to allow a surrounding date to be
parsed. This only happens if the format of the timezone is not too
unusual. The following are examples of forms that are understood:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">+0100
2021-05-11 02:29:21 +02:00
GMT
GMT-7
CET+1CDT
</code></pre>
</div>
<p>Any part of the timezone that is not numeric must have exactly three
capital letters in the name.</p>
2022-08-24 15:22:41 +02:00
<p>Dates suffer from the ambiguity between <code>DD</code>/<code>MM</code>/<code>YYYY</code> and
<code>MM</code>/<code>DD</code>/<code>YYYY</code>. It is recommended this form is avoided with purely
numeric dates, but use of ordinals, eg. 3rd/04/2007, will resolve the
2021-05-11 02:29:21 +02:00
ambiguity as the ordinal is always parsed as the day of the month. Years
2022-08-24 15:22:41 +02:00
must be four digits (and the first two must be 19 or 20); 03/04/08 is
not recognised. Other numbers may have leading zeroes, but they are not
required. The following are handled:</p>
<ul>
<li><code>YYYY</code>/<code>MM</code>/<code>DD</code></li>
<li><code>YYYY</code>-<code>MM</code>-<code>DD</code></li>
<li><code>YYYY</code>/<code>MNM</code>/<code>DD</code></li>
<li><code>YYYY</code>-<code>MNM</code>-<code>DD</code></li>
<li><code>DD</code>[th|st|rd] <code>MNM</code>[,] [ <code>YYYY</code> ]</li>
<li><code>MNM</code> <code>DD</code>[th|st|rd][,] [ <code>YYYY</code> ]</li>
<li><code>DD</code>[th|st|rd]/<code>MM</code>[,] <code>YYYY</code></li>
<li><code>DD</code>[th|st|rd]/<code>MM</code>/<code>YYYY</code></li>
<li><code>MM</code>/<code>DD</code>[th|st|rd][,] <code>YYYY</code></li>
<li><code>MM</code>/<code>DD</code>[th|st|rd]/<code>YYYY</code></li>
2021-05-11 02:29:21 +02:00
</ul>
<p>Here, <code>MNM</code> is at least the first three letters of a month name, matched
case-insensitively. The remainder of the month name may appear but its
contents are irrelevant, so janissary, febrile, martial, apricot, maybe,
junta, etc. are happily handled.</p>
<p>Where the year is shown as optional, the current year is assumed. There
2022-08-24 15:22:41 +02:00
are only two such cases, the form Jun 20 or 14 September (the only two
commonly occurring forms, apart from a &quot;the&quot; in some forms of English,
which isnt currently supported). Such dates will of course become
ambiguous in the future, so should ideally be avoided.</p>
<p>Times may follow dates with a colon, e.g. 1965/07/12:09:45; this is in
2021-05-11 02:29:21 +02:00
order to provide a format with no whitespace. A comma and whitespace are
2022-08-24 15:22:41 +02:00
allowed, e.g. 1965/07/12, 09:45. Currently the order of these separators
is not checked, so illogical formats such as 1965/07/12, : ,09:45 will
also be matched. For simplicity such variations are not shown in the
list above. Otherwise, a time is only recognised as being associated
with a date if there is only whitespace in between, or if the time was
embedded in the date.</p>
2021-05-11 02:29:21 +02:00
<p>Days of the week are not normally scanned, but will be ignored if they
occur at the start of the date pattern only. However, in contexts where
it is useful to specify dates relative to today, days of the week with
no other date specification may be given. The day is assumed to be
2022-08-24 15:22:41 +02:00
either today or within the past week. Likewise, the words yesterday,
today and tomorrow are handled. All matches are case-insensitive. Hence
if today is Monday, then Sunday is equivalent to yesterday, Monday is
equivalent to today, but Tuesday gives a date six days ago. This is not
generally useful within the calendar file. Dates in this format may be
combined with a time specification; for example Tomorrow, 8 p.m..</p>
2021-05-11 02:29:21 +02:00
<p>For example, the standard date format:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">Fri Aug 18 17:00:48 BST 2006
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>is handled by matching <code>HH</code>:<code>MM</code>:<code>SS</code> and removing it together with the
matched (but unused) time zone. This leaves the following:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">Fri Aug 18 2006
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Fri is ignored and the rest is matched according to the standard rules.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Relative-Time-Format"></span></p>
<h3 id="2323-relative-time-format"><a class="header" href="#2323-relative-time-format">23.2.3 Relative Time Format</a></h3>
<p>In certain places relative times are handled. Here, a date is not
allowed; instead a combination of various supported periods are allowed,
together with an optional time. The periods must be in order from most
to least significant.</p>
<p>In some cases, a more accurate calculation is possible when there is an
anchor date: offsets of months or years pick the correct day, rather
than being rounded, and it is possible to pick a particular day in a
month as (1st Friday), etc., as described in more detail below.</p>
<p>Anchors are available in the following cases. If one or two times are
2022-08-24 15:22:41 +02:00
passed to the function calendar, the start time acts an anchor for the
2021-05-11 02:29:21 +02:00
end time when the end time is relative (even if the start time is
implicit). When examining calendar files, the scheduled event being
examined anchors the warning time when it is given explicitly by means
2022-08-24 15:22:41 +02:00
of the WARN keyword; likewise, the scheduled event anchors a repetition
period when given by the RPT keyword, so that specifications such as RPT
2 months, 3rd Thursday are handled properly. Finally, the -R argument to
calendar_scandate directly provides an anchor for relative calculations.</p>
2021-05-11 02:29:21 +02:00
<p>The periods handled, with possible abbreviations are:</p>
<p>Years<br />
2022-08-24 15:22:41 +02:00
years, yrs, ys, year, yr, y, yearly. A year is 365.25 days unless there
is an anchor.</p>
2021-05-11 02:29:21 +02:00
<p>Months<br />
2022-08-24 15:22:41 +02:00
months, mons, mnths, mths, month, mon, mnth, mth, monthly. Note that m,
ms, mn, mns are ambiguous and are <em>not</em> handled. A month is a period of
30 days rather than a calendar month unless there is an anchor.</p>
2021-05-11 02:29:21 +02:00
<p>Weeks<br />
2022-08-24 15:22:41 +02:00
weeks, wks, ws, week, wk, w, weekly</p>
2021-05-11 02:29:21 +02:00
<p>Days<br />
2022-08-24 15:22:41 +02:00
days, dys, ds, day, dy, d, daily</p>
2021-05-11 02:29:21 +02:00
<p>Hours<br />
2022-08-24 15:22:41 +02:00
hours, hrs, hs, hour, hr, h, hourly</p>
2021-05-11 02:29:21 +02:00
<p>Minutes<br />
2022-08-24 15:22:41 +02:00
minutes, mins, minute, min, but <em>not</em> m, ms, mn or mns</p>
2021-05-11 02:29:21 +02:00
<p>Seconds<br />
2022-08-24 15:22:41 +02:00
seconds, secs, ss, second, sec, s</p>
2021-05-11 02:29:21 +02:00
<p>Spaces between the numbers are optional, but are required between items,
although a comma may be used (with or without spaces).</p>
2022-08-24 15:22:41 +02:00
<p>The forms yearly to hourly allow the number to be omitted; it is assumed
to be 1. For example, 1 d and daily are equivalent. Note that using
those forms with plurals is confusing; 2 yearly is the same as 2 years,
<em>not</em> twice yearly, so it is recommended they only be used without
numbers.</p>
2021-05-11 02:29:21 +02:00
<p>When an anchor time is present, there is an extension to handle regular
events in the form of the <code>n</code>th <code>some</code>day of the month. Such a
specification must occur immediately after any year and month
specification, but before any time of day, and must be in the form
2022-08-24 15:22:41 +02:00
<code>n</code>(th|st|rd) <code>day</code>, for example 1st Tuesday or 3rd Monday. As in
other places, days are matched case insensitively, must be in English,
and only the first three letters are significant except that a form
beginning month does not match Monday. No attempt is made to
2021-05-11 02:29:21 +02:00
sanitize the resulting date; attempts to squeeze too many occurrences
into a month will push the day into the next month (but in the obvious
fashion, retaining the correct day of the week).</p>
<p>Here are some examples:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">30 years 3 months 4 days 3:42:41
2021-05-11 02:29:21 +02:00
14 days 5 hours
Monthly, 3rd Thursday
4d,10hr
</code></pre>
</div>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Example-3"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="2324-example"><a class="header" href="#2324-example">23.2.4 Example</a></h3>
<p>Here is an example calendar file. It uses a consistent date format, as
recommended above.</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">Feb 1, 2006 14:30 Pointless bureaucratic meeting
2021-05-11 02:29:21 +02:00
Mar 27, 2006 11:00 Mutual recrimination and finger pointing
Bring water pistol and waterproofs
Mar 31, 2006 14:00 Very serious managerial pontification
# UID 12C7878A9A50
Apr 10, 2006 13:30 Even more pointless blame assignment exercise WARN 30 mins
May 18, 2006 16:00 Regular moaning session RPT monthly, 3rd Thursday
</code></pre>
</div>
<p>The second entry has a continuation line. The third entry has a
continuation line that will not be shown when the entry is displayed,
2022-08-24 15:22:41 +02:00
but the unique identifier will be used by the calendar_add function when
updating the event. The fourth entry will produce a warning 30 minutes
before the event (to allow you to equip yourself appropriately). The
fifth entry repeats after a month on the 3rd Thursday, i.e. June 15,
2021-05-11 02:29:21 +02:00
2006, at the same time.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Calendar-System-User-Functions"></span> <span
id="User-Functions"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="233-user-functions"><a class="header" href="#233-user-functions">23.3 User Functions</a></h2>
<p>This section describes functions that are designed to be called directly
by the user. The first part describes those functions associated with
the users calendar; the second part describes the use in glob
qualifiers.</p>
<hr />
<p><span id="Calendar-system-functions"></span></p>
<h3 id="2331-calendar-system-functions"><a class="header" href="#2331-calendar-system-functions">23.3.1 Calendar system functions</a></h3>
<p><span id="index-calendar"></span></p>
2022-08-24 15:22:41 +02:00
<p>calendar [ -abdDsv ] [ -C <code>calfile</code> ] [ -n <code>num</code> ] [ -S
<code>showprog</code> ]</p>
<p>         [ [ <code>start</code> ] <code>end</code> ]</p>
<p>calendar -r [ -abdDrsv ] [ -C <code>calfile</code> ] [ -n <code>num</code> ] [ -S
<code>showprog</code> ]</p>
<p>         [ <code>start</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>Show events in the calendar.</p>
<p>With no arguments, show events from the start of today until the end of
the next working day after today. In other words, if today is Friday,
Saturday, or Sunday, show up to the end of the following Monday,
otherwise show today and tomorrow.</p>
<p>If <code>end</code> is given, show events from the start of today up to the time
and date given, which is in the format described in the previous
section. Note that if this is a date the time is assumed to be midnight
at the start of the date, so that effectively this shows all events
before the given date.</p>
2022-08-24 15:22:41 +02:00
<p><code>end</code> may start with a +, in which case the remainder of the
2021-05-11 02:29:21 +02:00
specification is a relative time format as described in the previous
section indicating the range of time from the start time that is to be
included.</p>
<p>If <code>start</code> is also given, show events starting from that time and date.
2022-08-24 15:22:41 +02:00
The word now can be used to indicate the current time.</p>
<p>To implement an alert when events are due, include calendar -s in your
~/.zshrc file.</p>
2021-05-11 02:29:21 +02:00
<p>Options:</p>
2022-08-24 15:22:41 +02:00
<p>-a<br />
Show all items in the calendar, regardless of the start and end.</p>
<p>-b<br />
Brief: dont display continuation lines (i.e. indented lines following
the line with the date/time), just the first line.</p>
<p>-B <code>lines</code><br />
Brief: display at most the first <code>lines</code> lines of the calendar entry.
-B 1 is equivalent to -b.</p>
<p>-C <code>calfile</code><br />
2021-05-11 02:29:21 +02:00
Explicitly specify a calendar file instead of the value of the
2022-08-24 15:22:41 +02:00
calendar-file style or the default ~/calendar.</p>
<p>-d<br />
Move any events that have passed from the calendar file to the &quot;done&quot;
file, as given by the done-file style or the default which is the
calendar file with .done appended. This option is implied by the -s
option.</p>
<p>-D<br />
Turns off the option -d, even if the -s option is also present.</p>
<p>-n <code>num</code>, -<code>num</code><br />
Show at least <code>num</code> events, if present in the calendar file, regardless
of the start and end.</p>
<p>-r<br />
Show all the remaining options in the calendar, ignoring the given <code>end</code>
time. The <code>start</code> time is respected; any argument given is treated as a
<code>start</code> time.</p>
<p>-s<br />
Use the shells sched command to schedule a timed event that will warn
the user when an event is due. Note that the sched command only runs if
the shell is at an interactive prompt; a foreground task blocks the
scheduled task from running until it is finished.</p>
<p>The timed event usually runs the programme calendar_show to show the
event, as described in <a href="Calendar-Function-System.html#Calendar-Utility-Functions">Utility functions</a>.</p>
<p>By default, a warning of the event is shown five minutes before it is
due. The warning period can be configured by the style warn-time or for
a single calendar entry by including WARN <code>reltime</code> in the first line of
the entry, where <code>reltime</code> is one of the usual relative time formats.</p>
<p>A repeated event may be indicated by including RPT <code>reldate</code> in the
first line of the entry. After the scheduled event has been displayed it
will be re-entered into the calendar file at a time <code>reldate</code> after the
existing event. Note that this is currently the only use made of the
repeat count, so that it is not possible to query the schedule for a
recurrence of an event in the calendar until the previous event has
passed.</p>
<p>If RPT is used, it is also possible to specify that certain recurrences
of an event are rescheduled or cancelled. This is done with the
OCCURRENCE keyword, followed by whitespace and the date and time of the
occurrence in the regular sequence, followed by whitespace and either
the date and time of the rescheduled event or the exact string
CANCELLED. In this case the date and time must be in exactly the &quot;date
with local time&quot; format used by the text/calendar MIME type (RFC 2445),
<code>&lt;YYYY&gt;&lt;MM&gt;&lt;DD&gt;</code>T<code>&lt;hh&gt;&lt;mm&gt;&lt;ss&gt;</code> (note the presence of the literal
character T). The first word (the regular recurrence) may be something
other than a proper date/time to indicate that the event is additional
to the normal sequence; a convention that retains the formatting
appearance is XXXXXXXXTXXXXXX.</p>
<p>Furthermore, it is useful to record the next regular recurrence (as then
the displayed date may be for a rescheduled event so cannot be used for
calculating the regular sequence). This is specified by RECURRENCE and a
time or date in the same format. calendar_add adds such an indication
when it encounters a recurring event that does not include one, based on
the headline date/time.</p>
<p>If calendar_add is used to update occurrences the UID keyword described
there should be present in both the existing entry and the added
occurrence in order to identify recurring event sequences.</p>
2021-05-11 02:29:21 +02:00
<p>For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">Thu May 6, 2010 11:00 Informal chat RPT 1 week
2021-05-11 02:29:21 +02:00
# RECURRENCE 20100506T110000
# OCCURRENCE 20100513T110000 20100513T120000
# OCCURRENCE 20100520T110000 CANCELLED
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The event that occurs at 11:00 on 13th May 2010 is rescheduled an hour
later. The event that occurs a week later is cancelled. The occurrences
are given on a continuation line starting with a # character so will not
usually be displayed as part of the event. As elsewhere, no account of
time zones is taken with the times. After the next event occurs the
headline date/time will be Thu May 13, 2010 12:00 while the RECURRENCE
date/time will be 20100513T110000 (note that cancelled and moved
events are not taken account of in the RECURRENCE, which records what
the next regular recurrence is, but they are accounted for in the
headline date/time).</p>
<p>It is safe to run calendar -s to reschedule an existing event (if the
calendar file has changed, for example), and also to have it running in
multiples instances of the shell since the calendar file is locked when
in use.</p>
<p>By default, expired events are moved to the &quot;done&quot; file; see the -d
option. Use -D to prevent this.</p>
<p>-S <code>showprog</code><br />
Explicitly specify a programme to be used for showing events instead of
the value of the show-prog style or the default calendar_show.</p>
<p>-v<br />
2021-05-11 02:29:21 +02:00
Verbose: show more information about stages of processing. This is
useful for confirming that the function has successfully parsed the
dates in the calendar file.</p>
<p><span id="index-calendar_005fadd"></span></p>
2022-08-24 15:22:41 +02:00
<p>calendar_add [ -BL ] <code>event</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>Adds a single event to the calendar in the appropriate location. The
event can contain multiple lines, as described in <a href="Calendar-Function-System.html#Calendar-File-and-Date-Formats">File and Date
Formats</a>. Using this function ensures
that the calendar file is sorted in date and time order. It also makes
special arrangements for locking the file while it is altered. The old
2022-08-24 15:22:41 +02:00
calendar is left in a file with the suffix .old.</p>
<p>The option -B indicates that backing up the calendar file will be
handled by the caller and should not be performed by calendar_add. The
option -L indicates that calendar_add does not need to lock the calendar
file as it is already locked. These options will not usually be needed
by users.</p>
<p>If the style reformat-date is true, the date and time of the new entry
2021-05-11 02:29:21 +02:00
will be rewritten into the standard date format: see the descriptions of
2022-08-24 15:22:41 +02:00
this style and the style date-format.</p>
2021-05-11 02:29:21 +02:00
<p>The function can use a unique identifier stored with each event to
ensure that updates to existing events are treated correctly. The entry
2022-08-24 15:22:41 +02:00
should contain the word UID, followed by whitespace, followed by a word
consisting entirely of hexadecimal digits of arbitrary length (all
2021-05-11 02:29:21 +02:00
digits are significant, including leading zeroes). As the UID is not
directly useful to the user, it is convenient to hide it on an indented
2022-08-24 15:22:41 +02:00
continuation line starting with a #, for example:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">Aug 31, 2007 09:30 Celebrate the end of the holidays
2021-05-11 02:29:21 +02:00
# UID 045B78A0
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The second line will not be shown by the calendar function.</p>
<p>It is possible to specify the RPT keyword followed by CANCELLED instead
of a relative time. This causes any matched event or series of events to
be cancelled (the original event does not have to be marked as recurring
in order to be cancelled by this method). A UID is required in order to
match an existing event in the calendar.</p>
<p>calendar_add will attempt to manage recurrences and occurrences of
repeating events as described for event scheduling by calendar -s above.
To reschedule or cancel a single event calendar_add should be called
with an entry that includes the correct UID but does <em>not</em> include the
RPT keyword as this is taken to mean the entry applies to a series of
repeating events and hence replaces all existing information. Each
rescheduled or cancelled occurrence must have an OCCURRENCE keyword in
the entry passed to calendar_add which will be merged into the calendar
file. Any existing reference to the occurrence is replaced. An
occurrence that does not refer to a valid existing event is added as a
one-off occurrence to the same calendar entry.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-calendar_005fedit"></span></p>
2022-08-24 15:22:41 +02:00
<p>calendar_edit</p>
2021-05-11 02:29:21 +02:00
<p>This calls the users editor to edit the calendar file. If there are
arguments, they are taken as the editor to use (the file name is
appended to the commands); otherwise, the editor is given by the
2022-08-24 15:22:41 +02:00
variable VISUAL, if set, else the variable EDITOR.</p>
2021-05-11 02:29:21 +02:00
<p>If the calendar scheduler was running, then after editing the file
2022-08-24 15:22:41 +02:00
calendar -s is called to update it.</p>
2021-05-11 02:29:21 +02:00
<p>This function locks out the calendar system during the edit. Hence it
should be used to edit the calendar file if there is any possibility of
a calendar event occurring meanwhile. Note this can lead to another
shell with calendar functions enabled hanging waiting for a lock, so it
is necessary to quit the editor as soon as possible.</p>
<p><span id="index-calendar_005fparse"></span></p>
2022-08-24 15:22:41 +02:00
<p>calendar_parse <code>calendar-entry</code></p>
2021-05-11 02:29:21 +02:00
<p>This is the internal function that analyses the parts of a calendar
entry, which is passed as the only argument. The function returns status
1 if the argument could not be parsed as a calendar entry and status 2
if the wrong number of arguments were passed; it also sets the parameter
2022-08-24 15:22:41 +02:00
reply to an empty associative array. Otherwise, it returns status 0 and
sets elements of the associative array reply as follows:</p>
<p>time<br />
The time as a string of digits in the same units as $EPOCHSECONDS</p>
<p>schedtime<br />
The regularly scheduled time. This may differ from the actual event time
time if this is a recurring event and the next occurrence has been
rescheduled. Then time gives the actual time and schedtime the time of
the regular recurrence before modification.</p>
<p>text1<br />
The text from the line not including the date and time of the event, but
including any WARN or RPT keywords and values.</p>
<p>warntime<br />
Any warning time given by the WARN keyword as a string of digits
containing the time at which to warn in the same units as $EPOCHSECONDS.
(Note this is an absolute time, not the relative time passed down.) Not
set no WARN keyword and value were matched.</p>
<p>warnstr<br />
The raw string matched after the WARN keyword, else unset.</p>
<p>rpttime<br />
Any recurrence time given by the RPT keyword as a string of digits
2021-05-11 02:29:21 +02:00
containing the time of the recurrence in the same units as
2022-08-24 15:22:41 +02:00
$EPOCHSECONDS. (Note this is an absolute time.) Not set if no RPT
keyword and value were matched.</p>
<p>schedrpttime<br />
2021-05-11 02:29:21 +02:00
The next regularly scheduled occurrence of a recurring event before
2022-08-24 15:22:41 +02:00
modification. This may differ from rpttime, which is the actual time of
the event that may have been rescheduled from the regular time.</p>
<p>rptstr<br />
The raw string matched after the RPT keyword, else unset.</p>
<p>text2<br />
The text from the line after removal of the date and any keywords and
values.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-calendar_005fshowdate"></span></p>
2022-08-24 15:22:41 +02:00
<p>calendar_showdate [ -r ] [ -f <code>fmt</code> ] <code>date-spec</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>The given <code>date-spec</code> is interpreted and the corresponding date and time
2022-08-24 15:22:41 +02:00
printed. If the initial <code>date-spec</code> begins with a + or - it is treated
as relative to the current time; <code>date-spec</code>s after the first are
treated as relative to the date calculated so far and a leading + is
optional in that case. This allows one to use the system as a date
calculator. For example, calendar_showdate +1 month, 1st Friday shows
the date of the first Friday of next month.</p>
<p>With the option -r nothing is printed but the value of the date and time
in seconds since the epoch is stored in the parameter REPLY.</p>
<p>With the option -f <code>fmt</code> the given date/time conversion format is passed
to strftime; see notes on the date-format style below.</p>
2021-05-11 02:29:21 +02:00
<p>In order to avoid ambiguity with negative relative date specifications,
2022-08-24 15:22:41 +02:00
options must occur in separate words; in other words, -r and -f should
not be combined in the same word.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-calendar_005fsort"></span></p>
2022-08-24 15:22:41 +02:00
<p>calendar_sort</p>
2021-05-11 02:29:21 +02:00
<p>Sorts the calendar file into date and time order. The old calendar is
2022-08-24 15:22:41 +02:00
left in a file with the suffix .old.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Glob-qualifiers"></span></p>
<h3 id="2332-glob-qualifiers"><a class="header" href="#2332-glob-qualifiers">23.3.2 Glob qualifiers</a></h3>
2022-08-24 15:22:41 +02:00
<p>age<br />
2021-05-11 02:29:21 +02:00
<span id="index-age"></span></p>
2022-08-24 15:22:41 +02:00
<p>The function age can be autoloaded and use separately from the calendar
system, although it uses the function calendar_scandate for date
formatting. It requires the zsh/stat builtin, but uses only the builtin
zstat.</p>
<p>age selects files having a given modification time for use as a glob
qualifier. The format of the date is the same as that understood by the
calendar system, described in <a href="Calendar-Function-System.html#Calendar-File-and-Date-Formats">File and Date
2021-05-11 02:29:21 +02:00
Formats</a>.</p>
2022-08-24 15:22:41 +02:00
<p>The function can take one or two arguments, which can be supplied either
directly as command or arguments, or separately as shell parameters.</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">print *(e:age 2006/10/04 2006/10/09:)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The example above matches all files modified between the start of those
dates. The second argument may alternatively be a relative time
introduced by a +:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">print *(e:age 2006/10/04 +5d:)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>The example above is equivalent to the previous example.</p>
2022-08-24 15:22:41 +02:00
<p>In addition to the special use of days of the week, today and yesterday,
times with no date may be specified; these apply to today. Obviously
such uses become problematic around midnight.</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">print *(e-age 12:00 13:30-)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The example above shows files modified between 12:00 and 13:00 today.</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">print *(e:age 2006/10/04:)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The example above matches all files modified on that date. If the second
argument is omitted it is taken to be exactly 24 hours after the first
argument (even if the first argument contains a time).</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">print *(e-age 2006/10/04:10:15 2006/10/04:10:45-)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The example above supplies times. Note that whitespace within the time
and date specification must be quoted to ensure age receives the correct
arguments, hence the use of the additional colon to separate the date
and time.</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">AGEREF=2006/10/04:10:15
2021-05-11 02:29:21 +02:00
AGEREF2=2006/10/04:10:45
print *(+age)
</code></pre>
</div>
<p>This shows the same example before using another form of argument
2022-08-24 15:22:41 +02:00
passing. The dates and times in the parameters AGEREF and AGEREF2 stay
in effect until unset, but will be overridden if any argument is passed
as an explicit argument to age. Any explicit argument causes both
parameters to be ignored.</p>
2021-05-11 02:29:21 +02:00
<p>Instead of an explicit date and time, its possible to use the
2022-08-24 15:22:41 +02:00
modification time of a file as the date and time for either argument by
introducing the file name with a colon:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">print *(e-age :file1-)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>matches all files created on the same day (24 hours starting from
2022-08-24 15:22:41 +02:00
midnight) as file1.</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">print *(e-age :file1 :file2-)
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>matches all files modified no earlier than file1 and no later than
file2; precision here is to the nearest second.</p>
<p>after<br />
before<br />
2021-05-11 02:29:21 +02:00
<span id="index-after"></span> <span id="index-before"></span></p>
2022-08-24 15:22:41 +02:00
<p>The functions after and before are simpler versions of age that take
just one argument. The argument is parsed similarly to an argument of
age; if it is not given the variable AGEREF is consulted. As the names
of the functions suggest, a file matches if its modification time is
after or before the time and date specified. If a time only is given the
date is today.</p>
2021-05-11 02:29:21 +02:00
<p>The two following examples are therefore equivalent:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">print *(e-after 12:00-)
2021-05-11 02:29:21 +02:00
print *(e-after today:12:00-)
</code></pre>
</div>
<hr />
<p><span id="Calendar-Styles"></span> <span id="Styles-1"></span></p>
<h2 id="234-styles"><a class="header" href="#234-styles">23.4 Styles</a></h2>
2022-08-24 15:22:41 +02:00
<p>The zsh style mechanism using the zstyle command is describe in <a href="Zsh-Modules.html#The-zsh_002fzutil-Module">The
2021-05-11 02:29:21 +02:00
zsh/zutil Module</a>. This is
the same mechanism used in the completion system.</p>
2022-08-24 15:22:41 +02:00
<p>The styles below are all examined in the context :datetime:<code>function</code>:,
for example :datetime:calendar:.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-calendar_002dfile"></span></p>
2022-08-24 15:22:41 +02:00
<p>calendar-file</p>
<p>The location of the main calendar. The default is ~/calendar.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-date_002dformat"></span></p>
2022-08-24 15:22:41 +02:00
<p>date-format</p>
<p>A strftime format string (see strftime(3)) with the zsh extensions
providing various numbers with no leading zero or space if the number is
a single digit as described for the %D{<code>string</code>} prompt format in
<a href="Prompt-Expansion.html#Prompt-Expansion">Prompt Expansion</a>.</p>
<p>This is used for outputting dates in calendar, both to support the -v
option and when adding recurring events back to the calendar file, and
in calendar_showdate as the final output format.</p>
2021-05-11 02:29:21 +02:00
<p>If the style is not set, the default used is similar the standard system
2022-08-24 15:22:41 +02:00
format as output by the date command (also known as ctime format): %a
%b %d %H:%M:%S %Z %Y.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-done_002dfile"></span></p>
2022-08-24 15:22:41 +02:00
<p>done-file</p>
2021-05-11 02:29:21 +02:00
<p>The location of the file to which events which have passed are appended.
2022-08-24 15:22:41 +02:00
The default is the calendar file location with the suffix .done. The
2021-05-11 02:29:21 +02:00
style may be set to an empty string in which case a &quot;done&quot; file will not
be maintained.</p>
<p><span id="index-reformat_002ddate"></span></p>
2022-08-24 15:22:41 +02:00
<p>reformat-date</p>
<p>Boolean, used by calendar_add. If it is true, the date and time of new
2021-05-11 02:29:21 +02:00
entries added to the calendar will be reformatted to the format given by
2022-08-24 15:22:41 +02:00
the style date-format or its default. Only the date and time of the
2021-05-11 02:29:21 +02:00
event itself is reformatted; any subsidiary dates and times such as
those associated with repeat and warning times are left alone.</p>
<p><span id="index-show_002dprog"></span></p>
2022-08-24 15:22:41 +02:00
<p>show-prog</p>
<p>The programme run by calendar for showing events. It will be passed the
start time and stop time of the events requested in seconds since the
epoch followed by the event text. Note that calendar -s uses a start
time and stop time equal to one another to indicate alerts for specific
events.</p>
<p>The default is the function calendar_show.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-warn_002dtime"></span></p>
2022-08-24 15:22:41 +02:00
<p>warn-time</p>
2021-05-11 02:29:21 +02:00
<p>The time before an event at which a warning will be displayed, if the
2022-08-24 15:22:41 +02:00
first line of the event does not include the text EVENT <code>reltime</code>. The
2021-05-11 02:29:21 +02:00
default is 5 minutes.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Calendar-Utility-Functions"></span> <span
id="Utility-functions"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="235-utility-functions"><a class="header" href="#235-utility-functions">23.5 Utility functions</a></h2>
<p><span id="index-calendar_005flockfiles"></span></p>
2022-08-24 15:22:41 +02:00
<p>calendar_lockfiles</p>
2021-05-11 02:29:21 +02:00
<p>Attempt to lock the files given in the argument. To prevent problems
with network file locking this is done in an ad hoc fashion by
attempting to create a symbolic link to the file with the name
2022-08-24 15:22:41 +02:00
<code>file</code>.lockfile. No other system level functions are used for locking,
2021-05-11 02:29:21 +02:00
i.e. the file can be accessed and modified by any utility that does not
use this mechanism. In particular, the user is not prevented from
2022-08-24 15:22:41 +02:00
editing the calendar file at the same time unless calendar_edit is used.</p>
2021-05-11 02:29:21 +02:00
<p>Three attempts are made to lock the file before giving up. If the module
2022-08-24 15:22:41 +02:00
zsh/zselect is available, the times of the attempts are jittered so that
multiple instances of the calling function are unlikely to retry at the
same time.</p>
<p>The files locked are appended to the array lockfiles, which should be
2021-05-11 02:29:21 +02:00
local to the caller.</p>
<p>If all files were successfully locked, status zero is returned, else
status one.</p>
<p>This function may be used as a general file locking function, although
this will only work if only this mechanism is used to lock files.</p>
<p><span id="index-calendar_005fread"></span></p>
2022-08-24 15:22:41 +02:00
<p>calendar_read</p>
2021-05-11 02:29:21 +02:00
<p>This is a backend used by various other functions to parse the calendar
2022-08-24 15:22:41 +02:00
file, which is passed as the only argument. The array calendar_entries
2021-05-11 02:29:21 +02:00
is set to the list of events in the file; no pruning is done except that
ampersands are removed from the start of the line. Each entry may
contain multiple lines.</p>
<p><span id="index-calendar_005fscandate"></span></p>
2022-08-24 15:22:41 +02:00
<p>calendar_scandate</p>
2021-05-11 02:29:21 +02:00
<p>This is a generic function to parse dates and times that may be used
separately from the calendar system. The argument is a date or time
specification as described in <a href="Calendar-Function-System.html#Calendar-File-and-Date-Formats">File and Date
2022-08-24 15:22:41 +02:00
Formats</a>. The parameter REPLY is set to
the number of seconds since the epoch corresponding to that date or
2021-05-11 02:29:21 +02:00
time. By default, the date and time may occur anywhere within the given
argument.</p>
<p>Returns status zero if the date and time were successfully parsed, else
one.</p>
<p>Options:</p>
2022-08-24 15:22:41 +02:00
<p>-a<br />
The date and time are anchored to the start of the argument; they will
not be matched if there is preceding text.</p>
<p>-A<br />
2021-05-11 02:29:21 +02:00
The date and time are anchored to both the start and end of the
argument; they will not be matched if the is any other text in the
argument.</p>
2022-08-24 15:22:41 +02:00
<p>-d<br />
2021-05-11 02:29:21 +02:00
Enable additional debugging output.</p>
2022-08-24 15:22:41 +02:00
<p>-m<br />
Minus. When -R <code>anchor_time</code> is also given the relative time is
2021-05-11 02:29:21 +02:00
calculated backwards from <code>anchor_time</code>.</p>
2022-08-24 15:22:41 +02:00
<p>-r<br />
2021-05-11 02:29:21 +02:00
The argument passed is to be parsed as a relative time.</p>
2022-08-24 15:22:41 +02:00
<p>-R <code>anchor_time</code><br />
2021-05-11 02:29:21 +02:00
The argument passed is to be parsed as a relative time. The time is
2022-08-24 15:22:41 +02:00
relative to <code>anchor_time</code>, a time in seconds since the epoch, and the
returned value is the absolute time corresponding to advancing
<code>anchor_time</code> by the relative time given. This allows lengths of months
to be correctly taken into account. If the final day does not exist in
the given month, the last day of the final month is given. For example,
if the anchor time is during 31st January 2007 and the relative time is
1 month, the final time is the same time of day during 28th
February 2007.</p>
<p>-s<br />
In addition to setting REPLY, set REPLY2 to the remainder of the
argument after the date and time have been stripped. This is empty if
the option -A was given.</p>
<p>-t<br />
2021-05-11 02:29:21 +02:00
Allow a time with no date specification. The date is assumed to be
2022-08-24 15:22:41 +02:00
today. The behaviour is unspecified if the iron tongue of midnight is
tolling twelve.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-calendar_005fshow"></span></p>
2022-08-24 15:22:41 +02:00
<p>calendar_show</p>
2021-05-11 02:29:21 +02:00
<p>The function used by default to display events. It accepts a start time
and end time for events, both in epoch seconds, and an event
description.</p>
<p>The event is always printed to standard output. If the command line
editor is active (which will usually be the case) the command line will
be redisplayed after the output.</p>
2022-08-24 15:22:41 +02:00
<p>If the parameter DISPLAY is set and the start and end times are the same
(indicating a scheduled event), the function uses the command xmessage
to display a window with the event details.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Calendar-Bugs"></span> <span id="Bugs"></span></p>
<h2 id="236-bugs"><a class="header" href="#236-bugs">23.6 Bugs</a></h2>
<p>As the system is based entirely on shell functions (with a little
2022-08-24 15:22:41 +02:00
support from the zsh/datetime module) the mechanisms used are not as
2021-05-11 02:29:21 +02:00
robust as those provided by a dedicated calendar utility. Consequently
the user should not rely on the shell for vital alerts.</p>
2022-08-24 15:22:41 +02:00
<p>There is no calendar_delete function.</p>
2021-05-11 02:29:21 +02:00
<p>There is no localization support for dates and times, nor any support
for the use of time zones.</p>
<p>Relative periods of months and years do not take into account the
variable number of days.</p>
2022-08-24 15:22:41 +02:00
<p>The calendar_show function is currently hardwired to use xmessage for
displaying alerts on X Window System displays. This should be
2021-05-11 02:29:21 +02:00
configurable and ideally integrate better with the desktop.</p>
2022-08-24 15:22:41 +02:00
<p>calendar_lockfiles hangs the shell while waiting for a lock on a file.
2021-05-11 02:29:21 +02:00
If called from a scheduled task, it should instead reschedule the event
that caused it.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="TCP-Function-System.html#24-tcp-function-system">24 TCP Function System</a>
<ul>
<li><a href="TCP-Function-System.html#241-description">24.1 Description</a></li>
<li><a href="TCP-Function-System.html#242-tcp-user-functions">24.2 TCP User Functions</a>
<ul>
<li><a href="TCP-Function-System.html#2421-basic-io">24.2.1 Basic I/O</a></li>
<li><a href="TCP-Function-System.html#2422-session-management">24.2.2 Session Management</a></li>
<li><a href="TCP-Function-System.html#2423-advanced-io">24.2.3 Advanced I/O</a></li>
<li><a href="TCP-Function-System.html#2424-one-shot-file-transfer">24.2.4 One-shot file transfer</a></li>
</ul>
</li>
<li><a href="TCP-Function-System.html#243-tcp-user-defined-functions">24.3 TCP User-defined Functions</a></li>
<li><a href="TCP-Function-System.html#244-tcp-utility-functions">24.4 TCP Utility Functions</a></li>
<li><a href="TCP-Function-System.html#245-tcp-user-parameters">24.5 TCP User Parameters</a></li>
<li><a href="TCP-Function-System.html#246-tcp-user-defined-parameters">24.6 TCP User-defined Parameters</a></li>
<li><a href="TCP-Function-System.html#247-tcp-utility-parameters">24.7 TCP Utility Parameters</a></li>
<li><a href="TCP-Function-System.html#248-tcp-examples">24.8 TCP Examples</a></li>
<li><a href="TCP-Function-System.html#249-tcp-bugs">24.9 TCP Bugs</a></li>
</ul>
</li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2022-08-24 15:22:41 +02:00
<p><span id="TCP-Function-System"></span> <span
id="TCP-Function-System-1"></span></p>
2021-05-11 02:29:21 +02:00
<h1 id="24-tcp-function-system"><a class="header" href="#24-tcp-function-system">24 TCP Function System</a></h1>
2022-08-24 15:22:41 +02:00
<p><span id="index-TCP-function-system"></span> <span
id="index-ztcp_002c-function-system-based-on"></span></p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Description-9"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="241-description"><a class="header" href="#241-description">24.1 Description</a></h2>
2022-08-24 15:22:41 +02:00
<p>A module zsh/net/tcp is provided to provide network I/O over TCP/IP from
within the shell; see its description in <a href="Zsh-Modules.html#Zsh-Modules">Zsh
2021-05-11 02:29:21 +02:00
Modules</a>. This manual page describes a
function suite based on the module. If the module is installed, the
functions are usually installed at the same time, in which case they
will be available for autoloading in the default function search path.
2022-08-24 15:22:41 +02:00
In addition to the zsh/net/tcp module, the zsh/zselect module is used to
implement timeouts on read operations. For troubleshooting tips, consult
the corresponding advice for the zftp functions described in <a href="Zftp-Function-System.html#Zftp-Function-System">Zftp
Function System</a>.</p>
2021-05-11 02:29:21 +02:00
<p>There are functions corresponding to the basic I/O operations open,
2022-08-24 15:22:41 +02:00
close, read and send, named tcp_open etc., as well as a function
tcp_expect for pattern match analysis of data read as input. The system
makes it easy to receive data from and send data to multiple named
sessions at once. In addition, it can be linked with the shells line
editor in such a way that input data is automatically shown at the
2021-05-11 02:29:21 +02:00
terminal. Other facilities available including logging, filtering and
configurable output prompts.</p>
<p>To use the system where it is available, it should be enough to
2022-08-24 15:22:41 +02:00
autoload -U tcp_open and run tcp_open as documented below to start a
session. The tcp_open function will autoload the remaining functions.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="TCP-Functions"></span> <span id="TCP-User-Functions"></span></p>
<h2 id="242-tcp-user-functions"><a class="header" href="#242-tcp-user-functions">24.2 TCP User Functions</a></h2>
<hr />
<p><span id="Basic-I_002fO"></span></p>
<h3 id="2421-basic-io"><a class="header" href="#2421-basic-io">24.2.1 Basic I/O</a></h3>
<p><span id="index-tcp_005fopen"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_open [ -qz ] <code>host port</code> [ <code>sess</code> ]</p>
<p>tcp_open [ -qz ] [ -s <code>sess</code> | -l <code>sess</code>[,...] ] ...</p>
<p>tcp_open [ -qz ] [ -a <code>fd</code> | -f <code>fd</code> ] [ <code>sess</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>Open a new session. In the first and simplest form, open a TCP
connection to host <code>host</code> at port <code>port</code>; numeric and symbolic forms are
understood for both.</p>
<p>If <code>sess</code> is given, this becomes the name of the session which can be
used to refer to multiple different TCP connections. If <code>sess</code> is not
given, the function will invent a numeric name value (note this is <em>not</em>
the same as the file descriptor to which the session is attached). It is
recommended that session names not include funny characters, where
funny characters are not well-defined but certainly do not include
alphanumerics or underscores, and certainly do include whitespace.</p>
<p>In the second case, one or more sessions to be opened are given by name.
2022-08-24 15:22:41 +02:00
A single session name is given after -s and a comma-separated list after
-l; both options may be repeated as many times as necessary. A failure
to open any session causes tcp_open to abort. The host and port are read
from the file .ztcp_sessions in the same directory as the users zsh
initialisation files, i.e. usually the home directory, but $ZDOTDIR if
that is set. The file consists of lines each giving a session name and
the corresponding host and port, in that order (note the session name
comes first, not last), separated by whitespace.</p>
<p>The third form allows passive and fake TCP connections. If the option -a
is used, its argument is a file descriptor open for listening for
2021-05-11 02:29:21 +02:00
connections. No function front-end is provided to open such a file
2022-08-24 15:22:41 +02:00
descriptor, but a call to ztcp -l <code>port</code> will create one with the file
descriptor stored in the parameter $REPLY. The listening port can be
closed with ztcp -c <code>fd</code>. A call to tcp_open -a <code>fd</code> will block
until a remote TCP connection is made to <code>port</code> on the local machine. At
this point, a session is created in the usual way and is largely
indistinguishable from an active connection created with one of the
first two forms.</p>
<p>If the option -f is used, its argument is a file descriptor which is
2021-05-11 02:29:21 +02:00
used directly as if it were a TCP session. How well the remainder of the
TCP function system copes with this depends on what actually underlies
this file descriptor. A regular file is likely to be unusable; a FIFO
(pipe) of some sort will work better, but note that it is not a good
idea for two different sessions to attempt to read from the same FIFO at
once.</p>
2022-08-24 15:22:41 +02:00
<p>If the option -q is given with any of the three forms, tcp_open will not
print informational messages, although it will in any case exit with an
appropriate status.</p>
2021-05-11 02:29:21 +02:00
<p>If the line editor (zle) is in use, which is typically the case if the
2022-08-24 15:22:41 +02:00
shell is interactive, tcp_open installs a handler inside zle which will
check for new data at the same time as it checks for keyboard input.
This is convenient as the shell consumes no CPU time while waiting; the
test is performed by the operating system. Giving the option -z to any
of the forms of tcp_open prevents the handler from being installed, so
data must be read explicitly. Note, however, this is not necessary for
executing complete sets of send and read commands from a function, as
zle is not active at this point. Generally speaking, the handler is only
active when the shell is waiting for input at a command prompt or in the
vared builtin. The option has no effect if zle is not active; [[ -o
zle]] will test for this.</p>
2021-05-11 02:29:21 +02:00
<p>The first session to be opened becomes the current session and
2022-08-24 15:22:41 +02:00
subsequent calls to tcp_open do not change it. The current session is
stored in the parameter $TCP_SESS; see below for more detail about the
2021-05-11 02:29:21 +02:00
parameters used by the system.</p>
2022-08-24 15:22:41 +02:00
<p>The function tcp_on_open, if defined, is called when a session is
2021-05-11 02:29:21 +02:00
opened. See the description below.</p>
<p><span id="index-tcp_005fclose"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_close [ -qn ] [ -a | -l <code>sess</code>[,...] | <code>sess</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>Close the named sessions, or the current session if none is given, or
2022-08-24 15:22:41 +02:00
all open sessions if -a is given. The options -l and -s are both handled
for consistency with tcp_open, although the latter is redundant.</p>
<p>If the session being closed is the current one, $TCP_SESS is unset,
2021-05-11 02:29:21 +02:00
leaving no current session, even if there are other sessions still open.</p>
2022-08-24 15:22:41 +02:00
<p>If the session was opened with tcp_open -f, the file descriptor is
2021-05-11 02:29:21 +02:00
closed so long as it is in the range 0 to 9 accessible directly from the
2022-08-24 15:22:41 +02:00
command line. If the option -n is given, no attempt will be made to
close file descriptors in this case. The -n option is not used for
genuine ztcp session; the file descriptors are always closed with the
2021-05-11 02:29:21 +02:00
session.</p>
2022-08-24 15:22:41 +02:00
<p>If the option -q is given, no informational messages will be printed.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-tcp_005fread"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_read [ -bdq ] [ -t <code>TO</code> ] [ -T <code>TO</code> ]</p>
<p>         [ -a | -u <code>fd</code>[,...] | -l <code>sess</code>[,...] | -s <code>sess</code> ...
]</p>
2021-05-11 02:29:21 +02:00
<p>Perform a read operation on the current session, or on a list of
2022-08-24 15:22:41 +02:00
sessions if any are given with -u, -l or -s, or all open sessions if the
option -a is given. Any of the -u, -l or -s options may be repeated or
mixed together. The -u option specifies a file descriptor directly (only
those managed by this system are useful), the other two specify sessions
as described for tcp_open above.</p>
2021-05-11 02:29:21 +02:00
<p>The function checks for new data available on all the sessions listed.
2022-08-24 15:22:41 +02:00
Unless the -b option is given, it will not block waiting for new data.
2021-05-11 02:29:21 +02:00
Any one line of data from any of the available sessions will be read,
2022-08-24 15:22:41 +02:00
stored in the parameter $TCP_LINE, and displayed to standard output
unless $TCP_SILENT contains a non-empty string. When printed to standard
output the string $TCP_PROMPT will be shown at the start of the line;
the default form for this includes the name of the session being read.
See below for more information on these parameters. In this mode,
tcp_read can be called repeatedly until it returns status 2 which
indicates all pending input from all specified sessions has been
2021-05-11 02:29:21 +02:00
handled.</p>
2022-08-24 15:22:41 +02:00
<p>With the option -b, equivalent to an infinite timeout, the function will
block until a line is available to read from one of the specified
2021-05-11 02:29:21 +02:00
sessions. However, only a single line is returned.</p>
2022-08-24 15:22:41 +02:00
<p>The option -d indicates that all pending input should be drained. In
this case tcp_read may process multiple lines in the manner given above;
only the last is stored in $TCP_LINE, but the complete set is stored in
the array $tcp_lines. This is cleared at the start of each call to
tcp_read.</p>
<p>The options -t and -T specify a timeout in seconds, which may be a
floating point number for increased accuracy. With -t the timeout is
applied before each line read. With -T, the timeout applies to the
2021-05-11 02:29:21 +02:00
overall operation, possibly including multiple read operations if the
2022-08-24 15:22:41 +02:00
option -d is present; without this option, there is no distinction
between -t and -T.</p>
<p>The function does not print informational messages, but if the option -q
is given, no error message is printed for a non-existent session.</p>
2021-05-11 02:29:21 +02:00
<p>A return status of 2 indicates a timeout or no data to read. Any other
non-zero return status indicates some error condition.</p>
2022-08-24 15:22:41 +02:00
<p>See tcp_log for how to control where data is sent by tcp_read.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-tcp_005fsend"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_send [ -cnq ] [ -s <code>sess</code> | -l <code>sess</code>[,...] ] <code>data</code> ...</p>
<p>tcp_send [ -cnq ] -a <code>data</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>Send the supplied data strings to all the specified sessions in turn.
2022-08-24 15:22:41 +02:00
The underlying operation differs little from a print -r to the
2021-05-11 02:29:21 +02:00
sessions file descriptor, although it attempts to prevent the shell
2022-08-24 15:22:41 +02:00
from dying owing to a SIGPIPE caused by an attempt to write to a defunct
session.</p>
<p>The option -c causes tcp_send to behave like cat. It reads lines from
standard input until end of input and sends them in turn to the
2021-05-11 02:29:21 +02:00
specified session(s) exactly as if they were given as <code>data</code> arguments
2022-08-24 15:22:41 +02:00
to individual tcp_send commands.</p>
<p>The option -n prevents tcp_send from putting a newline at the end of the
data strings.</p>
<p>The remaining options all behave as for tcp_read.</p>
2021-05-11 02:29:21 +02:00
<p>The data arguments are not further processed once they have been passed
2022-08-24 15:22:41 +02:00
to tcp_send; they are simply passed down to print -r.</p>
<p>If the parameter $TCP_OUTPUT is a non-empty string and logging is
2021-05-11 02:29:21 +02:00
enabled then the data sent to each session will be echoed to the log
2022-08-24 15:22:41 +02:00
file(s) with $TCP_OUTPUT in front where appropriate, much in the manner
of $TCP_PROMPT.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Session-Management"></span></p>
<h3 id="2422-session-management"><a class="header" href="#2422-session-management">24.2.2 Session Management</a></h3>
<p><span id="index-tcp_005falias"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_alias [ -q ] <code>alias</code>=<code>sess</code> ...</p>
<p>tcp_alias [ -q ] [ <code>alias</code> ... ]</p>
<p>tcp_alias -d [ -q ] <code>alias</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>This function is not particularly well tested.</p>
<p>The first form creates an alias for a session name; <code>alias</code> can then be
used to refer to the existing session <code>sess</code>. As many aliases may be
listed as required.</p>
<p>The second form lists any aliases specified, or all aliases if none.</p>
<p>The third form deletes all the aliases listed. The underlying sessions
are not affected.</p>
2022-08-24 15:22:41 +02:00
<p>The option -q suppresses an inconsistently chosen subset of error
2021-05-11 02:29:21 +02:00
messages.</p>
<p><span id="index-tcp_005flog"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_log [ -asc ] [ -n | -N ] [ <code>logfile</code> ]</p>
<p>With an argument <code>logfile</code>, all future input from tcp_read will be
logged to the named file. Unless -a (append) is given, this file will
2021-05-11 02:29:21 +02:00
first be truncated or created empty. With no arguments, show the current
status of logging.</p>
2022-08-24 15:22:41 +02:00
<p>With the option -s, per-session logging is enabled. Input from tcp_read
is output to the file <code>logfile</code>.<code>sess</code>. As the session is automatically
discriminated by the filename, the contents are raw (no $TCP_PROMPT).
The option -a applies as above. Per-session logging and logging of all
data in one file are not mutually exclusive.</p>
<p>The option -c closes all logging, both complete and per-session logs.</p>
<p>The options -n and -N respectively turn off or restore output of data
read by tcp_read to standard output; hence tcp_log -cn turns off all
output by tcp_read.</p>
2021-05-11 02:29:21 +02:00
<p>The function is purely a convenient front end to setting the parameters
2022-08-24 15:22:41 +02:00
$TCP_LOG, $TCP_LOG_SESS, $TCP_SILENT, which are described below.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-tcp_005frename"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_rename <code>old</code> <code>new</code></p>
2021-05-11 02:29:21 +02:00
<p>Rename session <code>old</code> to session <code>new</code>. The old name becomes invalid.</p>
<p><span id="index-tcp_005fsess"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_sess [ <code>sess</code> [ <code>command</code> [ <code>arg</code> ... ] ] ]</p>
2021-05-11 02:29:21 +02:00
<p>With no arguments, list all the open sessions and associated file
descriptors. The current session is marked with a star. For use in
2022-08-24 15:22:41 +02:00
functions, direct access to the parameters $tcp_by_name, $tcp_by_fd and
$TCP_SESS is probably more convenient; see below.</p>
2021-05-11 02:29:21 +02:00
<p>With a <code>sess</code> argument, set the current session to <code>sess</code>. This is
2022-08-24 15:22:41 +02:00
equivalent to changing $TCP_SESS directly.</p>
2021-05-11 02:29:21 +02:00
<p>With additional arguments, temporarily set the current session while
executing <code>command</code> <code>arg</code> .... <code>command</code> is re-evaluated so as to
expand aliases etc., but the remaining <code>arg</code>s are passed through as that
2022-08-24 15:22:41 +02:00
appear to tcp_sess. The original session is restored when tcp_sess
2021-05-11 02:29:21 +02:00
exits.</p>
<hr />
<p><span id="Advanced-I_002fO"></span></p>
<h3 id="2423-advanced-io"><a class="header" href="#2423-advanced-io">24.2.3 Advanced I/O</a></h3>
<p><span id="index-tcp_005fcommand"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_command <code>send-option</code> ... <code>send-argument</code> ...</p>
<p>This is a convenient front-end to tcp_send. All arguments are passed to
tcp_send, then the function pauses waiting for data. While data is
arriving at least every $TCP_TIMEOUT (default 0.3) seconds, data is
2021-05-11 02:29:21 +02:00
handled and printed out according to the current settings. Status 0 is
always returned.</p>
<p>This is generally only useful for interactive use, to prevent the
display becoming fragmented by output returned from the connection.
Within a programme or function it is generally better to handle reading
data by a more explicit method.</p>
<p><span id="index-tcp_005fexpect"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_expect [ -q ] [ -p <code>var</code> | -P <code>var</code> ] [ -t <code>TO</code> | -T <code>TO</code> ]</p>
<p>           [ -a | -s <code>sess</code> | -l <code>sess</code>[,...] ] <code>pattern</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>Wait for input matching any of the given <code>pattern</code>s from any of the
specified sessions. Input is ignored until an input line matches one of
the given patterns; at this point status zero is returned, the matching
2022-08-24 15:22:41 +02:00
line is stored in $TCP_LINE, and the full set of lines read during the
call to tcp_expect is stored in the array $tcp_expect_lines.</p>
<p>Sessions are specified in the same way as tcp_read: the default is to
use the current session, otherwise the sessions specified by -a, -s, or
-l are used.</p>
2021-05-11 02:29:21 +02:00
<p>Each <code>pattern</code> is a standard zsh extended-globbing pattern; note that it
needs to be quoted to avoid it being expanded immediately by filename
generation. It must match the full line, so to match a substring there
2022-08-24 15:22:41 +02:00
must be a * at the start and end. The line matched against includes
the $TCP_PROMPT added by tcp_read. It is possible to include the
globbing flags #b or #m in the patterns to make backreferences
available in the parameters $MATCH, $match, etc., as described in the
base zsh documentation on pattern matching.</p>
<p>Unlike tcp_read, the default behaviour of tcp_expect is to block
2021-05-11 02:29:21 +02:00
indefinitely until the required input is found. This can be modified by
2022-08-24 15:22:41 +02:00
specifying a timeout with -t or -T; these function as in tcp_read,
2021-05-11 02:29:21 +02:00
specifying a per-read or overall timeout, respectively, in seconds, as
2022-08-24 15:22:41 +02:00
an integer or floating-point number. As tcp_read, the function returns
2021-05-11 02:29:21 +02:00
status 2 if a timeout occurs.</p>
<p>The function returns as soon as any one of the patterns given match. If
2022-08-24 15:22:41 +02:00
the caller needs to know which of the patterns matched, the option -p
<code>var</code> can be used; on return, $var is set to the number of the pattern
2021-05-11 02:29:21 +02:00
using ordinary zsh indexing, i.e. the first is 1, and so on. Note the
2022-08-24 15:22:41 +02:00
absence of a $ in front of <code>var</code>. To avoid clashes, the parameter
cannot begin with _expect. The index -1 is used if there is a timeout
and 0 if there is no match.</p>
<p>The option -P <code>var</code> works similarly to -p, but instead of numerical
2021-05-11 02:29:21 +02:00
indexes the regular arguments must begin with a prefix followed by a
colon: that prefix is then used as a tag to which <code>var</code> is set when the
2022-08-24 15:22:41 +02:00
argument matches. The tag timeout is used if there is a timeout and the
empty string if there is no match. Note it is matches do not need to be
distinguished.</p>
<p>The option -q is passed directly down to tcp_read.</p>
<p>As all input is done via tcp_read, all the usual rules about output of
lines read apply. One exception is that the parameter $tcp_lines will
only reflect the line actually matched by tcp_expect; use
$tcp_expect_lines for the full set of lines read during the function
2021-05-11 02:29:21 +02:00
call.</p>
<p><span id="index-tcp_005fproxy"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_proxy</p>
2021-05-11 02:29:21 +02:00
<p>This is a simple-minded function to accept a TCP connection and execute
a command with I/O redirected to the connection. Extreme caution should
be taken as there is no security whatsoever and this can leave your
computer open to the world. Ideally, it should only be used behind a
firewall.</p>
<p>The first argument is a TCP port on which the function will listen.</p>
<p>The remaining arguments give a command and its arguments to execute with
standard input, standard output and standard error redirected to the
file descriptor on which the TCP session has been accepted. If no
command is given, a new zsh is started. This gives everyone on your
network direct access to your account, which in many cases will be a bad
thing.</p>
2022-08-24 15:22:41 +02:00
<p>The command is run in the background, so tcp_proxy can then accept new
2021-05-11 02:29:21 +02:00
connections. It continues to accept new connections until interrupted.</p>
<p><span id="index-tcp_005fspam"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_spam [ -ertv ] [ -a | -s <code>sess</code> | -l <code>sess</code>[,...] ] <code>cmd</code> [
<code>arg</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>Execute <code>cmd</code> [ <code>arg</code> ... ] for each session in turn. Note this
executes the command and arguments; it does not send the command line as
2022-08-24 15:22:41 +02:00
data unless the -t (transmit) option is given.</p>
<p>The sessions may be selected explicitly with the standard -a, -s or -l
options, or may be chosen implicitly. If none of the three options is
given the rules are: first, if the array $tcp_spam_list is set, this is
taken as the list of sessions, otherwise all sessions are taken. Second,
any sessions given in the array $tcp_no_spam_list are removed from the
list of sessions.</p>
<p>Normally, any sessions added by the -a flag or when all sessions are
2021-05-11 02:29:21 +02:00
chosen implicitly are spammed in alphabetic order; sessions given by the
2022-08-24 15:22:41 +02:00
$tcp_spam_list array or on the command line are spammed in the order
given. The -r flag reverses the order however it was arrived it.</p>
<p>The -v flag specifies that a $TCP_PROMPT will be output before each
session. This is output after any modification to TCP_SESS by the
user-defined tcp_on_spam function described below. (Obviously that
2021-05-11 02:29:21 +02:00
function is able to generate its own output.)</p>
2022-08-24 15:22:41 +02:00
<p>If the option -e is present, the line given as <code>cmd</code> [ <code>arg</code> ... ]
is executed using eval, otherwise it is executed without any further
2021-05-11 02:29:21 +02:00
processing.</p>
<p><span id="index-tcp_005ftalk"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_talk</p>
2021-05-11 02:29:21 +02:00
<p>This is a fairly simple-minded attempt to force input to the line editor
2022-08-24 15:22:41 +02:00
to go straight to the default TCP_SESS.</p>
<p>An escape string, $TCP_TALK_ESCAPE, default :, is used to allow access
to normal shell operation. If it is on its own at the start of the line,
or followed only by whitespace, the line editor returns to normal
operation. Otherwise, the string and any following whitespace are
2021-05-11 02:29:21 +02:00
skipped and the remainder of the line executed as shell input without
any change of the line editors operating mode.</p>
<p>The current implementation is somewhat deficient in terms of use of the
command history. For this reason, many users will prefer to use some
form of alternative approach for sending data easily to the current
session. One simple approach is to alias some special character (such as
2022-08-24 15:22:41 +02:00
%) to tcp_command --.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-tcp_005fwait"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_wait</p>
2021-05-11 02:29:21 +02:00
<p>The sole argument is an integer or floating point number which gives the
seconds to delay. The shell will do nothing for that period except wait
2022-08-24 15:22:41 +02:00
for input on all TCP sessions by calling tcp_read -a. This is similar to
the interactive behaviour at the command prompt when zle handlers are
2021-05-11 02:29:21 +02:00
installed.</p>
<hr />
<p><span id="g_t_0060One_002dshot_0027-file-transfer"></span></p>
<h3 id="2424-one-shot-file-transfer"><a class="header" href="#2424-one-shot-file-transfer">24.2.4 One-shot file transfer</a></h3>
2022-08-24 15:22:41 +02:00
<p>tcp_point <code>port</code><br />
tcp_shoot <code>host</code> <code>port</code><br />
This pair of functions provide a simple way to transfer a file between
two hosts within the shell. Note, however, that bulk data transfer is
currently done using cat. tcp_point reads any data arriving at <code>port</code>
and sends it to standard output; tcp_shoot connects to <code>port</code> on <code>host</code>
and sends its standard input. Any unused <code>port</code> may be used; the
standard mechanism for picking a port is to think of a random four-digit
number above 1024 until one works.</p>
<p>To transfer a file from host woodcock to host springes, on springes:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">tcp_point 8091 &gt;output_file
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>and on woodcock:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">tcp_shoot springes 8091 &lt;input_file
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>As these two functions do not require tcp_open to set up a TCP
2021-05-11 02:29:21 +02:00
connection first, they may need to be autoloaded separately.</p>
<hr />
<p><span id="TCP-User_002ddefined-Functions"></span></p>
<h2 id="243-tcp-user-defined-functions"><a class="header" href="#243-tcp-user-defined-functions">24.3 TCP User-defined Functions</a></h2>
<p>Certain functions, if defined by the user, will be called by the
function system in certain contexts. This facility depends on the module
2022-08-24 15:22:41 +02:00
zsh/parameter, which is usually available in interactive shells as the
2021-05-11 02:29:21 +02:00
completion system depends on it. None of the functions need be defined;
they simply provide convenient hooks when necessary.</p>
<p>Typically, these are called after the requested action has been taken,
so that the various parameters will reflect the new state.</p>
<p><span id="index-tcp_005fon_005falias"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_on_alias <code>alias</code> <code>fd</code></p>
2021-05-11 02:29:21 +02:00
<p>When an alias is defined, this function will be called with two
arguments: the name of the alias, and the file descriptor of the
corresponding session.</p>
<p><span id="index-tcp_005fon_005fawol"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_on_awol <code>sess</code> <code>fd</code></p>
<p>If the function tcp_fd_handler is handling input from the line editor
2021-05-11 02:29:21 +02:00
and detects that the file descriptor is no longer reusable, by default
it removes it from the list of file descriptors handled by this method
2022-08-24 15:22:41 +02:00
and prints a message. If the function tcp_on_awol is defined it is
2021-05-11 02:29:21 +02:00
called immediately before this point. It may return status 100, which
indicates that the normal handling should still be performed; any other
return status indicates that no further action should be taken and the
2022-08-24 15:22:41 +02:00
tcp_fd_handler should return immediately with the given status.
Typically the action of tcp_on_awol will be to close the session.</p>
<p>The variable TCP_INVALIDATE_ZLE will be a non-empty string if it is
necessary to invalidate the line editor display using zle -I before
2021-05-11 02:29:21 +02:00
printing output from the function.</p>
<p>(AWOL is military jargon for absent without leave or some variation.
It has no pre-existing technical meaning known to the author.)</p>
<p><span id="index-tcp_005fon_005fclose"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_on_close <code>sess</code> <code>fd</code></p>
2021-05-11 02:29:21 +02:00
<p>This is called with the name of a session being closed and the file
descriptor which corresponded to that session. Both will be invalid by
the time the function is called.</p>
<p><span id="index-tcp_005fon_005fopen"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_on_open <code>sess</code> <code>fd</code></p>
2021-05-11 02:29:21 +02:00
<p>This is called after a new session has been defined with the session
name and file descriptor as arguments. If it returns a non-zero status,
opening the session is assumed to fail and the session is closed again;
2022-08-24 15:22:41 +02:00
however, tcp_open will continue to attempt to open any remaining
2021-05-11 02:29:21 +02:00
sessions given on the command line.</p>
<p><span id="index-tcp_005fon_005frename"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_on_rename <code>oldsess</code> <code>fd</code> <code>newsess</code></p>
2021-05-11 02:29:21 +02:00
<p>This is called after a session has been renamed with the three arguments
old session name, file descriptor, new session name.</p>
<p><span id="index-tcp_005fon_005fspam"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_on_spam <code>sess</code> <code>command ...</code></p>
2021-05-11 02:29:21 +02:00
<p>This is called once for each session spammed, just <em>before</em> a command is
2022-08-24 15:22:41 +02:00
executed for a session by tcp_spam. The arguments are the session name
followed by the command list to be executed. If tcp_spam was called with
the option -t, the first command will be tcp_send.</p>
<p>This function is called after $TCP_SESS is set to reflect the session to
be spammed, but before any use of it is made. Hence it is possible to
alter the value of $TCP_SESS within this function. For example, the
session arguments to tcp_spam could include extra information to be
stripped off and processed in tcp_on_spam.</p>
<p>If the function sets the parameter $REPLY to done, the command line is
not executed; in addition, no prompt is printed for the -v option to
tcp_spam.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-tcp_005fon_005funalias"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_on_unalias <code>alias</code> <code>fd</code></p>
2021-05-11 02:29:21 +02:00
<p>This is called with the name of an alias and the corresponding sessions
file descriptor after an alias has been deleted.</p>
<hr />
<p><span id="TCP-Utility-Functions"></span></p>
<h2 id="244-tcp-utility-functions"><a class="header" href="#244-tcp-utility-functions">24.4 TCP Utility Functions</a></h2>
<p>The following functions are used by the TCP function system but will
rarely if ever need to be called directly.</p>
<p><span id="index-tcp_005ffd_005fhandler"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_fd_handler</p>
<p>This is the function installed by tcp_open for handling input from
2021-05-11 02:29:21 +02:00
within the line editor, if that is required. It is in the format
2022-08-24 15:22:41 +02:00
documented for the builtin zle -F in <a href="Zsh-Line-Editor.html#Zle-Builtins">Zle
2021-05-11 02:29:21 +02:00
Builtins</a> .</p>
2022-08-24 15:22:41 +02:00
<p>While active, the function sets the parameter TCP_HANDLER_ACTIVE to 1.
2021-05-11 02:29:21 +02:00
This allows shell code called internally (for example, by setting
2022-08-24 15:22:41 +02:00
tcp_on_read) to tell if is being called when the shell is otherwise idle
at the editor prompt.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-tcp_005foutput"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_output [ -q ] -P <code>prompt</code> -F <code>fd</code> -S <code>sess</code></p>
2021-05-11 02:29:21 +02:00
<p>This function is used for both logging and handling output to standard
2022-08-24 15:22:41 +02:00
output, from within tcp_read and (if $TCP_OUTPUT is set) tcp_send.</p>
<p>The <code>prompt</code> to use is specified by -P; the default is the empty string.
It can contain:</p>
<p>%c<br />
Expands to 1 if the session is the current session, otherwise 0. Used
with ternary expressions such as %(c.-.+) to output + for the
current session and - otherwise.</p>
<p>%f<br />
2021-05-11 02:29:21 +02:00
Replaced by the sessions file descriptor.</p>
2022-08-24 15:22:41 +02:00
<p>%s<br />
2021-05-11 02:29:21 +02:00
Replaced by the session name.</p>
2022-08-24 15:22:41 +02:00
<p>%%<br />
Replaced by a single %.</p>
<p>The option -q suppresses output to standard output, but not to any log
2021-05-11 02:29:21 +02:00
files which are configured.</p>
2022-08-24 15:22:41 +02:00
<p>The -S and -F options are used to pass in the session name and file
2021-05-11 02:29:21 +02:00
descriptor for possible replacement in the prompt.</p>
<hr />
<p><span id="TCP-Parameters"></span> <span id="TCP-User-Parameters"></span></p>
<h2 id="245-tcp-user-parameters"><a class="header" href="#245-tcp-user-parameters">24.5 TCP User Parameters</a></h2>
<p>Parameters follow the usual convention that uppercase is used for
scalars and integers, while lowercase is used for normal and associative
array. It is always safe for user code to read these parameters. Some
parameters may also be set; these are noted explicitly. Others are
included in this group as they are set by the function system for the
users benefit, i.e. setting them is typically not useful but is benign.</p>
2022-08-24 15:22:41 +02:00
<p>For example, local TCP_SILENT=1 specifies that data read during the
2021-05-11 02:29:21 +02:00
function call will not be printed to standard output, regardless of the
2022-08-24 15:22:41 +02:00
setting outside the function. Likewise, local TCP_SESS=<code>sess</code> sets a
session for the duration of a function, and local TCP_PROMPT=
2021-05-11 02:29:21 +02:00
specifies that no prompt is used for input during the function.</p>
<p><span id="index-tcp_005fexpect_005flines"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_expect_lines</p>
<p>Array. The set of lines read during the last call to tcp_expect,
including the last ($TCP_LINE).</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-tcp_005ffilter"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_filter</p>
2021-05-11 02:29:21 +02:00
<p>Array. May be set directly. A set of extended globbing patterns which,
2022-08-24 15:22:41 +02:00
if matched in tcp_output, will cause the line not to be printed to
2021-05-11 02:29:21 +02:00
standard output. The patterns should be defined as described for the
2022-08-24 15:22:41 +02:00
arguments to tcp_expect. Output of line to log files is not affected.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-TCP_005fHANDLER_005fACTIVE"></span></p>
2022-08-24 15:22:41 +02:00
<p>TCP_HANDLER_ACTIVE</p>
<p>Scalar. Set to 1 within tcp_fd_handler to indicate to functions called
2021-05-11 02:29:21 +02:00
recursively that they have been called during an editor session.
Otherwise unset.</p>
<p><span id="index-TCP_005fLINE"></span></p>
2022-08-24 15:22:41 +02:00
<p>TCP_LINE</p>
<p>The last line read by tcp_read, and hence also tcp_expect.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-TCP_005fLINE_005fFD"></span></p>
2022-08-24 15:22:41 +02:00
<p>TCP_LINE_FD</p>
<p>The file descriptor from which $TCP_LINE was read.
${tcp_by_fd[$TCP_LINE_FD]} will give the corresponding session name.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-tcp_005flines"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_lines</p>
<p>Array. The set of lines read during the last call to tcp_read, including
the last ($TCP_LINE).</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-TCP_005fLOG"></span></p>
2022-08-24 15:22:41 +02:00
<p>TCP_LOG</p>
<p>May be set directly, although it is also controlled by tcp_log. The name
of a file to which output from all sessions will be sent. The output is
proceeded by the usual $TCP_PROMPT. If it is not an absolute path name,
it will follow the users current directory.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-TCP_005fLOG_005fSESS"></span></p>
2022-08-24 15:22:41 +02:00
<p>TCP_LOG_SESS</p>
<p>May be set directly, although it is also controlled by tcp_log. The
2021-05-11 02:29:21 +02:00
prefix for a set of files to which output from each session separately
2022-08-24 15:22:41 +02:00
will be sent; the full filename is ${TCP_LOG_SESS}.<code>sess</code>. Output to
2021-05-11 02:29:21 +02:00
each file is raw; no prompt is added. If it is not an absolute path
name, it will follow the users current directory.</p>
<p><span id="index-tcp_005fno_005fspam_005flist"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_no_spam_list</p>
<p>Array. May be set directly. See tcp_spam for how this is used.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-TCP_005fOUTPUT"></span></p>
2022-08-24 15:22:41 +02:00
<p>TCP_OUTPUT</p>
2021-05-11 02:29:21 +02:00
<p>May be set directly. If a non-empty string, any data sent to a session
2022-08-24 15:22:41 +02:00
by tcp_send will be logged. This parameter gives the prompt to be used
in a file specified by $TCP_LOG but not in a file generated from
$TCP_LOG_SESS. The prompt string has the same format as TCP_PROMPT and
the same rules for its use apply.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-TCP_005fPROMPT"></span></p>
2022-08-24 15:22:41 +02:00
<p>TCP_PROMPT</p>
<p>May be set directly. Used as the prefix for data read by tcp_read which
is printed to standard output or to the log file given by $TCP_LOG, if
any. Any %s, %f or %% occurring in the string will be replaced by
the name of the session, the sessions underlying file descriptor, or a
single %, respectively. The expression %c expands to 1 if the
session being read is the current session, else 0; this is most useful
in ternary expressions such as %(c.-.+) which outputs + if the
session is the current one, else -.</p>
<p>If the prompt starts with %P, this is stripped and the complete result
of the previous stage is passed through standard prompt %-style
2021-05-11 02:29:21 +02:00
formatting before being output.</p>
<p><span id="index-TCP_005fREAD_005fDEBUG"></span></p>
2022-08-24 15:22:41 +02:00
<p>TCP_READ_DEBUG</p>
<p>May be set directly. If this has non-zero length, tcp_read will give
2021-05-11 02:29:21 +02:00
some limited diagnostics about data being read.</p>
<p><span id="index-TCP_005fSECONDS_005fSTART"></span></p>
2022-08-24 15:22:41 +02:00
<p>TCP_SECONDS_START</p>
2021-05-11 02:29:21 +02:00
<p>This value is created and initialised to zero by tcp_open.</p>
2022-08-24 15:22:41 +02:00
<p>The functions tcp_read and tcp_expect use the shells SECONDS parameter
for their own timing purposes. If that parameter is not of floating
point type on entry to one of the functions, it will create a local
parameter SECONDS which is floating point and set the parameter
TCP_SECONDS_START to the previous value of $SECONDS. If the parameter is
already floating point, it is used without a local copy being created
and TCP_SECONDS_START is not set. As the global value is zero, the shell
elapsed time is guaranteed to be the sum of $SECONDS and
$TCP_SECONDS_START.</p>
<p>This can be avoided by setting SECONDS globally to a floating point
value using typeset -F SECONDS; then the TCP functions will never make
a local copy and never set TCP_SECONDS_START to a non-zero value.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-TCP_005fSESS"></span></p>
2022-08-24 15:22:41 +02:00
<p>TCP_SESS</p>
2021-05-11 02:29:21 +02:00
<p>May be set directly. The current session; must refer to one of the
2022-08-24 15:22:41 +02:00
sessions established by tcp_open.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-TCP_005fSILENT"></span></p>
2022-08-24 15:22:41 +02:00
<p>TCP_SILENT</p>
<p>May be set directly, although it is also controlled by tcp_log. If of
non-zero length, data read by tcp_read will not be written to standard
2021-05-11 02:29:21 +02:00
output, though may still be written to a log file.</p>
<p><span id="index-tcp_005fspam_005flist"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_spam_list</p>
<p>Array. May be set directly. See the description of the function tcp_spam
for how this is used.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-TCP_005fTALK_005fESCAPE"></span></p>
2022-08-24 15:22:41 +02:00
<p>TCP_TALK_ESCAPE</p>
<p>May be set directly. See the description of the function tcp_talk for
2021-05-11 02:29:21 +02:00
how this is used.</p>
<p><span id="index-TCP_005fTIMEOUT"></span></p>
2022-08-24 15:22:41 +02:00
<p>TCP_TIMEOUT</p>
2021-05-11 02:29:21 +02:00
<p>May be set directly. Currently this is only used by the function
2022-08-24 15:22:41 +02:00
tcp_command, see above.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="TCP-User_002ddefined-Parameters"></span></p>
<h2 id="246-tcp-user-defined-parameters"><a class="header" href="#246-tcp-user-defined-parameters">24.6 TCP User-defined Parameters</a></h2>
<p>The following parameters are not set by the function system, but have a
special effect if set by the user.</p>
<p><span id="index-tcp_005fon_005fread"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_on_read</p>
2021-05-11 02:29:21 +02:00
<p>This should be an associative array; if it is not, the behaviour is
undefined. Each key is the name of a shell function or other command,
2022-08-24 15:22:41 +02:00
and the corresponding value is a shell pattern (using EXTENDED_GLOB).
Every line read from a TCP session directly or indirectly using tcp_read
(which includes lines read by tcp_expect) is compared against the
pattern. If the line matches, the command given in the key is called
with two arguments: the name of the session from which the line was
read, and the line itself.</p>
2021-05-11 02:29:21 +02:00
<p>If any function called to handle a line returns a non-zero status, the
2022-08-24 15:22:41 +02:00
line is not output. Thus a tcp_on_read handler containing only the
instruction return 1 can be used to suppress output of particular
lines (see, however, tcp_filter above). However, the line is still
stored in TCP_LINE and tcp_lines; this occurs after all tcp_on_read
processing.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="TCP-Utility-Parameters"></span></p>
<h2 id="247-tcp-utility-parameters"><a class="header" href="#247-tcp-utility-parameters">24.7 TCP Utility Parameters</a></h2>
<p>These parameters are controlled by the function system; they may be read
directly, but should not usually be set by user code.</p>
<p><span id="index-tcp_005faliases"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_aliases</p>
2021-05-11 02:29:21 +02:00
<p>Associative array. The keys are the names of sessions established with
2022-08-24 15:22:41 +02:00
tcp_open; each value is a space-separated list of aliases which refer to
that session.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-tcp_005fby_005ffd"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_by_fd</p>
2021-05-11 02:29:21 +02:00
<p>Associative array. The keys are session file descriptors; each value is
the name of that session.</p>
<p><span id="index-tcp_005fby_005fname"></span></p>
2022-08-24 15:22:41 +02:00
<p>tcp_by_name</p>
2021-05-11 02:29:21 +02:00
<p>Associative array. The keys are the names of sessions; each value is the
file descriptor associated with that session.</p>
<hr />
<p><span id="TCP-Examples"></span> <span id="TCP-Examples-1"></span></p>
<h2 id="248-tcp-examples"><a class="header" href="#248-tcp-examples">24.8 TCP Examples</a></h2>
<p>Here is a trivial example using a remote calculator.</p>
2022-08-24 15:22:41 +02:00
<p>To create a calculator server on port 7337 (see the dc manual page for
2021-05-11 02:29:21 +02:00
quite how infuriating the underlying command is):</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">tcp_proxy 7337 dc
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>To connect to this from the same host with a session also named dc:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">tcp_open localhost 7337 dc
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>To send a command to the remote session and wait a short while for
2022-08-24 15:22:41 +02:00
output (assuming dc is the current session):</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">tcp_command 2 4 + p
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>To close the session:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">tcp_close
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The tcp_proxy needs to be killed to be stopped. Note this will not
2021-05-11 02:29:21 +02:00
usually kill any connections which have already been accepted, and also
that the port is not immediately available for reuse.</p>
<p>The following chunk of code puts a list of sessions into an xterm
header, with the current session followed by a star.</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">print -n &quot;\033]2;TCP:&quot; ${(k)tcp_by_name:/$TCP_SESS/$TCP_SESS\*} &quot;\a&quot;
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<hr />
<p><span id="TCP-Bugs"></span> <span id="TCP-Bugs-1"></span></p>
<h2 id="249-tcp-bugs"><a class="header" href="#249-tcp-bugs">24.9 TCP Bugs</a></h2>
2022-08-24 15:22:41 +02:00
<p>The function tcp_read uses the shells normal read builtin. As this
2021-05-11 02:29:21 +02:00
reads a complete line at once, data arriving without a terminating
newline can cause the function to block indefinitely.</p>
<p>Though the function suite works well for interactive use and for data
arriving in small amounts, the performance when large amounts of data
are being exchanged is likely to be extremely poor.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="Zftp-Function-System.html#25-zftp-function-system">25 Zftp Function System</a>
<ul>
<li><a href="Zftp-Function-System.html#251-description">25.1 Description</a></li>
<li><a href="Zftp-Function-System.html#252-installation">25.2 Installation</a></li>
<li><a href="Zftp-Function-System.html#253-functions">25.3 Functions</a>
<ul>
<li><a href="Zftp-Function-System.html#2531-opening-a-connection">25.3.1 Opening a connection</a></li>
<li><a href="Zftp-Function-System.html#2532-directory-management">25.3.2 Directory management</a></li>
<li><a href="Zftp-Function-System.html#2533-status-commands">25.3.3 Status commands</a></li>
<li><a href="Zftp-Function-System.html#2534-retrieving-files">25.3.4 Retrieving files</a></li>
<li><a href="Zftp-Function-System.html#2535-sending-files">25.3.5 Sending files</a></li>
<li><a href="Zftp-Function-System.html#2536-closing-the-connection">25.3.6 Closing the connection</a></li>
<li><a href="Zftp-Function-System.html#2537-session-management">25.3.7 Session management</a></li>
<li><a href="Zftp-Function-System.html#2538-bookmarks">25.3.8 Bookmarks</a></li>
<li><a href="Zftp-Function-System.html#2539-other-functions">25.3.9 Other functions</a></li>
</ul>
</li>
<li><a href="Zftp-Function-System.html#254-miscellaneous-features">25.4 Miscellaneous Features</a>
<ul>
<li><a href="Zftp-Function-System.html#2541-configuration">25.4.1 Configuration</a></li>
<li><a href="Zftp-Function-System.html#2542-remote-globbing">25.4.2 Remote globbing</a></li>
<li><a href="Zftp-Function-System.html#2543-automatic-and-temporary-reopening">25.4.3 Automatic and temporary reopening</a></li>
<li><a href="Zftp-Function-System.html#2544-completion">25.4.4 Completion</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2022-08-24 15:22:41 +02:00
<p><span id="Zftp-Function-System"></span> <span
id="Zftp-Function-System-1"></span></p>
2021-05-11 02:29:21 +02:00
<h1 id="25-zftp-function-system"><a class="header" href="#25-zftp-function-system">25 Zftp Function System</a></h1>
2022-08-24 15:22:41 +02:00
<p><span id="index-zftp-function-system"></span> <span
id="index-FTP_002c-functions-for-using-shell-as-client"></span></p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Description-8"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="251-description"><a class="header" href="#251-description">25.1 Description</a></h2>
<p>This describes the set of shell functions supplied with the source
2022-08-24 15:22:41 +02:00
distribution as an interface to the zftp builtin command, allowing you
2021-05-11 02:29:21 +02:00
to perform FTP operations from the shell command line or within
functions or scripts. The interface is similar to a traditional FTP
2022-08-24 15:22:41 +02:00
client (e.g. the ftp command itself, see ftp(1)), but as it is entirely
done within the shell all the familiar completion, editing and globbing
features, and so on, are present, and macros are particularly simple to
write as they are just ordinary shell functions.</p>
<p>The prerequisite is that the zftp command, as described in <a href="Zsh-Modules.html#The-zsh_002fzftp-Module">The zsh/zftp
Module</a> , must be available in
the version of zsh installed at your site. If the shell is configured to
load new commands at run time, it probably is: typing zmodload
zsh/zftp will make sure (if that runs silently, it has worked). If this
is not the case, it is possible zftp was linked into the shell anyway:
to test this, type which zftp and if zftp is available you will get
the message zftp: shell built-in command.</p>
<p>Commands given directly with zftp builtin may be interspersed between
the functions in this suite; in a few cases, using zftp directly may
2021-05-11 02:29:21 +02:00
cause some of the status information stored in shell parameters to
become invalid. Note in particular the description of the variables
2022-08-24 15:22:41 +02:00
$ZFTP_TMOUT, $ZFTP_PREFS and $ZFTP_VERBOSE for zftp.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Installation"></span> <span id="Installation-1"></span></p>
<h2 id="252-installation"><a class="header" href="#252-installation">25.2 Installation</a></h2>
2022-08-24 15:22:41 +02:00
<p>You should make sure all the functions from the Functions/Zftp directory
of the source distribution are available; they all begin with the two
letters zf. They may already have been installed on your system;
otherwise, you will need to find them and copy them. The directory
should appear as one of the elements of the $fpath array (this should
already be the case if they were installed), and at least the function
zfinit should be autoloaded; it will autoload the rest. Finally, to
initialize the use of the system you need to call the zfinit function.
The following code in your .zshrc will arrange for this; assume the
functions are stored in the directory ~/myfns:</p>
<div class="example">
<pre><code class="language-zsh">fpath=(~/myfns $fpath)
2021-05-11 02:29:21 +02:00
autoload -U zfinit
zfinit
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Note that zfinit assumes you are using the zmodload method to load the
zftp command. If it is already built into the shell, change zfinit to
zfinit -n. It is helpful (though not essential) if the call to zfinit
appears after any code to initialize the new completion system, else
unnecessary compctl commands will be given.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Zftp-Functions"></span> <span id="Functions-2"></span></p>
<h2 id="253-functions"><a class="header" href="#253-functions">25.3 Functions</a></h2>
<p>The sequence of operations in performing a file transfer is essentially
the same as that in a standard FTP client. Note that, due to a quirk of
2022-08-24 15:22:41 +02:00
the shells getopts builtin, for those functions that handle options you
must use -- rather than - to ensure the remaining arguments are
treated literally (a single - is treated as an argument).</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Opening-a-connection"></span></p>
<h3 id="2531-opening-a-connection"><a class="header" href="#2531-opening-a-connection">25.3.1 Opening a connection</a></h3>
<p><span id="index-zfparams"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfparams [ <code>host</code> [ <code>user</code> [ <code>password</code> ... ] ] ]</p>
<p>Set or show the parameters for a future zfopen with no arguments. If no
arguments are given, the current parameters are displayed (the password
will be shown as a line of asterisks). If a <code>host</code> is given, and either
the <code>user</code> or <code>password</code> is not, they will be prompted for; also, any
parameter given as ? will be prompted for, and if the ? is followed
by a string, that will be used as the prompt. As zfopen calls zfparams
to store the parameters, this usually need not be called directly.</p>
<p>A single argument - will delete the stored parameters. This will also
cause the memory of the last directory (and so on) on the other host to
be deleted.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zfopen"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfopen [ -1 ] [ <code>host</code> [ <code>user</code> [ <code>password</code> [ <code>account</code> ] ] ]
]</p>
2021-05-11 02:29:21 +02:00
<p>If <code>host</code> is present, open a connection to that host under username
<code>user</code> with password <code>password</code> (and, on the rare occasions when it is
necessary, account <code>account</code>). If a necessary parameter is missing or
2022-08-24 15:22:41 +02:00
given as ? it will be prompted for. If <code>host</code> is not present, use a
2021-05-11 02:29:21 +02:00
previously stored set of parameters.</p>
2022-08-24 15:22:41 +02:00
<p>If the command was successful, and the terminal is compatible with xterm
or is sun-cmd, a summary will appear in the title bar, giving the local
host:directory and the remote host:directory; this is handled by the
function zftp_chpwd, described below.</p>
2021-05-11 02:29:21 +02:00
<p>Normally, the <code>host</code>, <code>user</code> and <code>password</code> are internally recorded for
2022-08-24 15:22:41 +02:00
later re-opening, either by a zfopen with no arguments, or automatically
(see below). With the option -1, no information is stored. Also, if an
open command with arguments failed, the parameters will not be retained
(and any previous parameters will also be deleted). A zfopen on its own,
or a zfopen -1, never alters the stored parameters.</p>
<p>Both zfopen and zfanon (but not zfparams) understand URLs of the form
ftp://<code>host</code>/<code>path...</code> as meaning to connect to the <code>host</code>, then change
directory to <code>path</code> (which must be a directory, not a file). The
ftp:// can be omitted; the trailing / is enough to trigger
recognition of the <code>path</code>. Note prefixes other than ftp: are not
2021-05-11 02:29:21 +02:00
recognized, and that all characters after the first slash beyond <code>host</code>
are significant in <code>path</code>.</p>
<p><span id="index-zfanon"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfanon [ -1 ] <code>host</code></p>
2021-05-11 02:29:21 +02:00
<p>Open a connection <code>host</code> for anonymous FTP. The username used is
2022-08-24 15:22:41 +02:00
anonymous. The password (which will be reported the first time) is
generated as <code>user</code>@<code>host</code>; this is then stored in the shell parameter
$EMAIL_ADDR which can alternatively be set manually to a</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Directory-management"></span></p>
<h3 id="2532-directory-management"><a class="header" href="#2532-directory-management">25.3.2 Directory management</a></h3>
<p><span id="index-zfcd"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfcd [ <code>dir</code> ]</p>
<p>zfcd -</p>
<p>zfcd <code>old</code> <code>new</code></p>
2021-05-11 02:29:21 +02:00
<p>Change the current directory on the remote server: this is implemented
2022-08-24 15:22:41 +02:00
to have many of the features of the shell builtin cd.</p>
2021-05-11 02:29:21 +02:00
<p>In the first form with <code>dir</code> present, change to the directory <code>dir</code>. The
2022-08-24 15:22:41 +02:00
command zfcd .. is treated specially, so is guaranteed to work on
non-UNIX servers (note this is handled internally by zftp). If <code>dir</code> is
omitted, has the effect of zfcd ~.</p>
2021-05-11 02:29:21 +02:00
<p>The second form changes to the directory previously current.</p>
<p>The third form attempts to change the current directory by replacing the
first occurrence of the string <code>old</code> with the string <code>new</code> in the
current directory.</p>
<p>Note that in this command, and indeed anywhere a remote filename is
2022-08-24 15:22:41 +02:00
expected, the string which on the local host corresponds to ~ is
converted back to a ~ before being passed to the remote machine. This
is convenient because of the way expansion is performed on the command
line before zfcd receives a string. For example, suppose the command is
zfcd ~/foo. The shell will expand this to a full path such as zfcd
/home/user2/pws/foo. At this stage, zfcd recognises the initial path as
corresponding to ~ and will send the directory to the remote host as
~/foo, so that the ~ will be expanded by the server to the correct
remote host directory. Other named directories of the form ~name are
not treated in this fashion.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zfhere"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfhere</p>
2021-05-11 02:29:21 +02:00
<p>Change directory on the remote server to the one corresponding to the
2022-08-24 15:22:41 +02:00
current local directory, with special handling of ~ as in zfcd. For
example, if the current local directory is ~/foo/bar, then zfhere
performs the effect of zfcd ~/foo/bar.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zfdir"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfdir [ -rfd ] [ - ] [ <code>dir-options</code> ] [ <code>dir</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>Produce a long directory listing. The arguments <code>dir-options</code> and <code>dir</code>
are passed directly to the server and their effect is implementation
dependent, but specifying a particular remote directory <code>dir</code> is usually
possible. The output is passed through a pager given by the environment
2022-08-24 15:22:41 +02:00
variable $PAGER, or more if that is not set.</p>
2021-05-11 02:29:21 +02:00
<p>The directory is usually cached for re-use. In fact, two caches are
maintained. One is for use when there is no <code>dir-options</code> or <code>dir</code>, i.e.
a full listing of the current remote directory; it is flushed when the
current remote directory changes. The other is kept for repeated use of
2022-08-24 15:22:41 +02:00
zfdir with the same arguments; for example, repeated use of zfdir
/pub/gnu will only require the directory to be retrieved on the first
call. Alternatively, this cache can be re-viewed with the -r option. As
relative directories will confuse zfdir, the -f option can be used to
force the cache to be flushed before the directory is listed. The option
-d will delete both caches without showing a directory listing; it will
also delete the cache of file names in the current remote directory, if
any.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zfls"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfls [ <code>ls-options</code> ] [ <code>dir</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>List files on the remote server. With no arguments, this will produce a
simple list of file names for the current remote directory. Any
arguments are passed directly to the server. No pager and no caching is
used.</p>
<hr />
<p><span id="Status-commands"></span></p>
<h3 id="2533-status-commands"><a class="header" href="#2533-status-commands">25.3.3 Status commands</a></h3>
<p><span id="index-zftype"></span></p>
2022-08-24 15:22:41 +02:00
<p>zftype [ <code>type</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>With no arguments, show the type of data to be transferred, usually
2022-08-24 15:22:41 +02:00
ASCII or binary. With an argument, change the type: the types A or
ASCII for ASCII data and B or BINARY, I or IMAGE for binary
data are understood case-insensitively.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zfstat"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfstat [ -v ]</p>
2021-05-11 02:29:21 +02:00
<p>Show the status of the current or last connection, as well as the status
2022-08-24 15:22:41 +02:00
of some of zftps status variables. With the -v option, a more verbose
listing is produced by querying the server for its version of events,
too.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Retrieving-files"></span></p>
<h3 id="2534-retrieving-files"><a class="header" href="#2534-retrieving-files">25.3.4 Retrieving files</a></h3>
2022-08-24 15:22:41 +02:00
<p>The commands for retrieving files all take at least two options. -G
2021-05-11 02:29:21 +02:00
suppresses remote filename expansion which would otherwise be performed
2022-08-24 15:22:41 +02:00
(see below for a more detailed description of that). -t attempts to set
the modification time of the local file to that of the remote file: see
the description of the function zfrtime below for more information.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zfget"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfget [ -Gtc ] <code>file1</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>Retrieve all the listed files <code>file1</code> ... one at a time from the remote
2022-08-24 15:22:41 +02:00
server. If a file contains a /, the full name is passed to the remote
server, but the file is stored locally under the name given by the part
after the final /. The option -c (cat) forces all files to be sent as
a single stream to standard output; in this case the -t option has no
effect.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zfuget"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfuget [ -Gvst ] <code>file1</code> ...</p>
<p>As zfget, but only retrieve files where the version on the remote server
is newer (has a later modification time), or where the local file does
not exist. If the remote file is older but the files have different
2021-05-11 02:29:21 +02:00
sizes, or if the sizes are the same but the remote file is newer, the
2022-08-24 15:22:41 +02:00
user will usually be queried. With the option -s, the command runs
2021-05-11 02:29:21 +02:00
silently and will always retrieve the file in either of those two cases.
2022-08-24 15:22:41 +02:00
With the option -v, the command prints more information about the files
while it is working out whether or not to transfer them.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zfcget"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfcget [ -Gt ] <code>file1</code> ...</p>
<p>As zfget, but if any of the local files exists, and is shorter than the
corresponding remote file, the command assumes that it is the result of
a partially completed transfer and attempts to transfer the rest of the
file. This is useful on a poor connection which keeps failing.</p>
2021-05-11 02:29:21 +02:00
<p>Note that this requires a commonly implemented, but non-standard,
version of the FTP protocol, so is not guaranteed to work on all
servers.</p>
<p><span id="index-zfgcp"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfgcp [ -Gt ] <code>remote-file</code> <code>local-file</code></p>
<p>zfgcp [ -Gt ] <code>rfile1</code> ... <code>ldir</code></p>
2021-05-11 02:29:21 +02:00
<p>This retrieves files from the remote server with arguments behaving
2022-08-24 15:22:41 +02:00
similarly to the cp command.</p>
2021-05-11 02:29:21 +02:00
<p>In the first form, copy <code>remote-file</code> from the server to the local file
<code>local-file</code>.</p>
<p>In the second form, copy all the remote files <code>rfile1</code> ... into the
local directory <code>ldir</code> retaining the same basenames. This assumes UNIX
directory semantics.</p>
<hr />
<p><span id="Sending-files"></span></p>
<h3 id="2535-sending-files"><a class="header" href="#2535-sending-files">25.3.5 Sending files</a></h3>
<p><span id="index-zfput"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfput [ -r ] <code>file1</code> ...</p>
2021-05-11 02:29:21 +02:00
<p>Send all the <code>file1</code> ... given separately to the remote server. If a
2022-08-24 15:22:41 +02:00
filename contains a /, the full filename is used locally to find the
2021-05-11 02:29:21 +02:00
file, but only the basename is used for the remote file name.</p>
2022-08-24 15:22:41 +02:00
<p>With the option -r, if any of the <code>files</code> are directories they are sent
recursively with all their subdirectories, including files beginning
with .. This requires that the remote machine understand UNIX file
semantics, since / is used as a directory separator.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zfuput"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfuput [ -vs ] <code>file1</code> ...</p>
<p>As zfput, but only send files which are newer than their remote
2021-05-11 02:29:21 +02:00
equivalents, or if the remote file does not exist. The logic is the same
2022-08-24 15:22:41 +02:00
as for zfuget, but reversed between local and remote files.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zfcput"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfcput <code>file1</code> ...</p>
<p>As zfput, but if any remote file already exists and is shorter than the
local equivalent, assume it is the result of an incomplete transfer and
send the rest of the file to append to the existing part. As the FTP
2021-05-11 02:29:21 +02:00
append command is part of the standard set, this is in principle more
2022-08-24 15:22:41 +02:00
likely to work than zfcget.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zfpcp"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfpcp <code>local-file</code> <code>remote-file</code></p>
<p>zfpcp <code>lfile1</code> ... <code>rdir</code></p>
2021-05-11 02:29:21 +02:00
<p>This sends files to the remote server with arguments behaving similarly
2022-08-24 15:22:41 +02:00
to the cp command.</p>
2021-05-11 02:29:21 +02:00
<p>With two arguments, copy <code>local-file</code> to the server as <code>remote-file</code>.</p>
<p>With more than two arguments, copy all the local files <code>lfile1</code> ... into
the existing remote directory <code>rdir</code> retaining the same basenames. This
assumes UNIX directory semantics.</p>
2022-08-24 15:22:41 +02:00
<p>A problem arises if you attempt to use zfpcp <code>lfile1</code> <code>rdir</code>, i.e. the
2021-05-11 02:29:21 +02:00
second form of copying but with two arguments, as the command has no
simple way of knowing if <code>rdir</code> corresponds to a directory or a
filename. It attempts to resolve this in various ways. First, if the
2022-08-24 15:22:41 +02:00
<code>rdir</code> argument is . or .. or ends in a slash, it is assumed to be a
directory. Secondly, if the operation of copying to a remote file in the
first form failed, and the remote server sends back the expected failure
code 553 and a reply including the string Is a directory, then zfpcp
will retry using the second form.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Closing-the-connection"></span></p>
<h3 id="2536-closing-the-connection"><a class="header" href="#2536-closing-the-connection">25.3.6 Closing the connection</a></h3>
<p><span id="index-zfclose"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfclose</p>
2021-05-11 02:29:21 +02:00
<p>Close the connection.</p>
<hr />
<p><span id="Session-management"></span></p>
<h3 id="2537-session-management"><a class="header" href="#2537-session-management">25.3.7 Session management</a></h3>
<p><span id="index-zfsession"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfsession [ -lvod ] [ <code>sessname</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>Allows you to manage multiple FTP sessions at once. By default,
2022-08-24 15:22:41 +02:00
connections take place in a session called default; by giving the
command zfsession <code>sessname</code> you can change to a new or existing
2021-05-11 02:29:21 +02:00
session with a name of your choice. The new session remembers its own
connection, as well as associated shell parameters, and also the
2022-08-24 15:22:41 +02:00
host/user parameters set by zfparams. Hence you can have different
2021-05-11 02:29:21 +02:00
sessions set up to connect to different hosts, each remembering the
appropriate host, user and password.</p>
2022-08-24 15:22:41 +02:00
<p>With no arguments, zfsession prints the name of the current session;
with the option -l it lists all sessions which currently exist, and with
the option -v it gives a verbose list showing the host and directory for
each session, where the current session is marked with an asterisk. With
-o, it will switch to the most recent previous session.</p>
<p>With -d, the given session (or else the current one) is removed;
2021-05-11 02:29:21 +02:00
everything to do with it is completely forgotten. If it was the only
2022-08-24 15:22:41 +02:00
session, a new session called default is created and made current. It
is safest not to delete sessions while background commands using zftp
are active.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zftransfer"></span></p>
2022-08-24 15:22:41 +02:00
<p>zftransfer <code>sess1</code>:<code>file1</code> <code>sess2</code>:<code>file2</code></p>
2021-05-11 02:29:21 +02:00
<p>Transfer files between two sessions; no local copy is made. The file is
read from the session <code>sess1</code> as <code>file1</code> and written to session <code>sess2</code>
as file <code>file2</code>; <code>file1</code> and <code>file2</code> may be relative to the current
directories of the session. Either <code>sess1</code> or <code>sess2</code> may be omitted
(though the colon should be retained if there is a possibility of a
colon appearing in the file name) and defaults to the current session;
<code>file2</code> may be omitted or may end with a slash, in which case the
basename of <code>file1</code> will be added. The sessions <code>sess1</code> and <code>sess2</code> must
be distinct.</p>
<p>The operation is performed using pipes, so it is required that the
connections still be valid in a subshell, which is not the case under
versions of some operating systems, presumably due to a system bug.</p>
<hr />
<p><span id="Bookmarks"></span></p>
<h3 id="2538-bookmarks"><a class="header" href="#2538-bookmarks">25.3.8 Bookmarks</a></h3>
2022-08-24 15:22:41 +02:00
<p>The two functions zfmark and zfgoto allow you to bookmark the present
location (host, user and directory) of the current FTP connection for
later use. The file to be used for storing and retrieving bookmarks is
given by the parameter $ZFTP_BMFILE; if not set when one of the two
functions is called, it will be set to the file .zfbkmarks in the
directory where your zsh startup files live (usually ~).</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zfmark"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfmark [ <code>bookmark</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>If given an argument, mark the current host, user and directory under
2022-08-24 15:22:41 +02:00
the name <code>bookmark</code> for later use by zfgoto. If there is no connection
2021-05-11 02:29:21 +02:00
open, use the values for the last connection immediately before it was
closed; it is an error if there was none. Any existing bookmark under
the same name will be silently replaced.</p>
<p>If not given an argument, list the existing bookmarks and the points to
2022-08-24 15:22:41 +02:00
which they refer in the form <code>user</code>@<code>host</code>:<code>directory</code>; this is the
2021-05-11 02:29:21 +02:00
format in which they are stored, and the file may be edited directly.</p>
<p><span id="index-zfgoto"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfgoto [ -n ] <code>bookmark</code></p>
<p>Return to the location given by <code>bookmark</code>, as previously set by zfmark.
If the location has user ftp or anonymous, open the connection with
zfanon, so that no password is required. If the user and host parameters
match those stored for the current session, if any, those will be used,
and again no password is required. Otherwise a password will be prompted
for.</p>
<p>With the option -n, the bookmark is taken to be a nickname stored by the
ncftp program in its bookmark file, which is assumed to be
~/.ncftp/bookmarks. The function works identically in other ways. Note
that there is no mechanism for adding or modifying ncftp bookmarks from
the zftp functions.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Other-functions"></span></p>
<h3 id="2539-other-functions"><a class="header" href="#2539-other-functions">25.3.9 Other functions</a></h3>
2022-08-24 15:22:41 +02:00
<p>Mostly, these functions will not be called directly (apart from zfinit),
but are described here for completeness. You may wish to alter
zftp_chpwd and zftp_progress, in particular.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zfinit"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfinit [ -n ]</p>
2021-05-11 02:29:21 +02:00
<p>As described above, this is used to initialize the zftp function system.
2022-08-24 15:22:41 +02:00
The -n option should be used if the zftp command is already built into
2021-05-11 02:29:21 +02:00
the shell.</p>
<p><span id="index-zfautocheck"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfautocheck [ -dn ]</p>
2021-05-11 02:29:21 +02:00
<p>This function is called to implement automatic reopening behaviour, as
described in more detail below. The options must appear in the first
2022-08-24 15:22:41 +02:00
argument; -n prevents the command from changing to the old directory,
while -d prevents it from setting the variable do_close, which it
2021-05-11 02:29:21 +02:00
otherwise does as a flag for automatically closing the connection after
a transfer. The host and directory for the last session are stored in
2022-08-24 15:22:41 +02:00
the variable $zflastsession, but the internal host/user/password
2021-05-11 02:29:21 +02:00
parameters must also be correctly set.</p>
<p><span id="index-zfcd_005fmatch"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfcd_match <code>prefix</code> <code>suffix</code></p>
2021-05-11 02:29:21 +02:00
<p>This performs matching for completion of remote directory names. If the
remote server is UNIX, it will attempt to persuade the server to list
the remote directory with subdirectories marked, which usually works but
2022-08-24 15:22:41 +02:00
is not guaranteed. On other hosts it simply calls zfget_match and hence
completes all files, not just directories. On some systems, directories
may not even look like filenames.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zfget_005fmatch"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfget_match <code>prefix</code> <code>suffix</code></p>
2021-05-11 02:29:21 +02:00
<p>This performs matching for completion of remote filenames. It caches
files for the current directory (only) in the shell parameter
2022-08-24 15:22:41 +02:00
$zftp_fcache. It is in the form to be called by the -K option of
compctl, but also works when called from a widget-style completion
2021-05-11 02:29:21 +02:00
function with <code>prefix</code> and <code>suffix</code> set appropriately.</p>
<p><span id="index-zfrglob"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfrglob <code>varname</code></p>
2021-05-11 02:29:21 +02:00
<p>Perform remote globbing, as describes in more detail below. <code>varname</code> is
the name of a variable containing the pattern to be expanded; if there
were any matches, the same variable will be set to the expanded set of
filenames on return.</p>
<p><span id="index-zfrtime"></span></p>
2022-08-24 15:22:41 +02:00
<p>zfrtime <code>lfile</code> <code>rfile</code> [ <code>time</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>Set the local file <code>lfile</code> to have the same modification time as the
remote file <code>rfile</code>, or the explicit time <code>time</code> in FTP format
2022-08-24 15:22:41 +02:00
CCYYMMDDhhmmSS for the GMT timezone. This uses the shells zsh/datetime
module to perform the conversion from GMT to local time.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zftp_005fchpwd_002c-supplied-version"></span></p>
2022-08-24 15:22:41 +02:00
<p>zftp_chpwd</p>
2021-05-11 02:29:21 +02:00
<p>This function is called every time a connection is opened, or closed, or
the remote directory changes. This version alters the title bar of an
2022-08-24 15:22:41 +02:00
xterm-compatible or sun-cmd terminal emulator to reflect the local and
remote hostnames and current directories. It works best when combined
with the function chpwd. In particular, a function of the form</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">chpwd() {
2021-05-11 02:29:21 +02:00
if [[ -n $ZFTP_USER ]]; then
zftp_chpwd
else
# usual chpwd e.g put host:directory in title bar
fi
}
</code></pre>
</div>
<p>fits in well.</p>
<p><span id="index-zftp_005fprogress_002c-supplied-version"></span></p>
2022-08-24 15:22:41 +02:00
<p>zftp_progress</p>
2021-05-11 02:29:21 +02:00
<p>This function shows the status of the transfer. It will not write
anything unless the output is going to a terminal; however, if you
transfer files in the background, you should turn off progress reports
2022-08-24 15:22:41 +02:00
by hand using zstyle :zftp:* progress none. Note also that if you
2021-05-11 02:29:21 +02:00
alter it, any output <em>must</em> be to standard error, as standard output may
be a file being received. The form of the progress meter, or whether it
is used at all, can be configured without altering the function, as
described in the next section.</p>
<p><span id="index-zffcache"></span></p>
2022-08-24 15:22:41 +02:00
<p>zffcache</p>
2021-05-11 02:29:21 +02:00
<p>This is used to implement caching of files in the current directory for
2022-08-24 15:22:41 +02:00
each session separately. It is used by zfget_match and zfrglob.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Miscellaneous-Features"></span> <span
id="Miscellaneous-Features-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="254-miscellaneous-features"><a class="header" href="#254-miscellaneous-features">25.4 Miscellaneous Features</a></h2>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Configuration-2"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="2541-configuration"><a class="header" href="#2541-configuration">25.4.1 Configuration</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-zftp-function-system_002c-configuration"></span> <span
id="index-zftp-function-system_002c-styles"></span> <span
id="index-styles-in-zftp-functions"></span></p>
2021-05-11 02:29:21 +02:00
<p>Various styles are available using the standard shell style mechanism,
described in <a href="Zsh-Modules.html#The-zsh_002fzutil-Module">The zsh/zutil
Module</a>. Briefly, the command
2022-08-24 15:22:41 +02:00
zstyle :zftp:* <code>style</code> <code>value</code> .... defines the <code>style</code> to have
2021-05-11 02:29:21 +02:00
value <code>value</code>; more than one value may be given, although that is not
useful in the cases described here. These values will then be used
throughout the zftp function system. For more precise control, the first
2022-08-24 15:22:41 +02:00
argument, which gives a pattern that matches <em>contexts</em> in which the
style applies, can be modified to include a particular function, as for
example :zftp:zfget: the style will then have the given value only in
the zfget function, and will override styles set under :zftp:*. Note
that only the top level function name, as called by the user, is used;
calling of lower level functions is transparent to the user. Hence
modifications to the title bar in zftp_chpwd use the contexts
:zftp:zfopen, :zftp:zfcd, etc., depending where it was called from. The
following styles are understood:</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-progress_002c-zftp-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>progress</p>
<p>Controls the way that zftp_progress reports on the progress of a
transfer. If empty, unset, or none, no progress report is made; if
bar a growing bar of inverse video is shown; if percent (or any
other string, though this may change in future), the percentage of the
file transferred is shown. The bar meter requires that the width of the
terminal be available via the $COLUMNS parameter (normally this is set
automatically). If the size of the file being transferred is not
available, bar and percent meters will simply show the number of bytes
transferred so far.</p>
<p>When zfinit is run, if this style is not defined for the context
:zftp:*, it will be set to bar.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-update_002c-zftp-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>update</p>
2021-05-11 02:29:21 +02:00
<p>Specifies the minimum time interval between updates of the progress
meter in seconds. No update is made unless new data has been received,
2022-08-24 15:22:41 +02:00
so the actual time interval is limited only by $ZFTP_TIMEOUT.</p>
<p>As described for progress, zfinit will force this to default to 1.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-remote_002dglob_002c-zftp-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>remote-glob</p>
<p>If set to 1, yes or true, filename generation (globbing) is
2021-05-11 02:29:21 +02:00
performed on the remote machine instead of by zsh itself; see below.</p>
<p><span id="index-titlebar_002c-zftp-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>titlebar</p>
<p>If set to 1, yes or true, zftp_chpwd will put the remote host and
remote directory into the titlebar of terminal emulators such as xterm
or sun-cmd that allow this.</p>
<p>As described for progress, zfinit will force this to default to 1.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-chpwd_002c-zftp-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>chpwd</p>
<p>If set to 1 yes or true, zftp_chpwd will call the function chpwd
when a connection is closed. This is useful if the remote host details
were put into the terminal title bar by zftp_chpwd and your usual chpwd
also modifies the title bar.</p>
<p>When zfinit is run, it will determine whether chpwd exists and if so it
will set the default value for the style to 1 if none exists already.</p>
<p>Note that there is also an associative array zfconfig which contains
2021-05-11 02:29:21 +02:00
values used by the function system. This should not be modified or
overwritten.</p>
<hr />
<p><span id="Remote-globbing"></span></p>
<h3 id="2542-remote-globbing"><a class="header" href="#2542-remote-globbing">25.4.2 Remote globbing</a></h3>
<p><span id="index-zftp-function-system_002c-remote-globbing"></span></p>
<p>The commands for retrieving files usually perform filename generation
(globbing) on their arguments; this can be turned off by passing the
2022-08-24 15:22:41 +02:00
option -G to each of the commands. Normally this operates by retrieving
a complete list of files for the directory in question, then matching
these locally against the pattern supplied. This has the advantage that
the full range of zsh patterns (respecting the setting of the option
EXTENDED_GLOB) can be used. However, it means that the directory part of
a filename will not be expanded and must be given exactly. If the remote
server does not support the UNIX directory semantics, directory handling
is problematic and it is recommended that globbing only be used within
the current directory. The list of files in the current directory, if
retrieved, will be cached, so that subsequent globs in the same
directory without an intervening zfcd are much faster.</p>
<p>If the remote-glob style (see above) is set, globbing is instead
2021-05-11 02:29:21 +02:00
performed on the remote host: the server is asked for a list of matching
files. This is highly dependent on how the server is implemented, though
typically UNIX servers will provide support for basic glob patterns.
This may in some cases be faster, as it avoids retrieving the entire
list of directory contents.</p>
<hr />
<p><span id="Automatic-and-temporary-reopening"></span></p>
<h3 id="2543-automatic-and-temporary-reopening"><a class="header" href="#2543-automatic-and-temporary-reopening">25.4.3 Automatic and temporary reopening</a></h3>
<p><span id="index-zftp-function-system_002c-automatic-reopening"></span></p>
2022-08-24 15:22:41 +02:00
<p>As described for the zfopen command, a subsequent zfopen with no
2021-05-11 02:29:21 +02:00
parameters will reopen the connection to the last host (this includes
2022-08-24 15:22:41 +02:00
connections made with the zfanon command). Opened in this fashion, the
2021-05-11 02:29:21 +02:00
connection starts in the default remote directory and will remain open
until explicitly closed.</p>
<p>Automatic re-opening is also available. If a connection is not currently
open and a command requiring a connection is given, the last connection
is implicitly reopened. In this case the directory which was current
when the connection was closed again becomes the current directory
(unless, of course, the command given changes it). Automatic reopening
will also take place if the connection was close by the remote server
2022-08-24 15:22:41 +02:00
for whatever reason (e.g. a timeout). It is not available if the -1
option to zfopen or zfanon was used.</p>
2021-05-11 02:29:21 +02:00
<p>Furthermore, if the command issued is a file transfer, the connection
will be closed after the transfer is finished, hence providing a
one-shot mode for transfers. This does not apply to directory changing
2022-08-24 15:22:41 +02:00
or listing commands; for example a zfdir may reopen a connection but
2021-05-11 02:29:21 +02:00
will leave it open. Also, automatic closure will only ever happen in the
2022-08-24 15:22:41 +02:00
same command as automatic opening, i.e a zfdir directly followed by a
zfget will never close the connection automatically.</p>
<p>Information about the previous connection is given by the zfstat
2021-05-11 02:29:21 +02:00
function. So, for example, if that reports:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">Session: default
2021-05-11 02:29:21 +02:00
Not connected.
Last session: ftp.bar.com:/pub/textfiles
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>then the command zfget file.txt will attempt to reopen a connection to
ftp.bar.com, retrieve the file /pub/textfiles/file.txt, and immediately
close the connection again. On the other hand, zfcd .. will open the
connection in the directory /pub and leave it open.</p>
2021-05-11 02:29:21 +02:00
<p>Note that all the above is local to each session; if you return to a
previous session, the connection for that session is the one which will
be reopened.</p>
<hr />
<p><span id="Completion-3"></span></p>
<h3 id="2544-completion"><a class="header" href="#2544-completion">25.4.4 Completion</a></h3>
<p>Completion of local and remote files, directories, sessions and
2022-08-24 15:22:41 +02:00
bookmarks is supported. The older, compctl-style completion is defined
when zfinit is called; support for the new widget-based completion
system is provided in the function Completion/Zsh/Command/_zftp, which
2021-05-11 02:29:21 +02:00
should be installed with the other functions of the completion system
and hence should automatically be available.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- START doctoc generated TOC please keep comment here to allow auto update -->
2021-05-11 02:29:21 +02:00
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<p><strong>Table of Contents</strong> <em>generated with <a href="https://github.com/thlorenz/doctoc">DocToc</a></em></p>
<ul>
<li><a href="User-Contributions.html#26-user-contributions">26 User Contributions</a>
<ul>
<li><a href="User-Contributions.html#261-description">26.1 Description</a></li>
<li><a href="User-Contributions.html#262-utilities">26.2 Utilities</a>
<ul>
<li><a href="User-Contributions.html#2621-accessing-on-line-help">26.2.1 Accessing On-Line Help</a></li>
<li><a href="User-Contributions.html#2622-recompiling-functions">26.2.2 Recompiling Functions</a></li>
<li><a href="User-Contributions.html#2623-keyboard-definition">26.2.3 Keyboard Definition</a></li>
<li><a href="User-Contributions.html#2624-dumping-shell-state">26.2.4 Dumping Shell State</a></li>
<li><a href="User-Contributions.html#2625-manipulating-hook-functions">26.2.5 Manipulating Hook Functions</a></li>
</ul>
</li>
<li><a href="User-Contributions.html#263-remembering-recent-directories">26.3 Remembering Recent Directories</a>
<ul>
<li><a href="User-Contributions.html#2631-installation">26.3.1 Installation</a></li>
<li><a href="User-Contributions.html#2632-use">26.3.2 Use</a></li>
<li><a href="User-Contributions.html#2633-options">26.3.3 Options</a></li>
<li><a href="User-Contributions.html#2634-configuration">26.3.4 Configuration</a></li>
<li><a href="User-Contributions.html#2635-use-with-dynamic-directory-naming">26.3.5 Use with dynamic directory naming</a></li>
<li><a href="User-Contributions.html#2636-details-of-directory-handling">26.3.6 Details of directory handling</a></li>
</ul>
</li>
<li><a href="User-Contributions.html#264-abbreviated-dynamic-references-to-directories">26.4 Abbreviated dynamic references to directories</a>
<ul>
<li><a href="User-Contributions.html#2641-usage">26.4.1 Usage</a></li>
<li><a href="User-Contributions.html#2642-configuration">26.4.2 Configuration</a></li>
<li><a href="User-Contributions.html#2643-complete-example">26.4.3 Complete example</a></li>
</ul>
</li>
<li><a href="User-Contributions.html#265-gathering-information-from-version-control-systems">26.5 Gathering information from version control systems</a>
<ul>
<li><a href="User-Contributions.html#2651-quickstart">26.5.1 Quickstart</a></li>
<li><a href="User-Contributions.html#2652-configuration">26.5.2 Configuration</a></li>
<li><a href="User-Contributions.html#2653-oddities">26.5.3 Oddities</a></li>
<li><a href="User-Contributions.html#2654-quilt-support">26.5.4 Quilt Support</a></li>
<li><a href="User-Contributions.html#2655-function-descriptions-public-api">26.5.5 Function Descriptions (Public API)</a></li>
<li><a href="User-Contributions.html#2656-variable-description">26.5.6 Variable Description</a></li>
2022-08-24 15:22:41 +02:00
<li><a href="User-Contributions.html#2657-hooks-in-vcs_info">26.5.7 Hooks in vcs_info</a></li>
2021-05-11 02:29:21 +02:00
<li><a href="User-Contributions.html#2658-examples">26.5.8 Examples</a></li>
</ul>
</li>
<li><a href="User-Contributions.html#266-prompt-themes">26.6 Prompt Themes</a>
<ul>
<li><a href="User-Contributions.html#2661-installation">26.6.1 Installation</a></li>
<li><a href="User-Contributions.html#2662-theme-selection">26.6.2 Theme Selection</a></li>
<li><a href="User-Contributions.html#2663-utility-themes">26.6.3 Utility Themes</a></li>
<li><a href="User-Contributions.html#2664-writing-themes">26.6.4 Writing Themes</a></li>
</ul>
</li>
<li><a href="User-Contributions.html#267-zle-functions">26.7 ZLE Functions</a>
<ul>
<li><a href="User-Contributions.html#2671-widgets">26.7.1 Widgets</a></li>
<li><a href="User-Contributions.html#2672-utility-functions">26.7.2 Utility Functions</a></li>
<li><a href="User-Contributions.html#2673-styles">26.7.3 Styles</a></li>
</ul>
</li>
<li><a href="User-Contributions.html#268-exception-handling">26.8 Exception Handling</a></li>
<li><a href="User-Contributions.html#269-mime-functions">26.9 MIME Functions</a></li>
<li><a href="User-Contributions.html#2610-mathematical-functions">26.10 Mathematical Functions</a></li>
<li><a href="User-Contributions.html#2611-user-configuration-functions">26.11 User Configuration Functions</a></li>
<li><a href="User-Contributions.html#2612-other-functions">26.12 Other Functions</a>
<ul>
<li><a href="User-Contributions.html#26121-descriptions">26.12.1 Descriptions</a></li>
<li><a href="User-Contributions.html#26122-styles">26.12.2 Styles</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2022-08-24 15:22:41 +02:00
<p><span id="User-Contributions"></span> <span
id="User-Contributions-1"></span></p>
2021-05-11 02:29:21 +02:00
<h1 id="26-user-contributions"><a class="header" href="#26-user-contributions">26 User Contributions</a></h1>
<p><span id="index-user-contributions"></span></p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Description-7"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="261-description"><a class="header" href="#261-description">26.1 Description</a></h2>
<p>The Zsh source distribution includes a number of items contributed by
the user community. These are not inherently a part of the shell, and
some may not be available in every zsh installation. The most
significant of these are documented here. For documentation on other
contributed items such as shell functions, look for comments in the
function source files.</p>
<hr />
<p><span id="Utilities"></span> <span id="Utilities-1"></span></p>
<h2 id="262-utilities"><a class="header" href="#262-utilities">26.2 Utilities</a></h2>
<hr />
<p><span id="Accessing-On_002dLine-Help"></span></p>
<h3 id="2621-accessing-on-line-help"><a class="header" href="#2621-accessing-on-line-help">26.2.1 Accessing On-Line Help</a></h3>
<p><span id="index-helpfiles-utility"></span></p>
2022-08-24 15:22:41 +02:00
<p>The key sequence ESC h is normally bound by ZLE to execute the run-help
widget (see <a href="Zsh-Line-Editor.html#Zsh-Line-Editor">Zsh Line Editor</a>).
This invokes the run-help command with the command word from the current
input line as its argument. By default, run-help is an alias for the man
command, so this often fails when the command word is a shell builtin or
a user-defined function. By redefining the run-help alias, one can
2021-05-11 02:29:21 +02:00
improve the on-line help provided by the shell.</p>
2022-08-24 15:22:41 +02:00
<p>The helpfiles utility, found in the Util directory of the distribution,
is a Perl program that can be used to process the zsh manual to produce
a separate help file for each shell builtin and for many other shell
features as well. The autoloadable run-help function, found in
Functions/Misc, searches for these helpfiles and performs several other
tests to produce the most complete help possible for the command.</p>
<p>Help files are installed by default to a subdirectory of /usr/share/zsh
or /usr/local/share/zsh.</p>
<p>To create your own help files with helpfiles, choose or create a
2021-05-11 02:29:21 +02:00
directory where the individual command help files will reside. For
2022-08-24 15:22:41 +02:00
example, you might choose ~/zsh_help. If you unpacked the zsh
2021-05-11 02:29:21 +02:00
distribution in your home directory, you would use the commands:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">mkdir ~/zsh_help
perl ~/zsh-5.9/Util/helpfiles ~/zsh_help
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p><span id="index-HELPDIR"></span></p>
2022-08-24 15:22:41 +02:00
<p>The HELPDIR parameter tells run-help where to look for the help files.
When unset, it uses the default installation path. To use your own set
of help files, set this to the appropriate path in one of your startup
files:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">HELPDIR=~/zsh_help
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p><span id="index-run_002dhelp_002c-use-of"></span></p>
2022-08-24 15:22:41 +02:00
<p>To use the run-help function, you need to add lines something like the
following to your .zshrc or equivalent startup file:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">unalias run-help
2021-05-11 02:29:21 +02:00
autoload run-help
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Note that in order for autoload run-help to work, the run-help file
must be in one of the directories named in your fpath array (see
2021-05-11 02:29:21 +02:00
<a href="Parameters.html#Parameters-Used-By-The-Shell">Parameters Used By The
Shell</a>). This should
already be the case if you have a standard zsh installation; if it is
2022-08-24 15:22:41 +02:00
not, copy Functions/Misc/run-help to an appropriate directory.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Recompiling-Functions"></span></p>
<h3 id="2622-recompiling-functions"><a class="header" href="#2622-recompiling-functions">26.2.2 Recompiling Functions</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-functions_002c-recompiling"></span> <span
id="index-zrecompile-utility"></span></p>
2021-05-11 02:29:21 +02:00
<p>If you frequently edit your zsh functions, or periodically update your
zsh installation to track the latest developments, you may find that
2022-08-24 15:22:41 +02:00
function digests compiled with the zcompile builtin are frequently out
2021-05-11 02:29:21 +02:00
of date with respect to the function source files. This is not usually a
problem, because zsh always looks for the newest file when loading a
function, but it may cause slower shell startup and function loading.
2022-08-24 15:22:41 +02:00
Also, if a digest file is explicitly used as an element of fpath, zsh
2021-05-11 02:29:21 +02:00
wont check whether any of its source files has changed.</p>
2022-08-24 15:22:41 +02:00
<p>The zrecompile autoloadable function, found in Functions/Misc, can be
used to keep function digests up to date.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zrecompile"></span></p>
2022-08-24 15:22:41 +02:00
<p>zrecompile [ -qt ] [ <code>name</code> ... ]</p>
<p>zrecompile [ -qt ] -p <code>arg</code> ... [ -- <code>arg</code> ... ]</p>
<p>This tries to find *.zwc files and automatically re-compile them if at
2021-05-11 02:29:21 +02:00
least one of the original files is newer than the compiled file. This
works only if the names stored in the compiled files are full paths or
2022-08-24 15:22:41 +02:00
are relative to the directory that contains the .zwc file.</p>
2021-05-11 02:29:21 +02:00
<p>In the first form, each <code>name</code> is the name of a compiled file or a
2022-08-24 15:22:41 +02:00
directory containing *.zwc files that should be checked. If no
arguments are given, the directories and *.zwc files in fpath are used.</p>
<p>When -t is given, no compilation is performed, but a return status of
2021-05-11 02:29:21 +02:00
zero (true) is set if there are files that need to be re-compiled and
2022-08-24 15:22:41 +02:00
non-zero (false) otherwise. The -q option quiets the chatty output that
describes what zrecompile is doing.</p>
<p>Without the -t option, the return status is zero if all files that
2021-05-11 02:29:21 +02:00
needed re-compilation could be compiled and non-zero if compilation for
at least one of the files failed.</p>
2022-08-24 15:22:41 +02:00
<p>If the -p option is given, the <code>arg</code>s are interpreted as one or more
sets of arguments for zcompile, separated by --. For example:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zrecompile -p \
2021-05-11 02:29:21 +02:00
-R ~/.zshrc -- \
-M ~/.zcompdump -- \
~/zsh/comp.zwc ~/zsh/Completion/*/_*
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>This compiles ~/.zshrc into ~/.zshrc.zwc if that doesnt exist or if
it is older than ~/.zshrc. The compiled file will be marked for reading
instead of mapping. The same is done for ~/.zcompdump and
~/.zcompdump.zwc, but this compiled file is marked for mapping. The
last line re-creates the file ~/zsh/comp.zwc if any of the files
2021-05-11 02:29:21 +02:00
matching the given pattern is newer than it.</p>
2022-08-24 15:22:41 +02:00
<p>Without the -p option, zrecompile does not create function digests that
do not already exist, nor does it add new functions to the digest.</p>
2021-05-11 02:29:21 +02:00
<p>The following shell loop is an example of a method for creating function
2022-08-24 15:22:41 +02:00
digests for all functions in your fpath, assuming that you have write
2021-05-11 02:29:21 +02:00
permission to the directories:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">for ((i=1; i &lt;= $#fpath; ++i)); do
2021-05-11 02:29:21 +02:00
dir=$fpath[i]
zwc=${dir:t}.zwc
if [[ $dir == (.|..) || $dir == (.|..)/* ]]; then
continue
fi
files=($dir/*(N-.))
if [[ -w $dir:h &amp;&amp; -n $files ]]; then
files=(${${(M)files%/*/*}#/})
if ( cd $dir:h &amp;&amp;
zrecompile -p -U -z $zwc $files ); then
fpath[i]=$fpath[i].zwc
fi
fi
done
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The -U and -z options are appropriate for functions in the default zsh
installation fpath; you may need to use different options for your
2021-05-11 02:29:21 +02:00
personal function directories.</p>
2022-08-24 15:22:41 +02:00
<p>Once the digests have been created and your fpath modified to refer to
them, you can keep them up to date by running zrecompile with no
2021-05-11 02:29:21 +02:00
arguments.</p>
<hr />
<p><span id="Keyboard-Definition"></span></p>
<h3 id="2623-keyboard-definition"><a class="header" href="#2623-keyboard-definition">26.2.3 Keyboard Definition</a></h3>
2022-08-24 15:22:41 +02:00
<p><span id="index-keyboard-definition"></span> <span
id="index-zkbd"></span></p>
2021-05-11 02:29:21 +02:00
<p>The large number of possible combinations of keyboards, workstations,
terminals, emulators, and window systems makes it impossible for zsh to
2022-08-24 15:22:41 +02:00
have built-in key bindings for every situation. The zkbd utility, found
in Functions/Misc, can help you quickly create key bindings for your
configuration.</p>
<p>Run zkbd either as an autoloaded function, or as a shell script:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zsh -f ~/zsh-5.9/Functions/Misc/zkbd
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>When you run zkbd, it first asks you to enter your terminal type; if the
default it offers is correct, just press return. It then asks you to
2021-05-11 02:29:21 +02:00
press a number of different keys to determine characteristics of your
2022-08-24 15:22:41 +02:00
keyboard and terminal; zkbd warns you if it finds anything out of the
ordinary, such as a Delete key that sends neither ^H nor ^?.</p>
<p>The keystrokes read by zkbd are recorded as a definition for an
associative array named key, written to a file in the subdirectory .zkbd
within either your HOME or ZDOTDIR directory. The name of the file is
composed from the TERM, VENDOR and OSTYPE parameters, joined by hyphens.</p>
<p>You may read this file into your .zshrc or another startup file with the
source or . commands, then reference the key parameter in bindkey
commands, like this:</p>
<div class="example">
<pre><code class="language-zsh">source ${ZDOTDIR:-$HOME}/.zkbd/$TERM-$VENDOR-$OSTYPE
2021-05-11 02:29:21 +02:00
[[ -n ${key[Left]} ]] &amp;&amp; bindkey &quot;${key[Left]}&quot; backward-char
[[ -n ${key[Right]} ]] &amp;&amp; bindkey &quot;${key[Right]}&quot; forward-char
# etc.
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Note that in order for autoload zkbd to work, the zkdb file must be in
one of the directories named in your fpath array (see <a href="Parameters.html#Parameters-Used-By-The-Shell">Parameters Used
By The Shell</a>). This
should already be the case if you have a standard zsh installation; if
it is not, copy Functions/Misc/zkbd to an appropriate directory.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Dumping-Shell-State"></span></p>
<h3 id="2624-dumping-shell-state"><a class="header" href="#2624-dumping-shell-state">26.2.4 Dumping Shell State</a></h3>
<p><span id="index-reporter-utility"></span></p>
<p>Occasionally you may encounter what appears to be a bug in the shell,
particularly if you are using a beta version of zsh or a development
release. Usually it is sufficient to send a description of the problem
to one of the zsh mailing lists (see <a href="Introduction.html#Mailing-Lists">Mailing
Lists</a>), but sometimes one of the zsh
developers will need to recreate your environment in order to track the
problem down.</p>
2022-08-24 15:22:41 +02:00
<p>The script named reporter, found in the Util directory of the
2021-05-11 02:29:21 +02:00
distribution, is provided for this purpose. (It is also possible to
2022-08-24 15:22:41 +02:00
autoload reporter, but reporter is not installed in fpath by default.)
This script outputs a detailed dump of the shell state, in the form of
another script that can be read with zsh -f to recreate that state.</p>
<p>To use reporter, read the script into your shell with the . command
and redirect the output into a file:</p>
<div class="example">
<pre><code class="language-zsh">. ~/zsh-5.9/Util/reporter &gt; zsh.report
</code></pre>
</div>
<p>You should check the zsh.report file for any sensitive information such
as passwords and delete them by hand before sending the script to the
developers. Also, as the output can be voluminous, its best to wait for
the developers to ask for this information before sending it.</p>
<p>You can also use reporter to dump only a subset of the shell state. This
is sometimes useful for creating startup files for the first time. Most
of the output from reporter is far more detailed than usually is
necessary for a startup file, but the aliases, options, and zstyles
states may be useful because they include only changes from the
defaults. The bindings state may be useful if you have created any of
your own keymaps, because reporter arranges to dump the keymap creation
commands as well as the bindings for every keymap.</p>
2021-05-11 02:29:21 +02:00
<p>As is usual with automated tools, if you create a startup file with
2022-08-24 15:22:41 +02:00
reporter, you should edit the results to remove unnecessary commands.
2021-05-11 02:29:21 +02:00
Note that if youre using the new completion system, you should <em>not</em>
2022-08-24 15:22:41 +02:00
dump the functions state to your startup files with reporter; use the
compdump function instead (see <a href="Completion-System.html#Completion-System">Completion
2021-05-11 02:29:21 +02:00
System</a>).</p>
2022-08-24 15:22:41 +02:00
<p>reporter [ <code>state</code> ... ]<br />
2021-05-11 02:29:21 +02:00
<span id="index-reporter"></span></p>
<p>Print to standard output the indicated subset of the current shell
state. The <code>state</code> arguments may be one or more of:</p>
2022-08-24 15:22:41 +02:00
<p>all<br />
2021-05-11 02:29:21 +02:00
Output everything listed below.</p>
2022-08-24 15:22:41 +02:00
<p>aliases<br />
2021-05-11 02:29:21 +02:00
Output alias definitions.</p>
2022-08-24 15:22:41 +02:00
<p>bindings<br />
2021-05-11 02:29:21 +02:00
Output ZLE key maps and bindings.</p>
2022-08-24 15:22:41 +02:00
<p>completion<br />
Output old-style compctl commands. New completion is covered by
functions and zstyles.</p>
<p>functions<br />
2021-05-11 02:29:21 +02:00
Output autoloads and function definitions.</p>
2022-08-24 15:22:41 +02:00
<p>limits<br />
Output limit commands.</p>
<p>options<br />
Output setopt commands.</p>
<p>styles<br />
Same as zstyles.</p>
<p>variables<br />
Output shell parameter assignments, plus export commands for any
environment variables.</p>
<p>zstyles<br />
Output zstyle commands.</p>
<p>If the <code>state</code> is omitted, all is assumed.</p>
<p>With the exception of all, every <code>state</code> can be abbreviated by any
prefix, even a single letter; thus a is the same as aliases, z is the
same as zstyles, etc.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Manipulating-Hook-Functions"></span></p>
<h3 id="2625-manipulating-hook-functions"><a class="header" href="#2625-manipulating-hook-functions">26.2.5 Manipulating Hook Functions</a></h3>
<p><span id="index-hook-function-utility"></span></p>
<p><span id="index-add_002dzsh_002dhook"></span></p>
2022-08-24 15:22:41 +02:00
<p>add-zsh-hook [ -L | -dD ] [ -Uzk ] <code>hook</code> <code>function</code></p>
2021-05-11 02:29:21 +02:00
<p>Several functions are special to the shell, as described in the section
Special Functions, <a href="Functions.html#Functions">Functions</a>, in that they
are automatically called at specific points during shell execution. Each
has an associated array consisting of names of functions to be called at
the same point; these are so-called hook functions. The shell function
2022-08-24 15:22:41 +02:00
add-zsh-hook provides a simple way of adding or removing functions from
the array.</p>
<p><code>hook</code> is one of chpwd, periodic, precmd, preexec, zshaddhistory,
zshexit, or zsh_directory_name, the special functions in question. Note
that zsh_directory_name is called in a different way from the other
functions, but may still be manipulated as a hook.</p>
2021-05-11 02:29:21 +02:00
<p><code>function</code> is name of an ordinary shell function. If no options are
given this will be added to the array of functions to be executed in the
given context. Functions are invoked in the order they were added.</p>
2022-08-24 15:22:41 +02:00
<p>If the option -L is given, the current values for the hook arrays are
listed with typeset.</p>
<p>If the option -d is given, the <code>function</code> is removed from the array of
2021-05-11 02:29:21 +02:00
functions to be executed.</p>
2022-08-24 15:22:41 +02:00
<p>If the option -D is given, the <code>function</code> is treated as a pattern and
2021-05-11 02:29:21 +02:00
any matching names of functions are removed from the array of functions
to be executed.</p>
2022-08-24 15:22:41 +02:00
<p>The options -U, -z and -k are passed as arguments to autoload for
<code>function</code>. For functions contributed with zsh, the options -Uz are
appropriate.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-add_002dzle_002dhook_002dwidget"></span></p>
2022-08-24 15:22:41 +02:00
<p>add-zle-hook-widget [ -L | -dD ] [ -Uzk ] <code>hook</code> <code>widgetname</code></p>
2021-05-11 02:29:21 +02:00
<p>Several widget names are special to the line editor, as described in the
2022-08-24 15:22:41 +02:00
section Special Widgets, <a href="Zsh-Line-Editor.html#Zle-Widgets">Zle
Widgets</a>, in that they are
automatically called at specific points during editing. Unlike function
hooks, these do not use a predefined array of other names to call at the
same point; the shell function add-zle-hook-widget maintains a similar
array and arranges for the special widget to invoke those additional
widgets.</p>
<p><code>hook</code> is one of isearch-exit, isearch-update, line-pre-redraw,
line-init, line-finish, history-line-set, or keymap-select,
corresponding to each of the special widgets zle-isearch-exit, etc. The
special widget names are also accepted as the <code>hook</code> argument.</p>
2021-05-11 02:29:21 +02:00
<p><code>widgetname</code> is the name of a ZLE widget. If no options are given this
is added to the array of widgets to be invoked in the given hook
context. Widgets are invoked in the order they were added, with</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zle widgetname -Nw -f &quot;nolast&quot; -- &quot;$@&quot;
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p><span id="index-WIDGET_002c-in-hooks"></span></p>
2022-08-24 15:22:41 +02:00
<p>Note that this means that the WIDGET special parameter tracks the
2021-05-11 02:29:21 +02:00
<code>widgetname</code> when the widget function is called, rather than tracking
the name of the corresponding special hook widget.</p>
2022-08-24 15:22:41 +02:00
<p>If the option -d is given, the <code>widgetname</code> is removed from the array of
widgets to be executed.</p>
<p>If the option -D is given, the <code>widgetname</code> is treated as a pattern and
any matching names of widgets are removed from the array.</p>
2021-05-11 02:29:21 +02:00
<p>If <code>widgetname</code> does not name an existing widget when added to the
array, it is assumed that a shell function also named <code>widgetname</code> is
meant to provide the implementation of the widget. This name is
2022-08-24 15:22:41 +02:00
therefore marked for autoloading, and the options -U, -z and -k are
passed as arguments to autoload as with add-zsh-hook. The widget is also
created with zle -N <code>widgetname</code> to cause the corresponding function
to be loaded the first time the hook is called.</p>
<p>The arrays of <code>widgetname</code> are currently maintained in zstyle contexts,
one for each <code>hook</code> context, with a style of widgets. If the -L option
is given, this set of styles is listed with zstyle -L. This
implementation may change, and the special widgets that refer to the
styles are created only if add-zle-hook-widget is called to add at least
one widget, so if this function is used for any hooks, then all hooks
should be managed only via this function.</p>
<hr />
<p><span id="Recent-Directories"></span> <span
id="index-recent-directories_002c-maintaining-list-of"></span> <span
id="index-directories_002c-maintaining-list-of-recent"></span> <span
id="index-cdr"></span> <span id="index-_005fcdr"></span> <span
id="index-chpwd_005frecent_005fadd"></span> <span
id="index-chpwd_005frecent_005fdirs"></span> <span
id="index-chpwd_005frecent_005ffilehandler"></span> <span
id="Remembering-Recent-Directories"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="263-remembering-recent-directories"><a class="header" href="#263-remembering-recent-directories">26.3 Remembering Recent Directories</a></h2>
2022-08-24 15:22:41 +02:00
<p>The function cdr allows you to change the working directory to a
2021-05-11 02:29:21 +02:00
previous working directory from a list maintained automatically. It is
2022-08-24 15:22:41 +02:00
similar in concept to the directory stack controlled by the pushd, popd
and dirs builtins, but is more configurable, and as it stores all
entries in files it is maintained across sessions and (by default)
2021-05-11 02:29:21 +02:00
between terminal emulators in the current session. Duplicates are
automatically removed, so that the list reflects the single most recent
use of each directory.</p>
2022-08-24 15:22:41 +02:00
<p>Note that the pushd directory stack is not actually modified or used by
cdr unless you configure it to do so as described in the configuration
section below.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Installation-2"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="2631-installation"><a class="header" href="#2631-installation">26.3.1 Installation</a></h3>
<p>The system works by means of a hook function that is called every time
the directory changes. To install the system, autoload the required
2022-08-24 15:22:41 +02:00
functions and use the add-zsh-hook function described above:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
2021-05-11 02:29:21 +02:00
add-zsh-hook chpwd chpwd_recent_dirs
</code></pre>
</div>
<p>Now every time you change directly interactively, no matter which
command you use, the directory to which you change will be remembered in
most-recent-first order.</p>
<hr />
<p><span id="Use"></span></p>
<h3 id="2632-use"><a class="header" href="#2632-use">26.3.2 Use</a></h3>
2022-08-24 15:22:41 +02:00
<p>All direct user interaction is via the cdr function.</p>
2021-05-11 02:29:21 +02:00
<p>The argument to cdr is a number <code>N</code> corresponding to the <code>N</code>th most
recently changed-to directory. 1 is the immediately preceding directory;
the current directory is remembered but is not offered as a destination.
Note that if you have multiple windows open 1 may refer to a directory
changed to in another window; you can avoid this by having per-terminal
2022-08-24 15:22:41 +02:00
files for storing directory as described for the recent-dirs-file style
below.</p>
<p>If you set the recent-dirs-default style described below cdr will behave
the same as cd if given a non-numeric argument, or more than one
argument. The recent directory list is updated just the same however you
change directory.</p>
<p>If the argument is omitted, 1 is assumed. This is similar to pushds
2021-05-11 02:29:21 +02:00
behaviour of swapping the two most recent directories on the stack.</p>
2022-08-24 15:22:41 +02:00
<p>Completion for the argument to cdr is available if compinit has been
2021-05-11 02:29:21 +02:00
run; menu selection is recommended, using:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*:*:cdr:*:*' menu selection
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>to allow you to cycle through recent directories; the order is
preserved, so the first choice is the most recent directory before the
current one. The verbose style is also recommended to ensure the
directory is shown; this style is on by default so no action is required
unless you have changed it.</p>
<hr />
<p><span id="Options-2"></span></p>
<h3 id="2633-options"><a class="header" href="#2633-options">26.3.3 Options</a></h3>
2022-08-24 15:22:41 +02:00
<p>The behaviour of cdr may be modified by the following options.</p>
<p>-l<br />
lists the numbers and the corresponding directories in abbreviated form
(i.e. with ~ substitution reapplied), one per line. The directories
here are not quoted (this would only be an issue if a directory name
contained a newline). This is used by the completion system.</p>
<p>-r<br />
sets the variable reply to the current set of directories. Nothing is
printed and the directory is not changed.</p>
<p>-e<br />
allows you to edit the list of directories, one per line. The list can
be edited to any extent you like; no sanity checking is performed.
Completion is available. No quoting is necessary (except for newlines,
where I have in any case no sympathy); directories are in unabbreviated
form and contain an absolute path, i.e. they start with /. Usually the
first entry should be left as the current directory.</p>
<p>-p <code>pattern</code><br />
2021-05-11 02:29:21 +02:00
Prunes any items in the directory list that match the given extended
2022-08-24 15:22:41 +02:00
glob pattern; the pattern needs to be quoted from immediate expansion on
the command line. The pattern is matched against each completely
expanded file name in the list; the full string must match, so wildcards
at the end (e.g. *removeme*) are needed to remove entries with a
given substring.</p>
<p>If output is to a terminal, then the function will print the new list
after pruning and prompt for confirmation by the user. This output and
confirmation step can be skipped by using -P instead of -p.</p>
<hr />
<p><span id="Configuration-1"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="2634-configuration"><a class="header" href="#2634-configuration">26.3.4 Configuration</a></h3>
<p>Configuration is by means of the styles mechanism that should be
2022-08-24 15:22:41 +02:00
familiar from completion; if not, see the description of the zstyle
2021-05-11 02:29:21 +02:00
command in <a href="Zsh-Modules.html#The-zsh_002fzutil-Module">The zsh/zutil
Module</a>. The context for
2022-08-24 15:22:41 +02:00
setting styles should be :chpwd:* in case the meaning of the context
2021-05-11 02:29:21 +02:00
is extended in future, for example:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':chpwd:*' recent-dirs-max 0
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>sets the value of the recent-dirs-max style to 0. In practice the style
name is specific enough that a context of * should be fine.</p>
<p>An exception is recent-dirs-insert, which is used exclusively by the
2021-05-11 02:29:21 +02:00
completion system and so has the usual completion system context
2022-08-24 15:22:41 +02:00
(:completion:* if nothing more specific is needed), though again *
should be fine in practice.</p>
<p>recent-dirs-default<br />
2021-05-11 02:29:21 +02:00
If true, and the command is expecting a recent directory index, and
either there is more than one argument or the argument is not an
2022-08-24 15:22:41 +02:00
integer, then fall through to &quot;cd&quot;. This allows the lazy to use only one
command for directory changing. Completion recognises this, too; see
recent-dirs-insert for how to control completion when this option is in
use.</p>
<p>recent-dirs-file<br />
2021-05-11 02:29:21 +02:00
The file where the list of directories is saved. The default is
2022-08-24 15:22:41 +02:00
${ZDOTDIR:-$HOME}/.chpwd-recent-dirs, i.e. this is in your home
directory unless you have set the variable ZDOTDIR to point somewhere
else. Directory names are saved in $<code>...</code> quoted form, so each line in
the file can be supplied directly to the shell as an argument.</p>
<p>The value of this style may be an array. In this case, the first file in
the list will always be used for saving directories while any other
files are left untouched. When reading the recent directory list, if
there are fewer than the maximum number of entries in the first file,
the contents of later files in the array will be appended with
duplicates removed from the list shown. The contents of the two files
are not sorted together, i.e. all the entries in the first file are
shown first. The special value + can appear in the list to indicate the
default file should be read at that point. This allows effects like the
following:</p>
<div class="example">
<pre><code class="language-zsh">zstyle ':chpwd:*' recent-dirs-file \
2021-05-11 02:29:21 +02:00
~/.chpwd-recent-dirs-${TTY##*/} +
</code></pre>
</div>
<p>Recent directories are read from a file numbered according to the
terminal. If there are insufficient entries the list is supplemented
from the default file.</p>
2022-08-24 15:22:41 +02:00
<p>It is possible to use zstyle -e to make the directory configurable at
run time:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle -e ':chpwd:*' recent-dirs-file pick-recent-dirs-file
2021-05-11 02:29:21 +02:00
pick-recent-dirs-file() {
if [[ $PWD = ~/text/writing(|/*) ]]; then
reply=(~/.chpwd-recent-dirs-writing)
else
reply=(+)
fi
}
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>In this example, if the current directory is ~/text/writing or a
2021-05-11 02:29:21 +02:00
directory under it, then use a special file for saving recent
directories, else use the default.</p>
2022-08-24 15:22:41 +02:00
<p>recent-dirs-insert<br />
Used by completion. If recent-dirs-default is true, then setting this to
true causes the actual directory, rather than its index, to be inserted
on the command line; this has the same effect as using the corresponding
index, but makes the history clearer and the line easier to edit. With
this setting, if part of an argument was already typed, normal directory
completion rather than recent directory completion is done; this is
because recent directory completion is expected to be done by cycling
through entries menu fashion.</p>
<p>If the value of the style is always, then only recent directories will
be completed; in that case, use the cd command when you want to complete
other directories.</p>
<p>If the value is fallback, recent directories will be tried first, then
normal directory completion is performed if recent directory completion
failed to find a match.</p>
<p>Finally, if the value is both then both sets of completions are
presented; the usual tag mechanism can be used to distinguish results,
with recent directories tagged as recent-dirs. Note that the recent
directories inserted are abbreviated with directory names where
appropriate.</p>
<p>recent-dirs-max<br />
The maximum number of directories to save to the file. If this is zero
or negative there is no maximum. The default is 20. Note this includes
the current directory, which isnt offered, so the highest number of
directories you will be offered is one less than the maximum.</p>
<p>recent-dirs-prune<br />
This style is an array determining what directories should (or should
not) be added to the recent list. Elements of the array can include:</p>
<p>parent<br />
Prune parents (more accurately, ancestors) from the recent list. If
present, changing directly down by any number of directories causes the
current directory to be overwritten. For example, changing from ~pws to
~pws/some/other/dir causes ~pws not to be left on the recent directory
stack. This only applies to direct changes to descendant directories;
earlier directories on the list are not pruned. For example, changing
from ~pws/yet/another to ~pws/some/other/dir does not cause ~pws to
be pruned.</p>
<p>pattern:<code>pattern</code><br />
Gives a zsh pattern for directories that should not be added to the
recent list (if not already there). This element can be repeated to add
different patterns. For example, pattern:/tmp(|/*) stops /tmp or its
descendants from being added. The EXTENDED_GLOB option is always turned
on for these patterns.</p>
<p>recent-dirs-pushd<br />
If set to true, cdr will use pushd instead of cd to change the
2021-05-11 02:29:21 +02:00
directory, so the directory is saved on the directory stack. As the
2022-08-24 15:22:41 +02:00
directory stack is completely separate from the list of files saved by
the mechanism used in this file there is no obvious reason to do this.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Use-with-dynamic-directory-naming"></span></p>
<h3 id="2635-use-with-dynamic-directory-naming"><a class="header" href="#2635-use-with-dynamic-directory-naming">26.3.5 Use with dynamic directory naming</a></h3>
<p>It is possible to refer to recent directories using the dynamic
directory name syntax by using the supplied function
2022-08-24 15:22:41 +02:00
zsh_directory_name_cdr a hook:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">autoload -Uz add-zsh-hook
2021-05-11 02:29:21 +02:00
add-zsh-hook -Uz zsh_directory_name zsh_directory_name_cdr
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>When this is done, ~[1] will refer to the most recent directory other
than $PWD, and so on. Completion after ~[<code>...</code> also works.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Details-of-directory-handling"></span></p>
<h3 id="2636-details-of-directory-handling"><a class="header" href="#2636-details-of-directory-handling">26.3.6 Details of directory handling</a></h3>
<p>This section is for the curious or confused; most users will not need to
know this information.</p>
<p>Recent directories are saved to a file immediately and hence are
preserved across sessions. Note currently no file locking is applied:
the list is updated immediately on interactive commands and nowhere else
(unlike history), and it is assumed you are only going to change
directory in one window at once. This is not safe on shared accounts,
but in any case the system has limited utility when someone else is
changing to a different set of directories behind your back.</p>
<p>To make this a little safer, only directory changes instituted from the
command line, either directly or indirectly through shell function calls
(but not through subshells, evals, traps, completion functions and the
2022-08-24 15:22:41 +02:00
like) are saved. Shell functions should use cd -q or pushd -q to avoid
side effects if the change to the directory is to be invisible at the
command line. See the contents of the function chpwd_recent_dirs for
more details.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Other-Directory-Functions"></span> <span
id="index-directories_002c-named_002c-dynamic_002c-helper-function"></span>
2021-05-11 02:29:21 +02:00
<span id="index-dynamic-directory-naming_002c-helper-function"></span>
2022-08-24 15:22:41 +02:00
<span
id="index-named-directories_002c-dynamic_002c-helper-function"></span>
<span id="index-zsh_005fdirectory_005fname_005fgeneric"></span> <span
id="Abbreviated-dynamic-references-to-directories"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="264-abbreviated-dynamic-references-to-directories"><a class="header" href="#264-abbreviated-dynamic-references-to-directories">26.4 Abbreviated dynamic references to directories</a></h2>
<p>The dynamic directory naming system is described in the subsection
<em>Dynamic named directories</em> of <a href="Expansion.html#Filename-Expansion">Filename
Expansion</a>. In this, a reference to
2022-08-24 15:22:41 +02:00
~[<code>...</code>] is expanded by a function found by the hooks mechanism.</p>
<p>The contributed function zsh_directory_name_generic provides a system
2021-05-11 02:29:21 +02:00
allowing the user to refer to directories with only a limited amount of
new code. It supports all three of the standard interfaces for directory
naming: converting from a name to a directory, converting in the reverse
direction to find a short name, and completion of names.</p>
<p>The main feature of this function is a path-like syntax, combining
abbreviations at multiple levels separated by &quot;:&quot;. As an example,
~[g:p:s] might specify:</p>
2022-08-24 15:22:41 +02:00
<p>g<br />
The top level directory for your git area. This first component has to
match, or the function will return indicating another directory name
hook function should be tried.</p>
<p>p<br />
2021-05-11 02:29:21 +02:00
The name of a project within your git area.</p>
2022-08-24 15:22:41 +02:00
<p>s<br />
2021-05-11 02:29:21 +02:00
The source area within that project.</p>
<p>This allows you to collapse references to long hierarchies to a very
compact form, particularly if the hierarchies are similar across
different areas of the disk.</p>
<p>Name components may be completed: if a description is shown at the top
of the list of completions, it includes the path to which previous
components expand, while the description for an individual completion
shows the path segment it would add. No additional configuration is
needed for this as the completion system is aware of the dynamic
directory name mechanism.</p>
<hr />
<p><span id="Usage"></span></p>
<h3 id="2641-usage"><a class="header" href="#2641-usage">26.4.1 Usage</a></h3>
<p>To use the function, first define a wrapper function for your specific
case. Well assume its to be autoloaded. This can have any name but
well refer to it as zdn_mywrapper. This wrapper function will define
various variables and then call this function with the same arguments
that the wrapper function gets. This configuration is described below.</p>
<p>Then arrange for the wrapper to be run as a zsh_directory_name hook:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">autoload -Uz add-zsh-hook zsh_directory_name_generic zdn_mywrapper
2021-05-11 02:29:21 +02:00
add-zsh-hook -U zsh_directory_name zdn_mywrapper
</code></pre>
</div>
<hr />
<p><span id="Configuration"></span></p>
<h3 id="2642-configuration"><a class="header" href="#2642-configuration">26.4.2 Configuration</a></h3>
<p>The wrapper function should define a local associative array zdn_top.
2022-08-24 15:22:41 +02:00
Alternatively, this can be set with a style called mapping. The context
for the style is :zdn:<code>wrapper-name</code> where <code>wrapper-name</code> is the
function calling zsh_directory_name_generic; for example:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle :zdn:zdn_mywrapper: mapping zdn_mywrapper_top
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>The keys in this associative array correspond to the first component of
the name. The values are matching directories. They may have an optional
suffix with a slash followed by a colon and the name of a variable in
the same format to give the next component. (The slash before the colon
is to disambiguate the case where a colon is needed in the path for a
drive. There is otherwise no syntax for escaping this, so path
components whose names start with a colon are not supported.) A special
2022-08-24 15:22:41 +02:00
component :default: specifies a variable in the form /:<code>var</code> (the path
section is ignored and so is usually empty) that will be used for the
next component if no variable is given for the path. Variables referred
to within zdn_top have the same format as zdn_top itself, but contain
relative paths.</p>
2021-05-11 02:29:21 +02:00
<p>For example,</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">local -A zdn_top=(
2021-05-11 02:29:21 +02:00
g ~/git
ga ~/alternate/git
gs /scratch/$USER/git/:second2
:default: /:second1
)
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>This specifies the behaviour of a directory referred to as ~[g:...]
or ~[ga:...] or ~[gs:...]. Later path components are optional; in
that case ~[g] expands to ~/git, and so on. gs expands to
/scratch/$USER/git and uses the associative array second2 to match the
second component; g and ga use the associative array second1 to match
the second component.</p>
<p>When expanding a name to a directory, if the first component is not g or
ga or gs, it is not an error; the function simply returns 1 so that a
later hook function can be tried. However, matching the first component
commits the function, so if a later component does not match, an error
is printed (though this still does not stop later hooks from being
executed).</p>
2021-05-11 02:29:21 +02:00
<p>For components after the first, a relative path is expected, but note
2022-08-24 15:22:41 +02:00
that multiple levels may still appear. Here is an example of second1:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">local -A second1=(
2021-05-11 02:29:21 +02:00
p myproject
s somproject
os otherproject/subproject/:third
)
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The path as found from zdn_top is extended with the matching directory,
so ~[g:p] becomes ~/git/myproject. The slash between is added
automatically (its not possible to have a later component modify the
name of a directory already matched). Only os specifies a variable for a
third component, and theres no :default:, so its an error to use a
name like ~[g:p:x] or ~[ga:s:y] because theres nowhere to look up
the x or y.</p>
2021-05-11 02:29:21 +02:00
<p>The associative arrays need to be visible within this function; the
generic function therefore uses internal variable names beginning
2022-08-24 15:22:41 +02:00
_zdn_ in order to avoid clashes. Note that the variable reply needs to
be passed back to the shell, so should not be local in the calling
2021-05-11 02:29:21 +02:00
function.</p>
<p>The function does not test whether directories assembled by component
actually exist; this allows the system to work across automounted file
systems. The error from the command trying to use a non-existent
directory should be sufficient to indicate the problem.</p>
<hr />
<p><span id="Complete-example"></span></p>
<h3 id="2643-complete-example"><a class="header" href="#2643-complete-example">26.4.3 Complete example</a></h3>
<p>Here is a full fictitious but usable autoloadable definition of the
2022-08-24 15:22:41 +02:00
example function defined by the code above. So ~[gs:p:s] expands to
/scratch/$USER/git/myscratchproject/top/srcdir (with $USER also
2021-05-11 02:29:21 +02:00
expanded).</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">local -A zdn_top=(
2021-05-11 02:29:21 +02:00
g ~/git
ga ~/alternate/git
gs /scratch/$USER/git/:second2
:default: /:second1
)
local -A second1=(
p myproject
s somproject
os otherproject/subproject/:third
)
local -A second2=(
p myscratchproject
s somescratchproject
)
local -A third=(
s top/srcdir
d top/documentation
)
# autoload not needed if you did this at initialisation...
autoload -Uz zsh_directory_name_generic
zsh_directory_name_generic &quot;$@
</code></pre>
</div>
<p>It is also possible to use global associative arrays, suitably named,
and set the style for the context of your wrapper function to refer to
this. Then your set up code would contain the following:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">typeset -A zdn_mywrapper_top=(...)
2021-05-11 02:29:21 +02:00
# ... and so on for other associative arrays ...
zstyle ':zdn:zdn_mywrapper:' mapping zdn_mywrapper_top
autoload -Uz add-zsh-hook zsh_directory_name_generic zdn_mywrapper
add-zsh-hook -U zsh_directory_name zdn_mywrapper
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>and the function zdn_mywrapper would contain only the following:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zsh_directory_name_generic &quot;$@&quot;
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Version-Control-Information"></span> <span
id="Gathering-information-from-version-control-systems"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="265-gathering-information-from-version-control-systems"><a class="header" href="#265-gathering-information-from-version-control-systems">26.5 Gathering information from version control systems</a></h2>
<p><span id="index-version-control-utility"></span></p>
<p>In a lot of cases, it is nice to automatically retrieve information from
version control systems (VCSs), such as subversion, CVS or git, to be
able to provide it to the user; possibly in the users prompt. So that
you can instantly tell which branch you are currently on, for example.</p>
2022-08-24 15:22:41 +02:00
<p>In order to do that, you may use the vcs_info function.</p>
2021-05-11 02:29:21 +02:00
<p>The following VCSs are supported, showing the abbreviated name by which
they are referred to within the system:</p>
2022-08-24 15:22:41 +02:00
<p>Bazaar (bzr)<br />
<a href="https://bazaar.canonical.com/">https://bazaar.canonical.com/</a></p>
<p>Codeville (cdv)<br />
<a href="http://freecode.com/projects/codeville/">http://freecode.com/projects/codeville/</a></p>
<p>Concurrent Versioning System (cvs)<br />
<a href="https://www.nongnu.org/cvs/">https://www.nongnu.org/cvs/</a></p>
<p>Darcs (darcs)<br />
<a href="http://darcs.net/">http://darcs.net/</a></p>
<p>Fossil (fossil)<br />
<a href="https://fossil-scm.org/">https://fossil-scm.org/</a></p>
<p>Git (git)<br />
<a href="https://git-scm.com/">https://git-scm.com/</a></p>
<p>GNU arch (tla)<br />
<a href="https://www.gnu.org/software/gnu-arch/">https://www.gnu.org/software/gnu-arch/</a></p>
<p>Mercurial (hg)<br />
<a href="https://www.mercurial-scm.org/">https://www.mercurial-scm.org/</a></p>
<p>Monotone (mtn)<br />
<a href="https://monotone.ca/">https://monotone.ca/</a></p>
<p>Perforce (p4)<br />
<a href="https://www.perforce.com/">https://www.perforce.com/</a></p>
<p>Subversion (svn)<br />
<a href="https://subversion.apache.org/">https://subversion.apache.org/</a></p>
<p>SVK (svk)<br />
<a href="https://svk.bestpractical.com/">https://svk.bestpractical.com/</a></p>
<p>There is also support for the patch management system quilt
(<a href="https://savannah.nongnu.org/projects/quilt">https://savannah.nongnu.org/projects/quilt</a>). See <a href="User-Contributions.html#vcs_005finfo-Quilt-Support">Quilt
2021-05-11 02:29:21 +02:00
Support</a> below for details.</p>
2022-08-24 15:22:41 +02:00
<p>To load vcs_info:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">autoload -Uz vcs_info
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>It can be used in any existing prompt, because it does not require any
2022-08-24 15:22:41 +02:00
specific $psvar entries to be available.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="vcs_005finfo-Quickstart"></span> <span id="Quickstart"></span></p>
<h3 id="2651-quickstart"><a class="header" href="#2651-quickstart">26.5.1 Quickstart</a></h3>
<p>To get this feature working quickly (including colors), you can do the
2022-08-24 15:22:41 +02:00
following (assuming, you loaded vcs_info properly - see above):</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':vcs_info:*' actionformats \
2021-05-11 02:29:21 +02:00
'%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f '
zstyle ':vcs_info:*' formats \
'%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{5}]%f '
zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r'
precmd () { vcs_info }
PS1='%F{5}[%F{2}%n%F{5}] %F{3}%3~ ${vcs_info_msg_0_}%f%# '
</code></pre>
</div>
<p>Obviously, the last two lines are there for demonstration. You need to
2022-08-24 15:22:41 +02:00
call vcs_info from your precmd function. Once that is done you need a
<em>single quoted</em> ${vcs_info_msg_0_} in your prompt.</p>
<p>To be able to use ${vcs_info_msg_0_} directly in your prompt like
this, you will need to have the PROMPT_SUBST option enabled.</p>
<p>Now call the vcs_info_printsys utility from the command line:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">% vcs_info_printsys
2021-05-11 02:29:21 +02:00
## list of supported version control backends:
## disabled systems are prefixed by a hash sign (#)
bzr
cdv
cvs
darcs
fossil
git
hg
mtn
p4
svk
svn
tla
## flavours (cannot be used in the enable or disable styles; they
## are enabled and disabled with their master [git-svn -&gt; git])
## they *can* be used in contexts: ':vcs_info:git-svn:*'.
git-p4
git-svn
hg-git
hg-hgsubversion
hg-hgsvn
</code></pre>
</div>
<p>You may not want all of these because there is no point in running the
code to detect systems you do not use. So there is a way to disable some
backends altogether:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':vcs_info:*' disable bzr cdv darcs mtn svk tla
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>You may also pick a few from that list and enable only those:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':vcs_info:*' enable git cvs svn
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>If you rerun vcs_info_printsys after one of these commands, you will see
the backends listed in the disable style (or backends not in the enable
style - if you used that) marked as disabled by a hash sign. That means
the detection of these systems is skipped <em>completely</em>. No wasted time
there.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="vcs_005finfo-Configuration"></span> <span
id="Configuration-3"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="2652-configuration"><a class="header" href="#2652-configuration">26.5.2 Configuration</a></h3>
2022-08-24 15:22:41 +02:00
<p>The vcs_info feature can be configured via zstyle.</p>
2021-05-11 02:29:21 +02:00
<p>First, the context in which we are working:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">:vcs_info:vcs-string:user-context:repo-root-name
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p><code>vcs-string</code><br />
2022-08-24 15:22:41 +02:00
is one of: git, git-svn, git-p4, hg, hg-git, hg-hgsubversion, hg-hgsvn,
darcs, bzr, cdv, mtn, svn, cvs, svk, tla, p4 or fossil. This is followed
by .quilt-<code>quilt-mode</code> in Quilt mode (see <a href="User-Contributions.html#vcs_005finfo-Quilt-Support">Quilt
Support</a> for details) and by +<code>hook-name</code>
while hooks are active (see <a href="User-Contributions.html#vcs_005finfo-Hooks">Hooks in vcs_info</a> for
details).</p>
<p>Currently, hooks in quilt mode dont add the .quilt-<code>quilt-mode</code>
2021-05-11 02:29:21 +02:00
information. This may change in the future.</p>
<p><code>user-context</code><br />
is a freely configurable string, assignable by the user as the first
2022-08-24 15:22:41 +02:00
argument to vcs_info (see its description below).</p>
2021-05-11 02:29:21 +02:00
<p><code>repo-root-name</code><br />
2022-08-24 15:22:41 +02:00
is the name of a repository in which you want a style to match. So, if
you want a setting specific to /usr/src/zsh, with that being a CVS
checkout, you can set <code>repo-root-name</code> to zsh to make it so.</p>
2021-05-11 02:29:21 +02:00
<p>There are three special values for <code>vcs-string</code>: The first is named
2022-08-24 15:22:41 +02:00
-init-, that is in effect as long as there was no decision what VCS
backend to use. The second is -preinit-; it is used <em>before</em> vcs_info is
run, when initializing the data exporting variables. The third special
value is formats and is used by the vcs_info_lastmsg for looking up its
styles.</p>
<p>The initial value of <code>repo-root-name</code> is -all- and it is replaced with
2021-05-11 02:29:21 +02:00
the actual name, as soon as it is known. Only use this part of the
2022-08-24 15:22:41 +02:00
context for defining the formats, actionformats or branchformat styles,
as it is guaranteed that <code>repo-root-name</code> is set up correctly for these
only. For all other styles, just use * instead.</p>
2021-05-11 02:29:21 +02:00
<p>There are two pre-defined values for <code>user-context</code>:</p>
2022-08-24 15:22:41 +02:00
<p>default<br />
2021-05-11 02:29:21 +02:00
the one used if none is specified</p>
2022-08-24 15:22:41 +02:00
<p>command<br />
2021-05-11 02:29:21 +02:00
used by vcs_info_lastmsg to lookup its styles</p>
2022-08-24 15:22:41 +02:00
<p>You can of course use :vcs_info:* to match all VCSs in all
2021-05-11 02:29:21 +02:00
user-contexts at once.</p>
<p>This is a description of all styles that are looked up.</p>
<p><span id="index-formats"></span></p>
2022-08-24 15:22:41 +02:00
<p>formats</p>
2021-05-11 02:29:21 +02:00
<p>A list of formats, used when actionformats is not used (which is most of
the time).</p>
<p><span id="index-actionformats"></span></p>
2022-08-24 15:22:41 +02:00
<p>actionformats</p>
2021-05-11 02:29:21 +02:00
<p>A list of formats, used if there is a special action going on in your
current repository; like an interactive rebase or a merge conflict.</p>
<p><span id="index-branchformat"></span></p>
2022-08-24 15:22:41 +02:00
<p>branchformat</p>
<p>Some backends replace %b in the formats and actionformats styles above,
not only by a branch name but also by a revision number. This style lets
you modify how that string should look.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-nvcsformats"></span></p>
2022-08-24 15:22:41 +02:00
<p>nvcsformats</p>
2021-05-11 02:29:21 +02:00
<p>These &quot;formats&quot; are set when we didnt detect a version control system
2022-08-24 15:22:41 +02:00
for the current directory or vcs_info was disabled. This is useful if
you want vcs_info to completely take over the generation of your prompt.
You would do something like PS1=${vcs_info_msg_0_} to accomplish
that.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-hgrevformat"></span></p>
2022-08-24 15:22:41 +02:00
<p>hgrevformat</p>
<p>hg uses both a hash and a revision number to reference a specific
2021-05-11 02:29:21 +02:00
changeset in a repository. With this style you can format the revision
2022-08-24 15:22:41 +02:00
string (see branchformat) to include either or both. Its only useful
when get-revision is true. Note, the full 40-character revision id is
not available (except when using the use-simple option) because
2021-05-11 02:29:21 +02:00
executing hg more than once per prompt is too slow; you may customize
this behavior using hooks.</p>
<p><span id="index-max_002dexports"></span></p>
2022-08-24 15:22:41 +02:00
<p>max-exports</p>
<p>Defines the maximum number of vcs_info_msg_*_ variables vcs_info will
set.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-enable-1"></span></p>
2022-08-24 15:22:41 +02:00
<p>enable</p>
<p>A list of backends you want to use. Checked in the -init- context. If
this list contains an item called NONE no backend is used at all and
vcs_info will do nothing. If this list contains ALL, vcs_info will use
all known backends. Only with ALL in enable will the disable style have
any effect. ALL and NONE are case insensitive.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-disable-1"></span></p>
2022-08-24 15:22:41 +02:00
<p>disable</p>
<p>A list of VCSs you dont want vcs_info to test for repositories (checked
in the -init- context, too). Only used if enable contains ALL.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-disable_002dpatterns"></span></p>
2022-08-24 15:22:41 +02:00
<p>disable-patterns</p>
<p>A list of patterns that are checked against $PWD. If a pattern matches,
vcs_info will be disabled. This style is checked in the
:vcs_info:-init-:*:-all- context.</p>
<p>Say, ~/.zsh is a directory under version control, in which you do not
want vcs_info to be active, do:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':vcs_info:*' disable-patterns &quot;${(b)HOME}/.zsh(|/*)&quot;
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p><span id="index-use_002dquilt"></span></p>
2022-08-24 15:22:41 +02:00
<p>use-quilt</p>
<p>If enabled, the quilt support code is active in addon mode. See <a href="User-Contributions.html#vcs_005finfo-Quilt-Support">Quilt
Support</a> for details.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-quilt_002dstandalone"></span></p>
2022-08-24 15:22:41 +02:00
<p>quilt-standalone</p>
2021-05-11 02:29:21 +02:00
<p>If enabled, standalone mode detection is attempted if no VCS is active
in a given directory. See <a href="User-Contributions.html#vcs_005finfo-Quilt-Support">Quilt Support</a>
for details.</p>
<p><span id="index-quilt_002dpatch_002ddir"></span></p>
2022-08-24 15:22:41 +02:00
<p>quilt-patch-dir</p>
<p>Overwrite the value of the $QUILT_PATCHES environment variable. See
2021-05-11 02:29:21 +02:00
<a href="User-Contributions.html#vcs_005finfo-Quilt-Support">Quilt Support</a> for details.</p>
<p><span id="index-quiltcommand"></span></p>
2022-08-24 15:22:41 +02:00
<p>quiltcommand</p>
<p>When quilt itself is called in quilt support, the value of this style is
used as the command name.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-check_002dfor_002dchanges"></span></p>
2022-08-24 15:22:41 +02:00
<p>check-for-changes</p>
<p>If enabled, this style causes the %c and %u format escapes to show when
the working directory has uncommitted changes. The strings displayed by
these escapes can be controlled via the stagedstr and unstagedstr
styles. The only backends that currently support this option are git,
hg, and bzr (the latter two only support unstaged).</p>
<p>For this style to be evaluated with the hg backend, the get-revision
style needs to be set and the use-simple style needs to be unset. The
2021-05-11 02:29:21 +02:00
latter is the default; the former is not.</p>
2022-08-24 15:22:41 +02:00
<p>With the bzr backend, <em>lightweight checkouts</em> only honor this style if
the use-server style is set.</p>
2021-05-11 02:29:21 +02:00
<p>Note, the actions taken if this style is enabled are potentially
expensive (read: they may be slow, depending on how big the current
repository is). Therefore, it is disabled by default.</p>
<p><span id="index-check_002dfor_002dstaged_002dchanges"></span></p>
2022-08-24 15:22:41 +02:00
<p>check-for-staged-changes</p>
<p>This style is like check-for-changes, but it never checks the worktree
files, only the metadata in the .${vcs} dir. Therefore, this style
initializes only the %c escape (with stagedstr) but not the %u escape.
This style is faster than check-for-changes.</p>
<p>In the git backend, this style checks for changes in the index. Other
2021-05-11 02:29:21 +02:00
backends do not currently implement this style.</p>
<p>This style is disabled by default.</p>
<p><span id="index-stagedstr"></span></p>
2022-08-24 15:22:41 +02:00
<p>stagedstr</p>
<p>This string will be used in the %c escape if there are staged changes in
the repository.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-unstagedstr"></span></p>
2022-08-24 15:22:41 +02:00
<p>unstagedstr</p>
<p>This string will be used in the %u escape if there are unstaged changes
in the repository.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-command-2"></span></p>
2022-08-24 15:22:41 +02:00
<p>command</p>
<p>This style causes vcs_info to use the supplied string as the command to
use as the VCSs binary. Note, that setting this in :vcs_info:* is
not a good idea.</p>
2021-05-11 02:29:21 +02:00
<p>If the value of this style is empty (which is the default), the used
2022-08-24 15:22:41 +02:00
binary name is the name of the backend in use (e.g. svn is used in an
svn repository).</p>
<p>The repo-root-name part in the context is always the default -all- when
this style is looked up.</p>
2021-05-11 02:29:21 +02:00
<p>For example, this style can be used to use binaries from non-default
2022-08-24 15:22:41 +02:00
installation directories. Assume, git is installed in /usr/bin but your
sysadmin installed a newer version in /usr/local/bin. Instead of
changing the order of your $PATH parameter, you can do this:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':vcs_info:git:*:-all-' command /usr/local/bin/git
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p><span id="index-use_002dserver"></span></p>
2022-08-24 15:22:41 +02:00
<p>use-server</p>
<p>This is used by the Perforce backend (p4) to decide if it should contact
the Perforce server to find out if a directory is managed by Perforce.
This is the only reliable way of doing this, but runs the risk of a
delay if the server name cannot be found. If the server (more
specifically, the <code>host</code>:<code>port</code> pair describing the server) cannot be
2021-05-11 02:29:21 +02:00
contacted, its name is put into the associative array
2022-08-24 15:22:41 +02:00
vcs_info_p4_dead_servers and is not contacted again during the session
until it is removed by hand. If you do not set this style, the p4
backend is only usable if you have set the environment variable P4CONFIG
to a file name and have corresponding files in the root directories of
each Perforce client. See comments in the function VCS_INFO_detect_p4
for more detail.</p>
<p>The Bazaar backend (bzr) uses this to permit contacting the server about
lightweight checkouts, see the check-for-changes style.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-use_002dsimple"></span></p>
2022-08-24 15:22:41 +02:00
<p>use-simple</p>
2021-05-11 02:29:21 +02:00
<p>If there are two different ways of gathering information, you can select
the simpler one by setting this style to true; the default is to use the
not-that-simple code, which is potentially a lot slower but might be
2022-08-24 15:22:41 +02:00
more accurate in all possible cases. This style is used by the bzr, hg,
and git backends. In the case of hg it will invoke the external hexdump
2021-05-11 02:29:21 +02:00
program to parse the binary dirstate cache file; this method will not
return the local revision number.</p>
<p><span id="index-get_002drevision"></span></p>
2022-08-24 15:22:41 +02:00
<p>get-revision</p>
2021-05-11 02:29:21 +02:00
<p>If set to true, vcs_info goes the extra mile to figure out the revision
2022-08-24 15:22:41 +02:00
of a repositorys work tree (currently for the git and hg backends,
where this kind of information is not always vital). For git, the hash
value of the currently checked out commit is available via the %i
expansion. With hg, the local revision number and the corresponding
global hash are available via %i.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-get_002dmq"></span></p>
2022-08-24 15:22:41 +02:00
<p>get-mq</p>
<p>If set to true, the hg backend will look for a Mercurial Queue (mq)
patch directory. Information will be available via the %m replacement.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-get_002dbookmarks"></span></p>
2022-08-24 15:22:41 +02:00
<p>get-bookmarks</p>
<p>If set to true, the hg backend will try to get a list of current
bookmarks. They will be available via the %m replacement.</p>
2021-05-11 02:29:21 +02:00
<p>The default is to generate a comma-separated list of all bookmark names
that refer to the currently checked out revision. If a bookmark is
active, its name is suffixed an asterisk and placed first in the list.</p>
<p><span id="index-use_002dprompt_002descapes"></span></p>
2022-08-24 15:22:41 +02:00
<p>use-prompt-escapes</p>
<p>Determines if we assume that the assembled string from vcs_info includes
prompt escapes. (Used by vcs_info_lastmsg.)</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-debug"></span></p>
2022-08-24 15:22:41 +02:00
<p>debug</p>
2021-05-11 02:29:21 +02:00
<p>Enable debugging output to track possible problems. Currently this style
2022-08-24 15:22:41 +02:00
is only used by vcs_infos hooks system.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-hooks"></span></p>
2022-08-24 15:22:41 +02:00
<p>hooks</p>
2021-05-11 02:29:21 +02:00
<p>A list style that defines hook-function names. See <a href="User-Contributions.html#vcs_005finfo-Hooks">Hooks in
vcs_info</a> below for details.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-patch_002dformat"></span> <span
id="index-nopatch_002dformat"></span></p>
<p>patch-format</p>
<p>nopatch-format</p>
<p>This pair of styles format the patch information used by the %m expando
in formats and actionformats for the git and hg backends. The value is
subject to certain %-expansions described below. The expanded value is
made available in the global backend_misc array as
${backend_misc[patches]} (also if a set-patch-format hook is used).</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-get_002dunapplied"></span></p>
2022-08-24 15:22:41 +02:00
<p>get-unapplied</p>
2021-05-11 02:29:21 +02:00
<p>This boolean style controls whether a backend should attempt to gather a
list of unapplied patches (for example with Mercurial Queue patches).</p>
2022-08-24 15:22:41 +02:00
<p>Used by the quilt, hg, and git backends.</p>
2021-05-11 02:29:21 +02:00
<p>The default values for these styles in all contexts are:</p>
2022-08-24 15:22:41 +02:00
<p>formats<br />
2021-05-11 02:29:21 +02:00
&quot; (%s)-[%b]%u%c-&quot;</p>
2022-08-24 15:22:41 +02:00
<p>actionformats<br />
2021-05-11 02:29:21 +02:00
&quot; (%s)-[%b|%a]%u%c-&quot;</p>
2022-08-24 15:22:41 +02:00
<p>branchformat<br />
2021-05-11 02:29:21 +02:00
&quot;%b:%r&quot; (for bzr, svn, svk and hg)</p>
2022-08-24 15:22:41 +02:00
<p>nvcsformats<br />
2021-05-11 02:29:21 +02:00
&quot;&quot;</p>
2022-08-24 15:22:41 +02:00
<p>hgrevformat<br />
2021-05-11 02:29:21 +02:00
&quot;%r:%h&quot;</p>
2022-08-24 15:22:41 +02:00
<p>max-exports<br />
2021-05-11 02:29:21 +02:00
2</p>
2022-08-24 15:22:41 +02:00
<p>enable<br />
2021-05-11 02:29:21 +02:00
ALL</p>
2022-08-24 15:22:41 +02:00
<p>disable<br />
2021-05-11 02:29:21 +02:00
(empty list)</p>
2022-08-24 15:22:41 +02:00
<p>disable-patterns<br />
2021-05-11 02:29:21 +02:00
(empty list)</p>
2022-08-24 15:22:41 +02:00
<p>check-for-changes<br />
2021-05-11 02:29:21 +02:00
false</p>
2022-08-24 15:22:41 +02:00
<p>check-for-staged-changes<br />
2021-05-11 02:29:21 +02:00
false</p>
2022-08-24 15:22:41 +02:00
<p>stagedstr<br />
2021-05-11 02:29:21 +02:00
(string: &quot;S&quot;)</p>
2022-08-24 15:22:41 +02:00
<p>unstagedstr<br />
2021-05-11 02:29:21 +02:00
(string: &quot;U&quot;)</p>
2022-08-24 15:22:41 +02:00
<p>command<br />
2021-05-11 02:29:21 +02:00
(empty string)</p>
2022-08-24 15:22:41 +02:00
<p>use-server<br />
2021-05-11 02:29:21 +02:00
false</p>
2022-08-24 15:22:41 +02:00
<p>use-simple<br />
2021-05-11 02:29:21 +02:00
false</p>
2022-08-24 15:22:41 +02:00
<p>get-revision<br />
2021-05-11 02:29:21 +02:00
false</p>
2022-08-24 15:22:41 +02:00
<p>get-mq<br />
2021-05-11 02:29:21 +02:00
true</p>
2022-08-24 15:22:41 +02:00
<p>get-bookmarks<br />
2021-05-11 02:29:21 +02:00
false</p>
2022-08-24 15:22:41 +02:00
<p>use-prompt-escapes<br />
2021-05-11 02:29:21 +02:00
true</p>
2022-08-24 15:22:41 +02:00
<p>debug<br />
2021-05-11 02:29:21 +02:00
false</p>
2022-08-24 15:22:41 +02:00
<p>hooks<br />
2021-05-11 02:29:21 +02:00
(empty list)</p>
2022-08-24 15:22:41 +02:00
<p>use-quilt<br />
2021-05-11 02:29:21 +02:00
false</p>
2022-08-24 15:22:41 +02:00
<p>quilt-standalone<br />
2021-05-11 02:29:21 +02:00
false</p>
2022-08-24 15:22:41 +02:00
<p>quilt-patch-dir<br />
empty - use $QUILT_PATCHES</p>
<p>quiltcommand<br />
2021-05-11 02:29:21 +02:00
quilt</p>
2022-08-24 15:22:41 +02:00
<p>patch-format<br />
2021-05-11 02:29:21 +02:00
<code>backend dependent</code></p>
2022-08-24 15:22:41 +02:00
<p>nopatch-format<br />
2021-05-11 02:29:21 +02:00
<code>backend dependent</code></p>
2022-08-24 15:22:41 +02:00
<p>get-unapplied<br />
2021-05-11 02:29:21 +02:00
false</p>
2022-08-24 15:22:41 +02:00
<p>In normal formats and actionformats the following replacements are done:</p>
<p>%s<br />
2021-05-11 02:29:21 +02:00
The VCS in use (git, hg, svn, etc.).</p>
2022-08-24 15:22:41 +02:00
<p>%b<br />
2021-05-11 02:29:21 +02:00
Information about the current branch.</p>
2022-08-24 15:22:41 +02:00
<p>%a<br />
2021-05-11 02:29:21 +02:00
An identifier that describes the action. Only makes sense in
2022-08-24 15:22:41 +02:00
actionformats.</p>
<p>%i<br />
The current revision number or identifier. For hg the hgrevformat style
may be used to customize the output.</p>
<p>%c<br />
The string from the stagedstr style if there are staged changes in the
repository.</p>
<p>%u<br />
The string from the unstagedstr style if there are unstaged changes in
2021-05-11 02:29:21 +02:00
the repository.</p>
2022-08-24 15:22:41 +02:00
<p>%R<br />
2021-05-11 02:29:21 +02:00
The base directory of the repository.</p>
2022-08-24 15:22:41 +02:00
<p>%r<br />
The repository name. If %R is /foo/bar/repoXY, %r is repoXY.</p>
<p>%S<br />
A subdirectory within a repository. If $PWD is
/foo/bar/repoXY/beer/tasty, %S is beer/tasty.</p>
<!-- -->
<p>%m<br />
A &quot;misc&quot; replacement. It is at the discretion of the backend to decide
what this replacement expands to.</p>
<p>The hg and git backends use this expando to display patch information.
hg sources patch information from the mq extensions; git from
in-progress rebase and cherry-pick operations and from the stgit
extension. The patch-format and nopatch-format styles control the
generated string. The former is used when at least one patch from the
patch queue has been applied, and the latter otherwise.</p>
<p>The hg backend displays bookmark information in this expando (in
addition to mq information). See the get-mq and get-bookmarks styles.
Both of these styles may be enabled at the same time. If both are
enabled, both resulting strings will be shown separated by a semicolon
(that cannot currently be customized).</p>
<p>The quilt standalone backend sets this expando to the same value as
the %Q expando.</p>
<p>%Q<br />
Quilt series information. When quilt is used (either in addon mode or
as a standalone backend), this expando is set to the quilt series
patch-format string. The set-patch-format hook and nopatch-format style
are honoured.</p>
2021-05-11 02:29:21 +02:00
<p>See <a href="User-Contributions.html#vcs_005finfo-Quilt-Support">Quilt Support</a> below for details.</p>
2022-08-24 15:22:41 +02:00
<p>In branchformat these replacements are done:</p>
<p>%b<br />
The branch name. For hg, the branch name can include a topic name.</p>
<p>%r<br />
The current revision number or the hgrevformat style for hg.</p>
<p>In hgrevformat these replacements are done:</p>
<p>%r<br />
2021-05-11 02:29:21 +02:00
The current local revision number.</p>
2022-08-24 15:22:41 +02:00
<p>%h<br />
2021-05-11 02:29:21 +02:00
The current global revision identifier.</p>
2022-08-24 15:22:41 +02:00
<p>In patch-format and nopatch-format these replacements are done:</p>
<p>%p<br />
2021-05-11 02:29:21 +02:00
The name of the top-most applied patch; may be overridden by the
2022-08-24 15:22:41 +02:00
applied-string hook.</p>
<p>%u<br />
2021-05-11 02:29:21 +02:00
The number of unapplied patches; may be overridden by the
2022-08-24 15:22:41 +02:00
unapplied-string hook.</p>
<p>%n<br />
2021-05-11 02:29:21 +02:00
The number of applied patches.</p>
2022-08-24 15:22:41 +02:00
<p>%c<br />
2021-05-11 02:29:21 +02:00
The number of unapplied patches.</p>
2022-08-24 15:22:41 +02:00
<p>%a<br />
The number of all patches (%a = %n + %c).</p>
<p>%g<br />
The names of active mq guards (hg backend).</p>
<p>%G<br />
The number of active mq guards (hg backend).</p>
<p>Not all VCS backends have to support all replacements. For nvcsformats
2021-05-11 02:29:21 +02:00
no replacements are performed at all, it is just a string.</p>
<hr />
<p><span id="vcs_005finfo-Oddities"></span> <span id="Oddities"></span></p>
<h3 id="2653-oddities"><a class="header" href="#2653-oddities">26.5.3 Oddities</a></h3>
2022-08-24 15:22:41 +02:00
<p>If you want to use the %b (bold off) prompt expansion in formats, which
expands %b itself, use %%b. That will cause the vcs_info expansion to
replace %%b with %b, so that zshs prompt expansion mechanism can handle
it. Similarly, to hand down %b from branchformat, use %%%%b. Sorry for
this inconvenience, but it cannot be easily avoided. Luckily we do not
clash with a lot of prompt expansions and this only needs to be done for
those.</p>
<p>When one of the gen-applied-string, gen-unapplied-string, and
set-patch-format hooks is defined, applying %-escaping
(foo=${foo//%/%%}) to the interpolated values for use in the prompt
is the responsibility of those hooks (jointly); when neither of those
hooks is defined, vcs_info handles escaping by itself. We regret this
coupling, but it was required for backwards compatibility.</p>
<hr />
<p><span id="vcs_005finfo-Quilt-Support"></span> <span
id="Quilt-Support"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="2654-quilt-support"><a class="header" href="#2654-quilt-support">26.5.4 Quilt Support</a></h3>
<p>Quilt is not a version control system, therefore this is not implemented
as a backend. It can help keeping track of a series of patches. People
use it to keep a set of changes they want to use on top of software
packages (which is tightly integrated into the package build process -
the Debian project does this for a large number of packages). Quilt can
also help individual developers keep track of their own patches on top
of real version control systems.</p>
2022-08-24 15:22:41 +02:00
<p>The vcs_info integration tries to support both ways of using quilt by
2021-05-11 02:29:21 +02:00
having two slightly different modes of operation: addon mode and
standalone mode).</p>
2022-08-24 15:22:41 +02:00
<p>Quilt integration is off by default; to enable it, set the use-quilt
style, and add %Q to your formats or actionformats style:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':vcs_info:*' use-quilt true
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>Styles looked up from the Quilt support code include
2022-08-24 15:22:41 +02:00
.quilt-<code>quilt-mode</code> in the <code>vcs-string</code> part of the context, where
<code>quilt-mode</code> is either addon or standalone. Example:
:vcs_info:git.quilt-addon:default:<code>repo-root-name</code>.</p>
<p>For addon mode to become active vcs_info must have already detected a
real version control system controlling the directory. If that is the
2021-05-11 02:29:21 +02:00
case, a directory that holds quilts patches needs to be found. That
2022-08-24 15:22:41 +02:00
directory is configurable via the QUILT_PATCHES environment variable.
If that variable exists its value is used, otherwise the value patches
is assumed. The value from $QUILT_PATCHES can be overwritten using the
quilt-patch-dir style. (Note: you can use vcs_info to keep the value
of $QUILT_PATCHES correct all the time via the post-quilt hook).</p>
2021-05-11 02:29:21 +02:00
<p>When the directory in question is found, quilt is assumed to be active.
2022-08-24 15:22:41 +02:00
To gather more information, vcs_info looks for a directory called .pc;
Quilt uses that directory to track its current state. If this directory
does not exist we know that quilt has not done anything to the working
directory (read: no patches have been applied yet).</p>
<p>If patches are applied, vcs_info will try to find out which. If you want
to know which patches of a series are not yet applied, you need to
activate the get-unapplied style in the appropriate context.</p>
<p>vcs_info allows for very detailed control over how the gathered
2021-05-11 02:29:21 +02:00
information is presented (see
<a href="User-Contributions.html#vcs_005finfo-Configuration">Configuration</a> and <a href="User-Contributions.html#vcs_005finfo-Hooks">Hooks in
2022-08-24 15:22:41 +02:00
vcs_info</a>), all of which are documented below. Note
there are a number of other patch tracking systems that work on top of a
certain version control system (like stgit for git, or mq for hg); the
configuration for systems like that are generally configured the same
way as the quilt support.</p>
2021-05-11 02:29:21 +02:00
<p>If the quilt support is working in addon mode, the produced string is
2022-08-24 15:22:41 +02:00
available as a simple format replacement (%Q to be precise), which can
be used in formats and actionformats; see below for details).</p>
2021-05-11 02:29:21 +02:00
<p>If, on the other hand, the support code is working in standalone mode,
2022-08-24 15:22:41 +02:00
vcs_info will pretend as if quilt were an actual version control system.
That means that the version control system identifier (which otherwise
would be something like svn or cvs) will be set to -quilt-. This
has implications on the used style context where this identifier is the
second element. vcs_info will have filled in a proper value for the
&quot;repositorys&quot; root directory and the string containing the information
about quilts state will be available as the misc replacement (and %Q
for compatibility with addon mode).</p>
2021-05-11 02:29:21 +02:00
<p>What is left to discuss is how standalone mode is detected. The
detection itself is a series of searches for directories. You can have
this detection enabled all the time in every directory that is not
otherwise under version control. If you know there is only a limited set
2022-08-24 15:22:41 +02:00
of trees where you would like vcs_info to try and look for Quilt in
2021-05-11 02:29:21 +02:00
standalone mode to minimise the amount of searching on every call to
2022-08-24 15:22:41 +02:00
vcs_info, there are a number of ways to do that:</p>
2021-05-11 02:29:21 +02:00
<p>Essentially, standalone mode detection is controlled by a style called
2022-08-24 15:22:41 +02:00
quilt-standalone. It is a string style and its value can have
different effects. The simplest values are: always to run detection
every time vcs_info is run, and never to turn the detection off
2021-05-11 02:29:21 +02:00
entirely.</p>
2022-08-24 15:22:41 +02:00
<p>If the value of quilt-standalone is something else, it is interpreted
2021-05-11 02:29:21 +02:00
differently. If the value is the name of a scalar variable the value of
that variable is checked and that value is used in the same
always/never way as described above.</p>
2022-08-24 15:22:41 +02:00
<p>If the value of quilt-standalone is an array, the elements of that array
are used as directory names under which you want the detection to be
active.</p>
<p>If quilt-standalone is an associative array, the keys are taken as
2021-05-11 02:29:21 +02:00
directory names under which you want the detection to be active, but
2022-08-24 15:22:41 +02:00
only if the corresponding value is the string true.</p>
<p>Last, but not least, if the value of quilt-standalone is the name of a
2021-05-11 02:29:21 +02:00
function, the function is called without arguments and the return value
decides whether detection should be active. A 0 return value is true;
a non-zero return value is interpreted as false.</p>
<p>Note, if there is both a function and a variable by the name of
2022-08-24 15:22:41 +02:00
quilt-standalone, the function will take precedence.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="vcs_005finfo-API"></span> <span
id="Function-Descriptions-_0028Public-API_0029"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="2655-function-descriptions-public-api"><a class="header" href="#2655-function-descriptions-public-api">26.5.5 Function Descriptions (Public API)</a></h3>
<p><span id="index-vcs_005finfo"></span></p>
2022-08-24 15:22:41 +02:00
<p>vcs_info [<code>user-context</code>]</p>
2021-05-11 02:29:21 +02:00
<p>The main function, that runs all backends and assembles all data into
2022-08-24 15:22:41 +02:00
${vcs_info_msg_*_}. This is the function you want to call from precmd
if you want to include up-to-date information in your prompt (see
<a href="User-Contributions.html#vcs_005finfo-Variables">Variable Description</a> below). If an argument
is given, that string will be used instead of default in the
2021-05-11 02:29:21 +02:00
<code>user-context</code> field of the style context.</p>
<p><span id="index-vcs_005finfo_005fhookadd"></span></p>
2022-08-24 15:22:41 +02:00
<p>vcs_info_hookadd</p>
2021-05-11 02:29:21 +02:00
<p>Statically registers a number of functions to a given hook. The hook
needs to be given as the first argument; what follows is a list of
2022-08-24 15:22:41 +02:00
hook-function names to register to the hook. The +vi- prefix needs to
be left out here. See <a href="User-Contributions.html#vcs_005finfo-Hooks">Hooks in vcs_info</a> below for
details.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-vcs_005finfo_005fhookdel"></span></p>
2022-08-24 15:22:41 +02:00
<p>vcs_info_hookdel</p>
2021-05-11 02:29:21 +02:00
<p>Remove hook-functions from a given hook. The hook needs to be given as
the first non-option argument; what follows is a list of hook-function
2022-08-24 15:22:41 +02:00
names to un-register from the hook. If -a is used as the first
argument, all occurrences of the functions are unregistered. Otherwise
2021-05-11 02:29:21 +02:00
only the last occurrence is removed (if a function was registered to a
2022-08-24 15:22:41 +02:00
hook more than once). The +vi- prefix needs to be left out here. See
2021-05-11 02:29:21 +02:00
<a href="User-Contributions.html#vcs_005finfo-Hooks">Hooks in vcs_info</a> below for details.</p>
<p><span id="index-vcs_005finfo_005flastmsg"></span></p>
2022-08-24 15:22:41 +02:00
<p>vcs_info_lastmsg</p>
<p>Outputs the current values of ${vcs_info_msg_*_}. Takes into account
the value of the use-prompt-escapes style in
:vcs_info:formats:command:-all-. It also only prints max-exports
2021-05-11 02:29:21 +02:00
values.</p>
<p><span id="index-vcs_005finfo_005fprintsys"></span></p>
2022-08-24 15:22:41 +02:00
<p>vcs_info_printsys [<code>user-context</code>]</p>
2021-05-11 02:29:21 +02:00
<p>Prints a list of all supported version control systems. Useful to find
out possible contexts (and which of them are enabled) or values for the
2022-08-24 15:22:41 +02:00
disable style.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-vcs_005finfo_005fsetsys"></span></p>
2022-08-24 15:22:41 +02:00
<p>vcs_info_setsys</p>
<p>Initializes vcs_infos internal list of available backends. With this
2021-05-11 02:29:21 +02:00
function, you can add support for new VCSs without restarting the shell.</p>
2022-08-24 15:22:41 +02:00
<p>All functions named VCS_INFO_* are for internal use only.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="vcs_005finfo-Variables"></span> <span
id="Variable-Description"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="2656-variable-description"><a class="header" href="#2656-variable-description">26.5.6 Variable Description</a></h3>
2022-08-24 15:22:41 +02:00
<p>${vcs_info_msg_<code>N</code>_} (Note the trailing underscore)<br />
Where <code>N</code> is an integer, e.g., vcs_info_msg_0_. These variables are the
storage for the informational message the last vcs_info call has
assembled. These are strongly connected to the formats, actionformats
and nvcsformats styles described above. Those styles are lists. The
first member of that list gets expanded into ${vcs_info_msg_0_}, the
second into ${vcs_info_msg_1_} and the Nth into ${vcs_info_msg_N-1_}.
(See the max-exports style above.)</p>
<p>All variables named VCS_INFO_* are for internal use only.</p>
<hr />
<p><span id="vcs_005finfo-Hooks"></span> <span
id="Hooks-in-vcs_005finfo"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="2657-hooks-in-vcs_info"><a class="header" href="#2657-hooks-in-vcs_info">26.5.7 Hooks in vcs_info</a></h3>
2022-08-24 15:22:41 +02:00
<p>Hooks are places in vcs_info where you can run your own code. That code
can communicate with the code that called it and through that, change
the systems behaviour.</p>
2021-05-11 02:29:21 +02:00
<p>For configuration, hooks change the style context:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">:vcs_info:vcs-string+hook-name:user-context:repo-root-name
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>To register functions to a hook, you need to list them in the hooks
2021-05-11 02:29:21 +02:00
style in the appropriate context.</p>
<p>Example:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':vcs_info:*+foo:*' hooks bar baz
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>This registers functions to the hook foo for all backends. In order to
avoid namespace problems, all registered function names are prepended by
2022-08-24 15:22:41 +02:00
a +vi-, so the actual functions called for the foo hook are
+vi-bar and +vi-baz.</p>
2021-05-11 02:29:21 +02:00
<p>If you would like to register a function to a hook regardless of the
2022-08-24 15:22:41 +02:00
current context, you may use the vcs_info_hookadd function. To remove a
function that was added like that, the vcs_info_hookdel function can be
used.</p>
2021-05-11 02:29:21 +02:00
<p>If something seems weird, you can enable the debug boolean style in
the proper context and the hook-calling code will print what it tried to
execute and whether the function in question existed.</p>
<p>When you register more than one function to a hook, all functions are
executed one after another until one function returns non-zero or until
all functions have been called. Context-sensitive hook functions are
2022-08-24 15:22:41 +02:00
executed before statically registered ones (the ones added by
vcs_info_hookadd).</p>
<p>You may pass data between functions via an associative array, user_data.
For example:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">+vi-git-myfirsthook(){
2021-05-11 02:29:21 +02:00
user_data[myval]=$myval
}
+vi-git-mysecondhook(){
# do something with ${user_data[myval]}
}
</code></pre>
</div>
<p>There are a number of variables that are special in hook contexts:</p>
2022-08-24 15:22:41 +02:00
<p>ret<br />
The return value that the hooks system will return to the caller. The
default is an integer zero. If and how a changed ret value changes the
execution of the caller depends on the specific hook. See the hook
documentation below for details.</p>
<p>hook_com<br />
An associated array which is used for bidirectional communication from
the caller to hook functions. The used keys depend on the specific hook.</p>
<p>context<br />
2021-05-11 02:29:21 +02:00
The active context of the hook. Functions that wish to change this
variable should make it local scope first.</p>
2022-08-24 15:22:41 +02:00
<p>vcs<br />
2021-05-11 02:29:21 +02:00
The current VCS after it was detected. The same values as in the
2022-08-24 15:22:41 +02:00
enable/disable style are used. Available in all hooks except start-up.</p>
2021-05-11 02:29:21 +02:00
<p>Finally, the full list of currently available hooks:</p>
2022-08-24 15:22:41 +02:00
<p>start-up<br />
Called after starting vcs_info but before the VCS in this directory is
determined. It can be used to deactivate vcs_info temporarily if
necessary. When ret is set to 1, vcs_info aborts and does nothing; when
set to 2, vcs_info sets up everything as if no version control were
active and exits.</p>
<p>pre-get-data<br />
Same as start-up but after the VCS was detected.</p>
<p>gen-hg-bookmark-string<br />
Called in the Mercurial backend when a bookmark string is generated; the
get-revision and get-bookmarks styles must be true.</p>
<p>This hook gets the names of the Mercurial bookmarks that vcs_info
2021-05-11 02:29:21 +02:00
collected from hg.</p>
2022-08-24 15:22:41 +02:00
<p>If a bookmark is active, the key ${hook_com[hg-active-bookmark]} is
set to its name. The key is otherwise unset.</p>
<p>When setting ret to non-zero, the string in
${hook_com[hg-bookmark-string]} will be used in the %m escape in
formats and actionformats and will be available in the global
backend_misc array as ${backend_misc[bookmarks]}.</p>
<p>gen-applied-string<br />
Called in the git (with stgit or during rebase or merge), and hg (with
mq) backends and in quilt support when the applied-string is generated;
the use-quilt zstyle must be true for quilt (the mq and stgit backends
are active by default).</p>
<p>The arguments to this hook describe applied patches in the opposite
order, which means that the first argument is the top-most patch and so
forth.</p>
<p>When the patches log messages can be extracted, those are embedded
within each argument after a space, so each argument is of the form
<code>patch-name</code> <code>first line of the log message</code>, where <code>patch-name</code>
contains no whitespace. The mq backend passes arguments of the form
<code>patch name</code>, with possible embedded spaces, but without extracting
the patchs log message.</p>
<p>When setting ret to non-zero, the string in
${hook_com[applied-string]} will be available as %p in the
patch-format and nopatch-format styles. This hook is, in concert with
set-patch-format, responsible for %-escaping that value for use in the
prompt. (See <a href="User-Contributions.html#vcs_005finfo-Oddities">Oddities</a>.)</p>
<p>The quilt backend passes to this hook the inputs
${hook_com[quilt-patches-dir]} and, if it has been determined,
${hook_com[quilt-pc-dir]}.</p>
<p>gen-unapplied-string<br />
Called in the git (with stgit or during rebase), and hg (with mq)
backend and in quilt support when the unapplied-string is generated; the
get-unapplied style must be true.</p>
<p>This hook gets the names of all unapplied patches which vcs_info in
order, which means that the first argument is the patch next-in-line to
be applied and so forth.</p>
<p>The format of each argument is as for gen-applied-string, above.</p>
<p>When setting ret to non-zero, the string in
${hook_com[unapplied-string]} will be available as %u in the
patch-format and nopatch-format styles. This hook is, in concert with
set-patch-format, responsible for %-escaping that value for use in the
prompt. (See <a href="User-Contributions.html#vcs_005finfo-Oddities">Oddities</a>.)</p>
<p>The quilt backend passes to this hook the inputs
${hook_com[quilt-patches-dir]} and, if it has been determined,
${hook_com[quilt-pc-dir]}.</p>
<p>gen-mqguards-string<br />
Called in the hg backend when guards-string is generated; the get-mq
style must be true (default).</p>
<p>This hook gets the names of any active mq guards.</p>
<p>When setting ret to non-zero, the string in ${hook_com[guards-string]}
will be used in the %g escape in the patch-format and nopatch-format
styles.</p>
<p>no-vcs<br />
2021-05-11 02:29:21 +02:00
This hooks is called when no version control system was detected.</p>
2022-08-24 15:22:41 +02:00
<p>The hook_com parameter is not used.</p>
<p>post-backend<br />
2021-05-11 02:29:21 +02:00
Called as soon as the backend has finished collecting information.</p>
2022-08-24 15:22:41 +02:00
<p>The hook_com keys available are as for the set-message hook.</p>
<p>post-quilt<br />
Called after the quilt support is done. The following information is
passed as arguments to the hook: 1. the quilt-support mode (addon or
standalone); 2. the directory that contains the patch series; 3. the
directory that holds quilts status information (the .pc directory) or
the string &quot;-nopc-&quot; if that directory wasnt found.</p>
2021-05-11 02:29:21 +02:00
<p>The hook_com parameter is not used.</p>
2022-08-24 15:22:41 +02:00
<p>set-branch-format<br />
Called before branchformat is set. The only argument to the hook is
the format that is configured at this point.</p>
<p>The hook_com keys considered are branch and revision. They are set
to the values figured out so far by vcs_info and any change will be used
directly when the actual replacement is done.</p>
<p>If ret is set to non-zero, the string in ${hook_com[branch-replace]}
will be used unchanged as the %b replacement in the variables set by
vcs_info.</p>
<p>set-hgrev-format<br />
Called before a hgrevformat is set. The only argument to the hook is
the format that is configured at this point.</p>
<p>The hook_com keys considered are hash and localrev. They are set
to the values figured out so far by vcs_info and any change will be used
directly when the actual replacement is done.</p>
<p>If ret is set to non-zero, the string in ${hook_com[rev-replace]} will
be used unchanged as the %i replacement in the variables set by
vcs_info.</p>
<p>pre-addon-quilt<br />
This hook is used when vcs_infos quilt functionality is active in
&quot;addon&quot; mode (quilt used on top of a real version control system). It is
activated right before any quilt specific action is taken.</p>
<p>Setting the ret variable in this hook to a non-zero value avoids any
quilt specific actions from being run at all.</p>
<p>set-patch-format<br />
2021-05-11 02:29:21 +02:00
This hook is used to control some of the possible expansions in
2022-08-24 15:22:41 +02:00
patch-format and nopatch-format styles with patch queue systems such as
quilt, mqueue and the like.</p>
<p>This hook is used in the git, hg and quilt backends.</p>
<p>The hook allows the control of the %p (${hook_com[applied]}) and %u
(${hook_com[unapplied]}) expansion in all backends that use the hook.
With the mercurial backend, the %g (${hook_com[guards]}) expansion is
controllable in addition to that.</p>
<p>If ret is set to non-zero, the string in ${hook_com[patch-replace]}
will be used unchanged instead of an expanded format from patch-format
or nopatch-format.</p>
<p>This hook is, in concert with the gen-applied-string or
gen-unapplied-string hooks if they are defined, responsible for
%-escaping the final patch-format value for use in the prompt. (See
<a href="User-Contributions.html#vcs_005finfo-Oddities">Oddities</a>.)</p>
<p>The quilt backend passes to this hook the inputs
${hook_com[quilt-patches-dir]} and, if it has been determined,
${hook_com[quilt-pc-dir]}.</p>
<p>set-message<br />
Called each time before a vcs_info_msg_<code>N</code>_ message is set. It takes
two arguments; the first being the <code>N</code> in the message variable name,
the second is the currently configured formats or actionformats.</p>
<p>There are a number of hook_com keys, that are used here: action,
branch, base, base-name, subdir, staged, unstaged,
revision, misc, vcs and one miscN entry for each
backend-specific data field (N starting at zero). They are set to the
values figured out so far by vcs_info and any change will be used
directly when the actual replacement is done.</p>
<p>Since this hook is triggered multiple times (once for each configured
formats or actionformats), each of the hook_com keys mentioned above
(except for the miscN entries) has an _orig counterpart, so even if
you changed a value to your liking you can still get the original value
in the next run. Changing the _orig values is probably not a good
idea.</p>
<p>If ret is set to non-zero, the string in ${hook_com[message]} will be
used unchanged as the message by vcs_info.</p>
2021-05-11 02:29:21 +02:00
<p>If all of this sounds rather confusing, take a look at
<a href="User-Contributions.html#vcs_005finfo-Examples">Examples</a> and also in the
2022-08-24 15:22:41 +02:00
Misc/vcs_info-examples file in the Zsh source. They contain some
2021-05-11 02:29:21 +02:00
explanatory code.</p>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="vcs_005finfo-Examples"></span> <span id="Examples-1"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="2658-examples"><a class="header" href="#2658-examples">26.5.8 Examples</a></h3>
2022-08-24 15:22:41 +02:00
<p>Dont use vcs_info at all (even though its in your prompt):</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':vcs_info:*' enable NONE
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Disable the backends for bzr and svk:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':vcs_info:*' disable bzr svk
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Disable everything <em>but</em> bzr and svk:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':vcs_info:*' enable bzr svk
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Provide a special formats for git:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':vcs_info:git:*' formats ' GIT, BABY! [%b]'
2021-05-11 02:29:21 +02:00
zstyle ':vcs_info:git:*' actionformats ' GIT ACTION! [%b|%a]'
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>All %x expansion in all sorts of formats (formats, actionformats,
branchformat, you name it) are done using the zformat builtin from the
zsh/zutil module. That means you can do everything with these %x items
what zformat supports. In particular, if you want something that is
really long to have a fixed width, like a hash in a mercurial
branchformat, you can do this: %12.12i. Thatll shrink the 40 character
hash to its 12 leading characters. The form is actually %<code>min</code>.<code>max</code>x.
More is possible. See <a href="Zsh-Modules.html#The-zsh_002fzutil-Module">The zsh/zutil
2021-05-11 02:29:21 +02:00
Module</a> for details.</p>
2022-08-24 15:22:41 +02:00
<p>Use the quicker bzr backend</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':vcs_info:bzr:*' use-simple true
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>If you do use use-simple, please report if it does
2021-05-11 02:29:21 +02:00
the-right-thing[tm].</p>
2022-08-24 15:22:41 +02:00
<p>Display the revision number in yellow for bzr and svn:</p>
<div class="example">
<pre><code class="language-zsh">zstyle ':vcs_info:(svn|bzr):*' \
branchformat '%b%%F{yellow}:%r'
</code></pre>
</div>
<p>The doubled percent sign is explained in
<a href="User-Contributions.html#vcs_005finfo-Oddities">Oddities</a>.</p>
<p>Alternatively, one can use the raw colour codes directly:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':vcs_info:(svn|bzr):*' \
2021-05-11 02:29:21 +02:00
branchformat '%b%{'${fg[yellow]}'%}:%r'
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Normally when a variable is interpolated into a format string, the
variable needs to be %-escaped. In this example we skipped that because
we assume the value of ${fg[yellow]} doesnt contain any % signs.</p>
<p>Make sure you enclose the color codes in %{<code>...</code>%} if you want to use
the string provided by vcs_info in prompts.</p>
2021-05-11 02:29:21 +02:00
<p>Here is how to print the VCS information as a command (not in a prompt):</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">vcsi() { vcs_info interactive; vcs_info_lastmsg }
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>This way, you can even define different formats for output via
2022-08-24 15:22:41 +02:00
vcs_info_lastmsg in the :vcs_info:*:interactive:* namespace.</p>
2021-05-11 02:29:21 +02:00
<p>Now as promised, some code that uses hooks: say, youd like to replace
2022-08-24 15:22:41 +02:00
the string svn by subversion in vcs_infos %s formats replacement.</p>
<p>First, we will tell vcs_info to call a function when populating the
2021-05-11 02:29:21 +02:00
message variables with the gathered information:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':vcs_info:*+set-message:*' hooks svn2subversion
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>Nothing happens. Which is reasonable, since we didnt define the actual
function yet. To see what the hooks subsystem is trying to do, enable
2022-08-24 15:22:41 +02:00
the debug style:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':vcs_info:*+*:*' debug true
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>That should give you an idea what is going on. Specifically, the
2022-08-24 15:22:41 +02:00
function that we are looking for is +vi-svn2subversion. Note, the
+vi- prefix. So, everything is in order, just as documented. When you
are done checking out the debugging output, disable it again:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':vcs_info:*+*:*' debug false
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>Now, lets define the function:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">function +vi-svn2subversion() {
2021-05-11 02:29:21 +02:00
[[ ${hook_com[vcs_orig]} == svn ]] &amp;&amp; hook_com[vcs]=subversion
}
</code></pre>
</div>
<p>Simple enough. And it could have even been simpler, if only we had
registered our function in a less generic context. If we do it only in
2022-08-24 15:22:41 +02:00
the svn backends context, we dont need to test which the active
2021-05-11 02:29:21 +02:00
backend is:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':vcs_info:svn+set-message:*' hooks svn2subversion
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">function +vi-svn2subversion() {
2021-05-11 02:29:21 +02:00
hook_com[vcs]=subversion
}
</code></pre>
</div>
<p>And finally a little more elaborate example, that uses a hook to create
2022-08-24 15:22:41 +02:00
a customised bookmark string for the hg backend.</p>
2021-05-11 02:29:21 +02:00
<p>Again, we start off by registering a function:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':vcs_info:hg+gen-hg-bookmark-string:*' hooks hgbookmarks
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>And then we define the +vi-hgbookmarks function:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">function +vi-hgbookmarks() {
2021-05-11 02:29:21 +02:00
# The default is to connect all bookmark names by
# commas. This mixes things up a little.
# Imagine, there's one type of bookmarks that is
# special to you. Say, because it's *your* work.
# Those bookmarks look always like this: &quot;sh/*&quot;
# (because your initials are sh, for example).
# This makes the bookmarks string use only those
# bookmarks. If there's more than one, it
# concatenates them using commas.
# The bookmarks returned by `hg' are available in
# the function's positional parameters.
local s=&quot;${(Mj:,:)@:#sh/*}&quot;
# Now, the communication with the code that calls
# the hook functions is done via the hook_com[]
# hash. The key at which the `gen-hg-bookmark-string'
# hook looks is `hg-bookmark-string'. So:
hook_com[hg-bookmark-string]=$s
# And to signal that we want to use the string we
# just generated, set the special variable `ret' to
# something other than the default zero:
ret=1
return 0
}
</code></pre>
</div>
<p>Some longer examples and code snippets which might be useful are
available in the examples file located at Misc/vcs_info-examples in the
Zsh source directory.</p>
2022-08-24 15:22:41 +02:00
<p>This concludes our guided tour through zshs vcs_info.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Prompt-Themes"></span> <span id="Prompt-Themes-1"></span></p>
<h2 id="266-prompt-themes"><a class="header" href="#266-prompt-themes">26.6 Prompt Themes</a></h2>
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Installation-3"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="2661-installation"><a class="header" href="#2661-installation">26.6.1 Installation</a></h3>
2022-08-24 15:22:41 +02:00
<p>You should make sure all the functions from the Functions/Prompts
2021-05-11 02:29:21 +02:00
directory of the source distribution are available; they all begin with
2022-08-24 15:22:41 +02:00
the string prompt_ except for the special function promptinit. You
also need the colors and add-zsh-hook functions from Functions/Misc.
All these functions may already be installed on your system; if not, you
will need to find them and copy them. The directory should appear as one
of the elements of the fpath array (this should already be the case if
they were installed), and at least the function promptinit should be
autoloaded; it will autoload the rest. Finally, to initialize the use of
the system you need to call the promptinit function. The following code
in your .zshrc will arrange for this; assume the functions are stored in
the directory ~/myfns:</p>
<div class="example">
<pre><code class="language-zsh">fpath=(~/myfns $fpath)
2021-05-11 02:29:21 +02:00
autoload -U promptinit
promptinit
</code></pre>
</div>
<hr />
<p><span id="Theme-Selection"></span></p>
<h3 id="2662-theme-selection"><a class="header" href="#2662-theme-selection">26.6.2 Theme Selection</a></h3>
2022-08-24 15:22:41 +02:00
<p>Use the prompt command to select your preferred theme. This command may
be added to your .zshrc following the call to promptinit in order to
start zsh with a theme already selected.</p>
<p>prompt [ -c | -l ]<br />
prompt [ -p | -h ] [ <code>theme</code> ... ]<br />
prompt [ -s ] <code>theme</code> [ <code>arg</code> ... ]<br />
Set or examine the prompt theme. With no options and a <code>theme</code> argument,
the theme with that name is set as the current theme. The available
themes are determined at run time; use the -l option to see a list. The
special <code>theme</code> random selects at random one of the available themes
and sets your prompt to that.</p>
2021-05-11 02:29:21 +02:00
<p>In some cases the <code>theme</code> may be modified by one or more arguments,
2022-08-24 15:22:41 +02:00
which should be given after the theme name. See the help for each theme
for descriptions of these arguments.</p>
2021-05-11 02:29:21 +02:00
<p>Options are:</p>
2022-08-24 15:22:41 +02:00
<p>-c<br />
2021-05-11 02:29:21 +02:00
Show the currently selected theme and its parameters, if any.</p>
2022-08-24 15:22:41 +02:00
<p>-l<br />
2021-05-11 02:29:21 +02:00
List all available prompt themes.</p>
2022-08-24 15:22:41 +02:00
<p>-p<br />
Preview the theme named by <code>theme</code>, or all themes if no <code>theme</code> is
given.</p>
<p>-h<br />
Show help for the theme named by <code>theme</code>, or for the prompt function if
no <code>theme</code> is given.</p>
<p>-s<br />
2021-05-11 02:29:21 +02:00
Set <code>theme</code> as the current theme and save state.</p>
2022-08-24 15:22:41 +02:00
<p>prompt_<code>theme</code>_setup<br />
2021-05-11 02:29:21 +02:00
Each available <code>theme</code> has a setup function which is called by the
2022-08-24 15:22:41 +02:00
prompt function to install that theme. This function may define other
functions as necessary to maintain the prompt, including functions used
to preview the prompt or provide help for its use. You should not
normally call a themes setup function directly.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Utility-Themes"></span></p>
<h3 id="2663-utility-themes"><a class="header" href="#2663-utility-themes">26.6.3 Utility Themes</a></h3>
2022-08-24 15:22:41 +02:00
<p>prompt off<br />
The theme off sets all the prompt variables to minimal values with no
special effects.</p>
<p>prompt default<br />
The theme default sets all prompt variables to the same state as if an
interactive zsh was started with no initialization files.</p>
<p>prompt restore<br />
The special theme restore erases all theme settings and sets prompt
variables to their state before the first time the prompt function was
run, provided each theme has properly defined its cleanup (see below).</p>
<p>Note that you can undo prompt off and prompt default with prompt
restore, but a second restore does not undo the first.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Writing-Themes"></span></p>
<h3 id="2664-writing-themes"><a class="header" href="#2664-writing-themes">26.6.4 Writing Themes</a></h3>
<p>The first step for adding your own theme is to choose a name for it, and
2022-08-24 15:22:41 +02:00
create a file prompt_<code>name</code>_setup in a directory in your fpath, such
as ~/myfns in the example above. The file should at minimum contain
2021-05-11 02:29:21 +02:00
assignments for the prompt variables that your theme wishes to modify.
2022-08-24 15:22:41 +02:00
By convention, themes use PS1, PS2, RPS1, etc., rather than the longer
PROMPT and RPROMPT.</p>
2021-05-11 02:29:21 +02:00
<p>The file is autoloaded as a function in the current shell context, so it
may contain any necessary commands to customize your theme, including
defining additional functions. To make some complex tasks easier, your
setup function may also do any of the following:</p>
2022-08-24 15:22:41 +02:00
<p>Assign prompt_opts<br />
The array prompt_opts may be assigned any of &quot;bang&quot;, &quot;cr&quot;, &quot;percent&quot;,
&quot;sp&quot;, and/or &quot;subst&quot; as values. The corresponding setopts (promptbang,
etc.) are turned on, all other prompt-related options are turned off.
The prompt_opts array preserves setopts even beyond the scope of
localoptions, should your function need that.</p>
<p>Modify hooks<br />
Use of add-zsh-hook and add-zle-hook-widget is recommended (see the
Manipulating Hook Functions section above). All hooks that follow the
naming pattern prompt_<code>theme</code>_<code>hook</code> are automatically removed when
the prompt theme changes or is disabled.</p>
2021-05-11 02:29:21 +02:00
<p>Declare cleanup<br />
2022-08-24 15:22:41 +02:00
If your function makes any other changes that should be undone when the
theme is disabled, your setup function may call</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">prompt_cleanup command
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>where <code>command</code> should be suitably quoted. If your theme is ever
2022-08-24 15:22:41 +02:00
disabled or replaced by another, <code>command</code> is executed with eval. You
may declare more than one such cleanup hook.</p>
2021-05-11 02:29:21 +02:00
<p>Define preview<br />
2022-08-24 15:22:41 +02:00
Define or autoload a function prompt_<code>name</code>_preview to display a
simulated version of your prompt. A simple default previewer is defined
by promptinit for themes that do not define their own. This preview
function is called by prompt -p.</p>
2021-05-11 02:29:21 +02:00
<p>Provide help<br />
2022-08-24 15:22:41 +02:00
Define or autoload a function prompt_<code>name</code>_help to display
documentation or help text for your theme. This help function is called
by prompt -h.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="ZLE-Functions"></span> <span id="ZLE-Functions-1"></span></p>
<h2 id="267-zle-functions"><a class="header" href="#267-zle-functions">26.7 ZLE Functions</a></h2>
<hr />
<p><span id="Widgets"></span></p>
<h3 id="2671-widgets"><a class="header" href="#2671-widgets">26.7.1 Widgets</a></h3>
<p>These functions all implement user-defined ZLE widgets (see <a href="Zsh-Line-Editor.html#Zsh-Line-Editor">Zsh Line
Editor</a>) which can be bound to
2022-08-24 15:22:41 +02:00
keystrokes in interactive shells. To use them, your .zshrc should
2021-05-11 02:29:21 +02:00
contain lines of the form</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">autoload function
2021-05-11 02:29:21 +02:00
zle -N function
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>followed by an appropriate bindkey command to associate the function
2021-05-11 02:29:21 +02:00
with a key sequence. Suggested bindings are described below.</p>
<p>bash-style word functions<br />
2022-08-24 15:22:41 +02:00
If you are looking for functions to implement moving over and editing
words in the manner of bash, where only alphanumeric characters are
considered word characters, you can use the functions described in the
next section. The following is sufficient:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">autoload -U select-word-style
2021-05-11 02:29:21 +02:00
select-word-style bash
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p><span id="index-forward_002dword_002dmatch"></span> <span
id="index-backward_002dword_002dmatch"></span> <span
id="index-kill_002dword_002dmatch"></span> <span
id="index-backward_002dkill_002dword_002dmatch"></span> <span
id="index-transpose_002dwords_002dmatch"></span> <span
id="index-capitalize_002dword_002dmatch"></span> <span
id="index-up_002dcase_002dword_002dmatch"></span> <span
id="index-down_002dcase_002dword_002dmatch"></span> <span
id="index-delete_002dwhole_002dword_002dmatch"></span> <span
id="index-select_002dword_002dmatch"></span> <span
id="index-select_002dword_002dstyle"></span> <span
id="index-match_002dword_002dcontext"></span> <span
id="index-match_002dwords_002dby_002dstyle"></span></p>
<p>forward-word-match, backward-word-match<br />
kill-word-match, backward-kill-word-match<br />
transpose-words-match, capitalize-word-match<br />
up-case-word-match, down-case-word-match<br />
delete-whole-word-match, select-word-match<br />
select-word-style, match-word-context, match-words-by-style<br />
The first eight -match functions are drop-in replacements for the
builtin widgets without the suffix. By default they behave in a similar
way. However, by the use of styles and the function select-word-style,
the way words are matched can be altered. select-word-match is intended
to be used as a text object in vi mode but with custom word styles. For
comparison, the widgets described in <a href="Zsh-Line-Editor.html#Text-Objects">Text
Objects</a> use fixed definitions of
words, compatible with the vim editor.</p>
2021-05-11 02:29:21 +02:00
<p>The simplest way of configuring the functions is to use
2022-08-24 15:22:41 +02:00
select-word-style, which can either be called as a normal function with
the appropriate argument, or invoked as a user-defined widget that will
prompt for the first character of the word style to be used. The first
time it is invoked, the first eight -match functions will automatically
replace the builtin versions, so they do not need to be loaded
explicitly.</p>
<p>The word styles available are as follows. Only the first character is
examined.</p>
<p>bash<br />
2021-05-11 02:29:21 +02:00
Word characters are alphanumeric characters only.</p>
2022-08-24 15:22:41 +02:00
<p>normal<br />
2021-05-11 02:29:21 +02:00
As in normal shell operation: word characters are alphanumeric
2022-08-24 15:22:41 +02:00
characters plus any characters present in the string given by the
parameter $WORDCHARS.</p>
<p>shell<br />
Words are complete shell command arguments, possibly including complete
quoted strings, or any tokens special to the shell.</p>
<p>whitespace<br />
2021-05-11 02:29:21 +02:00
Words are any set of characters delimited by whitespace.</p>
2022-08-24 15:22:41 +02:00
<p>default<br />
Restore the default settings; this is usually the same as normal.</p>
<p>All but default can be input as an upper case character, which has the
same effect but with subword matching turned on. In this case, words
with upper case characters are treated specially: each separate run of
upper case characters, or an upper case character followed by any number
of other characters, is considered a word. The style subword-range can
supply an alternative character range to the default [:upper:]; the
value of the style is treated as the contents of a [<code>...</code>] pattern
(note that the outer brackets should not be supplied, only those
surrounding named ranges).</p>
<p>More control can be obtained using the zstyle command, as described in
<a href="Zsh-Modules.html#The-zsh_002fzutil-Module">The zsh/zutil Module</a>. Each
style is looked up in the context :zle:<code>widget</code> where <code>widget</code> is the
name of the user-defined widget, not the name of the function
2021-05-11 02:29:21 +02:00
implementing it, so in the case of the definitions supplied by
2022-08-24 15:22:41 +02:00
select-word-style the appropriate contexts are :zle:forward-word, and so
on. The function select-word-style itself always defines styles for the
context :zle:* which can be overridden by more specific (longer)
patterns as well as explicit contexts.</p>
<p>The style word-style specifies the rules to use. This may have the
2021-05-11 02:29:21 +02:00
following values.</p>
2022-08-24 15:22:41 +02:00
<p>normal<br />
Use the standard shell rules, i.e. alphanumerics and $WORDCHARS, unless
overridden by the styles word-chars or word-class.</p>
<p>specified<br />
Similar to normal, but <em>only</em> the specified characters, and not also
alphanumerics, are considered word characters.</p>
<p>unspecified<br />
The negation of specified. The given characters are those which will
<em>not</em> be considered part of a word.</p>
<p>shell<br />
Words are obtained by using the syntactic rules for generating shell
command arguments. In addition, special tokens which are never command
arguments such as () are also treated as words.</p>
<p>whitespace<br />
2021-05-11 02:29:21 +02:00
Words are whitespace-delimited strings of characters.</p>
2022-08-24 15:22:41 +02:00
<p>The first three of those rules usually use $WORDCHARS, but the value in
the parameter can be overridden by the style word-chars, which works in
exactly the same way as $WORDCHARS. In addition, the style word-class
uses character class syntax to group characters and takes precedence
over word-chars if both are set. The word-class style does not include
the surrounding brackets of the character class; for example,
-:[:alnum:] is a valid word-class to include all alphanumerics plus
the characters - and :. Be careful including ], ^ and - as
these are special inside character classes.</p>
<p>word-style may also have -subword appended to its value to turn on
subword matching, as described above.</p>
<p>The style skip-chars is mostly useful for transpose-words and similar
functions. If set, it gives a count of characters starting at the cursor
position which will not be considered part of the word and are treated
as space, regardless of what they actually are. For example, if</p>
<div class="example">
<pre><code class="language-zsh">zstyle ':zle:transpose-words' skip-chars 1
</code></pre>
</div>
<p>has been set, and transpose-words-match is called with the cursor on the
<code>X</code> of foo<code>X</code>bar, where <code>X</code> can be any character, then the resulting
expression is bar<code>X</code>foo.</p>
<p>Finer grained control can be obtained by setting the style word-context
to an array of pairs of entries. Each pair of entries consists of a
<code>pattern</code> and a <code>subcontext</code>. The shell argument the cursor is on is
matched against each <code>pattern</code> in turn until one matches; if it does,
the context is extended by a colon and the corresponding <code>subcontext</code>.
Note that the test is made against the original word on the line, with
no stripping of quotes. Special handling is done between words: the
current context is examined and if it contains the string between the
word is set to a single space; else if it is contains the string back,
the word before the cursor is considered, else the word after cursor is
considered. Some examples are given below.</p>
<p>The style skip-whitespace-first is only used with the forward-word
widget. If it is set to true, then forward-word skips any
non-word-characters, followed by any non-word-characters: this is
similar to the behaviour of other word-orientated widgets, and also that
used by other editors, however it differs from the standard zsh
behaviour. When using select-word-style the widget is set in the context
:zle:* to true if the word style is bash and false otherwise. It may be
overridden by setting it in the more specific context
:zle:forward-word*.</p>
<p>It is possible to create widgets with specific behaviour by defining a
new widget implemented by the appropriate generic function, then setting
a style for the context of the specific widget. For example, the
following defines a widget backward-kill-space-word using
backward-kill-word-match, the generic widget implementing
backward-kill-word behaviour, and ensures that the new widget always
implements space-delimited behaviour.</p>
<div class="example">
<pre><code class="language-zsh">zle -N backward-kill-space-word backward-kill-word-match
2021-05-11 02:29:21 +02:00
zstyle :zle:backward-kill-space-word word-style space
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The widget backward-kill-space-word can now be bound to a key.</p>
<p>Here are some further examples of use of the styles, actually taken from
the simplified interface in select-word-style:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':zle:*' word-style standard
2021-05-11 02:29:21 +02:00
zstyle ':zle:*' word-chars ''
</code></pre>
</div>
<p>Implements bash-style word handling for all widgets, i.e. only
2022-08-24 15:22:41 +02:00
alphanumerics are word characters; equivalent to setting the parameter
WORDCHARS empty for the given context.</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">style ':zle:*kill*' word-style space
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Uses space-delimited words for widgets with the word kill in the name.
Neither of the styles word-chars nor word-class is used in this case.</p>
<p>Here are some examples of use of the word-context style to extend the
context.</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':zle:*' word-context \
2021-05-11 02:29:21 +02:00
&quot;*/*&quot; filename &quot;[[:space:]]&quot; whitespace
zstyle ':zle:transpose-words:whitespace' word-style shell
zstyle ':zle:transpose-words:filename' word-style normal
zstyle ':zle:transpose-words:filename' word-chars ''
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>This provides two different ways of using transpose-words depending on
whether the cursor is on whitespace between words or on a filename, here
any word containing a /. On whitespace, complete arguments as defined by
standard shell rules will be transposed. In a filename, only
alphanumerics will be transposed. Elsewhere, words will be transposed
using the default style for :zle:transpose-words.</p>
<p>The word matching and all the handling of zstyle settings is actually
implemented by the function match-words-by-style. This can be used to
create new user-defined widgets. The calling function should set the
local parameter curcontext to :zle:<code>widget</code>, create the local parameter
matched_words and call match-words-by-style with no arguments. On
return, matched_words will be set to an array with the elements: (1) the
start of the line (2) the word before the cursor (3) any non-word
characters between that word and the cursor (4) any non-word character
at the cursor position plus any remaining non-word characters before the
next word, including all characters specified by the skip-chars
style, (5) the word at or following the cursor (6) any non-word
characters following that word (7) the remainder of the line. Any of the
elements may be an empty string; the calling function should test for
this to decide whether it can perform its function.</p>
<p>If the variable matched_words is defined by the caller to
match-words-by-style as an associative array (local -A matched_words),
then the seven values given above should be retrieved from it as
elements named start, word-before-cursor, ws-before-cursor,
ws-after-cursor, word-after-cursor, ws-after-word, and end. In addition
the element is-word-start is 1 if the cursor is on the start of a word
or subword, or on white space before it (the cases can be distinguished
by testing the ws-after-cursor element) and 0 otherwise. This form is
recommended for future compatibility.</p>
<p>It is possible to pass options with arguments to match-words-by-style to
override the use of styles. The options are:</p>
<p>-w<br />
2021-05-11 02:29:21 +02:00
<code>word-style</code></p>
2022-08-24 15:22:41 +02:00
<p>-s<br />
2021-05-11 02:29:21 +02:00
<code>skip-chars</code></p>
2022-08-24 15:22:41 +02:00
<p>-c<br />
2021-05-11 02:29:21 +02:00
<code>word-class</code></p>
2022-08-24 15:22:41 +02:00
<p>-C<br />
2021-05-11 02:29:21 +02:00
<code>word-chars</code></p>
2022-08-24 15:22:41 +02:00
<p>-r<br />
2021-05-11 02:29:21 +02:00
<code>subword-range</code></p>
2022-08-24 15:22:41 +02:00
<p>For example, match-words-by-style -w shell -c 0 may be used to extract
the command argument around the cursor.</p>
<p>The word-context style is implemented by the function
match-word-context. This should not usually need to be called directly.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-bracketed_002dpaste_002dmagic"></span></p>
2022-08-24 15:22:41 +02:00
<p>bracketed-paste-magic<br />
The bracketed-paste widget (see
<a href="Zsh-Line-Editor.html#Miscellaneous">Miscellaneous</a> in <a href="Zsh-Line-Editor.html#Standard-Widgets">Standard
Widgets</a>) inserts pasted text
literally into the editor buffer rather than interpret it as keystrokes.
This disables some common usages where the self-insert widget is
replaced in order to accomplish some extra processing. An example is the
contributed url-quote-magic widget described below.</p>
<p>The bracketed-paste-magic widget is meant to replace bracketed-paste
with a wrapper that re-enables these self-insert actions, and other
actions as selected by zstyles. Therefore this widget is installed with</p>
<div class="example">
<pre><code class="language-zsh">autoload -Uz bracketed-paste-magic
2021-05-11 02:29:21 +02:00
zle -N bracketed-paste bracketed-paste-magic
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Other than enabling some widget processing, bracketed-paste-magic
attempts to replicate bracketed-paste as faithfully as possible.</p>
<p>The following zstyles may be set to control processing of pasted text.
All are looked up in the context :bracketed-paste-magic.</p>
<p>active-widgets<br />
A list of patterns matching widget names that should be activated during
the paste. All other key sequences are processed as self-insert-unmeta.
The default is self-* so any user-defined widgets named with that
prefix are active along with the builtin self-insert.</p>
<p>If this style is not set (explicitly deleted) or set to an empty value,
no widgets are active and the pasted text is inserted literally. If the
value includes undefined-key, any unknown sequences are discarded from
the pasted text.</p>
<p>inactive-keys<br />
The inverse of active-widgets, a list of key sequences that always use
self-insert-unmeta even when bound to an active widget. Note that this
is a list of literal key sequences, not patterns.</p>
<p>paste-init<br />
A list of function names, called in widget context (but not as widgets).
The functions are called in order until one of them returns a non-zero
status. The parameter PASTED contains the initial state of the pasted
text. All other ZLE parameters such as BUFFER have their normal values
and side-effects, and full history is available, so for example
paste-init functions may move words from BUFFER into PASTED to make
those words visible to the active-widgets.</p>
<p>A non-zero return from a paste-init function does <em>not</em> prevent the
paste itself from proceeding.</p>
<p>Loading bracketed-paste-magic defines backward-extend-paste, a helper
function for use in paste-init.</p>
<div class="example">
<pre><code class="language-zsh">zstyle :bracketed-paste-magic paste-init \
2021-05-11 02:29:21 +02:00
backward-extend-paste
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>When a paste would insert into the middle of a word or append text to a
word already on the line, backward-extend-paste moves the prefix from
LBUFFER into PASTED so that the active-widgets see the full word so far.
This may be useful with url-quote-magic.</p>
<p>paste-finish<br />
2021-05-11 02:29:21 +02:00
Another list of function names called in order until one returns
2022-08-24 15:22:41 +02:00
non-zero. These functions are called <em>after</em> the pasted text has been
processed by the active-widgets, but <em>before</em> it is inserted into
BUFFER. ZLE parameters have their normal values and side-effects.</p>
<p>A non-zero return from a paste-finish function does <em>not</em> prevent the
paste itself from proceeding.</p>
<p>Loading bracketed-paste-magic also defines quote-paste, a helper
function for use in paste-finish.</p>
<div class="example">
<pre><code class="language-zsh">zstyle :bracketed-paste-magic paste-finish \
2021-05-11 02:29:21 +02:00
quote-paste
zstyle :bracketed-paste-magic:finish quote-style \
qqq
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>When the pasted text is inserted into BUFFER, it is quoted per the
quote-style value. To forcibly turn off the built-in numeric prefix
quoting of bracketed-paste, use:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle :bracketed-paste-magic:finish quote-style \
2021-05-11 02:29:21 +02:00
none
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p><em>Important:</em> During active-widgets processing of the paste (after
paste-init and before paste-finish), BUFFER starts empty and history is
restricted, so cursor motions, etc., may not pass outside of the pasted
content. Text assigned to BUFFER by the active widgets is copied back
into PASTED before paste-finish.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-copy_002dearlier_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>copy-earlier-word<br />
This widget works like a combination of insert-last-word and
copy-prev-shell-word. Repeated invocations of the widget retrieve
earlier words on the relevant history line. With a numeric argument <code>N</code>,
insert the <code>N</code>th word from the history line; <code>N</code> may be negative to
count from the end of the line.</p>
<p>If insert-last-word has been used to retrieve the last word on a
previous history line, repeated invocations will replace that word with
earlier words from the same line.</p>
2021-05-11 02:29:21 +02:00
<p>Otherwise, the widget applies to words on the line currently being
2022-08-24 15:22:41 +02:00
edited. The widget style can be set to the name of another widget that
should be called to retrieve words. This widget must accept the same
three arguments as insert-last-word.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-cycle_002dcompletion_002dpositions"></span></p>
2022-08-24 15:22:41 +02:00
<p>cycle-completion-positions<br />
2021-05-11 02:29:21 +02:00
After inserting an unambiguous string into the command line, the new
2022-08-24 15:22:41 +02:00
function based completion system may know about multiple places in this
string where characters are missing or differ from at least one of the
possible matches. It will then place the cursor on the position it
considers to be the most interesting one, i.e. the one where one can
disambiguate between as many matches as possible with as little typing
as possible.</p>
2021-05-11 02:29:21 +02:00
<p>This widget allows the cursor to be easily moved to the other
interesting spots. It can be invoked repeatedly to cycle between all
positions reported by the completion system.</p>
<p><span id="index-delete_002dwhole_002dword_002dmatch-1"></span></p>
2022-08-24 15:22:41 +02:00
<p>delete-whole-word-match<br />
This is another function which works like the -match functions described
immediately above, i.e. using styles to decide the word boundaries.
However, it is not a replacement for any existing function.</p>
<p>The basic behaviour is to delete the word around the cursor. There is no
numeric argument handling; only the single word around the cursor is
considered. If the widget contains the string kill, the removed text
will be placed in the cutbuffer for future yanking. This can be obtained
by defining kill-whole-word-match as follows:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zle -N kill-whole-word-match delete-whole-word-match
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>and then binding the widget kill-whole-word-match.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-down_002dline_002dor_002dbeginning_002dsearch"></span>
<span id="index-up_002dline_002dor_002dbeginning_002dsearch"></span></p>
2022-08-24 15:22:41 +02:00
<p>up-line-or-beginning-search, down-line-or-beginning-search<br />
These widgets are similar to the builtin functions up-line-or-search and
down-line-or-search: if in a multiline buffer they move up or down
within the buffer, otherwise they search for a history line matching the
start of the current line. In this case, however, they search for a line
which matches the current line up to the current cursor position, in the
manner of history-beginning-search-backward and -forward, rather than
the first word on the line.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-edit_002dcommand_002dline"></span></p>
2022-08-24 15:22:41 +02:00
<p>edit-command-line<br />
Edit the command line using your visual editor, as in ksh.</p>
<div class="example">
<pre><code class="language-zsh">bindkey -M vicmd v edit-command-line
</code></pre>
</div>
<p>The editor to be used can also be specified using the editor style in
the context of the widget. It is specified as an array of command and
arguments:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle :zle:edit-command-line editor gvim -f
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p><span id="index-expand_002dabsolute_002dpath"></span></p>
2022-08-24 15:22:41 +02:00
<p>expand-absolute-path<br />
2021-05-11 02:29:21 +02:00
Expand the file name under the cursor to an absolute path, resolving
2022-08-24 15:22:41 +02:00
symbolic links. Where possible, the initial path segment is turned into
a named directory or reference to a users home directory.</p>
<p><span
id="index-history_002dbeginning_002dsearch_002dbackward_002dend"></span>
<span
id="index-history_002dbeginning_002dsearch_002dforward_002dend"></span></p>
<p>history-search-end<br />
2021-05-11 02:29:21 +02:00
This function implements the widgets
2022-08-24 15:22:41 +02:00
history-beginning-search-backward-end and
history-beginning-search-forward-end. These commands work by first
2021-05-11 02:29:21 +02:00
calling the corresponding builtin widget (see <a href="Zsh-Line-Editor.html#History-Control">History
Control</a>) and then moving the
cursor to the end of the line. The original cursor position is
2022-08-24 15:22:41 +02:00
remembered and restored before calling the builtin widget a second time,
so that the same search is repeated to look farther through the history.</p>
<p>Although you autoload only one function, the commands to use it are
slightly different because it implements two widgets.</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zle -N history-beginning-search-backward-end \
2021-05-11 02:29:21 +02:00
history-search-end
zle -N history-beginning-search-forward-end \
history-search-end
bindkey '\e^P' history-beginning-search-backward-end
bindkey '\e^N' history-beginning-search-forward-end
</code></pre>
</div>
<p><span id="index-history_002dbeginning_002dsearch_002dmenu"></span></p>
2022-08-24 15:22:41 +02:00
<p>history-beginning-search-menu<br />
This function implements yet another form of history searching. The text
before the cursor is used to select lines from the history, as for
history-beginning-search-backward except that all matches are shown in a
numbered menu. Typing the appropriate digits inserts the full history
line. Note that leading zeroes must be typed (they are only shown when
necessary for removing ambiguity). The entire history is searched; there
is no distinction between forwards and backwards.</p>
<p>With a numeric argument, the search is not anchored to the start of the
line; the string typed by the use may appear anywhere in the line in the
history.</p>
<p>If the widget name contains -end the cursor is moved to the end of the
line inserted. If the widget name contains -space any space in the
text typed is treated as a wildcard and can match anything (hence a
leading space is equivalent to giving a numeric argument). Both forms
can be combined, for example:</p>
<div class="example">
<pre><code class="language-zsh">zle -N history-beginning-search-menu-space-end \
2021-05-11 02:29:21 +02:00
history-beginning-search-menu
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p><span id="index-history_002dpattern_002dsearch"></span> <span
id="index-history_002dpattern_002dsearch_002dbackward"></span> <span
id="index-history_002dpattern_002dsearch_002dforward"></span></p>
<p>history-pattern-search<br />
The function history-pattern-search implements widgets which prompt for
a pattern with which to search the history backwards or forwards. The
pattern is in the usual zsh format, however the first character may be ^
to anchor the search to the start of the line, and the last character
may be $ to anchor the search to the end of the line. If the search was
not anchored to the end of the line the cursor is positioned just after
the pattern found.</p>
2021-05-11 02:29:21 +02:00
<p>The commands to create bindable widgets are similar to those in the
example immediately above:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">autoload -U history-pattern-search
2021-05-11 02:29:21 +02:00
zle -N history-pattern-search-backward history-pattern-search
zle -N history-pattern-search-forward history-pattern-search
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p><span id="index-incarg"></span> <span
id="index-incarg_002c-use-of"></span></p>
<p>incarg<br />
Typing the keystrokes for this widget with the cursor placed on or to
the left of an integer causes that integer to be incremented by one.
With a numeric argument, the number is incremented by the amount of the
argument (decremented if the numeric argument is negative). The shell
parameter incarg may be set to change the default increment to something
other than one.</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">bindkey '^X+' incarg
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p><span id="index-incremental_002dcomplete_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>incremental-complete-word<br />
2021-05-11 02:29:21 +02:00
This allows incremental completion of a word. After starting this
2022-08-24 15:22:41 +02:00
command, a list of completion choices can be shown after every character
you type, which you can delete with ^H or DEL. Pressing return accepts
the completion so far and returns you to normal editing (that is, the
command line is <em>not</em> immediately executed). You can hit TAB to do
normal completion, ^G to abort back to the state when you started, and
^D to list the matches.</p>
2021-05-11 02:29:21 +02:00
<p>This works only with the new function based completion system.</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">bindkey '^Xi' incremental-complete-word
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p><span id="index-insert_002dcomposed_002dchar"></span></p>
2022-08-24 15:22:41 +02:00
<p>insert-composed-char<br />
This function allows you to compose characters that dont appear on the
keyboard to be inserted into the command line. The command is followed
by two keys corresponding to ASCII characters (there is no prompt). For
accented characters, the two keys are a base character followed by a
code for the accent, while for other special characters the two
characters together form a mnemonic for the character to be inserted.
The two-character codes are a subset of those given by RFC 1345 (see for
example <a href="http://www.faqs.org/rfcs/rfc1345.html">http://www.faqs.org/rfcs/rfc1345.html</a>).</p>
<p>The function may optionally be followed by up to two characters which
replace one or both of the characters read from the keyboard; if both
characters are supplied, no input is read. For example,
insert-composed-char a: can be used within a widget to insert an a with
umlaut into the command line. This has the advantages over use of a</p>
<p>For best results zsh should have been built with support for multibyte
characters (configured with enable-multibyte); however, the function
works for the limited range of characters available in single-byte
character sets such as ISO-8859-1.</p>
<p>The character is converted into the local representation and inserted
into the command line at the cursor position. (The conversion is done
within the shell, using whatever facilities the C library provides.)
With a numeric argument, the character and its code are previewed in the
status line</p>
2021-05-11 02:29:21 +02:00
<p>The function may be run outside zle in which case it prints the
2022-08-24 15:22:41 +02:00
character (together with a newline) to standard output. Input is still
read from keystrokes.</p>
<p>See insert-unicode-char for an alternative way of inserting Unicode
characters using their hexadecimal character number.</p>
2021-05-11 02:29:21 +02:00
<p>The set of accented characters is reasonably complete up to Unicode
2022-08-24 15:22:41 +02:00
character U+0180, the set of special characters less so. However, it is
very sporadic from that point. Adding new characters is easy, however;
see the function define-composed-chars. Please send any additions to
zsh-workers@zsh.org.</p>
<p>The codes for the second character when used to accent the first are as
follows. Note that not every character can take every accent.</p>
<p>!<br />
2021-05-11 02:29:21 +02:00
Grave.</p>
2022-08-24 15:22:41 +02:00
<p><br />
2021-05-11 02:29:21 +02:00
Acute.</p>
2022-08-24 15:22:41 +02:00
<p>&gt;<br />
2021-05-11 02:29:21 +02:00
Circumflex.</p>
2022-08-24 15:22:41 +02:00
<p>?<br />
Tilde. (This is not ~ as RFC 1345 does not assume that character is
present on the keyboard.)</p>
<p>-<br />
2021-05-11 02:29:21 +02:00
Macron. (A horizontal bar over the base character.)</p>
2022-08-24 15:22:41 +02:00
<p>(<br />
2021-05-11 02:29:21 +02:00
Breve. (A shallow dish shape over the base character.)</p>
2022-08-24 15:22:41 +02:00
<p>.<br />
Dot above the base character, or in the case of i no dot, or in the case
of L and l a centered dot.</p>
<p>:<br />
2021-05-11 02:29:21 +02:00
Diaeresis (Umlaut).</p>
2022-08-24 15:22:41 +02:00
<p>c<br />
2021-05-11 02:29:21 +02:00
Cedilla.</p>
2022-08-24 15:22:41 +02:00
<p>_<br />
2021-05-11 02:29:21 +02:00
Underline, however there are currently no underlined characters.</p>
2022-08-24 15:22:41 +02:00
<p>/<br />
2021-05-11 02:29:21 +02:00
Stroke through the base character.</p>
2022-08-24 15:22:41 +02:00
<p>&quot;<br />
2021-05-11 02:29:21 +02:00
Double acute (only supported on a few letters).</p>
2022-08-24 15:22:41 +02:00
<p>;<br />
2021-05-11 02:29:21 +02:00
Ogonek. (A little forward facing hook at the bottom right of the
character.)</p>
2022-08-24 15:22:41 +02:00
<p>&lt;<br />
2021-05-11 02:29:21 +02:00
Caron. (A little v over the letter.)</p>
2022-08-24 15:22:41 +02:00
<p>0<br />
2021-05-11 02:29:21 +02:00
Circle over the base character.</p>
2022-08-24 15:22:41 +02:00
<p>2<br />
2021-05-11 02:29:21 +02:00
Hook over the base character.</p>
2022-08-24 15:22:41 +02:00
<p>9<br />
2021-05-11 02:29:21 +02:00
Horn over the base character.</p>
2022-08-24 15:22:41 +02:00
<p>The most common characters from the Arabic, Cyrillic, Greek and Hebrew
alphabets are available; consult RFC 1345 for the appropriate sequences.
In addition, a set of two letter codes not in RFC 1345 are available for
the double-width characters corresponding to ASCII characters from ! to
~ (0x21 to 0x7e) by preceding the character with ^, for example ^A for
a double-width A.</p>
2021-05-11 02:29:21 +02:00
<p>The following other two-character sequences are understood.</p>
<p>ASCII characters<br />
These are already present on most keyboards:</p>
2022-08-24 15:22:41 +02:00
<p>&lt;(<br />
2021-05-11 02:29:21 +02:00
Left square bracket</p>
2022-08-24 15:22:41 +02:00
<p>//<br />
2021-05-11 02:29:21 +02:00
Backslash (solidus)</p>
2022-08-24 15:22:41 +02:00
<p>)&gt;<br />
2021-05-11 02:29:21 +02:00
Right square bracket</p>
2022-08-24 15:22:41 +02:00
<p>(!<br />
2021-05-11 02:29:21 +02:00
Left brace (curly bracket)</p>
2022-08-24 15:22:41 +02:00
<p>!!<br />
2021-05-11 02:29:21 +02:00
Vertical bar (pipe symbol)</p>
2022-08-24 15:22:41 +02:00
<p>!)<br />
2021-05-11 02:29:21 +02:00
Right brace (curly bracket)</p>
2022-08-24 15:22:41 +02:00
<p>?<br />
2021-05-11 02:29:21 +02:00
Tilde</p>
<p>Special letters<br />
Characters found in various variants of the Latin alphabet:</p>
2022-08-24 15:22:41 +02:00
<p>ss<br />
2021-05-11 02:29:21 +02:00
Eszett (scharfes S)</p>
2022-08-24 15:22:41 +02:00
<p>D-, d-<br />
2021-05-11 02:29:21 +02:00
Eth</p>
2022-08-24 15:22:41 +02:00
<p>TH, th<br />
2021-05-11 02:29:21 +02:00
Thorn</p>
2022-08-24 15:22:41 +02:00
<p>kk<br />
2021-05-11 02:29:21 +02:00
Kra</p>
2022-08-24 15:22:41 +02:00
<p>n<br />
2021-05-11 02:29:21 +02:00
n</p>
2022-08-24 15:22:41 +02:00
<p>NG, ng<br />
2021-05-11 02:29:21 +02:00
Ng</p>
2022-08-24 15:22:41 +02:00
<p>OI, oi<br />
2021-05-11 02:29:21 +02:00
Oi</p>
2022-08-24 15:22:41 +02:00
<p>yr<br />
2021-05-11 02:29:21 +02:00
yr</p>
2022-08-24 15:22:41 +02:00
<p>ED<br />
2021-05-11 02:29:21 +02:00
ezh</p>
2022-08-24 15:22:41 +02:00
<p>Currency symbols<br />
Ct<br />
2021-05-11 02:29:21 +02:00
Cent</p>
2022-08-24 15:22:41 +02:00
<p>Pd<br />
2021-05-11 02:29:21 +02:00
Pound sterling (also lira and others)</p>
2022-08-24 15:22:41 +02:00
<p>Cu<br />
2021-05-11 02:29:21 +02:00
Currency</p>
2022-08-24 15:22:41 +02:00
<p>Ye<br />
2021-05-11 02:29:21 +02:00
Yen</p>
2022-08-24 15:22:41 +02:00
<p>Eu<br />
2021-05-11 02:29:21 +02:00
Euro (N.B. not in RFC 1345)</p>
<p>Punctuation characters<br />
2022-08-24 15:22:41 +02:00
References to &quot;right&quot; quotes indicate the shape (like a 9 rather than 6)
rather than their grammatical use. (For example, a &quot;right&quot; low double
quote is used to open quotations in German.)</p>
<p>!I<br />
2021-05-11 02:29:21 +02:00
Inverted exclamation mark</p>
2022-08-24 15:22:41 +02:00
<p>BB<br />
2021-05-11 02:29:21 +02:00
Broken vertical bar</p>
2022-08-24 15:22:41 +02:00
<p>SE<br />
2021-05-11 02:29:21 +02:00
Section</p>
2022-08-24 15:22:41 +02:00
<p>Co<br />
2021-05-11 02:29:21 +02:00
Copyright</p>
2022-08-24 15:22:41 +02:00
<p>-a<br />
2021-05-11 02:29:21 +02:00
Spanish feminine ordinal indicator</p>
2022-08-24 15:22:41 +02:00
<p>&lt;&lt;<br />
2021-05-11 02:29:21 +02:00
Left guillemet</p>
2022-08-24 15:22:41 +02:00
<p>--<br />
2021-05-11 02:29:21 +02:00
Soft hyphen</p>
2022-08-24 15:22:41 +02:00
<p>Rg<br />
2021-05-11 02:29:21 +02:00
Registered trade mark</p>
2022-08-24 15:22:41 +02:00
<p>PI<br />
2021-05-11 02:29:21 +02:00
Pilcrow (paragraph)</p>
2022-08-24 15:22:41 +02:00
<p>-o<br />
2021-05-11 02:29:21 +02:00
Spanish masculine ordinal indicator</p>
2022-08-24 15:22:41 +02:00
<p>&gt;&gt;<br />
2021-05-11 02:29:21 +02:00
Right guillemet</p>
2022-08-24 15:22:41 +02:00
<p>?I<br />
2021-05-11 02:29:21 +02:00
Inverted question mark</p>
2022-08-24 15:22:41 +02:00
<p>-1<br />
2021-05-11 02:29:21 +02:00
Hyphen</p>
2022-08-24 15:22:41 +02:00
<p>-N<br />
2021-05-11 02:29:21 +02:00
En dash</p>
2022-08-24 15:22:41 +02:00
<p>-M<br />
2021-05-11 02:29:21 +02:00
Em dash</p>
2022-08-24 15:22:41 +02:00
<p>-3<br />
2021-05-11 02:29:21 +02:00
Horizontal bar</p>
2022-08-24 15:22:41 +02:00
<p>:3<br />
2021-05-11 02:29:21 +02:00
Vertical ellipsis</p>
2022-08-24 15:22:41 +02:00
<p>.3<br />
2021-05-11 02:29:21 +02:00
Horizontal midline ellipsis</p>
2022-08-24 15:22:41 +02:00
<p>!2<br />
2021-05-11 02:29:21 +02:00
Double vertical line</p>
2022-08-24 15:22:41 +02:00
<p>=2<br />
2021-05-11 02:29:21 +02:00
Double low line</p>
2022-08-24 15:22:41 +02:00
<p>6<br />
2021-05-11 02:29:21 +02:00
Left single quote</p>
2022-08-24 15:22:41 +02:00
<p>9<br />
2021-05-11 02:29:21 +02:00
Right single quote</p>
2022-08-24 15:22:41 +02:00
<p>.9<br />
2021-05-11 02:29:21 +02:00
&quot;Right&quot; low quote</p>
2022-08-24 15:22:41 +02:00
<p>9<br />
2021-05-11 02:29:21 +02:00
Reversed &quot;right&quot; quote</p>
2022-08-24 15:22:41 +02:00
<p>&quot;6<br />
2021-05-11 02:29:21 +02:00
Left double quote</p>
2022-08-24 15:22:41 +02:00
<p>&quot;9<br />
2021-05-11 02:29:21 +02:00
Right double quote</p>
2022-08-24 15:22:41 +02:00
<p>:9<br />
2021-05-11 02:29:21 +02:00
&quot;Right&quot; low double quote</p>
2022-08-24 15:22:41 +02:00
<p>9&quot;<br />
2021-05-11 02:29:21 +02:00
Reversed &quot;right&quot; double quote</p>
2022-08-24 15:22:41 +02:00
<p>/-<br />
2021-05-11 02:29:21 +02:00
Dagger</p>
2022-08-24 15:22:41 +02:00
<p>/=<br />
2021-05-11 02:29:21 +02:00
Double dagger</p>
2022-08-24 15:22:41 +02:00
<p>Mathematical symbols<br />
DG<br />
2021-05-11 02:29:21 +02:00
Degree</p>
2022-08-24 15:22:41 +02:00
<p>-2, +-, -+<br />
2021-05-11 02:29:21 +02:00
- sign, +/- sign, -/+ sign</p>
2022-08-24 15:22:41 +02:00
<p>2S<br />
2021-05-11 02:29:21 +02:00
Superscript 2</p>
2022-08-24 15:22:41 +02:00
<p>3S<br />
2021-05-11 02:29:21 +02:00
Superscript 3</p>
2022-08-24 15:22:41 +02:00
<p>1S<br />
2021-05-11 02:29:21 +02:00
Superscript 1</p>
2022-08-24 15:22:41 +02:00
<p>My<br />
2021-05-11 02:29:21 +02:00
Micro</p>
2022-08-24 15:22:41 +02:00
<p>.M<br />
2021-05-11 02:29:21 +02:00
Middle dot</p>
2022-08-24 15:22:41 +02:00
<p>14<br />
2021-05-11 02:29:21 +02:00
Quarter</p>
2022-08-24 15:22:41 +02:00
<p>12<br />
2021-05-11 02:29:21 +02:00
Half</p>
2022-08-24 15:22:41 +02:00
<p>34<br />
2021-05-11 02:29:21 +02:00
Three quarters</p>
2022-08-24 15:22:41 +02:00
<p>*X<br />
2021-05-11 02:29:21 +02:00
Multiplication</p>
2022-08-24 15:22:41 +02:00
<p>-:<br />
2021-05-11 02:29:21 +02:00
Division</p>
2022-08-24 15:22:41 +02:00
<p>%0<br />
2021-05-11 02:29:21 +02:00
Per mille</p>
2022-08-24 15:22:41 +02:00
<p>FA, TE, /0<br />
2021-05-11 02:29:21 +02:00
For all, there exists, empty set</p>
2022-08-24 15:22:41 +02:00
<p>dP, DE, NB<br />
2021-05-11 02:29:21 +02:00
Partial derivative, delta (increment), del (nabla)</p>
2022-08-24 15:22:41 +02:00
<p>(-, -)<br />
2021-05-11 02:29:21 +02:00
Element of, contains</p>
2022-08-24 15:22:41 +02:00
<p>*P, +Z<br />
2021-05-11 02:29:21 +02:00
Product, sum</p>
2022-08-24 15:22:41 +02:00
<p>*-, Ob, Sb<br />
Asterisk, ring, bullet</p>
<p>RT, 0(, 00<br />
2021-05-11 02:29:21 +02:00
Root sign, proportional to, infinity</p>
2022-08-24 15:22:41 +02:00
<p>Other symbols<br />
cS, cH, cD, cC<br />
2021-05-11 02:29:21 +02:00
Card suits: spades, hearts, diamonds, clubs</p>
2022-08-24 15:22:41 +02:00
<p>Md, M8, M2, Mb, Mx, MX<br />
Musical notation: crotchet (quarter note), quaver (eighth note),
semiquavers (sixteenth notes), flag sign, natural sign, sharp sign</p>
<p>Fm, Ml<br />
2021-05-11 02:29:21 +02:00
Female, male</p>
2022-08-24 15:22:41 +02:00
<p>Accents on their own<br />
&gt;<br />
Circumflex (same as caret, ^)</p>
<p>!<br />
Grave (same as backtick, )</p>
<p>,<br />
2021-05-11 02:29:21 +02:00
Cedilla</p>
2022-08-24 15:22:41 +02:00
<p>:<br />
2021-05-11 02:29:21 +02:00
Diaeresis (Umlaut)</p>
2022-08-24 15:22:41 +02:00
<p>m<br />
2021-05-11 02:29:21 +02:00
Macron</p>
2022-08-24 15:22:41 +02:00
<p><br />
2021-05-11 02:29:21 +02:00
Acute</p>
<p><span id="index-insert_002dfiles"></span></p>
2022-08-24 15:22:41 +02:00
<p>insert-files<br />
This function allows you type a file pattern, and see the results of the
expansion at each step. When you hit return, all expansions are inserted
into the command line.</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">bindkey '^Xf' insert-files
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p><span id="index-insert_002dunicode_002dchar"></span></p>
2022-08-24 15:22:41 +02:00
<p>insert-unicode-char<br />
When first executed, the user inputs a set of hexadecimal digits. This
is terminated with another call to insert-unicode-char. The digits are
then turned into the corresponding Unicode character. For example, if
the widget is bound to ^XU, the character sequence ^XU 4 c ^XU inserts
L (Unicode U+004c).</p>
<p>See insert-composed-char for a way of inserting characters using a
2021-05-11 02:29:21 +02:00
two-character mnemonic.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-narrow_002dto_002dregion"></span> <span
id="index-narrow_002dto_002dregion_002dinvisible"></span></p>
<p>narrow-to-region [ -p <code>pre</code> ] [ -P <code>post</code> ]<br />
                 [ -S <code>statepm</code> | -R <code>statepm</code> | [ -l <code>lbufvar</code> ] [ -r <code>rbufvar</code> ] ]<br />
                 [ -n ] [ <code>start</code> <code>end</code> ]<br />
narrow-to-region-invisible<br />
predict-on<br />
This set of functions implements predictive typing using history search.
After predict-on, typing characters causes the editor to look backward
in the history for the first line beginning with what you have typed so
far. After predict-off, editing returns to normal for the line found. In
fact, you often dont even need to use predict-off, because if the line
doesnt match something in the history, adding a key performs standard
completion, and then inserts itself if no completions were found.
However, editing in the middle of a line is liable to confuse
prediction; see the toggle style below.</p>
<p>With the function based completion system (which is needed for this),
you should be able to type TAB at almost any point to advance the cursor
to the next interesting character position (usually the end of the
current word, but sometimes somewhere in the middle of the word). And of
course as soon as the entire line is what you want, you can accept with
return, without needing to move the cursor to the end first.</p>
<p>The first time predict-on is used, it creates several additional widget
functions:</p>
<p>delete-backward-and-predict<br />
Replaces the backward-delete-char widget. You do not need to bind this
yourself.</p>
<p>insert-and-predict<br />
Implements predictive typing by replacing the self-insert widget. You do
not need to bind this yourself.</p>
<p>predict-off<br />
2021-05-11 02:29:21 +02:00
Turns off predictive typing.</p>
2022-08-24 15:22:41 +02:00
<p>Although you autoload only the predict-on function, it is necessary to
create a keybinding for predict-off as well.</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zle -N predict-on
2021-05-11 02:29:21 +02:00
zle -N predict-off
bindkey '^X^Z' predict-on
bindkey '^Z' predict-off
</code></pre>
</div>
<p><span id="index-read_002dfrom_002dminibuffer"></span></p>
2022-08-24 15:22:41 +02:00
<p>read-from-minibuffer<br />
This is most useful when called as a function from inside a widget, but
will work correctly as a widget in its own right. It prompts for a value
below the current command line; a value may be input using all of the
standard zle operations (and not merely the restricted set available
when executing, for example, execute-named-cmd). The value is then
returned to the calling function in the parameter $REPLY and the editing
buffer restored to its previous state. If the read was aborted by a
keyboard break (typically ^G), the function returns status 1 and $REPLY
is not set.</p>
2021-05-11 02:29:21 +02:00
<p>If one argument is supplied to the function it is taken as a prompt,
2022-08-24 15:22:41 +02:00
otherwise ? is used. If two arguments are supplied, they are the
prompt and the initial value of $LBUFFER, and if a third argument is
given it is the initial value of $RBUFFER. This provides a default value
and starting cursor placement. Upon return the entire buffer is the
value of $REPLY.</p>
<p>One option is available: -k <code>num</code> specifies that <code>num</code> characters are
to be read instead of a whole line. The line editor is not invoked
recursively in this case, so depending on the terminal settings the
input may not be visible, and only the input keys are placed in $REPLY,
not the entire buffer. Note that unlike the read builtin <code>num</code> must be
given; there is no default.</p>
<p>The name is a slight misnomer, as in fact the shells own minibuffer is
not used. Hence it is still possible to call executed-named-cmd and
similar functions while reading a value.</p>
<p><span id="index-replace_002dargument"></span> <span
id="index-replace_002dargument_002dedit"></span></p>
<p>replace-argument, replace-argument-edit<br />
The function replace-argument can be used to replace a command line
argument in the current command line or, if the current command line is
empty, in the last command line executed (the new command line is not
executed). Arguments are as delimited by standard shell syntax,</p>
2021-05-11 02:29:21 +02:00
<p>If a numeric argument is given, that specifies the argument to be
2022-08-24 15:22:41 +02:00
replaced. 0 means the command name, as in history expansion. A negative
numeric argument counts backward from the last word.</p>
<p>If no numeric argument is given, the current argument is replaced; this
is the last argument if the previous history line is being used.</p>
2021-05-11 02:29:21 +02:00
<p>The function prompts for a replacement argument.</p>
2022-08-24 15:22:41 +02:00
<p>If the widget contains the string edit, for example is defined as</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zle -N replace-argument-edit replace-argument
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>then the function presents the current value of the argument for
2022-08-24 15:22:41 +02:00
editing, otherwise the editing buffer for the replacement is initially
empty.</p>
<p><span id="index-replace_002dstring"></span> <span
id="index-replace_002dstring_002dagain"></span> <span
id="index-replace_002dpattern"></span></p>
<p>replace-string, replace-pattern<br />
replace-string-again, replace-pattern-again<br />
The function replace-string implements three widgets. If defined under
the same name as the function, it prompts for two strings; the first
(source) string will be replaced by the second everywhere it occurs in
the line editing buffer.</p>
<p>If the widget name contains the word pattern, for example by defining
the widget using the command zle -N replace-pattern replace-string,
then the matching is performed using zsh patterns. All zsh extended
globbing patterns can be used in the source string; note that unlike
filename generation the pattern does not need to match an entire word,
nor do glob qualifiers have any effect. In addition, the replacement
string can contain parameter or command substitutions. Furthermore, a
&amp; in the replacement string will be replaced with the matched source
string, and a backquoted digit \<code>N</code> will be replaced by the <code>N</code>th
parenthesised expression matched. The form \{<code>N</code>} may be used to
protect the digit from following digits.</p>
<p>If the widget instead contains the word regex (or regexp), then the
matching is performed using regular expressions, respecting the setting
of the option RE_MATCH_PCRE (see the description of the function
regexp-replace below). The special replacement facilities described
above for pattern matching are available.</p>
<p>By default the previous source or replacement string will not be offered
for editing. However, this feature can be activated by setting the style
edit-previous in the context :zle:<code>widget</code> (for example,
:zle:replace-string) to true. In addition, a positive numeric argument
forces the previous values to be offered, a negative or zero argument
forces them not to be.</p>
<p>The function replace-string-again can be used to repeat the previous
replacement; no prompting is done. As with replace-string, if the name
of the widget contains the word pattern or regex, pattern or regular
expression matching is performed, else a literal string replacement.
Note that the previous source and replacement text are the same whether
pattern, regular expression or string matching is used.</p>
<p>In addition, replace-string shows the previous replacement above the
prompt, so long as there was one during the current session; if the
source string is empty, that replacement will be repeated without the
widget prompting for a replacement string.</p>
2021-05-11 02:29:21 +02:00
<p>For example, starting from the line:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">print This line contains fan and fond
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>and invoking replace-pattern with the source string f(?)n and the
replacement string c\1r produces the not very useful line:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">print This line contains car and cord
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>The range of the replacement string can be limited by using the
2022-08-24 15:22:41 +02:00
narrow-to-region-invisible widget. One limitation of the current version
is that undo will cycle through changes to the replacement and source
strings before undoing the replacement itself.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-send_002dinvisible"></span></p>
2022-08-24 15:22:41 +02:00
<p>send-invisible<br />
This is similar to read-from-minibuffer in that it may be called as a
function from a widget or as a widget of its own, and interactively
reads input from the keyboard. However, the input being typed is
concealed and a string of asterisks (*) is shown instead. The value
is saved in the parameter $INVISIBLE to which a reference is inserted
into the editing buffer at the restored cursor position. If the read was
aborted by a keyboard break (typically ^G) or another escape from
editing such as push-line, $INVISIBLE is set to empty and the original
buffer is restored unchanged.</p>
2021-05-11 02:29:21 +02:00
<p>If one argument is supplied to the function it is taken as a prompt,
2022-08-24 15:22:41 +02:00
otherwise Non-echoed text: is used (as in emacs). If a second and
third argument are supplied they are used to begin and end the reference
to $INVISIBLE that is inserted into the buffer. The default is to open
with ${, then INVISIBLE, and close with }, but many other effects are
possible.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-smart_002dinsert_002dlast_002dword"></span></p>
2022-08-24 15:22:41 +02:00
<p>smart-insert-last-word<br />
This function may replace the insert-last-word widget, like so:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zle -N insert-last-word smart-insert-last-word
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>With a numeric argument, or when passed command line arguments in a call
from another widget, it behaves like insert-last-word, except that words
in comments are ignored when INTERACTIVE_COMMENTS is set.</p>
<p>Otherwise, the rightmost interesting word from the previous command
is found and inserted. The default definition of interesting is that
the word contains at least one alphabetic character, slash, or
backslash. This definition may be overridden by use of the match style.
The context used to look up the style is the widget name, so usually the
context is :insert-last-word. However, you can bind this function to
2021-05-11 02:29:21 +02:00
different widgets to use different patterns:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zle -N insert-last-assignment smart-insert-last-word
2021-05-11 02:29:21 +02:00
zstyle :insert-last-assignment match '[[:alpha:]][][[:alnum:]]#=*'
bindkey '\e=' insert-last-assignment
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>If no interesting word is found and the auto-previous style is set to a
true value, the search continues upward through the history. When
auto-previous is unset or false (the default), the widget must be
invoked repeatedly in order to search earlier history lines.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-transpose_002dlines"></span></p>
2022-08-24 15:22:41 +02:00
<p>transpose-lines<br />
Only useful with a multi-line editing buffer; the lines here are lines
within the current on-screen buffer, not history lines. The effect is
similar to the function of the same name in Emacs.</p>
<p>Transpose the current line with the previous line and move the cursor to
the start of the next line. Repeating this (which can be done by
providing a positive numeric argument) has the effect of moving the line
above the cursor down by a number of lines.</p>
<p>With a negative numeric argument, requires two lines above the cursor.
These two lines are transposed and the cursor moved to the start of the
previous line. Using a numeric argument less than -1 has the effect of
moving the line above the cursor up by minus that number of lines.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-url_002dquote_002dmagic"></span></p>
2022-08-24 15:22:41 +02:00
<p>url-quote-magic<br />
This widget replaces the built-in self-insert to make it easier to type
URLs as command line arguments. As you type, the input character is
analyzed and, if it may need quoting, the current word is checked for a
URI scheme. If one is found and the current word is not already in
quotes, a backslash is inserted before the input character.</p>
2021-05-11 02:29:21 +02:00
<p>Styles to control quoting behavior:</p>
2022-08-24 15:22:41 +02:00
<p>url-metas<br />
This style is looked up in the context :url-quote-magic:<code>scheme</code>
(where <code>scheme</code> is that of the current URL, e.g. &quot;ftp&quot;). The value is a
string listing the characters to be treated as globbing metacharacters
when appearing in a URL using that scheme. The default is to quote all
zsh extended globbing characters, excluding &lt; and &gt; but including
braces (as in brace expansion). See also url-seps.</p>
<p>url-seps<br />
Like url-metas, but lists characters that should be considered command
separators, redirections, history references, etc. The default is to
quote the standard set of shell separators, excluding those that overlap
with the extended globbing characters, but including &lt; and &gt; and
the first character of $histchars.</p>
<p>url-globbers<br />
This style is looked up in the context :url-quote-magic. The values
form a list of command names that are expected to do their own globbing
on the URL string. This implies that they are aliased to use the
noglob modifier. When the first word on the line matches one of the
values <em>and</em> the URL refers to a local file (see url-local-schema), only
the url-seps characters are quoted; the url-metas are left alone,
allowing them to affect command-line parsing, completion, etc. The
default values are a literal noglob plus (when the zsh/parameter
module is available) any commands aliased to the helper function
urlglobber or its alias globurl.</p>
<p>url-local-schema<br />
This style is always looked up in the context :urlglobber, even though
it is used by both url-quote-magic and urlglobber. The values form a
list of URI schema that should be treated as referring to local files by
their real local path names, as opposed to files which are specified
relative to a web-server-defined document root. The defaults are &quot;ftp&quot;
and &quot;file&quot;.</p>
<p>url-other-schema<br />
Like url-local-schema, but lists all other URI schema upon which
urlglobber and url-quote-magic should act. If the URI on the command
line does not have a scheme appearing either in this list or in
url-local-schema, it is not magically quoted. The default values are
&quot;http&quot;, &quot;https&quot;, and &quot;ftp&quot;. When a scheme appears both here and in
url-local-schema, it is quoted differently depending on whether the
command name appears in url-globbers.</p>
<p>Loading url-quote-magic also defines a helper function urlglobber and
aliases globurl to noglob urlglobber. This function takes a local
URL apart, attempts to pattern-match the local file portion of the URL
path, and then puts the results back into URL format again.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-vi_002dpipe"></span></p>
2022-08-24 15:22:41 +02:00
<p>vi-pipe<br />
2021-05-11 02:29:21 +02:00
This function reads a movement command from the keyboard and then
2022-08-24 15:22:41 +02:00
prompts for an external command. The part of the buffer covered by the
movement is piped to the external command and then replaced by the
commands output. If the movement command is bound to vi-pipe, the
current line is used.</p>
<p>The function serves as an example for reading a vi movement command from
within a user-defined widget.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-which_002dcommand-1"></span></p>
2022-08-24 15:22:41 +02:00
<p>which-command<br />
2021-05-11 02:29:21 +02:00
This function is a drop-in replacement for the builtin widget
2022-08-24 15:22:41 +02:00
which-command. It has enhanced behaviour, in that it correctly detects
whether or not the command word needs to be expanded as an alias; if so,
it continues tracing the command word from the expanded alias until it
reaches the command that will be executed.</p>
<p>The style whence is available in the context :zle:$WIDGET; this may be
set to an array to give the command and options that will be used to
investigate the command word found. The default is whence -c.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zcalc_002dauto_002dinsert"></span></p>
2022-08-24 15:22:41 +02:00
<p>zcalc-auto-insert<br />
This function is useful together with the zcalc function described in
<a href="User-Contributions.html#Mathematical-Functions">Mathematical Functions</a>. It should be bound to
a key representing a binary operator such as +, -, * or /. When
running in zcalc, if the key occurs at the start of the line or
immediately following an open parenthesis, the text &quot;ans &quot; is inserted
before the representation of the key itself. This allows easy use of the
answer from the previous calculation in the current line. The text to be
inserted before the symbol typed can be modified by setting the variable
ZCALC_AUTO_INSERT_PREFIX.</p>
<p>Hence, for example, typing +12 followed by return adds 12 to the
2021-05-11 02:29:21 +02:00
previous result.</p>
2022-08-24 15:22:41 +02:00
<p>If zcalc is in RPN mode (-r option) the effect of this binding is
automatically suppressed as operators alone on a line are meaningful.</p>
2021-05-11 02:29:21 +02:00
<p>When not in zcalc, the key simply inserts the symbol itself.</p>
<hr />
<p><span id="Utility-Functions"></span></p>
<h3 id="2672-utility-functions"><a class="header" href="#2672-utility-functions">26.7.2 Utility Functions</a></h3>
<p>These functions are useful in constructing widgets. They should be
2022-08-24 15:22:41 +02:00
loaded with autoload -U <code>function</code> and called as indicated from
2021-05-11 02:29:21 +02:00
user-defined widgets.</p>
<p><span id="index-split_002dshell_002darguments"></span></p>
2022-08-24 15:22:41 +02:00
<p>split-shell-arguments</p>
2021-05-11 02:29:21 +02:00
<p>This function splits the line currently being edited into shell
2022-08-24 15:22:41 +02:00
arguments and whitespace. The result is stored in the array reply. The
2021-05-11 02:29:21 +02:00
array contains all the parts of the line in order, starting with any
whitespace before the first argument, and finishing with any whitespace
2022-08-24 15:22:41 +02:00
after the last argument. Hence (so long as the option KSH_ARRAYS is not
set) whitespace is given by odd indices in the array and arguments by
even indices. Note that no stripping of quotes is done; joining together
all the elements of reply in order is guaranteed to produce the original
line.</p>
<p>The parameter REPLY is set to the index of the word in reply which
2021-05-11 02:29:21 +02:00
contains the character after the cursor, where the first element has
2022-08-24 15:22:41 +02:00
index 1. The parameter REPLY2 is set to the index of the character under
the cursor in that word, where the first character has index 1.</p>
<p>Hence reply, REPLY and REPLY2 should all be made local to the enclosing
function.</p>
<p>See the function modify-current-argument, described below, for an
2021-05-11 02:29:21 +02:00
example of how to call this function.</p>
<p><span id="index-modify_002dcurrent_002dargument"></span></p>
2022-08-24 15:22:41 +02:00
<p>modify-current-argument [ <code>expr-using-</code>$ARG | <code>func</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>This function provides a simple method of allowing user-defined widgets
to modify the command line argument under the cursor (or immediately to
the left of the cursor if the cursor is between arguments).</p>
<p>The argument can be an expression which when evaluated operates on the
2022-08-24 15:22:41 +02:00
shell parameter ARG, which will have been set to the command line
2021-05-11 02:29:21 +02:00
argument under the cursor. The expression should be suitably quoted to
prevent it being evaluated too early.</p>
2022-08-24 15:22:41 +02:00
<p>Alternatively, if the argument does not contain the string ARG, it is
2021-05-11 02:29:21 +02:00
assumed to be a shell function, to which the current command line
argument is passed as the only argument. The function should set the
2022-08-24 15:22:41 +02:00
variable REPLY to the new value for the command line argument. If the
2021-05-11 02:29:21 +02:00
function returns non-zero status, so does the calling function.</p>
<p>For example, a user-defined widget containing the following code
converts the characters in the argument under the cursor into all upper
case:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">modify-current-argument '${(U)ARG}'
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>The following strips any quoting from the current word (whether
backslashes or one of the styles of quotes), and replaces it with single
quoting throughout:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">modify-current-argument '${(qq)${(Q)ARG}}'
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>The following performs directory expansion on the command line argument
and replaces it by the absolute path:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">expand-dir() {
2021-05-11 02:29:21 +02:00
REPLY=${~1}
REPLY=${REPLY:a}
}
modify-current-argument expand-dir
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>In practice the function expand-dir would probably not be defined within
the widget where modify-current-argument is called.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Styles-2"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="2673-styles"><a class="header" href="#2673-styles">26.7.3 Styles</a></h3>
<p>The behavior of several of the above widgets can be controlled by the
2022-08-24 15:22:41 +02:00
use of the zstyle mechanism. In particular, widgets that interact with
2021-05-11 02:29:21 +02:00
the completion system pass along their context to any completions that
they invoke.</p>
<p><span id="index-break_002dkeys_002c-widget-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>break-keys</p>
<p>This style is used by the incremental-complete-word widget. Its value
2021-05-11 02:29:21 +02:00
should be a pattern, and all keys matching this pattern will cause the
widget to stop incremental completion without the key having any further
2022-08-24 15:22:41 +02:00
effect. Like all styles used directly by incremental-complete-word, this
style is looked up using the context :incremental.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-completer_002c-completion-style-1"></span></p>
2022-08-24 15:22:41 +02:00
<p>completer</p>
<p>The incremental-complete-word and insert-and-predict widgets set up
2021-05-11 02:29:21 +02:00
their top-level context name before calling completion. This allows one
to define different sets of completer functions for normal completion
and for these widgets. For example, to use completion, approximation and
correction for normal completion, completion and correction for
incremental completion and only completion for prediction one could use:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':completion:*' completer \
2021-05-11 02:29:21 +02:00
_complete _correct _approximate
zstyle ':completion:incremental:*' completer \
_complete _correct
zstyle ':completion:predict:*' completer \
_complete
</code></pre>
</div>
<p>It is a good idea to restrict the completers used in prediction, because
2022-08-24 15:22:41 +02:00
they may be automatically invoked as you type. The _list and _menu
completers should never be used with prediction. The _approximate,
_correct, _expand, and _match completers may be used, but be aware
2021-05-11 02:29:21 +02:00
that they may change characters anywhere in the word behind the cursor,
so you need to watch carefully that the result is what you intended.</p>
<p><span id="index-cursor_002c-completion-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>cursor</p>
<p>The insert-and-predict widget uses this style, in the context
:predict, to decide where to place the cursor after completion has
2021-05-11 02:29:21 +02:00
been tried. Values are:</p>
2022-08-24 15:22:41 +02:00
<p>complete<br />
The cursor is left where it was when completion finished, but only if it
is after a character equal to the one just inserted by the user. If it
is after another character, this value is the same as key.</p>
<p>key<br />
2021-05-11 02:29:21 +02:00
The cursor is left after the <code>n</code>th occurrence of the character just
2022-08-24 15:22:41 +02:00
inserted, where <code>n</code> is the number of times that character appeared in
the word before completion was attempted. In short, this has the effect
of leaving the cursor after the character just typed even if the
completion code found out that no other characters need to be inserted
at that position.</p>
2021-05-11 02:29:21 +02:00
<p>Any other value for this style unconditionally leaves the cursor at the
position where the completion code left it.</p>
<p><span id="index-list_002c-widget-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>list</p>
<p>When using the incremental-complete-word widget, this style says if the
matches should be listed on every key press (if they fit on the screen).
Use the context prefix :completion:incremental.</p>
<p>The insert-and-predict widget uses this style to decide if the
2021-05-11 02:29:21 +02:00
completion should be shown even if there is only one possible
completion. This is done if the value of this style is the string
2022-08-24 15:22:41 +02:00
always. In this case the context is :predict (<em>not</em>
:completion:predict).</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-match_002c-widget-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>match</p>
<p>This style is used by smart-insert-last-word to provide a pattern (using
full EXTENDED_GLOB syntax) that matches an interesting word. The context
is the name of the widget to which smart-insert-last-word is bound (see
above). The default behavior of smart-insert-last-word is equivalent to:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle :insert-last-word match '*[[:alpha:]/\\]*'
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>However, you might want to include words that contain spaces:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle :insert-last-word match '*[[:alpha:][:space:]/\\]*'
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>Or include numbers as long as the word is at least two characters long:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle :insert-last-word match '*([[:digit:]]?|[[:alpha:]/\\])*'
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>The above example causes redirections like &quot;2&gt;&quot; to be included.</p>
<p><span id="index-prompt_002c-widget-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>prompt</p>
<p>The incremental-complete-word widget shows the value of this style in
2021-05-11 02:29:21 +02:00
the status line during incremental completion. The string value may
2022-08-24 15:22:41 +02:00
contain any of the following substrings in the manner of the PS1 and
2021-05-11 02:29:21 +02:00
other prompt parameters:</p>
2022-08-24 15:22:41 +02:00
<p>%c<br />
2021-05-11 02:29:21 +02:00
Replaced by the name of the completer function that generated the
matches (without the leading underscore).</p>
2022-08-24 15:22:41 +02:00
<p>%l<br />
When the list style is set, replaced by ... if the list of matches is
too long to fit on the screen and with an empty string otherwise. If the
list style is false or not set, %l is always removed.</p>
<p>%n<br />
2021-05-11 02:29:21 +02:00
Replaced by the number of matches generated.</p>
2022-08-24 15:22:41 +02:00
<p>%s<br />
Replaced by -no match-, -no prefix-, or an empty string if there is
no completion matching the word on the line, if the matches have no
common prefix different from the word on the line, or if there is such a
common prefix, respectively.</p>
<p>%u<br />
Replaced by the unambiguous part of all matches, if there is any, and if
it is different from the word on the line.</p>
<p>Like break-keys, this uses the :incremental context.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-stop_002dkeys_002c-widget-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>stop-keys</p>
<p>This style is used by the incremental-complete-word widget. Its value is
treated similarly to the one for the break-keys style (and uses the same
context: :incremental). However, in this case all keys matching the
pattern given as its value will stop incremental completion and will
2021-05-11 02:29:21 +02:00
then execute their usual function.</p>
<p><span id="index-toggle_002c-widget-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>toggle</p>
<p>This boolean style is used by predict-on and its related widgets in the
context :predict. If set to one of the standard true values,
2021-05-11 02:29:21 +02:00
predictive typing is automatically toggled off in situations where it is
unlikely to be useful, such as when editing a multi-line buffer or after
moving into the middle of a line and then deleting a character. The
default is to leave prediction turned on until an explicit call to
2022-08-24 15:22:41 +02:00
predict-off.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-verbose_002c-widget-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>verbose</p>
<p>This boolean style is used by predict-on and its related widgets in the
context :predict. If set to one of the standard true values, these
widgets display a message below the prompt when the predictive state is
toggled. This is most useful in combination with the toggle style. The
default does not display these messages.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-widget_002c-widget-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>widget</p>
<p>This style is similar to the command style: For widget functions that
use zle to call other widgets, this style can sometimes be used to
2021-05-11 02:29:21 +02:00
override the widget which is called. The context for this style is the
name of the calling widget (<em>not</em> the name of the calling function,
because one function may be bound to multiple widget names).</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle :copy-earlier-word widget smart-insert-last-word
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>Check the documentation for the calling widget or function to determine
2022-08-24 15:22:41 +02:00
whether the widget style is used.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Exception-Handling"></span> <span
id="Exception-Handling-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="268-exception-handling"><a class="header" href="#268-exception-handling">26.8 Exception Handling</a></h2>
<p>Two functions are provided to enable zsh to provide exception handling
in a form that should be familiar from other languages.</p>
<p><span id="index-throw"></span></p>
2022-08-24 15:22:41 +02:00
<p>throw <code>exception</code></p>
<p>The function throw throws the named <code>exception</code>. The name is an
arbitrary string and is only used by the throw and catch functions. An
exception is for the most part treated the same as a shell error, i.e.
an unhandled exception will cause the shell to abort all processing in a
function or script and to return to the top level in an interactive
2021-05-11 02:29:21 +02:00
shell.</p>
2022-08-24 15:22:41 +02:00
<p>catch <code>exception-pattern</code></p>
<p>The function catch returns status zero if an exception was thrown and
2021-05-11 02:29:21 +02:00
the pattern <code>exception-pattern</code> matches its name. Otherwise it returns
status 1. <code>exception-pattern</code> is a standard shell pattern, respecting
2022-08-24 15:22:41 +02:00
the current setting of the EXTENDED_GLOB option. An alias catch is also
defined to prevent the argument to the function from matching filenames,
so patterns may be used unquoted. Note that as exceptions are not
fundamentally different from other shell errors it is possible to catch
shell errors by using an empty string as the exception name. The shell
variable CAUGHT is set by catch to the name of the exception caught. It
is possible to rethrow an exception by calling the throw function again
once an exception has been caught. <span id="index-catch"></span></p>
<p>The functions are designed to be used together with the always construct
described in <a href="Shell-Grammar.html#Complex-Commands">Complex Commands</a>.
This is important as only this construct provides the required support
for exceptions. A typical example is as follows.</p>
<div class="example">
<pre><code class="language-zsh">{
2021-05-11 02:29:21 +02:00
# &quot;try&quot; block
# ... nested code here calls &quot;throw MyExcept&quot;
} always {
# &quot;always&quot; block
if catch MyExcept; then
print &quot;Caught exception MyExcept&quot;
elif catch ''; then
print &quot;Caught a shell error. Propagating...&quot;
throw ''
fi
# Other exceptions are not handled but may be caught further
# up the call stack.
}
</code></pre>
</div>
<p>If all exceptions should be caught, the following idiom might be
preferable.</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">{
2021-05-11 02:29:21 +02:00
# ... nested code here throws an exception
} always {
if catch *; then
case $CAUGHT in
(MyExcept)
print &quot;Caught my own exception&quot;
;;
(*)
print &quot;Caught some other exception&quot;
;;
esac
fi
}
</code></pre>
</div>
<p>In common with exception handling in other languages, the exception may
be thrown by code deeply nested inside the try block. However, note
that it must be thrown inside the current shell, not in a subshell
forked for a pipeline, parenthesised current-shell construct, or some
form of command or process substitution.</p>
2022-08-24 15:22:41 +02:00
<p>The system internally uses the shell variable EXCEPTION to record the
2021-05-11 02:29:21 +02:00
name of the exception between throwing and catching. One drawback of
this scheme is that if the exception is not handled the variable
2022-08-24 15:22:41 +02:00
EXCEPTION remains set and may be incorrectly recognised as the name of
an exception if a shell error subsequently occurs. Adding unset
EXCEPTION at the start of the outermost layer of any code that uses
2021-05-11 02:29:21 +02:00
exception handling will eliminate this problem.</p>
<hr />
<p><span id="MIME-Functions"></span> <span id="MIME-Functions-1"></span></p>
<h2 id="269-mime-functions"><a class="header" href="#269-mime-functions">26.9 MIME Functions</a></h2>
<p>Three functions are available to provide handling of files recognised by
2022-08-24 15:22:41 +02:00
extension, for example to dispatch a file text.ps when executed as a
2021-05-11 02:29:21 +02:00
command to an appropriate viewer.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-zsh_002dmime_002dsetup"></span> <span
id="index-zsh_002dmime_002dhandler"></span></p>
<p>zsh-mime-setup [ -fv ] [ -l [ <code>suffix</code> ... ] ]</p>
<p>zsh-mime-handler [ -l ] <code>command argument</code> ...</p>
<p>These two functions use the files ~/.mime.types and /etc/mime.types,
which associate types and extensions, as well as ~/.mailcap and
/etc/mailcap files, which associate types and the programs that handle
2021-05-11 02:29:21 +02:00
them. These are provided on many systems with the Multimedia Internet
Mail Extensions.</p>
2022-08-24 15:22:41 +02:00
<p>To enable the system, the function zsh-mime-setup should be autoloaded
2021-05-11 02:29:21 +02:00
and run. This allows files with extensions to be treated The function
2022-08-24 15:22:41 +02:00
zsh-mime-handler should not need to be called by the user.</p>
<p>The system works by setting up suffix aliases with alias -s. Suffix
2021-05-11 02:29:21 +02:00
aliases already installed by the user will not be overwritten.</p>
<p>For suffixes defined in lower case, upper case variants will also
2022-08-24 15:22:41 +02:00
automatically be handled (e.g. PDF is automatically handled if handling
for the suffix pdf is defined), but not vice versa.</p>
<p>Repeated calls to zsh-mime-setup do not override the existing is given.
Note, however, that this does not override existing suffix aliases
assigned to handlers other than zsh-mime-handler.</p>
<p>Calling zsh-mime-setup with the option -l lists the existing mappings
without altering them. Suffixes to list (which may contain pattern
characters that should be quoted from immediate interpretation on the
command line) may be given as additional arguments, otherwise all
2021-05-11 02:29:21 +02:00
suffixes are listed.</p>
2022-08-24 15:22:41 +02:00
<p>Calling zsh-mime-setup with the option -v causes verbose output to be
shown during the setup operation.</p>
<p>The system respects the mailcap flags needsterminal and copiousoutput;
see mailcap(4) or mailcap(5) (the man pages name varies across
platforms).</p>
2021-05-11 02:29:21 +02:00
<p>The functions use the following styles, which are defined with the
2022-08-24 15:22:41 +02:00
zstyle builtin command (<a href="Zsh-Modules.html#The-zsh_002fzutil-Module">The zsh/zutil
2021-05-11 02:29:21 +02:00
Module</a>). They should be
2022-08-24 15:22:41 +02:00
defined before zsh-mime-setup is run. The contexts used all start with
:mime:, with additional components in some cases. It is recommended that
a trailing * (suitably quoted) be appended to style patterns in case
the system is extended in future. Some examples are given below.</p>
<p>For files that have multiple suffixes, e.g. .pdf.gz, where the context
2021-05-11 02:29:21 +02:00
includes the suffix it will be looked up starting with the longest
possible suffix until a match for the style is found. For example, if
2022-08-24 15:22:41 +02:00
.pdf.gz produces a match for the handler, that will be used; otherwise
the handler for .gz will be used. Note that, owing to the way suffix
2021-05-11 02:29:21 +02:00
aliases work, it is always required that there be a handler for the
2022-08-24 15:22:41 +02:00
shortest possible suffix, so in this example .pdf.gz can only be handled
if .gz is also handled (though not necessarily in the same way).
Alternatively, if no handling for .gz on its own is needed, simply
adding the command</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">alias -s gz=zsh-mime-handler
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>to the initialisation code is sufficient; .gz will not be handled on its
own, but may be in combination with other suffixes.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-current_002dshell_002c-MIME-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>current-shell</p>
2021-05-11 02:29:21 +02:00
<p>If this boolean style is true, the mailcap handler for the context in
2022-08-24 15:22:41 +02:00
question is run using the eval builtin instead of by starting a new sh
process. This is more efficient, but may not work in the occasional
2021-05-11 02:29:21 +02:00
cases where the mailcap handler uses strict POSIX syntax.</p>
<p><span id="index-disown_002c-MIME-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>disown</p>
2021-05-11 02:29:21 +02:00
<p>If this boolean style is true, mailcap handlers started in the
background will be disowned, i.e. not subject to job control within the
parent shell. Such handlers nearly always produce their own windows, so
the only likely harmful side effect of setting the style is that it
becomes harder to kill jobs from within the shell.</p>
<p><span id="index-execute_002das_002dis_002c-MIME-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>execute-as-is</p>
2021-05-11 02:29:21 +02:00
<p>This style gives a list of patterns to be matched against files passed
for execution with a handler program. If the file matches the pattern,
the entire command line is executed in its current form, with no
handler. This is useful for files which might have suffixes is not set,
2022-08-24 15:22:41 +02:00
the pattern *(*) *(/) is used; handler, and the option AUTO_CD may be
used to change to directories that happen to have MIME suffixes.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-execute_002dnever_002c-MIME-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>execute-never</p>
<p>This style is useful in combination with execute-as-is. It is set to an
array of patterns corresponding to full paths to files that the MIME
handler matches execute-as-is. This is useful for file from another
operating system. For example, if /mnt/windows is a Windows mount, then</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':mime:*' execute-never '/mnt/windows/*'
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>will ensure that any files found in that area will be executed as MIME
file name is matched against the pattern, regardless of how the file was
2022-08-24 15:22:41 +02:00
passed to the handler. The file is resolved to a full path using the :P
modifier described in <a href="Expansion.html#Modifiers">Modifiers</a>; this means
that symbolic links are resolved where possible, so that links into
other file systems behave in the correct fashion.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-file_002dpath_002c-MIME-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>file-path</p>
<p>Used if the style find-file-in-path is true for the same context. Set to
an array of directories that are used for searching for the file to be
handled; the default is the command path given by the special parameter
path. The shell option PATH_DIRS is respected; if that is set, the
appropriate path will be searched even if the name of the file to be
handled as it appears on the command line contains a /. The full
context is :mime:.<code>suffix</code>:, as described for the style handler.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-find_002dfile_002din_002dpath_002c-MIME-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>find-file-in-path</p>
2021-05-11 02:29:21 +02:00
<p>If set, allows files whose names do not contain absolute paths to be
2022-08-24 15:22:41 +02:00
searched for in the command path or the path specified by the file-path
style. If the file is not found in the path, it is looked for locally
(whether or not the current directory is in the path); if it is not
found locally, the handler will abort unless the handle-nonexistent
style is set. Files found in the path are tested as described for the
style execute-as-is. The full context is :mime:.<code>suffix</code>:, as described
for the style handler.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-flags_002c-MIME-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>flags</p>
<p>Defines flags to go with a handler; the context is as for the handler
style, and the format is as for the flags in mailcap.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-handle_002dnonexistent_002c-MIME-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>handle-nonexistent</p>
2021-05-11 02:29:21 +02:00
<p>By default, arguments that dont correspond to files are not passed to
the MIME handler in order to prevent it from intercepting commands found
in the path that happen to have suffixes. This style may be set to an
array of extended glob patterns for arguments that will be passed to the
handler even if they dont exist. If it is not explicitly set it
2022-08-24 15:22:41 +02:00
defaults to [[:alpha:]]#:/* which allows URLs to be passed to the
MIME handler even though they dont exist in that format in the file
system. The full context is :mime:.<code>suffix</code>:, as described for the style
handler.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-handler_002c-MIME-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>handler</p>
2021-05-11 02:29:21 +02:00
<p>Specifies a handler for a suffix; the suffix is given by the context as
2022-08-24 15:22:41 +02:00
:mime:.<code>suffix</code>:, and the format of the handler is exactly that in
mailcap. Note in particular the . and trailing colon to distinguish
this use of the context. This overrides any handler specified by the
mailcap files. If the handler requires a terminal, the flags style
should be set to include the word needsterminal, or if the output is to
be displayed through a pager (but not if the handler is itself a pager),
it should include copiousoutput.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-mailcap_002c-MIME-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>mailcap</p>
<p>A list of files in the format of ~/.mailcap and /etc/mailcap to be read
during setup, replacing the default list which consists of those two
files. The context is :mime:. A + in the list will be replaced by the
default files.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-mailcap_002dpriorities_002c-MIME-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>mailcap-priorities</p>
2021-05-11 02:29:21 +02:00
<p>This style is used to resolve multiple mailcap entries for the same MIME
type. It consists of an array of the following elements, in descending
order of priority; later entries will be used if earlier entries are
unable to resolve the entries being compared. If none of the tests
resolve the entries, the first entry encountered is retained.</p>
2022-08-24 15:22:41 +02:00
<p>files<br />
The order of files (entries in the mailcap style) read. Earlier files
are preferred. (Note this does not resolve entries in the same file.)</p>
<p>priority<br />
2021-05-11 02:29:21 +02:00
The priority flag from the mailcap entry. The priority is an integer
from 0 to 9 with the default value being 5.</p>
2022-08-24 15:22:41 +02:00
<p>flags<br />
The test given by the mailcap-prio-flags option is used to resolve
2021-05-11 02:29:21 +02:00
entries.</p>
2022-08-24 15:22:41 +02:00
<p>place<br />
Later entries are preferred; as the entries are strictly ordered, this
test always succeeds.</p>
2021-05-11 02:29:21 +02:00
<p>Note that as this style is handled during initialisation, the context is
2022-08-24 15:22:41 +02:00
always :mime:, with no discrimination by suffix.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-mailcap_002dprio_002dflags_002c-MIME-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>mailcap-prio-flags</p>
<p>This style is used when the keyword flags is encountered in the list of
tests specified by the mailcap-priorities style. It should be set to a
list of patterns, each of which is tested against the flags specified in
the mailcap entry (in other words, the sets of assignments found with
some entries in the mailcap file). Earlier patterns in the list are
preferred to later ones, and matched patterns are preferred to unmatched
ones.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-mime_002dtypes_002c-MIME-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>mime-types</p>
<p>A list of files in the format of ~/.mime.types and /etc/mime.types to
be read during setup, replacing the default list which consists of those
two files. The context is :mime:. A + in the list will be replaced by
the default files.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-never_002dbackground_002c-MIME-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>never-background</p>
2021-05-11 02:29:21 +02:00
<p>If this boolean style is set, the handler for the given context is
always run in the foreground, even if the flags provided in the mailcap
entry suggest it need not be (for example, it doesnt require a
terminal).</p>
<p><span id="index-pager_002c-MIME-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>pager</p>
<p>If set, will be used instead of $PAGER or more to handle suffixes where
the copiousoutput flag is set. The context is as for handler, i.e.
:mime:.<code>suffix</code>: for handling a file with the given <code>suffix</code>.</p>
2021-05-11 02:29:21 +02:00
<p>Examples:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle ':mime:*' mailcap ~/.mailcap /usr/local/etc/mailcap
2021-05-11 02:29:21 +02:00
zstyle ':mime:.txt:' handler less %s
zstyle ':mime:.txt:' flags needsterminal
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>When zsh-mime-setup is subsequently run, it will look for mailcap
entries in the two files given. Files of suffix .txt will be handled by
running less <code>file.txt</code>. The flag needsterminal is set to show that
this program must run attached to a terminal.</p>
2021-05-11 02:29:21 +02:00
<p>As there are several steps to dispatching a command, the following
2022-08-24 15:22:41 +02:00
should be checked if attempting to execute a file by extension .<code>ext</code>
2021-05-11 02:29:21 +02:00
does not have the expected effect.</p>
2022-08-24 15:22:41 +02:00
<p>The command alias -s <code>ext</code> should show ps=zsh-mime-handler. If it
shows something else, another suffix alias was already installed and was
not overwritten. If it shows nothing, no handler was installed: this is
most likely because no handler was found in the .mime.types and mailcap
combination for .ext files. In that case, appropriate handling should be
added to ~/.mime.types and mailcap.</p>
<p>If the extension is handled by zsh-mime-handler but the file is not
2021-05-11 02:29:21 +02:00
opened correctly, either the handler defined for the type is incorrect,
or the flags associated with it are in appropriate. Running
2022-08-24 15:22:41 +02:00
zsh-mime-setup -l will show the handler and, if there are any, the
flags. A %s in the handler is replaced by the file (suitably quoted if
2021-05-11 02:29:21 +02:00
necessary). Check that the handler program listed lists and can be run
2022-08-24 15:22:41 +02:00
in the way shown. Also check that the flags needsterminal or
copiousoutput are set if the handler needs to be run under a terminal;
2021-05-11 02:29:21 +02:00
the second flag is used if the output should be sent to a pager.</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">text/html; /usr/bin/lynx '%s'; needsterminal
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Running zsh-mime-handler -l <code>command line</code> prints the command line
2021-05-11 02:29:21 +02:00
that would be executed, simplified to remove the effect of any flags,
and quoted so that the output can be run as a complete zsh command line.
This is used by the completion system to decide how to complete after a
2022-08-24 15:22:41 +02:00
file handled by zsh-mime-setup.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-pick_002dweb_002dbrowser"></span></p>
2022-08-24 15:22:41 +02:00
<p>pick-web-browser</p>
2021-05-11 02:29:21 +02:00
<p>This function is separate from the two MIME functions described above
and can be assigned directly to a suffix:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">autoload -U pick-web-browser
2021-05-11 02:29:21 +02:00
alias -s html=pick-web-browser
</code></pre>
</div>
<p>It is provided as an intelligent front end to dispatch a web browser. It
may be run as either a function or a shell script. The status 255 is
returned if no browser could be started.</p>
<p>Various styles are available to customize the choice of browsers:</p>
2022-08-24 15:22:41 +02:00
<p>browser-style<br />
2021-05-11 02:29:21 +02:00
The value of the style is an array giving preferences in decreasing
order for the type of browser to use. The values of elements may be</p>
2022-08-24 15:22:41 +02:00
<p>running<br />
Use a GUI browser that is already running when an X Window display is
available. The browsers listed in the x-browsers style are tried in
order until one is found; if it is, the file will be displayed in that
browser, so the user may need to check whether it has appeared. If no
running browser is found, one is not started. Browsers other than
Firefox, Opera and Konqueror are assumed to understand the Mozilla
syntax for opening a URL remotely.</p>
<p>x<br />
Start a new GUI browser when an X Window display is available. Search
for the availability of one of the browsers listed in the x-browsers
style and start the first one that is found. No check is made for an
already running browser.</p>
<p>tty<br />
Start a terminal-based browser. Search for the availability of one of
the browsers listed in the tty-browsers style and start the first one
that is found.</p>
<p>If the style is not set the default running x tty is used.</p>
<p>x-browsers<br />
2021-05-11 02:29:21 +02:00
An array in decreasing order of preference of browsers to use when
running under the X Window System. The array consists of the command
2022-08-24 15:22:41 +02:00
name under which to start the browser. They are looked up in the context
:mime: (which may be extended in future, so appending * is
recommended). For example,</p>
<div class="example">
<pre><code class="language-zsh">zstyle ':mime:*' x-browsers opera konqueror firefox
</code></pre>
</div>
<p>specifies that pick-web-browser should first look for a running instance
of Opera, Konqueror or Firefox, in that order, and if it fails to find
any should attempt to start Opera. The default is firefox mozilla
netscape opera konqueror.</p>
<p>tty-browsers<br />
An array similar to x-browsers, except that it gives browsers to use
when no X Window display is available. The default is elinks links lynx.</p>
<p>command<br />
If it is set this style is used to pick the command used to open a page
for a browser. The context is :mime:browser:new:$browser: to start a new
browser or :mime:browser:running:$browser: to open a URL in a browser
already running on the current X display, where $browser is the value
matched in the x-browsers or tty-browsers style. The escape sequence %b
in the styles value will be replaced by the browser, while %u will be
replaced by the URL. If the style is not set, the default for all new
instances is equivalent to %b %u and the defaults for using running
browsers are equivalent to the values kfmclient openURL %u for
Konqueror, firefox -new-tab %u for Firefox, opera -newpage %u for Opera,
and %b -remote &quot;openUrl(%u)&quot; for all others.</p>
<hr />
<p><span id="Mathematical-Functions"></span> <span
id="Mathematical-Functions-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="2610-mathematical-functions"><a class="header" href="#2610-mathematical-functions">26.10 Mathematical Functions</a></h2>
<p><span id="index-zcalc"></span></p>
2022-08-24 15:22:41 +02:00
<p>zcalc [ -erf ] [ <code>expression</code> ... ]</p>
2021-05-11 02:29:21 +02:00
<p>A reasonably powerful calculator based on zshs arithmetic evaluation
facility. The syntax is similar to that of formulae in most programming
languages; see <a href="Arithmetic-Evaluation.html#Arithmetic-Evaluation">Arithmetic
Evaluation</a> for
details.</p>
<p>Non-programmers should note that, as in many other programming
languages, expressions involving only integers (whether constants
2022-08-24 15:22:41 +02:00
without a ., variables containing such constants as strings, or
2021-05-11 02:29:21 +02:00
variables declared to be integers) are by default evaluated using
integer arithmetic, which is not how an ordinary desk calculator
2022-08-24 15:22:41 +02:00
operates. To force floating point operation, pass the option -f; see
2021-05-11 02:29:21 +02:00
further notes below.</p>
2022-08-24 15:22:41 +02:00
<p>If the file ~/.zcalcrc exists it will be sourced inside the function
2021-05-11 02:29:21 +02:00
once it is set up and about to process the command line. This can be
2022-08-24 15:22:41 +02:00
used, for example, to set shell options; emulate -L zsh and setopt
extendedglob are in effect at this point. Any failure to source the file
if it exists is treated as fatal. As with other initialisation files,
the directory $ZDOTDIR is used instead of $HOME if it is set.</p>
<p>The mathematical library zsh/mathfunc will be loaded if it is available;
see <a href="Zsh-Modules.html#The-zsh_002fmathfunc-Module">The zsh/mathfunc
2021-05-11 02:29:21 +02:00
Module</a>. The mathematical
functions correspond to the raw system libraries, so trigonometric
functions are evaluated using radians, and so on.</p>
<p>Each line typed is evaluated as an expression. The prompt shows a
number, which corresponds to a positional parameter where the result of
that calculation is stored. For example, the result of the calculation
2022-08-24 15:22:41 +02:00
on the line preceded by 4&gt; is available as $4. The last value
calculated is available as ans. Full command line editing, including the
history of previous calculations, is available; the history is saved in
the file ~/.zcalc_history. To exit, enter a blank line or type :q on
its own (q is allowed for historical compatibility).</p>
2021-05-11 02:29:21 +02:00
<p>A line ending with a single backslash is treated in the same fashion as
it is in command line editing: the backslash is removed, the function
2022-08-24 15:22:41 +02:00
prompts for more input (the prompt is preceded by ... to indicate
2021-05-11 02:29:21 +02:00
this), and the lines are combined into one to get the final result. In
addition, if the input so far contains more open than close parentheses
2022-08-24 15:22:41 +02:00
zcalc will prompt for more input.</p>
<p>If arguments are given to zcalc on start up, they are used to prime the
first few positional parameters. A visual indication of this is given
when the calculator starts.</p>
<p>The constants PI (3.14159...) and E (2.71828...) are provided. Parameter
assignment is possible, but note that all parameters will be put into
the global namespace unless the :local special command is used. The
function creates local variables whose names start with _, so users
should avoid doing so. The variables ans (the last answer) and stack
(the stack in RPN mode) may be referred to directly; stack is an array
but elements of it are numeric. Various other special variables are used
locally with their standard meaning, for example compcontext, match,
mbegin, mend, psvar.</p>
<p>The output base can be initialised by passing the option -#<code>base</code>, for
example zcalc -#16 (the # may have to be quoted, depending on the
globbing options set).</p>
<p>If the option -e is set, the function runs non-interactively: the
2021-05-11 02:29:21 +02:00
arguments are treated as expressions to be evaluated as if entered
interactively line by line.</p>
2022-08-24 15:22:41 +02:00
<p>If the option -f is set, all numbers are treated as floating point,
hence for example the expression 3/4 evaluates to 0.75 rather than 0.
Options must appear in separate words.</p>
<p>If the option -r is set, RPN (Reverse Polish Notation) mode is
2021-05-11 02:29:21 +02:00
entered. This has various additional properties:</p>
<p>Stack<br />
Evaluated values are maintained in a stack; this is contained in an
2022-08-24 15:22:41 +02:00
array named stack with the most recent value in ${stack[1]}.</p>
2021-05-11 02:29:21 +02:00
<p>Operators and functions<br />
2022-08-24 15:22:41 +02:00
If the line entered matches an operator (+, -, *, /, **, ^, | or &amp;)
or a function supplied by the zsh/mathfunc library, the bottom element
or elements of the stack are popped to use as the argument or arguments.
The higher elements of stack (least recent) are used as earlier
arguments. The result is then pushed into ${stack[1]}.</p>
2021-05-11 02:29:21 +02:00
<p>Expressions<br />
Other expressions are evaluated normally, printed, and added to the
2022-08-24 15:22:41 +02:00
stack as numeric values. The syntax within expressions on a single line
is normal shell arithmetic (not RPN).</p>
2021-05-11 02:29:21 +02:00
<p>Stack listing<br />
2022-08-24 15:22:41 +02:00
If an integer follows the option -r with no space, then on every
evaluation that many elements of the stack, where available, are printed
instead of just the most recent result. Hence, for example, zcalc -r4
shows $stack[4] to $stack[1] each time results are printed.</p>
<p>Duplication: =<br />
The pseudo-operator = causes the most recent element of the stack to be
duplicated onto the stack.</p>
<p>pop<br />
The pseudo-function pop causes the most recent element of the stack to
be popped. A &gt; on its own has the same effect.</p>
<p>&gt;<code>ident</code><br />
The expression &gt; followed (with no space) by a shell identifier causes
the most recent element of the stack to be popped and assigned to the
variable with that name. The variable is local to the zcalc function.</p>
<p>&lt;<code>ident</code><br />
The expression &lt; followed (with no space) by a shell identifier causes
the value of the variable with that name to be pushed onto the stack.
<code>ident</code> may be an integer, in which case the previous result with that
number (as shown before the &gt; in the standard zcalc prompt) is put on
the stack.</p>
<p>Exchange: xy<br />
The pseudo-function xy causes the most recent two elements of the stack
to be exchanged. &lt;&gt; has the same effect.</p>
<p>The prompt is configurable via the parameter ZCALCPROMPT, which
2021-05-11 02:29:21 +02:00
undergoes standard prompt expansion. The index of the current entry is
2022-08-24 15:22:41 +02:00
stored locally in the first element of the array psvar, which can be
referred to in ZCALCPROMPT as %1v. The default prompt is %1v&gt; .</p>
<p>The variable ZCALC_ACTIVE is set within the function and can be tested
by nested functions; it has the value rpn if RPN mode is active, else 1.</p>
2021-05-11 02:29:21 +02:00
<p>A few special commands are available; these are introduced by a colon.
For backward compatibility, the colon may be omitted for certain
2022-08-24 15:22:41 +02:00
commands. Completion is available if compinit has been run.</p>
2021-05-11 02:29:21 +02:00
<p>The output precision may be specified within zcalc by special commands
familiar from many calculators.</p>
2022-08-24 15:22:41 +02:00
<p>:norm<br />
The default output format. It corresponds to the printf %g
2021-05-11 02:29:21 +02:00
specification. Typically this shows six decimal digits.</p>
2022-08-24 15:22:41 +02:00
<p>:sci <code>digits</code><br />
Scientific notation, corresponding to the printf %g output format with
the precision given by <code>digits</code>. This produces either fixed point or
exponential notation depending on the value output.</p>
<p>:fix <code>digits</code><br />
Fixed point notation, corresponding to the printf %f output format with
the precision given by <code>digits</code>.</p>
<p>:eng <code>digits</code><br />
Exponential notation, corresponding to the printf %E output format with
the precision given by <code>digits</code>.</p>
<p>:raw<br />
2021-05-11 02:29:21 +02:00
Raw output: this is the default form of the output from a math
evaluation. This may show more precision than the number actually
possesses.</p>
<p>Other special commands:</p>
2022-08-24 15:22:41 +02:00
<p>:!<code>line...</code><br />
2021-05-11 02:29:21 +02:00
Execute <code>line...</code> as a normal shell command line. Note that it is
executed in the context of the function, i.e. with local variables.
2022-08-24 15:22:41 +02:00
Space is optional after :!.</p>
<p>:local <code>arg</code> ...<br />
Declare variables local to the function. Other variables may be used,
too, but they will be taken from or put into the global scope.</p>
<p>:function <code>name</code> [ <code>body</code> ]<br />
Define a mathematical function or (with no <code>body</code>) delete it. :function
may be abbreviated to :func or simply :f. The <code>name</code> may contain the
same characters as a shell function name. The function is defined using
zmathfuncdef, see below.</p>
<p>Note that zcalc takes care of all quoting. Hence for example:</p>
<div class="example">
<pre><code class="language-zsh">:f cube $1 * $1 * $1
</code></pre>
</div>
<p>defines a function to cube the sole argument. Functions so defined, or
indeed any functions defined directly or indirectly using functions -M,
are available to execute by typing only the name on the line in RPN
mode; this pops the appropriate number of arguments off the stack to
pass to the function, i.e. 1 in the case of the example cube function.
If there are optional arguments only the mandatory arguments are
supplied by this means.</p>
<p>[#<code>base</code>]<br />
This is not a special command, rather part of normal arithmetic syntax;
however, when this form appears on a line by itself the default output
radix is set to <code>base</code>. Use, for example, [#16] to display
hexadecimal output preceded by an indication of the base, or [##16]
just to display the raw number in the given base. Bases themselves are
always specified in decimal. [#] restores the normal output format.
Note that setting an output base suppresses floating point output; use
[#] to return to normal operation.</p>
<p>$<code>var</code><br />
Print out the value of var literally; does not affect the calculation.
To use the value of var, omit the leading $.</p>
2021-05-11 02:29:21 +02:00
<p>See the comments in the function for a few extra tips.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-max"></span> <span id="index-min"></span> <span
id="index-sum"></span> <span id="index-zmathfunc"></span></p>
<p>min(<code>arg</code>, ...)</p>
<p>max(<code>arg</code>, ...)</p>
<p>sum(<code>arg</code>, ...)</p>
<p>zmathfunc</p>
<p>The function zmathfunc defines the three mathematical functions min,
max, and sum. The functions min and max take one or more arguments. The
function sum takes zero or more arguments. Arguments can be of different
types (ints and floats).</p>
<p>Not to be confused with the zsh/mathfunc module, described in <a href="Zsh-Modules.html#The-zsh_002fmathfunc-Module">The
2021-05-11 02:29:21 +02:00
zsh/mathfunc Module</a>.</p>
<p><span id="index-zmathfuncdef"></span></p>
2022-08-24 15:22:41 +02:00
<p>zmathfuncdef [ <code>mathfunc</code> [ <code>body</code> ] ]</p>
<p>A convenient front end to functions -M.</p>
2021-05-11 02:29:21 +02:00
<p>With two arguments, define a mathematical function named <code>mathfunc</code>
which can be used in any form of arithmetic evaluation. <code>body</code> is a
mathematical expression to implement the function. It may contain
2022-08-24 15:22:41 +02:00
references to position parameters $1, $2, ... to refer to mandatory
parameters and ${1:-<code>defvalue</code>} ... to refer to optional parameters.
2021-05-11 02:29:21 +02:00
Note that the forms must be strictly adhered to for the function to
calculate the correct number of arguments. The implementation is held in
2022-08-24 15:22:41 +02:00
a shell function named zsh_math_func_<code>mathfunc</code>; usually the user will
2021-05-11 02:29:21 +02:00
not need to refer to the shell function directly. Any existing function
of the same name is silently replaced.</p>
<p>With one argument, remove the mathematical function <code>mathfunc</code> as well
as the shell function implementation.</p>
<p>With no arguments, list all <code>mathfunc</code> functions in a form The functions
2022-08-24 15:22:41 +02:00
have not necessarily been defined by zmathfuncdef.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="User-Configuration-Functions"></span> <span
id="User-Configuration-Functions-1"></span></p>
2021-05-11 02:29:21 +02:00
<h2 id="2611-user-configuration-functions"><a class="header" href="#2611-user-configuration-functions">26.11 User Configuration Functions</a></h2>
2022-08-24 15:22:41 +02:00
<p>The zsh/newuser module comes with a function to aid in configuring shell
options for new users. If the module is installed, this function can
also be run by hand. It is available even if the modules default
2021-05-11 02:29:21 +02:00
behaviour, namely running the function for a new user logging in without
startup files, is inhibited.</p>
2022-08-24 15:22:41 +02:00
<p>zsh-newuser-install [ -f ]<br />
2021-05-11 02:29:21 +02:00
The function presents the user with various options for customizing
2022-08-24 15:22:41 +02:00
their initialization scripts. Currently only ~/.zshrc is handled.
$ZDOTDIR/.zshrc is used instead if the parameter ZDOTDIR is set; this
provides a way for the user to configure a file without altering an
existing .zshrc.</p>
<p>By default the function exits immediately if it finds any of the files
.zshenv, .zprofile, .zshrc, or .zlogin in the appropriate directory. The
option -f is required in order to force the function to continue. Note
this may happen even if .zshrc itself does not exist.</p>
<p>As currently configured, the function will exit immediately if the user
has root privileges; this behaviour cannot be overridden.</p>
2021-05-11 02:29:21 +02:00
<p>Once activated, the functions behaviour is supposed to be
2022-08-24 15:22:41 +02:00
self-explanatory. Menus are present allowing the user to alter the value
of options and parameters. Suggestions for improvements are always
welcome.</p>
<p>When the script exits, the user is given the opportunity to save the new
file or not; changes are not irreversible until this point. However, the
script is careful to restrict changes to the file only to a group marked
by the lines # Lines configured by zsh-newuser-install and # End of
lines configured by zsh-newuser-install. In addition, the old version
of .zshrc is saved to a file with the suffix .zni appended.</p>
<p>If the function edits an existing .zshrc, it is up to the user to ensure
that the changes made will take effect. For example, if control usually
returns early from the existing .zshrc the lines will not be executed;
or a later initialization file may override options or parameters, and
so on. The function itself does not attempt to detect any such
conflicts.</p>
2021-05-11 02:29:21 +02:00
<hr />
<p><span id="Other-Functions"></span> <span id="Other-Functions-1"></span></p>
<h2 id="2612-other-functions"><a class="header" href="#2612-other-functions">26.12 Other Functions</a></h2>
2022-08-24 15:22:41 +02:00
<p>There are a large number of helpful functions in the Functions/Misc
2021-05-11 02:29:21 +02:00
directory of the zsh distribution. Most are very simple and do not
require documentation here, but a few are worthy of special mention.</p>
<hr />
<p><span id="Descriptions"></span></p>
<h3 id="26121-descriptions"><a class="header" href="#26121-descriptions">26.12.1 Descriptions</a></h3>
<p><span id="index-colors"></span></p>
2022-08-24 15:22:41 +02:00
<p>colors</p>
2021-05-11 02:29:21 +02:00
<p>This function initializes several associative arrays to map color names
to (and from) the ANSI standard eight-color terminal codes. These are
used by the prompt theme system (<a href="User-Contributions.html#Prompt-Themes">Prompt Themes</a>). You
2022-08-24 15:22:41 +02:00
seldom should need to run colors more than once.</p>
<p>The eight base colors are: black, red, green, yellow, blue, magenta,
cyan, and white. Each of these has codes for foreground and background.
In addition there are seven intensity attributes: bold, faint, standout,
underline, blink, reverse, and conceal. Finally, there are seven codes
used to negate attributes: none (reset all attributes to the defaults),
normal (neither bold nor faint), no-standout, no-underline, no-blink,
no-reverse, and no-conceal.</p>
2021-05-11 02:29:21 +02:00
<p>Some terminals do not support all combinations of colors and
intensities.</p>
<p>The associative arrays are:</p>
2022-08-24 15:22:41 +02:00
<p>color<br />
colour<br />
Map all the color names to their integer codes, and integer codes to the
color names. The eight base names map to the foreground color codes, as
do names prefixed with fg-, such as fg-red. Names prefixed with
bg-, such as bg-blue, refer to the background codes. The reverse
mapping from code to color yields base name for foreground codes and the
bg- form for backgrounds.</p>
<p>Although it is a misnomer to call them colors, these arrays also map
the other fourteen attributes from names to codes and codes to names.</p>
<p>fg<br />
fg_bold<br />
fg_no_bold<br />
Map the eight basic color names to ANSI terminal escape sequences that
set the corresponding foreground text properties. The fg sequences
2021-05-11 02:29:21 +02:00
change the color without changing the eight intensity attributes.</p>
2022-08-24 15:22:41 +02:00
<p>bg<br />
bg_bold<br />
bg_no_bold<br />
Map the eight basic color names to ANSI terminal escape sequences that
set the corresponding background properties. The bg sequences change the
color without changing the eight intensity attributes.</p>
<p>In addition, the scalar parameters reset_color and bold_color are set to
the ANSI terminal escapes that turn off all attributes and turn on bold
intensity, respectively.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-fned"></span></p>
2022-08-24 15:22:41 +02:00
<p>fned [ -x <code>num</code> ] <code>name</code></p>
<p>Same as zed -f. This function does not appear in the zsh distribution,
but can be created by linking zed to the name fned in some directory in
your fpath.</p>
<p><span id="index-histed"></span></p>
<p>histed [ [ <code>name</code> ] <code>size</code> ]</p>
<p>Same as zed -h. This function does not appear in the zsh distribution,
but can be created by linking zed to the name histed in some directory
in your fpath.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-is_002dat_002dleast"></span></p>
2022-08-24 15:22:41 +02:00
<p>is-at-least <code>needed</code> [ <code>present</code> ]</p>
2021-05-11 02:29:21 +02:00
<p>Perform a greater-than-or-equal-to comparison of two strings having the
format of a zsh version number; that is, a string of numbers and text
with segments separated by dots or dashes. If the <code>present</code> string is
2022-08-24 15:22:41 +02:00
not provided, $ZSH_VERSION is used. Segments are paired left-to-right in
the two strings with leading non-number parts ignored. If one string has
fewer segments than the other, the missing segments are considered zero.</p>
2021-05-11 02:29:21 +02:00
<p>This is useful in startup files to set options and other state that are
not available in all versions of zsh.</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">is-at-least 3.1.6-15 &amp;&amp; setopt NO_GLOBAL_RCS
2021-05-11 02:29:21 +02:00
is-at-least 3.1.0 &amp;&amp; setopt HIST_REDUCE_BLANKS
is-at-least 2.6-17 || print &quot;You can't use is-at-least here.&quot;
</code></pre>
</div>
<p><span id="index-nslookup"></span></p>
2022-08-24 15:22:41 +02:00
<p>nslookup [ <code>arg</code> ... ]</p>
<p>This wrapper function for the nslookup command requires the zsh/zpty
2021-05-11 02:29:21 +02:00
module (see <a href="Zsh-Modules.html#The-zsh_002fzpty-Module">The zsh/zpty
Module</a>). It behaves exactly
2022-08-24 15:22:41 +02:00
like the standard nslookup except that it provides customizable prompts
(including a right-side prompt) and completion of nslookup commands,
host names, etc. (if you use the function-based completion system).
Completion styles may be set with the context prefix
:completion:nslookup.</p>
<p>See also the pager, prompt and rprompt styles below.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-regexp_002dreplace"></span></p>
2022-08-24 15:22:41 +02:00
<p>regexp-replace <code>var</code> <code>regexp</code> <code>replace</code></p>
2021-05-11 02:29:21 +02:00
<p>Use regular expressions to perform a global search and replace operation
2022-08-24 15:22:41 +02:00
on a variable. POSIX extended regular expressions (ERE) are used, unless
the option RE_MATCH_PCRE has been set, in which case Perl-compatible
2021-05-11 02:29:21 +02:00
regular expressions are used (this requires the shell to be linked
2022-08-24 15:22:41 +02:00
against the pcre library).</p>
2021-05-11 02:29:21 +02:00
<p><code>var</code> is the name of the variable containing the string to be matched.
The variable will be modified directly by the function. The variables
2022-08-24 15:22:41 +02:00
MATCH, MBEGIN, MEND, match, mbegin, mend should be avoided as these are
used by the regular expression code.</p>
2021-05-11 02:29:21 +02:00
<p><code>regexp</code> is the regular expression to match against the string.</p>
<p><code>replace</code> is the replacement text. This can contain parameter, command
and arithmetic expressions which will be replaced: in particular, a
2022-08-24 15:22:41 +02:00
reference to $MATCH will be replaced by the text matched by the pattern.</p>
2021-05-11 02:29:21 +02:00
<p>The return status is 0 if at least one match was performed, else 1.</p>
2022-08-24 15:22:41 +02:00
<p>Note that if using POSIX EREs, the ^ or word boundary operators (where
available) may not work properly.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-run_002dhelp-1"></span></p>
2022-08-24 15:22:41 +02:00
<p>run-help <code>cmd</code></p>
<p>This function is designed to be invoked by the run-help ZLE widget, in
2021-05-11 02:29:21 +02:00
place of the default alias. See Accessing On-Line Help
(<a href="User-Contributions.html#Utilities">Utilities</a>) for setup instructions.</p>
<p>In the discussion which follows, if <code>cmd</code> is a file system path, it is
first reduced to its rightmost component (the file name).</p>
<p>Help is first sought by looking for a file named <code>cmd</code> in the directory
2022-08-24 15:22:41 +02:00
named by the HELPDIR parameter. If no file is found, an assistant
function, alias, or command named run-help-<code>cmd</code> is sought. If found,
2021-05-11 02:29:21 +02:00
the assistant is executed with the rest of the current command line
(everything after the command name <code>cmd</code>) as its arguments. When neither
2022-08-24 15:22:41 +02:00
file nor assistant is found, the external command man <code>cmd</code> is run.</p>
2021-05-11 02:29:21 +02:00
<p>An example assistant for the &quot;ssh&quot; command:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">run-help-ssh() {
2021-05-11 02:29:21 +02:00
emulate -LR zsh
local -a args
# Delete the &quot;-l username&quot; option
zparseopts -D -E -a args l:
# Delete other options, leaving: host command
args=(${@:#-*})
if [[ ${#args} -lt 2 ]]; then
man ssh
else
run-help $args[2]
fi
}
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>Several of these assistants are provided in the Functions/Misc your
search path, in order to be found and used by run-help.</p>
<p><span id="index-run_002dhelp_002dbtrfs"></span> <span
id="index-run_002dhelp_002dgit"></span> <span
id="index-run_002dhelp_002dip"></span> <span
id="index-run_002dhelp_002dopenssl"></span> <span
id="index-run_002dhelp_002dp4"></span> <span
id="index-run_002dhelp_002dsudo"></span> <span
id="index-run_002dhelp_002dsvk"></span> <span
id="index-run_002dhelp_002dsvn"></span></p>
<p>run-help-btrfs</p>
2021-05-11 02:29:21 +02:00
<p>run-help-git</p>
<p>run-help-ip</p>
<p>run-help-openssl</p>
<p>run-help-p4</p>
<p>run-help-sudo</p>
<p>run-help-svk</p>
2022-08-24 15:22:41 +02:00
<p>run-help-svn</p>
<p>Assistant functions for the btrfs, git, ip, openssl, p4, sudo, svk, and
svn, commands.</p>
<p>tetris</p>
2021-05-11 02:29:21 +02:00
<p>Zsh was once accused of not being as complete as Emacs, because it
lacked a Tetris game. This function was written to refute this vicious
slander.</p>
<p>This function must be used as a ZLE widget:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">autoload -U tetris
2021-05-11 02:29:21 +02:00
zle -N tetris
bindkey keys tetris
</code></pre>
</div>
<p>To start a game, execute the widget by typing the <code>keys</code>. Whatever
command line you were editing disappears temporarily, and your keymap is
also temporarily replaced by the Tetris control keys. The previous
2022-08-24 15:22:41 +02:00
editor state is restored when you quit the game (by pressing q) or
2021-05-11 02:29:21 +02:00
when you lose.</p>
2022-08-24 15:22:41 +02:00
<p>If you quit in the middle of a game, the next invocation of the tetris
2021-05-11 02:29:21 +02:00
widget will continue where you left off. If you lost, it will start a
new game.</p>
2022-08-24 15:22:41 +02:00
<p>tetriscurses</p>
2021-05-11 02:29:21 +02:00
<p>This is a port of the above to zcurses. The input handling is improved a
bit so that moving a block sideways doesnt automatically advance a
timestep, and the graphics use unicode block graphics.</p>
<p>This version does not save the game state between invocations, and is
not invoked as a widget, but rather as:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">autoload -U tetriscurses
2021-05-11 02:29:21 +02:00
tetriscurses
</code></pre>
</div>
<p><span id="index-zargs"></span></p>
2022-08-24 15:22:41 +02:00
<p>zargs [ <code>option</code> ... -- ] [ <code>input</code> ... ] [ -- <code>command</code> [ <code>arg</code>
... ] ]</p>
2021-05-11 02:29:21 +02:00
<p>This function has a similar purpose to GNU xargs. Instead of reading
lines of arguments from the standard input, it takes them from the
command line. This is useful because zsh, especially with recursive glob
operators, often can construct a command line for a shell function that
is longer than can be accepted by an external command.</p>
2022-08-24 15:22:41 +02:00
<p>The <code>option</code> list represents options of the zargs command itself, which
are the same as those of xargs. The <code>input</code> list is the collection of
strings (often file names) that become the arguments of the command,
analogous to the standard input of xargs. Finally, the <code>arg</code> list
consists of those arguments (usually options) that are passed to the
<code>command</code> each time it runs. The <code>arg</code> list precedes the elements from
the input list in each run. If no <code>command</code> is provided, then no <code>arg</code>
list may be provided, and in that event the default command is print
with arguments -r --.</p>
<p>For example, to get a long ls listing of all non-hidden plain files in
2021-05-11 02:29:21 +02:00
the current directory or its subdirectories:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">autoload -U zargs
2021-05-11 02:29:21 +02:00
zargs -- **/*(.) -- ls -ld --
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>The first and third occurrences of -- are used to mark the end of
options for zargs and ls respectively to guard against filenames
starting with -, while the second is used to separate the list of
files from the command to run (ls -ld ).</p>
<p>The first -- would also be needed if there was a chance the list might
be empty as in:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zargs -r -- ./*.back(#qN) -- rm -f
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>In the event that the string -- is or may be an <code>input</code>, the -e option
may be used to change the end-of-inputs marker. Note that this does
<em>not</em> change the end-of-options marker. For example, to use .. as the
marker:</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zargs -e.. -- **/*(.) .. ls -ld --
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>This is a good choice in that example because no plain file can be named
2022-08-24 15:22:41 +02:00
.., but the best end-marker depends on the circumstances.</p>
<p>The options -i, -I, -l, -L, and -n differ slightly from their usage in
xargs. There are no input lines for zargs to count, so -l and -L count
through the <code>input</code> list, and -n counts the number of arguments passed
to each execution of <code>command</code>, <em>including</em> any <code>arg</code> list. Also, any
time -i or -I is used, each <code>input</code> is processed separately as if by -L
1.</p>
<p>For details of the other zargs options, see the xargs(1) man page (but
note the difference in function between zargs and xargs) or run zargs
with the --help option.</p>
2021-05-11 02:29:21 +02:00
<p><span id="index-zed"></span></p>
2022-08-24 15:22:41 +02:00
<p>zed [ -f [ -x <code>num</code> ] ] <code>name</code></p>
<p>zed [ -h [ <code>name</code> ] <code>size</code> ]</p>
<p>zed -b</p>
2021-05-11 02:29:21 +02:00
<p>This function uses the ZLE editor to edit a file or function.</p>
2022-08-24 15:22:41 +02:00
<p>Only one <code>name</code> argument is allowed. If the -f option is given, the name
is taken to be that of a function; if the function is marked for
autoloading, zed searches for it in the fpath and loads it. Note that
functions edited this way are installed into the current shell, but
<em>not</em> written back to the autoload file. In this case the -x option
2021-05-11 02:29:21 +02:00
specifies that leading tabs indenting the function according to syntax
2022-08-24 15:22:41 +02:00
should be converted into the given number of spaces; -x 2 is
2021-05-11 02:29:21 +02:00
consistent with the layout of functions distributed with the shell.</p>
2022-08-24 15:22:41 +02:00
<p>Without -f, <code>name</code> is the path name of the file to edit, which need not
exist; it is created on write, if necessary. With -h, the file is
presumed to contain history events.</p>
<p>When no file name is provided for -h the current shell history is edited
in place. The history is renumbered when zed exits successfully.</p>
<p>When editing history, multi-line events must have a trailing backslash
on every line before the last.</p>
<p>While editing, the function sets the main keymap to zed and the vi
command keymap to zed-vicmd. These will be copied from the existing main
and vicmd keymaps if they do not exist the first time zed is run. They
can be used to provide special key bindings used only in zed.</p>
<p>If it creates the keymap, zed rebinds the return key to insert a line
break and ^X^W to accept the edit in the zed keymap, and binds ZZ to
accept the edit in the zed-vicmd keymap.</p>
<p>The bindings alone can be installed by running zed -b. This is this
will overwrite the existing zed and zed-vicmd keymaps.</p>
2021-05-11 02:29:21 +02:00
<p>Completion is available, and styles may be set with the context prefix
2022-08-24 15:22:41 +02:00
:completion:zed:.</p>
<p><span id="index-zed_002dset_002dfile_002dname"></span></p>
<p>A zle widget zed-set-file-name is available. This can be called by name
from within zed using \ex zed-set-file-name or can be bound to a key
in either of the zed or zed-vicmd keymaps after zed -b has been run.
When the widget is called, it prompts for a new name for the file being
edited. When zed exits the file will be written under that name and the
original file will be left alone. The widget has no effect when invoked
from zed -f. The completion context is changed to
:completion:zed-set-file-name:. When editing the current history with
zed -h, the history is first updated and then the file is written, but
the global setting of HISTFILE is not altered.</p>
<p>While zed-set-file-name is running, zed uses the keymap
zed-normal-keymap, which is linked from the main keymap in effect at the
time zed initialised its bindings. (This is to make the return key
2021-05-11 02:29:21 +02:00
operate normally.) The result is that if the main keymap has been
changed, the widget wont notice. This is not a concern for most users.</p>
<p><span id="index-zcp"></span> <span id="index-zln"></span></p>
2022-08-24 15:22:41 +02:00
<p>zcp [ -finqQvwW ] <code>srcpat</code> <code>dest</code></p>
<p>zln [ -finqQsvwW ] <code>srcpat</code> <code>dest</code></p>
<p>Same as zmv -C and zmv -L, respectively. These functions do not appear
in the zsh distribution, but can be created by linking zmv to the names
zcp and zln in some directory in your fpath.</p>
<p>zkbd</p>
2021-05-11 02:29:21 +02:00
<p>See Keyboard Definition (<a href="User-Contributions.html#Utilities">Utilities</a>).</p>
<p><span id="index-zmv"></span></p>
2022-08-24 15:22:41 +02:00
<p>zmv [ -finqQsvwW ] [ -C | -L | -M | -{p|P} <code>program</code> ] [ -o
<code>optstring</code> ]</p>
<p>    <code>srcpat</code> <code>dest</code></p>
2021-05-11 02:29:21 +02:00
<p>Move (usually, rename) files matching the pattern <code>srcpat</code> to
corresponding files having names of the form given by <code>dest</code>, where
<code>srcpat</code> contains parentheses surrounding patterns which will be
2022-08-24 15:22:41 +02:00
replaced in turn by $1, $2, ... in <code>dest</code>. For example,</p>
2021-05-11 02:29:21 +02:00
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zmv '(*).lis' '$1.txt'
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>renames foo.lis to foo.txt, my.old.stuff.lis to
my.old.stuff.txt, and so on.</p>
<p>The pattern is always treated as an EXTENDED_GLOB pattern. Any file
2021-05-11 02:29:21 +02:00
whose name is not changed by the substitution is simply ignored. Any
error (a substitution resulted in an empty string, two substitutions
gave the same result, the destination was an existing regular file and
2022-08-24 15:22:41 +02:00
-f was not given) causes the entire function to abort without doing
2021-05-11 02:29:21 +02:00
anything.</p>
2022-08-24 15:22:41 +02:00
<p>In addition to pattern replacement, the variable $f can be referred to
in the second (replacement) argument. This makes it possible to use
2021-05-11 02:29:21 +02:00
variable substitution to alter the argument; see examples below.</p>
<p>Options:</p>
2022-08-24 15:22:41 +02:00
<p>-f<br />
Force overwriting of destination files. Not currently passed down to the
mv/cp/ln command due to vagaries of implementations (but you can use
-o-f to do that).</p>
<p>-i<br />
Interactive: show each line to be executed and ask the user whether to
execute it. Y or y will execute it, anything else will skip it. Note
that you just need to type one character.</p>
<p>-n<br />
2021-05-11 02:29:21 +02:00
No execution: print what would happen, but dont do it.</p>
2022-08-24 15:22:41 +02:00
<p>-q<br />
Turn bare glob qualifiers off: now assumed by default, so this has no
effect.</p>
<p>-Q<br />
2021-05-11 02:29:21 +02:00
Force bare glob qualifiers on. Dont turn this on unless you are
actually using glob qualifiers in a pattern.</p>
2022-08-24 15:22:41 +02:00
<p>-s<br />
Symbolic, passed down to ln; only works with -L.</p>
<p>-v<br />
2021-05-11 02:29:21 +02:00
Verbose: print each command as its being executed.</p>
2022-08-24 15:22:41 +02:00
<p>-w<br />
2021-05-11 02:29:21 +02:00
Pick out wildcard parts of the pattern, as described above, and
implicitly add parentheses for referring to them.</p>
2022-08-24 15:22:41 +02:00
<p>-W<br />
Just like -w, with the addition of turning wildcards in the replacement
pattern into sequential ${1} .. ${N} references.</p>
<p>-C<br />
-L<br />
-M<br />
Force cp, ln or mv, respectively, regardless of the name of the
function.</p>
<p>-p <code>program</code><br />
Call <code>program</code> instead of cp, ln or mv. Whatever it does, it should at
least understand the form</p>
<div class="example">
<pre><code class="language-zsh">program -- oldname newname
</code></pre>
</div>
<p>where <code>oldname</code> and <code>newname</code> are filenames generated by zmv. <code>program</code>
will be split into words, so might be e.g. the name of an archive tool
plus a copy or rename subcommand.</p>
<p>-P <code>program</code><br />
As -p <code>program</code>, except that <code>program</code> does not accept a following -- to
indicate the end of options. In this case filenames must already be in a
sane form for the program in question.</p>
<p>-o <code>optstring</code><br />
The <code>optstring</code> is split into words and passed down verbatim to the cp,
ln or mv command called to perform the work. It should probably begin
with a -.</p>
2021-05-11 02:29:21 +02:00
<p>Further examples:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zmv -v '(* *)' '${1// /_}'
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
<p>For any file in the current directory with at least one space in the
name, replace every space by an underscore and display the commands
executed.</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zmv -v '* *' '${f// /_}'
2021-05-11 02:29:21 +02:00
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>This does exactly the same by referring to the file name stored in $f.</p>
<p>For more complete examples and other implementation details, see the zmv
source file, usually located in one of the directories named in your
fpath, or in Functions/Misc/zmv in the zsh distribution.</p>
<p>zrecompile</p>
2021-05-11 02:29:21 +02:00
<p>See Recompiling Functions (<a href="User-Contributions.html#Utilities">Utilities</a>).</p>
<p><span id="index-zstyle_002b"></span></p>
2022-08-24 15:22:41 +02:00
<p>zstyle+ <code>context</code> <code>style</code> <code>value</code> [ + <code>subcontext</code> <code>style</code> <code>value</code> ...
]</p>
<p>This makes defining styles a bit simpler by using a single + as a
2021-05-11 02:29:21 +02:00
special token that allows you to append a context name to the previously
used context name. Like this:</p>
<div class="example">
2022-08-24 15:22:41 +02:00
<pre><code class="language-zsh">zstyle+ ':foo:bar' style1 value1 \
2021-05-11 02:29:21 +02:00
+':baz' style2 value2 \
+':frob' style3 value3
</code></pre>
</div>
2022-08-24 15:22:41 +02:00
<p>This defines <code>style1</code> with <code>value1</code> for the context :foo:bar as usual,
but it also defines <code>style2</code> with <code>value2</code> for the context :foo:bar:baz
and <code>style3</code> with <code>value3</code> for :foo:bar:frob. Any <code>subcontext</code> may be
the empty string to re-use the first context unchanged.</p>
2021-05-11 02:29:21 +02:00
<hr />
2022-08-24 15:22:41 +02:00
<p><span id="Styles"></span></p>
2021-05-11 02:29:21 +02:00
<h3 id="26122-styles"><a class="header" href="#26122-styles">26.12.2 Styles</a></h3>
<p><span id="index-insert_002dtab_002c-completion-style-1"></span></p>
2022-08-24 15:22:41 +02:00
<p>insert-tab</p>
<p>The zed function <em>sets</em> this style in context :completion:zed:* to
turn off completion when TAB is typed at the beginning of a line. You
2021-05-11 02:29:21 +02:00
may override this by setting your own value for this context and style.</p>
<p><span id="index-pager_002c-nslookup-style"></span></p>
2022-08-24 15:22:41 +02:00
<p>pager</p>
<p>The nslookup function looks up this style in the context :nslookup to
determine the program used to display output that does not fit on a
2021-05-11 02:29:21 +02:00
single screen.</p>
2022-08-24 15:22:41 +02:00
<p><span id="index-prompt_002c-nslookup-style"></span> <span
id="index-rprompt_002c-nslookup-style"></span></p>
<p>prompt</p>
<p>rprompt</p>
<p>The nslookup function looks up this style in the context :nslookup to
set the prompt and the right-side prompt, respectively. The usual
expansions for the PS1 and RPS1 parameters may be used (see <a href="Prompt-Expansion.html#Prompt-Expansion">Prompt
2021-05-11 02:29:21 +02:00
Expansion</a>).</p>
<hr />
2022-08-24 15:22:41 +02:00
<p>This document was generated on <em>May 14, 2022</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html
5.0</em></a>.<br />
Zsh version 5.9, released on May 14, 2022.</p>
2021-05-11 02:29:21 +02:00
</main>
<nav class="nav-wrapper" aria-label="Page navigation">
<!-- Mobile navigation buttons -->
<div style="clear: both"></div>
</nav>
</div>
</div>
<nav class="nav-wide-wrapper" aria-label="Page navigation">
</nav>
</div>
2022-09-01 07:20:37 +02:00
<!-- Livereload script (if served using the cli tool) -->
<script type="text/javascript">
const wsProtocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsAddress = wsProtocol + "//" + location.host + "/" + "__livereload";
const socket = new WebSocket(wsAddress);
socket.onmessage = function (event) {
if (event.data === "reload") {
socket.close();
location.reload();
}
};
window.onbeforeunload = function() {
socket.close();
}
</script>
2021-05-11 02:29:21 +02:00
<script type="text/javascript">
window.playground_copyable = true;
</script>
<script src="elasticlunr.min.js" type="text/javascript" charset="utf-8"></script>
<script src="mark.min.js" type="text/javascript" charset="utf-8"></script>
<script src="searcher.js" type="text/javascript" charset="utf-8"></script>
<script src="clipboard.min.js" type="text/javascript" charset="utf-8"></script>
<script src="highlight.js" type="text/javascript" charset="utf-8"></script>
<script src="book.js" type="text/javascript" charset="utf-8"></script>
<!-- Custom JS scripts -->
<script type="text/javascript">
window.addEventListener('load', function() {
window.setTimeout(window.print, 100);
});
</script>
</body>
</html>