/usr/share/doc/zsh-common/html/Prompt-Expansion.html is in zsh-doc 5.0.2-3ubuntu6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
<html>
<!-- Created on December 21, 2012 by texi2html 1.82
texi2html was written by:
Lionel Cons <Lionel.Cons@cern.ch> (original author)
Karl Berry <karl@freefriends.org>
Olaf Bachmann <obachman@mathematik.uni-kl.de>
and many others.
Maintained by: Many creative people.
Send bugs and suggestions to <texi2html-bug@nongnu.org>
-->
<head>
<title>zsh: 13. Prompt Expansion</title>
<meta name="description" content="zsh: 13. Prompt Expansion">
<meta name="keywords" content="zsh: 13. Prompt Expansion">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2html 1.82">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
pre.display {font-family: serif}
pre.format {font-family: serif}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: serif; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: serif; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.roman {font-family:serif; font-weight:normal;}
span.sansserif {font-family:sans-serif; font-weight:normal;}
ul.toc {list-style: none}
-->
</style>
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Prompt-Expansion"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="Conditional-Expressions.html#Conditional-Expressions" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Expansion-of-Prompt-Sequences" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="Conditional-Expressions.html#Conditional-Expressions" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="zsh.html#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Expansion.html#Expansion" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="zsh.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Prompt-Expansion-1"></a>
<h1 class="chapter">13. Prompt Expansion</h1>
<hr size="6">
<a name="Expansion-of-Prompt-Sequences"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Prompt-Expansion" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Simple-Prompt-Escapes" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Prompt-Expansion" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Prompt-Expansion" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Expansion.html#Expansion" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="zsh.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section">13.1 Expansion of Prompt Sequences</h2>
<a name="index-prompt-expansion"></a>
<a name="index-expansion_002c-prompt"></a>
<p>Prompt sequences undergo a special form of expansion. This type of expansion
is also available using the <tt>-P</tt> option to the <tt>print</tt> builtin.
</p>
<a name="index-PROMPT_005fSUBST_002c-use-of"></a>
<p>If the <tt>PROMPT_SUBST</tt> 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>
<a name="index-PROMPT_005fBANG_002c-use-of"></a>
<p>If the <tt>PROMPT_BANG</tt> option is set, a ‘<tt>!</tt>’ in the prompt is replaced
by the current history event number. A literal ‘<tt>!</tt>’ may then be
represented as ‘<tt>!!</tt>’.
</p>
<a name="index-PROMPT_005fPERCENT_002c-use-of"></a>
<p>If the <tt>PROMPT_PERCENT</tt> option is set, certain escape sequences that
start with ‘<tt>%</tt>’ are expanded.
Many escapes are followed by a single character, although some of these
take an optional integer argument that
should appear between the ‘<tt>%</tt>’ and the next character of the
sequence. More complicated escape sequences are available to provide
conditional expansion.
</p>
<hr size="6">
<a name="Simple-Prompt-Escapes"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Expansion-of-Prompt-Sequences" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Special-characters" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Prompt-Expansion" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Prompt-Expansion" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Expansion.html#Expansion" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="zsh.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section">13.2 Simple Prompt Escapes</h2>
<hr size="6">
<a name="Special-characters"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Simple-Prompt-Escapes" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Login-information" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Prompt-Expansion" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Simple-Prompt-Escapes" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Expansion.html#Expansion" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="zsh.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">13.2.1 Special characters</h3>
<dl compact="compact">
<dt> <tt>%%</tt></dt>
<dd><p>A ‘<tt>%</tt>’.
</p>
</dd>
<dt> <tt>%)</tt></dt>
<dd><p>A ‘<tt>)</tt>’.
</p>
</dd>
</dl>
<hr size="6">
<a name="Login-information"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Special-characters" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Shell-state" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Prompt-Expansion" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Simple-Prompt-Escapes" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Expansion.html#Expansion" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="zsh.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">13.2.2 Login information</h3>
<dl compact="compact">
<dt> <tt>%l</tt></dt>
<dd><p>The line (tty) the user is logged in on, without ‘<tt>/dev/</tt>’ prefix.
If the name starts with ‘<tt>/dev/tty</tt>’, that prefix is stripped.
</p>
</dd>
<dt> <tt>%M</tt></dt>
<dd><p>The full machine hostname.
</p>
</dd>
<dt> <tt>%m</tt></dt>
<dd><p>The hostname up to the first ‘<tt>.</tt>’.
An integer may follow the ‘<tt>%</tt>’ to specify
how many components of the hostname are desired. With a negative integer,
trailing components of the hostname are shown.
</p>
</dd>
<dt> <tt>%n</tt></dt>
<dd><p><tt>$USERNAME</tt>.
</p>
</dd>
<dt> <tt>%y</tt></dt>
<dd><p>The line (tty) the user is logged in on, without ‘<tt>/dev/</tt>’ prefix.
This does not treat ‘<tt>/dev/tty</tt>’ names specially.
</p>
</dd>
</dl>
<hr size="6">
<a name="Shell-state"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Login-information" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Date-and-time" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Prompt-Expansion" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Simple-Prompt-Escapes" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Expansion.html#Expansion" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="zsh.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">13.2.3 Shell state</h3>
<dl compact="compact">
<dt> <tt>%#</tt></dt>
<dd><p>A ‘<tt>#</tt>’ if the shell is running with privileges, a ‘<tt>%</tt>’ if not.
Equivalent to ‘<tt>%(!.#.%%)</tt>’.
The definition of ‘privileged’, for these purposes, is that either the
effective user ID is zero, or, if POSIX.1e capabilities are supported, that
at least one capability is raised in either the Effective or Inheritable
capability vectors.
</p>
</dd>
<dt> <tt>%?</tt></dt>
<dd><p>The return status of the last command executed just before the prompt.
</p>
</dd>
<dt> <tt>%_</tt></dt>
<dd><p>The status of the parser, i.e. the shell constructs (like ‘<tt>if</tt>’ and
‘<tt>for</tt>’) 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 <tt>PS2</tt> for
continuation lines and <tt>PS4</tt> for debugging with the <tt>XTRACE</tt> option; in
the latter case it will also work non-interactively.
</p>
</dd>
<dt> <tt>%d</tt></dt>
<dt> <tt>/</tt></dt>
<dd><p>Current working directory. If an integer follows the ‘<tt>%</tt>’,
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. <tt>%-1d</tt> specifies the first component.
</p>
</dd>
<dt> <tt>%~</tt></dt>
<dd><p>As <tt>%d</tt> and <tt>%/</tt>, but if the current working directory has a named
directory as its prefix, that part is replaced by a ‘<tt>~</tt>’ followed by
the name of the directory. If it starts with <tt>$HOME</tt>, that part is
replaced by a ‘<tt>~</tt>’.
</p>
</dd>
<dt> <tt>%h</tt></dt>
<dt> <tt>%!</tt></dt>
<dd><p>Current history event number.
</p>
</dd>
<dt> <tt>%i</tt></dt>
<dd><p>The line number currently being executed in the script, sourced file, or
shell function given by <tt>%N</tt>. This is most useful for debugging as part
of <tt>$PS4</tt>.
</p>
</dd>
<dt> <tt>%I</tt></dt>
<dd><p>The line number currently being executed in the file <tt>%x</tt>. This is
similar to <tt>%i</tt>, 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>
</dd>
<dt> <tt>%j</tt></dt>
<dd><p>The number of jobs.
</p>
</dd>
<dt> <tt>%L</tt></dt>
<dd><p>The current value of <tt>$SHLVL</tt>.
</p>
</dd>
<dt> <tt>%N</tt></dt>
<dd><p>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 <tt>$0</tt>. An integer may follow
the ‘<tt>%</tt>’ to specify a number of trailing path components to show; zero
means the full path. A negative integer specifies leading components.
</p>
</dd>
<dt> <tt>%x</tt></dt>
<dd><p>The name of the file containing the source code currently being
executed. This behaves as <tt>%N</tt> except that function and eval command
names are not shown, instead the file where they were defined.
</p>
</dd>
<dt> <tt>%c</tt></dt>
<dt> <tt>%.</tt></dt>
<dt> <tt>%C</tt></dt>
<dd><p>Trailing component of the current working directory.
An integer may follow the ‘<tt>%</tt>’ to get more than one component.
Unless ‘<tt>%C</tt>’ is used, tilde contraction is performed first. These are
deprecated as <tt>%c</tt> and <tt>%C</tt> are equivalent to <tt>%1~</tt> and <tt>%1/</tt>,
respectively, while explicit positive integers have the same effect as for
the latter two sequences.
</p>
</dd>
</dl>
<hr size="6">
<a name="Date-and-time"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Shell-state" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Visual-effects" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Prompt-Expansion" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Simple-Prompt-Escapes" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Expansion.html#Expansion" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="zsh.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">13.2.4 Date and time</h3>
<dl compact="compact">
<dt> <tt>%D</tt></dt>
<dd><p>The date in <var>yy</var><tt>-</tt><var>mm</var><tt>-</tt><var>dd</var> format.
</p>
</dd>
<dt> <tt>%T</tt></dt>
<dd><p>Current time of day, in 24-hour format.
</p>
</dd>
<dt> <tt>%t</tt></dt>
<dt> <tt>%@</tt></dt>
<dd><p>Current time of day, in 12-hour, am/pm format.
</p>
</dd>
<dt> <tt>%*</tt></dt>
<dd><p>Current time of day in 24-hour format, with seconds.
</p>
</dd>
<dt> <tt>%w</tt></dt>
<dd><p>The date in <var>day</var><tt>-</tt><var>dd</var> format.
</p>
</dd>
<dt> <tt>%W</tt></dt>
<dd><p>The date in <var>mm</var><tt>/</tt><var>dd</var><tt>/</tt><var>yy</var> format.
</p>
</dd>
<dt> <tt>%D{</tt><var>string</var><tt>}</tt></dt>
<dd><p><var>string</var> is formatted using the <tt>strftime</tt> 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>
<dl compact="compact">
<dt> <tt>%f</tt></dt>
<dd><p>a day of the month
</p></dd>
<dt> <tt>%K</tt></dt>
<dd><p>the hour of the day on the 24-hour clock
</p></dd>
<dt> <tt>%L</tt></dt>
<dd><p>the hour of the day on the 12-hour clock
</p></dd>
</dl>
<p>The GNU extension that a ‘<tt>-</tt>’ between the <tt>%</tt> and the
format character causes a leading zero or space to be stripped
is handled directly by the shell for the format characters <tt>d</tt>, <tt>f</tt>,
<tt>H</tt>, <tt>k</tt>, <tt>l</tt>, <tt>m</tt>, <tt>M</tt>, <tt>S</tt> and <tt>y</tt>; any other format
characters are provided to <tt>strftime()</tt> with any leading ‘<tt>-</tt>’,
present, so the handling is system dependent. Further GNU
extensions are not supported at present.
</p>
</dd>
</dl>
<hr size="6">
<a name="Visual-effects"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Date-and-time" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Conditional-Substrings-in-Prompts" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Prompt-Expansion" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Simple-Prompt-Escapes" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Expansion.html#Expansion" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="zsh.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">13.2.5 Visual effects</h3>
<dl compact="compact">
<dt> <tt>%B</tt> (<tt>%b</tt>)</dt>
<dd><p>Start (stop) boldface mode.
</p>
</dd>
<dt> <tt>%E</tt></dt>
<dd><p>Clear to end of line.
</p>
</dd>
<dt> <tt>%U</tt> (<tt>%u</tt>)</dt>
<dd><p>Start (stop) underline mode.
</p>
</dd>
<dt> <tt>%S</tt> (<tt>%s</tt>)</dt>
<dd><p>Start (stop) standout mode.
</p>
</dd>
<dt> <tt>%F</tt> (<tt>%f</tt>)</dt>
<dd><p>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 <tt>%F</tt>, for example <tt>%F{red}</tt>. In the latter case
the values allowed are as described for the <tt>fg</tt> <tt>zle_highlight</tt>
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>
</dd>
<dt> <tt>%K</tt> (<tt>%k</tt>)</dt>
<dd><p>Start (stop) using a different bacKground colour. The syntax is
identical to that for <tt>%F</tt> and <tt>%f</tt>.
</p>
</dd>
<dt> <tt>%{</tt>...<tt>%}</tt></dt>
<dd><p>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 <tt>%</tt> and the <tt>{</tt> is treated as
described for <tt>%G</tt> below.
</p>
</dd>
<dt> <tt>%G</tt></dt>
<dd><p>Within a <tt>%{</tt>...<tt>%}</tt> 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 <tt>%{</tt>...<tt>%}</tt>
sequence together with the appropriate number of <tt>%G</tt> sequences to
indicate the correct width. An integer between the ‘<tt>%</tt>’ and ‘<tt>G</tt>’
indicates a character width other than one. Hence <tt>%{</tt><var>seq</var><tt>%2G%}</tt>
outputs <var>seq</var> and assumes it takes up the width of two standard
characters.
</p>
<p>Multiple uses of <tt>%G</tt> accumulate in the obvious fashion; the position
of the <tt>%G</tt> 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 <tt>%{</tt>...<tt>%}</tt> group so that
the correct truncation point can be found.
</p>
</dd>
</dl>
<hr size="6">
<a name="Conditional-Substrings-in-Prompts"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Visual-effects" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="Expansion.html#Expansion" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Prompt-Expansion" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Prompt-Expansion" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Expansion.html#Expansion" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="zsh.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section">13.3 Conditional Substrings in Prompts</h2>
<dl compact="compact">
<dt> <tt>%v</tt></dt>
<dd><a name="index-psvar_002c-use-of"></a>
<p>The value of the first element of the <tt>psvar</tt> array parameter. Following
the ‘<tt>%</tt>’ with an integer gives that element of the array. Negative
integers count from the end of the array.
</p>
</dd>
<dt> <tt>%(</tt><var>x.true-text.false-text</var><tt>)</tt></dt>
<dd><p>Specifies a ternary expression. The character following the <var>x</var> 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 <var>true-text</var>, except as part of a
%-escape
sequence. A ‘<tt>)</tt>’ may appear in the <var>false-text</var> as ‘<tt>%)</tt>’.
<var>true-text</var>
and <var>false-text</var> 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 <var>n</var>,
which defaults to zero. A negative integer will be multiplied by -1.
The test character <var>x</var> may be any of the following:
</p>
<dl compact="compact">
<dt> <tt>!</tt></dt>
<dd><p>True if the shell is running with privileges.
</p></dd>
<dt> <tt>#</tt></dt>
<dd><p>True if the effective uid of the current process is <var>n</var>.
</p></dd>
<dt> <tt>?</tt></dt>
<dd><p>True if the exit status of the last command was <var>n</var>.
</p></dd>
<dt> <tt>_</tt></dt>
<dd><p>True if at least <var>n</var> shell constructs were started.
</p></dd>
<dt> <tt>C</tt></dt>
<dt> <tt>/</tt></dt>
<dd><p>True if the current absolute path has at least <var>n</var> elements
relative to the root directory, hence <tt>/</tt> is counted as 0 elements.
</p></dd>
<dt> <tt>c</tt></dt>
<dt> <tt>.</tt></dt>
<dt> <tt>~</tt></dt>
<dd><p>True if the current path, with prefix replacement, has at
least <var>n</var> elements relative to the root directory, hence <tt>/</tt> is
counted as 0 elements.
</p></dd>
<dt> <tt>D</tt></dt>
<dd><p>True if the month is equal to <var>n</var> (January = 0).
</p></dd>
<dt> <tt>d</tt></dt>
<dd><p>True if the day of the month is equal to <var>n</var>.
</p></dd>
<dt> <tt>g</tt></dt>
<dd><p>True if the effective gid of the current process is <var>n</var>.
</p></dd>
<dt> <tt>j</tt></dt>
<dd><p>True if the number of jobs is at least <var>n</var>.
</p></dd>
<dt> <tt>L</tt></dt>
<dd><p>True if the <tt>SHLVL</tt> parameter is at least <var>n</var>.
</p></dd>
<dt> <tt>l</tt></dt>
<dd><p>True if at least <var>n</var> characters have already been
printed on the current line.
</p></dd>
<dt> <tt>S</tt></dt>
<dd><p>True if the <tt>SECONDS</tt> parameter is at least <var>n</var>.
</p></dd>
<dt> <tt>T</tt></dt>
<dd><p>True if the time in hours is equal to <var>n</var>.
</p></dd>
<dt> <tt>t</tt></dt>
<dd><p>True if the time in minutes is equal to <var>n</var>.
</p></dd>
<dt> <tt>v</tt></dt>
<dd><p>True if the array <tt>psvar</tt> has at least <var>n</var> elements.
</p></dd>
<dt> <tt>V</tt></dt>
<dd><p>True if element <var>n</var> of the array <tt>psvar</tt> is set and
non-empty.
</p></dd>
<dt> <tt>w</tt></dt>
<dd><p>True if the day of the week is equal to <var>n</var> (Sunday = 0).
</p></dd>
</dl>
</dd>
<dt> <tt>%<</tt><var>string</var><tt><</tt></dt>
<dt> <tt>%></tt><var>string</var><tt>></tt></dt>
<dt> <tt>%[</tt><var>xstring</var><tt>]</tt></dt>
<dd><p>Specifies truncation behaviour for the remainder of the prompt string.
The third, deprecated, form is equivalent to ‘<tt>%</tt><var>xstringx</var>’,
i.e. <var>x</var> may be ‘<tt><</tt>’ or ‘<tt>></tt>’.
The numeric argument, which in the third form may appear immediately
after the ‘<tt>[</tt>’, specifies the maximum permitted length of
the various strings that can be displayed in the prompt.
The <var>string</var> will be displayed in
place of the truncated portion of any string; note this does not
undergo prompt expansion.
</p>
<p>The forms with ‘<tt><</tt>’ truncate at the left of the string,
and the forms with ‘<tt>></tt>’ truncate at the right of the string.
For example, if the current directory is ‘<tt>/home/pike</tt>’,
the prompt ‘<tt>%8<..<%/</tt>’ will expand to ‘<tt>..e/pike</tt>’.
In this string, the terminating character (‘<tt><</tt>’, ‘<tt>></tt>’ or ‘<tt>]</tt>’),
or in fact any character, may be quoted by a preceding ‘<tt>\</tt>’; note
when using <tt>print -P</tt>, however, that this must be doubled as the
string is also subject to standard <tt>print</tt> processing, in addition
to any backslashes removed by a double quoted string: the worst case
is therefore ‘<tt>print -P "%<\\\\<<..."</tt>’.
</p>
<p>If the <var>string</var> 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 ‘<tt>%(</tt>’
construct, or to the next truncation encountered at the same grouping
level (i.e. truncations inside a ‘<tt>%(</tt>’ are separate), which
ever comes first. In particular, a truncation with argument zero
(e.g. ‘<tt>%<<</tt>’) marks the end of the range of the string to be
truncated while turning off truncation from there on. For example, the
prompt ’%10<...<%~%<<%# ’ will print a truncated representation of the
current directory, followed by a ‘<tt>%</tt>’ or ‘<tt>#</tt>’, followed by a
space. Without the ‘<tt>%<<</tt>’, those two characters would be included
in the string to be truncated.
</p>
</dd>
</dl>
<hr size="6">
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Prompt-Expansion" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="Expansion.html#Expansion" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="zsh.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<p>
<font size="-1">
This document was generated by <em>Peter Stephenson</em> on <em>December 21, 2012</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html 1.82</em></a>.
</font>
<br>
</p>
</body>
</html>
|