<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://lug.mtu.edu/w/index.php?action=history&amp;feed=atom&amp;title=CustomBashPrompt</id>
	<title>CustomBashPrompt - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://lug.mtu.edu/w/index.php?action=history&amp;feed=atom&amp;title=CustomBashPrompt"/>
	<link rel="alternate" type="text/html" href="https://lug.mtu.edu/w/index.php?title=CustomBashPrompt&amp;action=history"/>
	<updated>2026-04-29T15:51:54Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.17</generator>
	<entry>
		<id>https://lug.mtu.edu/w/index.php?title=CustomBashPrompt&amp;diff=5590&amp;oldid=prev</id>
		<title>Agmeyer: Outline!</title>
		<link rel="alternate" type="text/html" href="https://lug.mtu.edu/w/index.php?title=CustomBashPrompt&amp;diff=5590&amp;oldid=prev"/>
		<updated>2009-10-22T23:05:00Z</updated>

		<summary type="html">&lt;p&gt;Outline!&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
1. default prompt &amp;quot;\u@\h:\w\$ &amp;quot;&lt;br /&gt;
        \u      username&lt;br /&gt;
        \h      hostname&lt;br /&gt;
        \w      current working directory&lt;br /&gt;
        \$      # if UID is 0 (root), $ otherwise&lt;br /&gt;
2. Pretty colors! \[ and \] keep bash from using the enclosed text in prompt-length calculations&lt;br /&gt;
        \e[XX;YYm for color, XX is foreground, YY is background. ;1 gives bold foreground, background unnecessary &lt;br /&gt;
                if default desired&lt;br /&gt;
        \e[0m resets to default, useful at end of prompt.&lt;br /&gt;
&lt;br /&gt;
        Foreground&lt;br /&gt;
        30 black&lt;br /&gt;
        31 red&lt;br /&gt;
        32 green&lt;br /&gt;
        33 yellow&lt;br /&gt;
        34 blue&lt;br /&gt;
        35 purple&lt;br /&gt;
        36 teal&lt;br /&gt;
        37 white&lt;br /&gt;
&lt;br /&gt;
        Background&lt;br /&gt;
        40 black&lt;br /&gt;
        41 red&lt;br /&gt;
        42 green&lt;br /&gt;
        43 yellow&lt;br /&gt;
        44 blue&lt;br /&gt;
        45 purple&lt;br /&gt;
        46 teal&lt;br /&gt;
        47 white&lt;br /&gt;
        &amp;quot;\[\e[32;1m\]\u@\h:\w\$ \[\e[0m\]&amp;quot; all green&lt;br /&gt;
        &amp;quot;\[\e[31;1m\]\u\[\e[0m\]@\[\e[33;1m\]\h\[\e[0m\]:\[\e[36;1m\]\w\[\e[32;1m\]\$ \[\e[0m\]&amp;quot; red user, yellow &lt;br /&gt;
                hostname, teal cwd, green UID symbol&lt;br /&gt;
3. Informative but kind of bulky and boring. In .bashrc, we can test if we are in an xterm or not using:&lt;br /&gt;
        if [ &amp;quot;$TERM&amp;quot; = &amp;quot;linux&amp;quot; ]&lt;br /&gt;
If we are, let us put some information up in the xterm titlebar, using the escape sequences &amp;quot;\[\e]2;&amp;quot; &amp;quot;\a&amp;quot;&lt;br /&gt;
        if [ &amp;quot;$TERM&amp;quot; = &amp;quot;linux&amp;quot; ]&lt;br /&gt;
        then&lt;br /&gt;
                export PS1=&amp;quot;\[\e[32;1m\]\u@\h:\W\$ \[\e[0m\]&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
                export PS1=&amp;quot;\[\e]2;\u@\h:\W\a\e[32;1m\]\$\[\e[0m\] &amp;quot;&lt;br /&gt;
        fi&lt;br /&gt;
Puts username, host, and base of cwd in titlebar, and leaves the UID symbol as prompt in green&lt;br /&gt;
4. Scripts! So, if we have scripts that produce output without newlines, we can include them in our prompt by&lt;br /&gt;
                enclosing the call in $()&lt;br /&gt;
        Battery status is useful on laptops, so we have a script that puts percentage and status (charging, &lt;br /&gt;
                discharging, or charged) in a compact form, and colors the percentage based on number (red under &lt;br /&gt;
                15%, yellow under 30%, green else&lt;br /&gt;
        &amp;quot;[ \$(/home/agmlego/bin/battery-status) ] \[\e]2;\u@\h:\W\a\e[32;1m\]\$\[\e[0m\] &amp;quot; Battery status followed &lt;br /&gt;
                by UID symbol in green, username/host/cwd is in titlebar&lt;br /&gt;
5. Further customization:&lt;br /&gt;
        \a      an ASCII bell character (07)&lt;br /&gt;
        \d      the date in &amp;quot;Weekday Month Date&amp;quot; format (e.g., &amp;quot;Tue May 26&amp;quot;)&lt;br /&gt;
        \e      an ASCII escape character (033)&lt;br /&gt;
        \h      the hostname up to the first &amp;#039;.&amp;#039;&lt;br /&gt;
        \H      the hostname&lt;br /&gt;
        \j      the number of jobs currently managed by the shell&lt;br /&gt;
        \l      the basename of the shell&amp;#039;s terminal device name&lt;br /&gt;
        \n      newline&lt;br /&gt;
        \r      carriage return&lt;br /&gt;
        \s      the name of the shell, the basename of $0 (the portion following the final slash)&lt;br /&gt;
        \t      the current time in 24-hour HH:MM:SS format&lt;br /&gt;
        \T      the current time in 12-hour HH:MM:SS format&lt;br /&gt;
        \@      the current time in 12-hour am/pm format&lt;br /&gt;
        \u      the username of the current user&lt;br /&gt;
        \v      the version of bash (e.g., 2.00)&lt;br /&gt;
        \V      the release of bash, version + patchlevel (e.g., 2.00.0)&lt;br /&gt;
        \w      the current working directory&lt;br /&gt;
        \W      the basename of the current working directory&lt;br /&gt;
        \!      the history number of this command&lt;br /&gt;
        \#      the command number of this command&lt;br /&gt;
        \$      if the effective UID is 0, a #, otherwise a $&lt;br /&gt;
        \nnn    the character corresponding to the octal number nnn&lt;br /&gt;
        \\      a backslash&lt;br /&gt;
        \[      begin a sequence of non-printing characters, which could be used to embed a terminal control &lt;br /&gt;
                sequence into the prompt&lt;br /&gt;
        \]      end a sequence of non-printing characters&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Agmeyer</name></author>
	</entry>
</feed>