754 lines
34 KiB
HTML
754 lines
34 KiB
HTML
<!DOCTYPE HTML>
|
||
<html lang="en" class="sidebar-visible no-js light">
|
||
<head>
|
||
<!-- Book generated using mdBook -->
|
||
<meta charset="UTF-8">
|
||
<title>Prompt Expansion - Zsh Manual</title>
|
||
|
||
|
||
|
||
|
||
<!-- 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 -->
|
||
|
||
|
||
|
||
</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">
|
||
<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-_0026-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" class="active"><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>
|
||
</div>
|
||
<div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
|
||
</nav>
|
||
|
||
<div id="page-wrapper" class="page-wrapper">
|
||
|
||
<div class="page">
|
||
|
||
<div id="menu-bar-hover-placeholder"></div>
|
||
<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>
|
||
</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>
|
||
|
||
|
||
|
||
|
||
</div>
|
||
</div>
|
||
|
||
|
||
<div id="search-wrapper" class="hidden">
|
||
<form id="searchbar-outer" class="searchbar-outer">
|
||
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
|
||
</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="#13-prompt-expansion">13 Prompt Expansion</a>
|
||
<ul>
|
||
<li><a href="#131-expansion-of-prompt-sequences">13.1 Expansion of Prompt Sequences</a></li>
|
||
<li><a href="#132-simple-prompt-escapes">13.2 Simple Prompt Escapes</a>
|
||
<ul>
|
||
<li><a href="#1321-special-characters">13.2.1 Special characters</a></li>
|
||
<li><a href="#1322-login-information">13.2.2 Login information</a></li>
|
||
<li><a href="#1323-shell-state">13.2.3 Shell state</a></li>
|
||
<li><a href="#1324-date-and-time">13.2.4 Date and time</a></li>
|
||
<li><a href="#1325-visual-effects">13.2.5 Visual effects</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a href="#133-conditional-substrings-in-prompts">13.3 Conditional Substrings in Prompts</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
||
<p><span id="Prompt-Expansion"></span>
|
||
<span id="Prompt-Expansion-1"></span></p>
|
||
<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>
|
||
<p><span id="index-prompt-expansion"></span>
|
||
<span id="index-expansion_002c-prompt"></span></p>
|
||
<p>Prompt sequences undergo a special form of expansion. This type of
|
||
expansion is also available using the <code>-P</code> option to the <code>print</code>
|
||
builtin.</p>
|
||
<p><span id="index-PROMPT_005fSUBST_002c-use-of"></span></p>
|
||
<p>If the <code>PROMPT_SUBST</code> 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>
|
||
<p>Certain escape sequences may be recognised in the prompt string.</p>
|
||
<p><span id="index-PROMPT_005fBANG_002c-use-of"></span></p>
|
||
<p>If the <code>PROMPT_BANG</code> option is set, a ‘<code>!</code>’ in the prompt is replaced by
|
||
the current history event number. A literal ‘<code>!</code>’ may then be
|
||
represented as ‘<code>!!</code>’.</p>
|
||
<p><span id="index-PROMPT_005fPERCENT_002c-use-of"></span></p>
|
||
<p>If the <code>PROMPT_PERCENT</code> option is set, certain escape sequences that
|
||
start with ‘<code>%</code>’ are expanded. Many escapes are followed by a single
|
||
character, although some of these take an optional integer argument that
|
||
should appear between the ‘<code>%</code>’ and the next character of the sequence.
|
||
More complicated escape sequences are available to provide conditional
|
||
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>
|
||
<ul>
|
||
<li>
|
||
<p><code>%%</code><br />
|
||
A ‘<code>%</code>’.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%)</code><br />
|
||
A ‘<code>)</code>’.</p>
|
||
</li>
|
||
</ul>
|
||
<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>
|
||
<ul>
|
||
<li>
|
||
<p><code>%l</code><br />
|
||
The line (tty) the user is logged in on, without ‘<code>/dev/</code>’ prefix.
|
||
If the name starts with ‘<code>/dev/tty</code>’, that prefix is stripped.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%M</code><br />
|
||
The full machine hostname.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%m</code><br />
|
||
The hostname up to the first ‘<code>.</code>’. An integer may follow the ‘<code>%</code>’
|
||
to specify how many components of the hostname are desired. With a
|
||
negative integer, trailing components of the hostname are shown.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%n</code><br />
|
||
<code>$USERNAME</code>.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%y</code><br />
|
||
The line (tty) the user is logged in on, without ‘<code>/dev/</code>’ prefix.
|
||
This does not treat ‘<code>/dev/tty</code>’ names specially.</p>
|
||
</li>
|
||
</ul>
|
||
<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>
|
||
<ul>
|
||
<li>
|
||
<p><code>%#</code><br />
|
||
A ‘<code>#</code>’ if the shell is running with privileges, a ‘<code>%</code>’ if not.
|
||
Equivalent to ‘<code>%(!.#.%%)</code>’. 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>
|
||
</li>
|
||
<li>
|
||
<p><code>%?</code><br />
|
||
The return status of the last command executed just before the
|
||
prompt.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%_</code><br />
|
||
The status of the parser, i.e. the shell constructs (like ‘<code>if</code>’ and
|
||
‘<code>for</code>’) 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 <code>PS2</code> for continuation lines and <code>PS4</code> for debugging with
|
||
the <code>XTRACE</code> option; in the latter case it will also work
|
||
non-interactively.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%^</code><br />
|
||
The status of the parser in reverse. This is the same as ‘<code>%_</code>’
|
||
other than the order of strings. It is often used in <code>RPS2</code>.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%d</code><br />
|
||
<code>%/</code><br />
|
||
Current working directory. If an integer follows the ‘<code>%</code>’, 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. <code>%-1d</code> specifies the first
|
||
component.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%~</code><br />
|
||
As <code>%d</code> and <code>%/</code>, but if the current working directory starts with
|
||
<code>$HOME</code>, that part is replaced by a ‘<code>~</code>’. Furthermore, if it has a
|
||
named directory as its prefix, that part is replaced by a ‘<code>~</code>’
|
||
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>
|
||
</li>
|
||
<li>
|
||
<p><code>%e</code><br />
|
||
Evaluation depth of the current sourced file, shell function, or
|
||
<code>eval</code>. This is incremented or decremented every time the value of
|
||
<code>%N</code> is set or reverted to a previous value, respectively. This is
|
||
most useful for debugging as part of <code>$PS4</code>.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%h</code><br />
|
||
<code>%!</code><br />
|
||
Current history event number.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%i</code><br />
|
||
The line number currently being executed in the script, sourced
|
||
file, or shell function given by <code>%N</code>. This is most useful for
|
||
debugging as part of <code>$PS4</code>.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%I</code><br />
|
||
The line number currently being executed in the file <code>%x</code>. This is
|
||
similar to <code>%i</code>, 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>
|
||
</li>
|
||
<li>
|
||
<p><code>%j</code><br />
|
||
The number of jobs.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%L</code><br />
|
||
The current value of <code>$SHLVL</code>.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%N</code><br />
|
||
The name of the script, sourced file, or shell function that zsh is
|
||
currently executing, whichever was started most recently. If there
|
||
is none, this is equivalent to the parameter <code>$0</code>. An integer may
|
||
follow the ‘<code>%</code>’ to specify a number of trailing path components to
|
||
show; zero means the full path. A negative integer specifies leading
|
||
components.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%x</code><br />
|
||
The name of the file containing the source code currently being
|
||
executed. This behaves as <code>%N</code> except that function and eval command
|
||
names are not shown, instead the file where they were defined.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%c</code><br />
|
||
<code>%.</code><br />
|
||
<code>%C</code><br />
|
||
Trailing component of the current working directory. An integer may
|
||
follow the ‘<code>%</code>’ to get more than one component. Unless ‘<code>%C</code>’ is
|
||
used, tilde contraction is performed first. These are deprecated as
|
||
<code>%c</code> and <code>%C</code> are equivalent to <code>%1~</code> and <code>%1/</code>, respectively, while
|
||
explicit positive integers have the same effect as for the latter
|
||
two sequences.</p>
|
||
</li>
|
||
</ul>
|
||
<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>
|
||
<ul>
|
||
<li>
|
||
<p><code>%D</code><br />
|
||
The date in <code>yy``-``mm``-``dd</code> format.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%T</code><br />
|
||
Current time of day, in 24-hour format.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%t</code><br />
|
||
<code>%@</code><br />
|
||
Current time of day, in 12-hour, am/pm format.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%*</code><br />
|
||
Current time of day in 24-hour format, with seconds.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%w</code><br />
|
||
The date in <code>day``-``dd</code> format.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%W</code><br />
|
||
The date in <code>mm``/``dd``/``yy</code> format.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%D{``string``}</code><br />
|
||
<code>string</code> is formatted using the <code>strftime</code> function. See man page
|
||
strftime(3) for more details. Various zsh extensions provide numbers
|
||
with no leading zero or space if the number is a single digit:</p>
|
||
<ul>
|
||
<li>
|
||
<p><code>%f</code><br />
|
||
a day of the month</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%K</code><br />
|
||
the hour of the day on the 24-hour clock</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%L</code><br />
|
||
the hour of the day on the 12-hour clock</p>
|
||
</li>
|
||
</ul>
|
||
<p>In addition, if the system supports the POSIX <code>gettimeofday</code> system
|
||
call, <code>%.</code> 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 <code>%</code>; hence
|
||
<code>%6.</code> outputs microseconds, and <code>%9.</code> outputs nanoseconds. (The
|
||
latter requires a nanosecond-precision <code>clock_gettime</code>; systems
|
||
lacking this will return a value multiplied by the appropriate power
|
||
of 10.) A typical example of this is the format ‘<code>%D{%H:%M:%S.%.}</code>’.</p>
|
||
<p>The GNU extension <code>%N</code> is handled as a synonym for <code>%9.</code>.</p>
|
||
<p>Additionally, the GNU extension that a ‘<code>-</code>’ between the <code>%</code> and the
|
||
format character causes a leading zero or space to be stripped is
|
||
handled directly by the shell for the format characters <code>d</code>, <code>f</code>,
|
||
<code>H</code>, <code>k</code>, <code>l</code>, <code>m</code>, <code>M</code>, <code>S</code> and <code>y</code>; any other format characters
|
||
are provided to the system’s strftime(3) with any leading ‘<code>-</code>’
|
||
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>
|
||
</li>
|
||
</ul>
|
||
<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>
|
||
<ul>
|
||
<li>
|
||
<p><code>%B</code> (<code>%b</code>)<br />
|
||
Start (stop) boldface mode.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%E</code><br />
|
||
Clear to end of line.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%U</code> (<code>%u</code>)<br />
|
||
Start (stop) underline mode.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%S</code> (<code>%s</code>)<br />
|
||
Start (stop) standout mode.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%F</code> (<code>%f</code>)<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 <code>%F</code>, for example <code>%F{red}</code>. In the latter case the values
|
||
allowed are as described for the <code>fg</code> <code>zle_highlight</code> 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>
|
||
</li>
|
||
<li>
|
||
<p><code>%K</code> (<code>%k</code>)<br />
|
||
Start (stop) using a different bacKground colour. The syntax is
|
||
identical to that for <code>%F</code> and <code>%f</code>.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%{</code>...<code>%}</code><br />
|
||
Include a string as a literal escape sequence. The string within the
|
||
braces should not change the cursor position. Brace pairs can nest.</p>
|
||
<p>A positive numeric argument between the <code>%</code> and the <code>{</code> is treated
|
||
as described for <code>%G</code> below.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%G</code><br />
|
||
Within a <code>%{</code>...<code>%}</code> 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 <code>%{</code>...<code>%}</code>
|
||
sequence together with the appropriate number of <code>%G</code> sequences to
|
||
indicate the correct width. An integer between the ‘<code>%</code>’ and ‘<code>G</code>’
|
||
indicates a character width other than one. Hence <code>%{``seq``%2G%}</code>
|
||
outputs <code>seq</code> and assumes it takes up the width of two standard
|
||
characters.</p>
|
||
<p>Multiple uses of <code>%G</code> accumulate in the obvious fashion; the
|
||
position of the <code>%G</code> 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 <code>%{</code>...<code>%}</code> group so
|
||
that the correct truncation point can be found.</p>
|
||
</li>
|
||
</ul>
|
||
<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>
|
||
<ul>
|
||
<li>
|
||
<p><code>%v</code><br />
|
||
<span id="index-psvar_002c-use-of"></span></p>
|
||
<p>The value of the first element of the <code>psvar</code> array parameter.
|
||
Following the ‘<code>%</code>’ with an integer gives that element of the array.
|
||
Negative integers count from the end of the array.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>%(``x``.``true-text``.``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
|
||
‘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 ‘<code>)</code>’ may appear in the <code>false-text</code> as ‘<code>%)</code>’.
|
||
<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 ‘<code>l</code>’. The test
|
||
character <code>x</code> may be any of the following:</p>
|
||
<ul>
|
||
<li>
|
||
<p><code>!</code><br />
|
||
True if the shell is running with privileges.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>#</code><br />
|
||
True if the effective uid of the current process is <code>n</code>.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>?</code><br />
|
||
True if the exit status of the last command was <code>n</code>.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>_</code><br />
|
||
True if at least <code>n</code> shell constructs were started.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>C</code><br />
|
||
<code>/</code><br />
|
||
True if the current absolute path has at least <code>n</code> elements
|
||
relative to the root directory, hence <code>/</code> is counted as 0
|
||
elements.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>c</code><br />
|
||
<code>.</code><br />
|
||
<code>~</code><br />
|
||
True if the current path, with prefix replacement, has at least
|
||
<code>n</code> elements relative to the root directory, hence <code>/</code> is
|
||
counted as 0 elements.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>D</code><br />
|
||
True if the month is equal to <code>n</code> (January = 0).</p>
|
||
</li>
|
||
<li>
|
||
<p><code>d</code><br />
|
||
True if the day of the month is equal to <code>n</code>.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>e</code><br />
|
||
True if the evaluation depth is at least <code>n</code>.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>g</code><br />
|
||
True if the effective gid of the current process is <code>n</code>.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>j</code><br />
|
||
True if the number of jobs is at least <code>n</code>.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>L</code><br />
|
||
True if the <code>SHLVL</code> parameter is at least <code>n</code>.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>l</code><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
|
||
<code>abs``(``n``)</code> characters remain before the opposite margin
|
||
(thus the left margin for <code>RPROMPT</code>).</p>
|
||
</li>
|
||
<li>
|
||
<p><code>S</code><br />
|
||
True if the <code>SECONDS</code> parameter is at least <code>n</code>.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>T</code><br />
|
||
True if the time in hours is equal to <code>n</code>.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>t</code><br />
|
||
True if the time in minutes is equal to <code>n</code>.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>v</code><br />
|
||
True if the array <code>psvar</code> has at least <code>n</code> elements.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>V</code><br />
|
||
True if element <code>n</code> of the array <code>psvar</code> is set and non-empty.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>w</code><br />
|
||
True if the day of the week is equal to <code>n</code> (Sunday = 0).</p>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li>
|
||
<p><code>%<``string``<</code><br />
|
||
<code>%>``string``></code><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 ‘<code><</code>’ or ‘<code>></code>’. The <code>string</code>
|
||
will be displayed in place of the truncated portion of any string;
|
||
note this does not undergo prompt expansion.</p>
|
||
<p>The numeric argument, which in the third form may appear immediately
|
||
after the ‘<code>[</code>’, 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 <code>RPROMPT</code>).</p>
|
||
<p>The forms with ‘<code><</code>’ truncate at the left of the string, and the
|
||
forms with ‘<code>></code>’ truncate at the right of the string. For example,
|
||
if the current directory is ‘<code>/home/pike</code>’, the prompt ‘<code>%8<..<%/</code>’
|
||
will expand to ‘<code>..e/pike</code>’. In this string, the terminating
|
||
character (‘<code><</code>’, ‘<code>></code>’ or ‘<code>]</code>’), or in fact any character, may be
|
||
quoted by a preceding ‘<code>\</code>’; note when using <code>print -P</code>, however,
|
||
that this must be doubled as the string is also subject to standard
|
||
<code>print</code> processing, in addition to any backslashes removed by a
|
||
double quoted string: the worst case is therefore ‘<code>print -P "%<\\<<..."</code>’.</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>
|
||
<p>The part of the prompt string to be truncated runs to the end of the
|
||
string, or to the end of the next enclosing group of the ‘<code>%(</code>’
|
||
construct, or to the next truncation encountered at the same
|
||
grouping level (i.e. truncations inside a ‘<code>%(</code>’ are separate),
|
||
which ever comes first. In particular, a truncation with argument
|
||
zero (e.g., ‘<code>%<<</code>’) marks the end of the range of the string to be
|
||
truncated while turning off truncation from there on. For example,
|
||
the prompt ‘<code>%10<...<%~%<<%# </code>’ will print a truncated
|
||
representation of the current directory, followed by a ‘<code>%</code>’ or
|
||
‘<code>#</code>’, followed by a space. Without the ‘<code>%<<</code>’, those two
|
||
characters would be included in the string to be truncated. Note
|
||
that ‘<code>%-0<<</code>’ is not equivalent to ‘<code>%<<</code>’ but specifies that the
|
||
prompt is truncated at the right margin.</p>
|
||
<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``(l.``true-text``.``false-text``)</code>’ to
|
||
remove parts of the prompt when the available space is less than
|
||
<code>n</code>.</p>
|
||
</li>
|
||
</ul>
|
||
<hr />
|
||
<p>This document was generated on <em>February 15, 2020</em> using
|
||
<a href="http://www.nongnu.org/texi2html/"><em>texi2html 5.0</em></a>.<br />
|
||
Zsh version 5.8, released on February 14, 2020.</p>
|
||
|
||
</main>
|
||
|
||
<nav class="nav-wrapper" aria-label="Page navigation">
|
||
<!-- Mobile navigation buttons -->
|
||
|
||
<a rel="prev" href="Conditional-Expressions.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
||
<i class="fa fa-angle-left"></i>
|
||
</a>
|
||
|
||
|
||
|
||
<a rel="next" href="Expansion.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||
<i class="fa fa-angle-right"></i>
|
||
</a>
|
||
|
||
|
||
<div style="clear: both"></div>
|
||
</nav>
|
||
</div>
|
||
</div>
|
||
|
||
<nav class="nav-wide-wrapper" aria-label="Page navigation">
|
||
|
||
<a rel="prev" href="Conditional-Expressions.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
||
<i class="fa fa-angle-left"></i>
|
||
</a>
|
||
|
||
|
||
|
||
<a rel="next" href="Expansion.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||
<i class="fa fa-angle-right"></i>
|
||
</a>
|
||
|
||
</nav>
|
||
|
||
</div>
|
||
|
||
|
||
<!-- Livereload script (if served using the cli tool) -->
|
||
<script type="text/javascript">
|
||
var socket = new WebSocket("ws://localhost:3000/__livereload");
|
||
socket.onmessage = function (event) {
|
||
if (event.data === "reload") {
|
||
socket.close();
|
||
location.reload();
|
||
}
|
||
};
|
||
|
||
window.onbeforeunload = function() {
|
||
socket.close();
|
||
}
|
||
</script>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<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 -->
|
||
|
||
|
||
|
||
|
||
</body>
|
||
</html>
|