<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-5853688862531392660</atom:id><lastBuildDate>Sun, 27 Nov 2011 23:38:51 +0000</lastBuildDate><category>howtos</category><category>misc</category><title>TwistedCode</title><description /><link>http://twistedcode.blogspot.com/</link><managingEditor>noreply@blogger.com (Derek)</managingEditor><generator>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Twistedcode" /><feedburner:info uri="twistedcode" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5853688862531392660.post-4896644830550754207</guid><pubDate>Sun, 13 Apr 2008 05:18:00 +0000</pubDate><atom:updated>2008-04-13T01:33:56.322-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">howtos</category><title>LS_COLORS Explained</title><description>&lt;p&gt;
 In my previous &lt;a href="http://twistedcode.blogspot.com/2008/03/colored-ls-output.html"&gt;article&lt;/a&gt; I showed you how to make the &lt;code&gt;ls&lt;/code&gt; command display colored output; now I am going to show you how to customize what colors get displayed.  We are going to use the &lt;code&gt;LS_COLORS&lt;/code&gt; environment variable to accomplish this task.
&lt;/p&gt;

&lt;p&gt;
 You can change your &lt;code&gt;LS_COLORS&lt;/code&gt; environment variable by setting it in your &lt;code&gt;$HOME/.bash_profile&lt;/code&gt; or &lt;code&gt;$HOME/.bashrc&lt;/code&gt; file.  The syntax for &lt;code&gt;LS_COLORS&lt;/code&gt; is as follows:
&lt;/p&gt;

&lt;div id="codeBox"&gt;LS_COLORS='di=1:fi=0:ln=31:pi=5:so=5:bd=5:cd=5:or=31:*.deb=90'&lt;/div&gt;

&lt;p&gt;
 The parameters for &lt;code&gt;LS_COLORS&lt;/code&gt; (&lt;code&gt;di&lt;/code&gt;, &lt;code&gt;fi&lt;/code&gt;, &lt;code&gt;ln&lt;/code&gt;, &lt;code&gt;pi&lt;/code&gt;, etc) refer to different file types:
&lt;/p&gt;

&lt;table border="0"&gt;
 &lt;tr&gt;&lt;td&gt; di &lt;/td&gt;&lt;td&gt; Directory &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; fi &lt;/td&gt;&lt;td&gt; File &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; ln &lt;/td&gt;&lt;td&gt; Symbolic Link &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; pi &lt;/td&gt;&lt;td&gt; Fifo file &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; so &lt;/td&gt;&lt;td&gt; Socket file &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; bd &lt;/td&gt;&lt;td&gt; Block (buffered) special file &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; cd &lt;/td&gt;&lt;td&gt; Character (unbuffered) special file &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; or &lt;/td&gt;&lt;td&gt; Symbolic Link pointing to a non-existent file (orphan) &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; mi &lt;/td&gt;&lt;td&gt; Non-existent file pointed to by a symbolic link (visible when you type ls -l) &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; ex &lt;/td&gt;&lt;td&gt; File which is executable (ie. has 'x' set in permissions). &lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;

&lt;br /&gt;

&lt;p&gt;
 The &lt;code&gt;*.deb=90&lt;/code&gt; parameter in the example above tells &lt;code&gt;ls&lt;/code&gt; to display any files ending with a &lt;code&gt;.deb&lt;/code&gt; extension using the color specified, 90 or dark grey in this case.  This can be applied to any types of files (eg. you could use &lt;code&gt;*.jpg=33&lt;/code&gt; to make JPEG files appear orange).  Any number of parameters can go into the &lt;code&gt;LS_COLORS&lt;/code&gt; variable, as long as the parameters are separated by colons.
&lt;/p&gt;


&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size:130%; font-weight: bold;"&gt;Color Codes&lt;/span&gt;
&lt;br /&gt;

&lt;p&gt;
 Through trial and error I worked out the color codes for &lt;code&gt;LS_COLORS&lt;/code&gt; to be:
&lt;/p&gt;

&lt;table border="0"&gt;
 &lt;tr&gt;&lt;td&gt;   0 =&lt;/td&gt;&lt;td&gt; Default Colour &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;   1 =&lt;/td&gt;&lt;td&gt; Bold &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;   4 =&lt;/td&gt;&lt;td&gt; Underlined &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;   5 =&lt;/td&gt;&lt;td&gt; Flashing Text &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;   7 =&lt;/td&gt;&lt;td&gt; Reverse Field &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;  31 =&lt;/td&gt;&lt;td&gt; Red &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;  32 =&lt;/td&gt;&lt;td&gt; Green &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;  33 =&lt;/td&gt;&lt;td&gt; Orange &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;  34 =&lt;/td&gt;&lt;td&gt; Blue &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;  35 =&lt;/td&gt;&lt;td&gt; Purple &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;  36 =&lt;/td&gt;&lt;td&gt; Cyan &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;  37 =&lt;/td&gt;&lt;td&gt; Grey &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;  40 =&lt;/td&gt;&lt;td&gt; Black Background &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;  41 =&lt;/td&gt;&lt;td&gt; Red Background &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;  42 =&lt;/td&gt;&lt;td&gt; Green Background &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;  43 =&lt;/td&gt;&lt;td&gt; Orange Background &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;  44 =&lt;/td&gt;&lt;td&gt; Blue Background &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;  45 =&lt;/td&gt;&lt;td&gt; Purple Background &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;  46 =&lt;/td&gt;&lt;td&gt; Cyan Background &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;  47 =&lt;/td&gt;&lt;td&gt; Grey Background &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;  90 =&lt;/td&gt;&lt;td&gt; Dark Grey &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;  91 =&lt;/td&gt;&lt;td&gt; Light Red &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;  92 =&lt;/td&gt;&lt;td&gt; Light Green &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;  93 =&lt;/td&gt;&lt;td&gt; Yellow &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;  94 =&lt;/td&gt;&lt;td&gt; Light Blue &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;  95 =&lt;/td&gt;&lt;td&gt; Light Purple &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;  96 =&lt;/td&gt;&lt;td&gt; Turquoise &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; 100 =&lt;/td&gt;&lt;td&gt; Dark Grey Background &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; 101 =&lt;/td&gt;&lt;td&gt; Light Red Background &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; 102 =&lt;/td&gt;&lt;td&gt; Light Green Background &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; 103 =&lt;/td&gt;&lt;td&gt; Yellow Background &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; 104 =&lt;/td&gt;&lt;td&gt; Light Blue Background &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; 105 =&lt;/td&gt;&lt;td&gt; Light Purple Background &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; 106 =&lt;/td&gt;&lt;td&gt; Turquoise Background &lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;

&lt;br /&gt;

&lt;p&gt;
 These codes can also be combined with one another:
&lt;/p&gt;

&lt;div id="codeBox"&gt;di=5;34;43&lt;/div&gt;

&lt;p&gt;
 Setting the &lt;code&gt;LS_COLORS&lt;/code&gt; &lt;code&gt;di&lt;/code&gt; parameter to the above example will make directories appear in flashing blue text with an orange background (just because flashing text is available doesn't mean you should use it!)
&lt;/p&gt;

&lt;br /&gt;

&lt;p&gt;
 Customizing the colors that &lt;code&gt;ls&lt;/code&gt; uses to display it's output can make sifting through your filesystem a very easy task.  If you have any questions post them in the comments below.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5853688862531392660-4896644830550754207?l=twistedcode.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/nEmsPyL5GzV12hzkKxry2DOMLOM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/nEmsPyL5GzV12hzkKxry2DOMLOM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/nEmsPyL5GzV12hzkKxry2DOMLOM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/nEmsPyL5GzV12hzkKxry2DOMLOM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Twistedcode/~4/_CISceiJpGs" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/Twistedcode/~3/_CISceiJpGs/lscolors-explained.html</link><author>noreply@blogger.com (Derek)</author><thr:total>3</thr:total><feedburner:origLink>http://twistedcode.blogspot.com/2008/04/lscolors-explained.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5853688862531392660.post-5528667436382168593</guid><pubDate>Tue, 01 Apr 2008 13:39:00 +0000</pubDate><atom:updated>2008-04-01T09:48:41.466-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">misc</category><title>Google Custom Time</title><description>&lt;p&gt;
 Today when I logged into my Gmail account I was presented with a &lt;code&gt;New!&lt;/code&gt; feature; &lt;a href="http://mail.google.com/mail/help/customtime/index.html"&gt;Gmail Custom Time&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
 I have to give props to Google, they have a great sense of humor.  Google was even able to throw in a reference to the coveted &lt;code&gt;Flux Capacitor&lt;/code&gt;, it is a must read!
&lt;/p&gt;

&lt;div id="codeBox"&gt;&lt;a href="http://mail.google.com/mail/help/customtime/index.html"&gt;Gmail Custom Time&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5853688862531392660-5528667436382168593?l=twistedcode.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/n5dOph7VCZFpBl52pHP5f2JX_9Q/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/n5dOph7VCZFpBl52pHP5f2JX_9Q/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/n5dOph7VCZFpBl52pHP5f2JX_9Q/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/n5dOph7VCZFpBl52pHP5f2JX_9Q/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Twistedcode/~4/-fMyi0Dzuks" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/Twistedcode/~3/-fMyi0Dzuks/google-custome-time.html</link><author>noreply@blogger.com (Derek)</author><thr:total>0</thr:total><feedburner:origLink>http://twistedcode.blogspot.com/2008/04/google-custome-time.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5853688862531392660.post-3251531117911800066</guid><pubDate>Fri, 28 Mar 2008 15:11:00 +0000</pubDate><atom:updated>2008-03-31T15:40:15.223-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">howtos</category><title>Customizing Your Bash Prompt</title><description>&lt;p&gt;
 I came to OS X from the wonderful world of Linux; upon doing so I really missed my customized terminal prompt; after all, the default Mac OS X prompt is really boring and blah.
&lt;/p&gt;

&lt;img style="border: 0; margin: 0px auto 10px; display: block; text-align: center;" src="http://2.bp.blogspot.com/_COw8R89gans/R-0L5z-PXgI/AAAAAAAAAh0/uharKrM3zOo/s400/terminal_default.png" alt="Default OS X Terminal" id="BLOGGER_PHOTO_ID_5182811834005020162" /&gt;

&lt;p&gt;
 Customizing the default shell prompt not only makes the terminal that much more exciting, it will also help you remember which system you are currently on and the directory you are about to run a command in (Yea!, no more incessant &lt;code&gt;pwd&lt;/code&gt; commands).  This is especially useful for those late night pesky phone calls letting you know that you have to come into work early, really, really early; to fix the server that the underpaid incompetent third string sysadmin was supposed to be watching!  Arriving on site with multiple windows open mixed with sleep deprivation can have some very devastating results.  Running shutdown or init in the wrong window can really hurt.
&lt;/p&gt;

&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size:130%; font-weight: bold;"&gt;Bash Prompt Variables&lt;/span&gt;
&lt;br /&gt;

&lt;p&gt;
 The primary Bash shell prompt is customized by setting the $PS1 shell environment variable.  In order to see what your current prompt is set to you must &lt;code&gt;echo $PS1&lt;/code&gt;:
&lt;/p&gt;

&lt;div id="codeBox"&gt;echo $PS1&lt;/div&gt;

&lt;p&gt;
 Characters prefixed by a backslash (&lt;code&gt;\&lt;/code&gt;) are actually variables that get expanded.  Here is a list of all Bash prompt variables as described in the PROMPTING section of the BASH(1) man page.
&lt;/p&gt;

&lt;table border="0"&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\a&lt;/code&gt; &lt;/td&gt;&lt;td&gt; an ASCII bell character (07) &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\d&lt;/code&gt; &lt;/td&gt;&lt;td&gt; the date in "Weekday Month Date" format (e.g., "Tue May 26") &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\D{format}&lt;/code&gt; &lt;/td&gt;&lt;td&gt; the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation. The braces are required. &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\e&lt;/code&gt; &lt;/td&gt;&lt;td&gt; an ASCII escape character (033) &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\h&lt;/code&gt; &lt;/td&gt;&lt;td&gt; the hostname up to the first &lt;code&gt;.&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\H&lt;/code&gt; &lt;/td&gt;&lt;td&gt; the full hostname &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\j&lt;/code&gt; &lt;/td&gt;&lt;td&gt; the number of jobs currently managed by the shell &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\l&lt;/code&gt; &lt;/td&gt;&lt;td&gt; the basename of the shells terminal device name &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\n&lt;/code&gt; &lt;/td&gt;&lt;td&gt; newline &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\r&lt;/code&gt; &lt;/td&gt;&lt;td&gt; carriage return &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\s&lt;/code&gt; &lt;/td&gt;&lt;td&gt; the name of the shell, the basename of $0 (the portion following the final slash) &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\t&lt;/code&gt; &lt;/td&gt;&lt;td&gt; the current time in 24-hour HH:MM:SS format &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\T&lt;/code&gt; &lt;/td&gt;&lt;td&gt; the current time in 12-hour HH:MM:SS format &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\@&lt;/code&gt; &lt;/td&gt;&lt;td&gt; the current time in 12-hour am/pm format &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\A&lt;/code&gt; &lt;/td&gt;&lt;td&gt; the current time in 24-hour HH:MM format &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\u&lt;/code&gt; &lt;/td&gt;&lt;td&gt; the username of the current user &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\v&lt;/code&gt; &lt;/td&gt;&lt;td&gt; the version of bash (e.g., 2.00) &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\V&lt;/code&gt; &lt;/td&gt;&lt;td&gt; the release of bash, version + patch level (e.g., 2.00.0) &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\w&lt;/code&gt; &lt;/td&gt;&lt;td&gt; the current working directory, with $HOME abbreviated with a tilde &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\W&lt;/code&gt; &lt;/td&gt;&lt;td&gt; the basename of the current working directory, with $HOME abbreviated with a tilde &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\!&lt;/code&gt; &lt;/td&gt;&lt;td&gt; the history number of this command &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\#&lt;/code&gt; &lt;/td&gt;&lt;td&gt; the command number of this command &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\$&lt;/code&gt; &lt;/td&gt;&lt;td&gt; if the effective UID is 0, a &lt;code&gt;#&lt;/code&gt;, otherwise a &lt;code&gt;$&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\nnn&lt;/code&gt; &lt;/td&gt;&lt;td&gt; the character corresponding to the octal number &lt;code&gt;nnn&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\\&lt;/code&gt; &lt;/td&gt;&lt;td&gt; a backslash &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\[&lt;/code&gt; &lt;/td&gt;&lt;td&gt; begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\]&lt;/code&gt; &lt;/td&gt;&lt;td&gt; end a sequence of non-printing characters &lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;

&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size:130%; font-weight: bold;"&gt;Setting Your Prompt&lt;/span&gt;
&lt;br /&gt;

&lt;p&gt;
 Set your new prompt by manipulating the $PS1 variable.
&lt;/p&gt;

&lt;div id="codeBox"&gt;export PS1='\h:\W \u\$ '&lt;/div&gt;

&lt;p&gt;
 That would make your prompt look like this:
&lt;/p&gt;

&lt;div id="codeBox"&gt;hostname:~ username$&lt;/div&gt;

&lt;p&gt;
 To keep your settings for the next Bash shell, place a line in your &lt;code&gt;$HOME/.bashrc&lt;/code&gt; that looks like this:
&lt;/p&gt;

&lt;div id="codeBox"&gt;PS1='\h:\W \u\$ '&lt;/div&gt;

&lt;p&gt;
 &lt;em&gt;Mac users note the following&lt;/em&gt;
 &lt;br /&gt;
 Due to the way OS X and the Terminal application handle command emulation you have to create the file &lt;code&gt;$HOME/.bash_profile&lt;/code&gt; and enter the following line:
&lt;/p&gt;

&lt;div id="codeBox"&gt;source ~/.bashrc&lt;/div&gt;

&lt;p&gt;
 Once you have done this every Terminal window you open up will have your custom prompt.
&lt;/p&gt;

&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size:130%; font-weight: bold;"&gt;Other Variables&lt;/span&gt;
&lt;br /&gt;

&lt;p&gt;
 &lt;code&gt;$PS1&lt;/code&gt; is not the only shell variable that affects your prompt.  &lt;code&gt;$PS2&lt;/code&gt; is the secondary prompt.  The secondary prompt shows up in command line loops:
&lt;/p&gt;

&lt;div id="codeBox"&gt;hostname:~ username$ export PS2="--&gt; " &lt;br /&gt;
hostname:~ username$ for x in $(seq 3); do &lt;br /&gt;
--&gt; echo $x &lt;br /&gt;
--&gt; done &lt;br /&gt;
1 2 3 &lt;br /&gt;
hostname:~ username$
&lt;/div&gt;

&lt;p&gt;
 &lt;code&gt;$PS3&lt;/code&gt; and &lt;code&gt;$PS4&lt;/code&gt; also exist.  From the Bash Reference Manual:
&lt;/p&gt;
 
&lt;table border="0"&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;PS1&lt;/code&gt; &lt;/td&gt;&lt;td&gt; the primary prompt string.  The default value is &lt;code&gt;'\s-\v\$ '&lt;/code&gt;. &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;PS2&lt;/code&gt; &lt;/td&gt;&lt;td&gt; the secondary prompt string.  The default value is &lt;code&gt;'&gt; '&lt;/code&gt;. &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;PS3&lt;/code&gt; &lt;/td&gt;&lt;td&gt; the value of this variable is used as the prompt for the select command.  If this variable is not set, the select command prompts with &lt;code&gt;'#? '&lt;/code&gt;. &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;PS4&lt;/code&gt; &lt;/td&gt;&lt;td&gt; the value is the prompt printed before the command line is echoed when the &lt;code&gt;-x&lt;/code&gt; option is set (see The Set Builtin).  The first character of &lt;code&gt;PS4&lt;/code&gt; is replicated multiple times, as necessary, to indicate multiple levels of indirection.  The default is &lt;code&gt;'+ '&lt;/code&gt;. &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;PROMPT_COMMAND&lt;/code&gt; &lt;/td&gt;&lt;td&gt; if set, the value is interpreted as a command to execute before the printing of each primary prompt (&lt;code&gt;$PS1&lt;/code&gt;).  &lt;code&gt;$PROMPT_COMMAND&lt;/code&gt; can be used in clever ways to run a command before each primary prompt display.  See below for an example &lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;

&lt;div id="codeBox"&gt;hostname:~ username$ export PROMPT_COMMAND='echo -n "$(uptime | cut -d',' -f1) "'&lt;br /&gt;
14:33:01 up 6 days hostname:~ username$
&lt;/div&gt;


&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size:130%; font-weight: bold;"&gt;Time to Colorize!&lt;/span&gt;
&lt;br /&gt;

&lt;p&gt;
 Some of you might want to present your shell prompt using color.  This is especially useful for privileged shells.  Lets make the root shell display using red:
&lt;/p&gt;

&lt;div id="codeBox"&gt;hostname:~ username$ export PS1="\e[01;31m\h:\W \u\$ \e[00m"&lt;/div&gt;

&lt;p&gt;
 This might look a little confusing so let's break it down.
&lt;/p&gt;

&lt;table border="0"&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\e[&lt;/code&gt; &lt;/td&gt;&lt;td&gt; is the Escape Character sequence (you can also use &lt;code&gt;\[\033[&lt;/code&gt;) &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;01;31m&lt;/code&gt; &lt;/td&gt;&lt;td&gt; Sets the color to light (&lt;code&gt;01&lt;/code&gt;) red (&lt;code&gt;31&lt;/code&gt;) &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\h:\W \u\$&lt;/code&gt; &lt;/td&gt;&lt;td&gt; Prints &lt;code&gt;hostname:(current directory) username$ &lt;/code&gt; &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;\e[&lt;/code&gt; &lt;/td&gt;&lt;td&gt; Escape Character sequence &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; &lt;code&gt;00m&lt;/code&gt; &lt;/td&gt;&lt;td&gt; Clears all color (no color after this point) &lt;/td&gt;&lt;/tr&gt; 
&lt;/table&gt;

&lt;p&gt;
 In this example if your username is alex, your hostname is 'hades', and you are currently in your $HOME directory the resulting prompt will look like:
&lt;/p&gt;

&lt;div id="codeBox"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;hades:~ alex$ &lt;/span&gt;&lt;/div&gt;


&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size:130%; font-weight: bold;"&gt;Bash Color Escape Codes&lt;/span&gt;
&lt;br /&gt;

&lt;p&gt;
 Use any of the following escape codes between &lt;code&gt;\e[&lt;/code&gt; and &lt;code&gt;m&lt;/code&gt; to colorize text in Bash:
&lt;/p&gt;

&lt;table border="0"&gt;
 &lt;tr&gt;&lt;td&gt; Black &lt;/td&gt;&lt;td&gt; &lt;code&gt;0;30&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; Dark Gray &lt;/td&gt;&lt;td&gt; &lt;code&gt;1;30&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; Blue &lt;/td&gt;&lt;td&gt; &lt;code&gt;0;34&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; Light Blue &lt;/td&gt;&lt;td&gt; &lt;code&gt;1;34&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; Green &lt;/td&gt;&lt;td&gt; &lt;code&gt;0;32&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; Light Green &lt;/td&gt;&lt;td&gt; &lt;code&gt;1;32&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; Cyan &lt;/td&gt;&lt;td&gt; &lt;code&gt;0;36&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; Light Cyan &lt;/td&gt;&lt;td&gt; &lt;code&gt;1;36&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; Red &lt;/td&gt;&lt;td&gt; &lt;code&gt;0;31&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; Light Red &lt;/td&gt;&lt;td&gt; &lt;code&gt;1;31&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; Purple &lt;/td&gt;&lt;td&gt; &lt;code&gt;0;35&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; Light Purple &lt;/td&gt;&lt;td&gt; &lt;code&gt;1;35&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; Brown &lt;/td&gt;&lt;td&gt; &lt;code&gt;0;33&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; Yellow &lt;/td&gt;&lt;td&gt; &lt;code&gt;1;33&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; Light Gray &lt;/td&gt;&lt;td&gt; &lt;code&gt;0;37&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt; White &lt;/td&gt;&lt;td&gt; &lt;code&gt;1;37&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;


&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size:130%; font-weight: bold;"&gt;My custom prompt...&lt;/span&gt;
&lt;br /&gt;

&lt;p&gt;
 Just in case you were wondering what I have set my prompt to here we go:
&lt;/p&gt;

&lt;div id="codeBox"&gt;PS1='\[\033[01;32m\]\u\[\033[01;34m\]::\[\033[01;31m\]\h \[\033[00;34m\]{ \[\033[01;34m\]\w \[\033[00;34m\]}\[\033[01;32m\]-&gt; \[\033[00m\]'&lt;/div&gt;

&lt;p&gt;
 Which looks like this:
&lt;/p&gt;

&lt;img style="border: 0; margin: 0px auto 10px; display: block; text-align: center;" src="http://4.bp.blogspot.com/_COw8R89gans/R-0MNT-PXhI/AAAAAAAAAh8/0bXEedsY4Ic/s400/terminal_tweaked.png" alt="My Custom Bash Terminal" id="BLOGGER_PHOTO_ID_5182812169012469266" /&gt;

&lt;p&gt;
 The &lt;code&gt;PS1&lt;/code&gt; string does not span multiple lines.  I decided to use &lt;code&gt;\[033[&lt;/code&gt; instead of &lt;code&gt;\e[&lt;/code&gt; to maximize compatibility between different terminals (I like to take my custom shell everywhere I go).  If you would like a breakdown of my prompt feel free to ask in the comments below.
&lt;/p&gt;


&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size:130%; font-weight: bold;"&gt;References&lt;/span&gt;
&lt;br /&gt;

&lt;a href="http://www.gnu.org/software/bash/manual/bashref.html"&gt;Bash Reference Manual&lt;/a&gt;
&lt;br /&gt;
&lt;a href="http://tldp.org/HOWTO/Bash-Prompt-HOWTO/"&gt;Bash Prompt Howto&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5853688862531392660-3251531117911800066?l=twistedcode.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/jMxtHPTJATH69y86sNAmZyg7rD0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/jMxtHPTJATH69y86sNAmZyg7rD0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/jMxtHPTJATH69y86sNAmZyg7rD0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/jMxtHPTJATH69y86sNAmZyg7rD0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Twistedcode/~4/2DwQ-8FW_RM" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/Twistedcode/~3/2DwQ-8FW_RM/customizing-your-bash-prompt.html</link><author>noreply@blogger.com (Derek)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/_COw8R89gans/R-0L5z-PXgI/AAAAAAAAAh0/uharKrM3zOo/s72-c/terminal_default.png" height="72" width="72" /><thr:total>7</thr:total><feedburner:origLink>http://twistedcode.blogspot.com/2008/03/customizing-your-bash-prompt.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5853688862531392660.post-4716248998930094824</guid><pubDate>Wed, 26 Mar 2008 20:59:00 +0000</pubDate><atom:updated>2008-04-13T01:38:18.320-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">howtos</category><title>Colored ls Output</title><description>&lt;p&gt;
 Unix uses the &lt;code&gt;ls&lt;/code&gt; command to list the contents of a directory.  By default &lt;code&gt;ls&lt;/code&gt; displays all directories and files the same way, leaving you without the ability to quickly determine what type of files you are looking at (in Unix everything is a file).  Here is an screenshot showing the default output of &lt;code&gt;ls&lt;/code&gt; on OS X:
&lt;/p&gt;

&lt;img style="border: 0; margin: 0px auto 10px; display: block; text-align: center;" src="http://3.bp.blogspot.com/_COw8R89gans/R-z1DT-PXeI/AAAAAAAAAhk/T8hi2EkqUHU/s400/terminal_ls_default.png" alt=""id="BLOGGER_PHOTO_ID_5182786708446338530" /&gt;

&lt;p&gt;
 &lt;code&gt;ls&lt;/code&gt; has the ability to color code different file types by passing the &lt;code&gt;--color&lt;/code&gt; option to &lt;code&gt;ls&lt;/code&gt;.  For example, type the following command at your shell prompt to see colorized output:
&lt;/p&gt;

&lt;div id="codeBox"&gt;$ ls --color&lt;/div&gt;

&lt;p&gt;
 Here is what that command looks like:
&lt;/p&gt;

&lt;img style="border: 0; margin: 0px auto 10px; display: block; text-align: center;" src="http://3.bp.blogspot.com/_COw8R89gans/R-z1PT-PXfI/AAAAAAAAAhs/ukPDtWAQK-I/s400/terminal_ls_tweaked.png" alt=""id="BLOGGER_PHOTO_ID_5182786914604768754" /&gt;

&lt;p&gt;
 If you get an error statement after running the last command then you most likely do not have the GNU version of &lt;code&gt;ls&lt;/code&gt; installed.  You can download the GNU version of &lt;code&gt;ls&lt;/code&gt; by downloading and installing the &lt;a href="http://www.gnu.org/software/coreutils/"&gt;GNU Coreutils&lt;/a&gt; package for your OS.
&lt;/p&gt;

&lt;p&gt;
 If you are not using xterm as your terminal you may have to set the &lt;code&gt;TERM&lt;/code&gt; environment variable to &lt;code&gt;xterm&lt;/code&gt; or &lt;code&gt;xterm-color&lt;/code&gt;.  The &lt;code&gt;TERM&lt;/code&gt; setting you choose will depend on your OS and distribution.  You change your &lt;code&gt;TERM&lt;/code&gt; variable by running the following:
&lt;/p&gt;

&lt;div id="codeBox"&gt;export TERM=xterm-color&lt;/div&gt;

&lt;p&gt;
 or
&lt;/p&gt;

&lt;div id="codeBox"&gt;export TERM=xterm&lt;/div&gt;

&lt;p&gt;
 To make your &lt;code&gt;TERM&lt;/code&gt; environment variable persistent you add either of the commands above to your &lt;code&gt;$HOME/.bash_profile&lt;/code&gt; or &lt;code&gt;$HOME/.bashrc&lt;/code&gt; just like we did for the alias definition.
&lt;/p&gt;

&lt;p&gt;
 To customize the color &lt;code&gt;ls&lt;/code&gt; displays you must modify the &lt;code&gt;LS_COLORS&lt;/code&gt; environment variable.  &lt;code&gt;LS_COLORS&lt;/code&gt; is formatted as a string of variables separated by colons.  Changing &lt;code&gt;LS_COLORS&lt;/code&gt; is out of the scope of this howto.  I have explained the &lt;code&gt;LS_COLORS&lt;/code&gt; variable in detail &lt;a href="http://twistedcode.blogspot.com/2008/04/lscolors-explained.html"&gt;here&lt;/a&gt;.
&lt;/p&gt;

&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size:130%; font-weight: bold;"&gt;Creating an Alias&lt;/span&gt;
&lt;br /&gt;

&lt;p&gt;
 Typing &lt;code&gt;ls --color&lt;/code&gt; everytime you need to use &lt;code&gt;ls&lt;/code&gt; seems a little tedious, that is where the wonderful &lt;code&gt;alias&lt;/code&gt; command comes in.  &lt;code&gt;alias&lt;/code&gt; allows you to create a shorthand definition to replace a command or a series of commands.  To create an alias you can either put your alias definition in the &lt;code&gt;$HOME/.bash_profile&lt;/code&gt; or &lt;code&gt;$HOME/.bashrc&lt;/code&gt; which is persistent across multiple logins and shells or you can specify an alias definition at the command line.  Examples of both are below:
&lt;/p&gt;

&lt;p&gt;
 Adding an alias definition to &lt;code&gt;$HOME/.bash_profile&lt;/code&gt;
&lt;/p&gt;

&lt;div id="codeBox"&gt;$ echo "alias ls='ls --color'" &gt;&gt; $HOME/.bash_profile&lt;/div&gt;

&lt;p&gt;
 If you want to put the alias definition in &lt;code&gt;$HOME/.bashrc&lt;/code&gt; just substitute it instead of &lt;code&gt;$HOME/.bash_profile&lt;/code&gt; in the example above.
&lt;/p&gt;

&lt;p&gt;
 Create an alias definition that will only be valid for your current shell session perform the following:
&lt;/p&gt;

&lt;div id="codeBox"&gt;$ alias ls='ls --color'&lt;/div&gt;

&lt;p&gt;
 Now whenever you use &lt;code&gt;ls&lt;/code&gt; it will use colored output.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5853688862531392660-4716248998930094824?l=twistedcode.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/4FK4gLuEDqF_KwsbsERuxLlo4SU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4FK4gLuEDqF_KwsbsERuxLlo4SU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/4FK4gLuEDqF_KwsbsERuxLlo4SU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4FK4gLuEDqF_KwsbsERuxLlo4SU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Twistedcode/~4/LWFYb0fR8II" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/Twistedcode/~3/LWFYb0fR8II/colored-ls-output.html</link><author>noreply@blogger.com (Derek)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_COw8R89gans/R-z1DT-PXeI/AAAAAAAAAhk/T8hi2EkqUHU/s72-c/terminal_ls_default.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://twistedcode.blogspot.com/2008/03/colored-ls-output.html</feedburner:origLink></item></channel></rss>

