426 lines
No EOL
24 KiB
HTML
426 lines
No EOL
24 KiB
HTML
<!DOCTYPE html>
|
|
<html lang='en'><head><meta charset='utf-8' /><meta name='pinterest' content='nopin' /><link href='../../../../static/css/style.css' rel='stylesheet' type='text/css' /><link href='../../../../static/css/print.css' rel='stylesheet' type='text/css' media='print' /><title>My Extravagant Zsh Prompt / Steve Losh</title></head><body><header><a id='logo' href='https://stevelosh.com/'>Steve Losh</a><nav><a href='../../../index.html'>Blog</a> - <a href='https://stevelosh.com/projects/'>Projects</a> - <a href='https://stevelosh.com/photography/'>Photography</a> - <a href='https://stevelosh.com/links/'>Links</a> - <a href='https://stevelosh.com/rss.xml'>Feed</a></nav></header><hr class='main-separator' /><main id='page-blog-entry'><article><h1><a href='index.html'>My Extravagant Zsh Prompt</a></h1><p class='date'>Posted on January 31st, 2010.</p><p>I spend a lot of time in a Terminal window at a command line. Up until about a
|
|
month ago I was using <a href="http://en.wikipedia.org/wiki/Bash">bash</a> for my shell. I decided to try switching to
|
|
<a href="http://www.zsh.org/">Zsh</a> after hearing a lot of good things about it and I'm very happy with
|
|
the change.</p>
|
|
|
|
<p>A few days ago I <a href="http://twitter.com/stevelosh/status/8259755151">tweeted</a> my current Zsh prompt and the general response
|
|
was: "Cool, but how did you do it?" I promised to write more about it when I
|
|
got some free time, and it looks like that time is now.</p>
|
|
|
|
<p><strong>One quick note:</strong> This entry is about the prompt that <em>I</em> find useful. You
|
|
are not me, so you'll almost certainly have different needs. That's great!
|
|
Take this prompt and hack it to make whatever works for you. If you're feeling
|
|
generous you should find me on <a href="http://twitter.com/stevelosh/">Twitter</a> and show me what you changed --
|
|
I might want to steal/appropriate your changes.</p>
|
|
|
|
<p><strong>Another quick note:</strong> I've customized the colors of my Terminal. They're
|
|
based on the <a href="http://www.monokai.nl/blog/2006/07/15/textmate-color-theme/">Monokai</a> TextMate theme, and I think they look very nice. The
|
|
colors will be different for you. If you want colors like mine you should take
|
|
a look at the <a href="../../../entry/2009/3/18/candy-colored-terminal/index.html">entry</a> I wrote about it.</p>
|
|
|
|
<ol class="table-of-contents"><li><a href="index.html#s1-why-should-you-care">Why Should You Care?</a></li><li><a href="index.html#s2-this-entry-is-about-zsh-prompts">This Entry is About Zsh Prompts</a></li><li><a href="index.html#s3-screenshots">Screenshots</a></li><li><a href="index.html#s4-oh-my-zsh">Oh My Zsh!</a></li><li><a href="index.html#s5-define-a-theme">Define a "Theme"</a></li><li><a href="index.html#s6-username-and-hostname">Username and Hostname</a></li><li><a href="index.html#s7-current-directory">Current Directory</a></li><li><a href="index.html#s8-my-right-prompt-battery-capacity">My Right-Prompt: Battery Capacity</a></li><li><a href="index.html#s9-repository-types">Repository Types</a></li><li><a href="index.html#s10-mercurial-repository-information">Mercurial Repository Information</a></li><li><a href="index.html#s11-git-repository-information">Git Repository Information</a></li><li><a href="index.html#s12-the-whole-thing">The Whole Thing</a></li></ol>
|
|
|
|
<h2 id="s1-why-should-you-care"><a href="index.html#s1-why-should-you-care">Why Should You Care?</a></h2>
|
|
|
|
<p>Many people use the command line every day and never bother to customize their
|
|
prompts. It's just a bit of text that's printed before every command — why
|
|
should you waste time learning how to customize it?</p>
|
|
|
|
<p>I feel that the <em>most</em> important aspect of my command line work is the prompt.
|
|
Your prompt is something you'll see <em>literally</em> thousands of times a day. Why
|
|
not take 30 minutes and customize it into something that's much more useful?</p>
|
|
|
|
<p>I firmly believe I'm right in thinking this way. 30 minutes (or even 3 hours)
|
|
of customization to make your work easier for the <strong>rest of your life</strong> (or at
|
|
least however long you stay with your current shell) <em>is</em> worth it.</p>
|
|
|
|
<h2 id="s2-this-entry-is-about-zsh-prompts"><a href="index.html#s2-this-entry-is-about-zsh-prompts">This Entry is About Zsh Prompts</a></h2>
|
|
|
|
<p>As I mentioned earlier I now use Zsh as my command line shell. If you use bash
|
|
(the default on most modern systems) the syntax to create the shell will be
|
|
different.</p>
|
|
|
|
<p>Really, though, you should give Zsh a try.</p>
|
|
|
|
<h2 id="s3-screenshots"><a href="index.html#s3-screenshots">Screenshots</a></h2>
|
|
|
|
<p>I can write all day, but in the end I think a screenshot will be more helpful
|
|
than anything I write.</p>
|
|
|
|
<p>Here's a sample of my current Zsh prompt:</p>
|
|
|
|
<p><img src="../../../../static/images/blog/2010/02/zsh-prompt.png" alt="My Zsh Prompt"></p>
|
|
|
|
<p>And here's a version of that screenshot with some comments added to explain
|
|
things:</p>
|
|
|
|
<p><img src="../../../../static/images/blog/2010/02/zsh-prompt-comments.png" alt="My Zsh Prompt with Comments"></p>
|
|
|
|
<p>If you want to know <em>how</em> I created that prompt, read on!</p>
|
|
|
|
<h2 id="s4-oh-my-zsh"><a href="index.html#s4-oh-my-zsh">Oh My Zsh!</a></h2>
|
|
|
|
<p>The first thing I'd do when starting out with Zsh is to install
|
|
<a href="http://github.com/robbyrussell">robbyrussell's</a> <a href="http://github.com/robbyrussell/oh-my-zsh">oh-my-zsh</a>. It's a great collection of very
|
|
useful Zsh configurations and aliases which set some sane defaults and make
|
|
working with Zsh much nicer.</p>
|
|
|
|
<p>The instructions for installing it are on the project page.</p>
|
|
|
|
<h2 id="s5-define-a-theme"><a href="index.html#s5-define-a-theme">Define a "Theme"</a></h2>
|
|
|
|
<p>oh-my-zsh uses <a href="http://github.com/robbyrussell/oh-my-zsh/tree/master/themes/">theme files</a> to specify how your prompt looks.</p>
|
|
|
|
<p>An oh-my-zsh theme file is just a Zsh script which sets a few variables that
|
|
the oh-my-zsh scripts use to render your prompt.</p>
|
|
|
|
<p>Go ahead and create a new theme file for your prompt. Call it whatever you
|
|
like. I called my theme "prose" because it's more verbose than the others.
|
|
Copy the contents of one of the other themes to get started.</p>
|
|
|
|
<p>The <code>PROMPT</code> variable is what you'll be modifying to change how your prompt
|
|
looks. That's the <code>PROMPT=whatever</code> line of the theme file.</p>
|
|
|
|
<p>Once you're done making your awesome prompt you should fork oh-my-zsh on
|
|
GitHub and commit/push your new theme so other people can see and use your
|
|
prompt.</p>
|
|
|
|
<h2 id="s6-username-and-hostname"><a href="index.html#s6-username-and-hostname">Username and Hostname</a></h2>
|
|
|
|
<p>The first two pieces of my prompt are the simplest: username and hostname. I
|
|
SSH between machines pretty frequently so I find it nice to have these in my
|
|
prompt to remind me of where I am.</p>
|
|
|
|
<p>These are things that you'll find in many, many Zsh prompts. For more
|
|
information about this kind of stuff check out <a href="http://www.acm.uiuc.edu/workshops/zsh/prompt/escapes.html">this page</a>.</p>
|
|
|
|
<p>After adding in the colors this piece of my <code>PROMPT</code> variable looks like this:</p>
|
|
|
|
<pre><code>%{$fg[magenta]%}%n%{$reset_color%} at %{$fg[yellow]%}%m%{$reset_color%}</code></pre>
|
|
|
|
<h2 id="s7-current-directory"><a href="index.html#s7-current-directory">Current Directory</a></h2>
|
|
|
|
<p>I like to have the current working directory displayed in my prompt. Zsh has
|
|
two built-in ways to show the current directory:</p>
|
|
|
|
<ul>
|
|
<li><strong>%d</strong> shows the <em>entire</em> path.</li>
|
|
<li><strong>%~</strong> shows the path with any variables replaced.</li>
|
|
</ul>
|
|
|
|
<p>Unfortunately neither of these work for me.</p>
|
|
|
|
<p>If I'm in a directory that's under my home directory I want to see <code>~</code> instead
|
|
of the full path. This would seem to mean that I should use <code>%~</code>, but there's
|
|
a catch.</p>
|
|
|
|
<p>The <code>%~</code> sequence also replaces any directories that happen to be environment
|
|
variables. That means if I'm in something under my <code>virtualenvs</code> directory
|
|
I'll see <code>~WORKON_HOME/venv_name</code> which is extremely ugly.</p>
|
|
|
|
<p>To get around this I defined a simple function that implements the behavior I
|
|
want.</p>
|
|
|
|
<p>To add this to your prompt you'll first need to add the following function to
|
|
your theme:</p>
|
|
|
|
<pre><code>function collapse_pwd {
|
|
echo $(pwd | sed -e "s,^$HOME,~,")
|
|
}</code></pre>
|
|
|
|
<p>Then add <code>$(collapse_pwd)</code> to your <code>PROMPT</code> variable wherever you'd like the
|
|
directory to show up.</p>
|
|
|
|
<p>After adding in the colors this piece of my <code>PROMPT</code> variable looks like this:</p>
|
|
|
|
<pre><code>in %{$fg_bold[green]%}$(collapse_pwd)%{$reset_color%}</code></pre>
|
|
|
|
<p><strong>UPDATE:</strong> In a comment Juliano pointed out a better way to do this. I've
|
|
gotten rid of the <code>collapse_pwd</code> function and put this into my <code>PROMPT</code>
|
|
variable instead:</p>
|
|
|
|
<pre><code>${PWD/#$HOME/~}</code></pre>
|
|
|
|
<h2 id="s8-my-right-prompt-battery-capacity"><a href="index.html#s8-my-right-prompt-battery-capacity">My Right-Prompt: Battery Capacity</a></h2>
|
|
|
|
<p>The next piece of my prompt I'll talk about is the most stand-alone one: the
|
|
battery charge.</p>
|
|
|
|
<p>I work exclusively on laptops. I don't own a desktop machine — I have a
|
|
Macbook, Macbook Pro and Asus EEE PC and my work machine is a Macbook Pro. I
|
|
work from coffeeshops and client meetings pretty often, so it's nice to have a
|
|
reminder of my remaining battery power to know when I need to plug in.</p>
|
|
|
|
<p>On the right-hand side of the prompt in the screenshot you can see a series of
|
|
green triangles. These represent my current battery charge and they turn to
|
|
empty triangles as the battery becomes depleted. Once the battery reaches 60%
|
|
they turn yellow and once it reaches 40% they turn red.</p>
|
|
|
|
<p>To do this I wrote a <em>very</em> simple Python script to output my current battery
|
|
capacity. The entire script is shown below.</p>
|
|
|
|
<pre><code><span class="code"><span class="comment">#!/usr/bin/env python
|
|
</span><span class="comment"># coding=UTF-8
|
|
</span>
|
|
<span class="symbol">import</span> math, subprocess
|
|
|
|
p = subprocess.Popen<span class="paren1">(<span class="code"><span class="paren2">[<span class="code"><span class="string">"ioreg"</span>, <span class="string">"-rc"</span>, <span class="string">"AppleSmartBattery"</span></span>]</span>, stdout=subprocess.PIPE</span>)</span>
|
|
output = p.communicate<span class="paren1">(<span class="code"></span>)</span><span class="paren1">[<span class="code">0</span>]</span>
|
|
|
|
o_max = <span class="paren1">[<span class="code">l <span class="symbol">for</span> l <span class="symbol">in</span> output.splitlines<span class="paren2">(<span class="code"></span>)</span> <span class="symbol">if</span> <span class="string">'MaxCapacity'</span> <span class="symbol">in</span> l</span>]</span><span class="paren1">[<span class="code">0</span>]</span>
|
|
o_cur = <span class="paren1">[<span class="code">l <span class="symbol">for</span> l <span class="symbol">in</span> output.splitlines<span class="paren2">(<span class="code"></span>)</span> <span class="symbol">if</span> <span class="string">'CurrentCapacity'</span> <span class="symbol">in</span> l</span>]</span><span class="paren1">[<span class="code">0</span>]</span>
|
|
|
|
b_max = float<span class="paren1">(<span class="code">o_max.rpartition<span class="paren2">(<span class="code"><span class="string">'='</span></span>)</span><span class="paren2">[<span class="code">-1</span>]</span>.strip<span class="paren2">(<span class="code"></span>)</span></span>)</span>
|
|
b_cur = float<span class="paren1">(<span class="code">o_cur.rpartition<span class="paren2">(<span class="code"><span class="string">'='</span></span>)</span><span class="paren2">[<span class="code">-1</span>]</span>.strip<span class="paren2">(<span class="code"></span>)</span></span>)</span>
|
|
|
|
charge = b_cur / b_max
|
|
charge_threshold = int<span class="paren1">(<span class="code">math.ceil<span class="paren2">(<span class="code">10 * charge</span>)</span></span>)</span>
|
|
|
|
<span class="comment"># Output
|
|
</span>
|
|
total_slots, slots = 10, <span class="paren1">[<span class="code"></span>]</span>
|
|
filled = int<span class="paren1">(<span class="code">math.ceil<span class="paren2">(<span class="code">charge_threshold * <span class="paren3">(<span class="code">total_slots / 10.0</span>)</span></span>)</span></span>)</span> * u<span class="string">'▸'</span>
|
|
empty = <span class="paren1">(<span class="code">total_slots - len<span class="paren2">(<span class="code">filled</span>)</span></span>)</span> * u<span class="string">'▹'</span>
|
|
|
|
out = <span class="paren1">(<span class="code">filled + empty</span>)</span>.encode<span class="paren1">(<span class="code"><span class="string">'utf-8'</span></span>)</span>
|
|
<span class="symbol">import</span> sys
|
|
|
|
color_green = <span class="string">'%{&#x1b;[32m%}'</span>
|
|
color_yellow = <span class="string">'%{&#x1b;[1;33m%}'</span>
|
|
color_red = <span class="string">'%{&#x1b;[31m%}'</span>
|
|
color_reset = <span class="string">'%{&#x1b;[00m%}'</span>
|
|
color_out = <span class="paren1">(<span class="code">
|
|
color_green <span class="symbol">if</span> len<span class="paren2">(<span class="code">filled</span>)</span> > 6
|
|
<span class="symbol">else</span> color_yellow <span class="symbol">if</span> len<span class="paren2">(<span class="code">filled</span>)</span> > 4
|
|
<span class="symbol">else</span> color_red
|
|
</span>)</span>
|
|
|
|
out = color_out + out + color_reset
|
|
sys.stdout.write<span class="paren1">(<span class="code">out</span>)</span></span></code></pre>
|
|
|
|
<p><strong>Note:</strong> The <code>color_*</code> variables contain UTF-8 characters which don't show up
|
|
in a normal web browser. They <em>should</em> be preserved when copying and pasting
|
|
from a decent browser. If the colors don't work find me on <a href="http://twitter.com/stevelosh/">Twitter</a> and
|
|
I'll put the raw script up somewhere so you can download it.</p>
|
|
|
|
<p><strong>UPDATE:</strong> <a href="http://twitter.com/ehamberg/">ehamberg</a> <a href="http://twitter.com/ehamberg/status/8503213690">sent me</a> the beginnings of a
|
|
Linux-compatible battery capacity script. If you flesh it out and make it into
|
|
a complete script please let me know and I'll add it here.</p>
|
|
|
|
<p>I've put this script in a file named <code>batcharge.py</code> in my <code>~/bin/</code> directory.
|
|
You can of course name it and place it anything/anywhere you like.</p>
|
|
|
|
<p>No, it's not perfect. No, I don't care. It gets the job done and any
|
|
brainpower I could spend on making it more efficient could be better spent on
|
|
writing or working on something else.</p>
|
|
|
|
<p>If you want to improve it, feel free and <em>please</em> send me the link to your work on
|
|
<a href="http://twitter.com/stevelosh/">Twitter</a> so I can use it!</p>
|
|
|
|
<p>Now that you've got the script, it's time to add it to your prompt.</p>
|
|
|
|
<p>If you want this to appear on the right-hand side of your screen (like mine
|
|
does) you'll need to add two things to your theme file. The first is a
|
|
function that calls the script:</p>
|
|
|
|
<pre><code>function battery_charge {
|
|
echo `$BAT_CHARGE` 2>/dev/null
|
|
}</code></pre>
|
|
|
|
<p>After that you'll need to define the Zsh <code>RPROMPT</code> variable:</p>
|
|
|
|
<pre><code>RPROMPT='$(battery_charge)'</code></pre>
|
|
|
|
<p>Once those are in your theme file any new Terminal windows you open should
|
|
show the battery capacity to the right of your prompt!</p>
|
|
|
|
<h2 id="s9-repository-types"><a href="index.html#s9-repository-types">Repository Types</a></h2>
|
|
|
|
<p>In my personal work and my full-time job I work with both
|
|
<a href="http://mercurial-scm.org/">Mercurial</a> and <a href="http://git-scm.com/">git</a> repositories. I find it helpful to have a
|
|
visual reminder of what kind of repository I'm working in.</p>
|
|
|
|
<p>To do this I've replaced the standard <code>$</code> character in my prompt with
|
|
different Unicode characters depending on what kind of repository I'm
|
|
currently in:</p>
|
|
|
|
<ul>
|
|
<li><code>○</code> means "I'm not in any repository."</li>
|
|
<li><code>☿</code> means "I'm in a Mercurial repository."</li>
|
|
<li><code>±</code> means "I'm in a git repository."</li>
|
|
</ul>
|
|
|
|
<p>Those particular characters are meant to reflect the logos of the various
|
|
projects. You can of course change them to anything that makes sense to you.</p>
|
|
|
|
<p>To add this feature to your prompt you'll need to do two things in your theme
|
|
file. First, add the following function:</p>
|
|
|
|
<pre><code>function prompt_char {
|
|
git branch >/dev/null 2>/dev/null && echo '±' && return
|
|
hg root >/dev/null 2>/dev/null && echo '☿' && return
|
|
echo '○'
|
|
}</code></pre>
|
|
|
|
<p>Then add <code>$(prompt_char)</code> somewhere inside your <code>PROMPT</code> variable — wherever
|
|
you want the character to be displayed (probably at the end).</p>
|
|
|
|
<h2 id="s10-mercurial-repository-information"><a href="index.html#s10-mercurial-repository-information">Mercurial Repository Information</a></h2>
|
|
|
|
<p>I use Mercurial at work and for my own personal projects and I find it very
|
|
handy to have some information about the current repository right in my
|
|
prompt. It keeps me "oriented," especially when I'm using <a href="http://mercurial.selenic.com/wiki/MqExtension">MQ</a> and
|
|
manipulating the state of a repo.</p>
|
|
|
|
<p>In the past I toyed around with some shell scripts to do this but eventually I
|
|
got fed up with the poor performance and horrible readability of that
|
|
solution.</p>
|
|
|
|
<p>To fix this I wrote a small Mercurial extension called <a href="https://stevelosh.com/projects/hg-prompt/">hg-prompt</a>. It adds
|
|
an <code>hg prompt</code> command to Mercurial that will let you output information about
|
|
the current repository. It's designed especially for use in shell prompts
|
|
(hence the name).</p>
|
|
|
|
<p>I open sourced the code a while ago and since then a few people have made
|
|
feature requests and/or contributed patches. It's grown into a nice, flexible
|
|
little tool. You can check out the <a href="https://sjl.bitbucket.io/hg-prompt/">documentation</a> to see all the
|
|
things it can do.</p>
|
|
|
|
<p>I only use a few of the features myself:</p>
|
|
|
|
<ul>
|
|
<li>The current repository branch.</li>
|
|
<li>The "dirty" state of the repo (whether there are untracked/uncommitted files).</li>
|
|
<li>Any tags pointing at the current revision.</li>
|
|
<li>An "update" character to show whether running <code>hg update</code> would do anything.</li>
|
|
<li>A list of MQ patches (if any are present).</li>
|
|
</ul>
|
|
|
|
<p>To put this into my prompt I've added a function to my theme:</p>
|
|
|
|
<pre><code>function hg_prompt_info {
|
|
hg prompt --angle-brackets "\
|
|
< on <branch>>\
|
|
< at <tags|, >>\
|
|
<status|modified|unknown><update><
|
|
patches: <patches|join( → )>>" 2>/dev/null
|
|
}</code></pre>
|
|
|
|
<p>Inside my <code>PROMPT</code> variable I use <code>$(hg_prompt_info)</code> to show the information.
|
|
The <code>2>/dev/null</code> makes sure no output is shown if I don't happen to be in a
|
|
Mercurial repository.</p>
|
|
|
|
<p>Of course this isn't nearly as pretty or readable without color. Unfortunately
|
|
adding color codes makes the actual code almost unreadable:</p>
|
|
|
|
<pre><code>function hg_prompt_info {
|
|
hg prompt --angle-brackets "\
|
|
< on %{$fg[magenta]%}<branch>%{$reset_color%}>\
|
|
< at %{$fg[yellow]%}<tags|%{$reset_color%}, %{$fg[yellow]%}>%{$reset_color%}>\
|
|
%{$fg[green]%}<status|modified|unknown><update>%{$reset_color%}<
|
|
patches: <patches|join( → )|pre_applied(%{$fg[yellow]%})|post_applied(%{$reset_color%})|pre_unapplied(%{$fg_bold[black]%})|post_unapplied(%{$reset_color%})>>" 2>/dev/null
|
|
}</code></pre>
|
|
|
|
<p><strong>Small note:</strong> My favorite part of this prompt is that applied MQ patches are
|
|
orange while unapplied patches are grey. It makes it very obvious what's going
|
|
on.</p>
|
|
|
|
<p>Showing all the MQ patches isn't something that will work for everyone. If you
|
|
work on repositories that ever have more than 5 or 6 patches at a time the
|
|
output is going to be too overwhelming. There are some other MQ-related
|
|
hg-prompt keywords that you might find useful though.</p>
|
|
|
|
<h2 id="s11-git-repository-information"><a href="index.html#s11-git-repository-information">Git Repository Information</a></h2>
|
|
|
|
<p>Unfortunately I can't <em>always</em> use Mercurial. Many projects that I contribute
|
|
to use git.</p>
|
|
|
|
<p>I could try to use the <a href="http://hg-git.github.com/">hg-git</a> extension to let me use Mercurial to work
|
|
with them, but the extension just isn't fast or mature enough for my taste.
|
|
I've ended up buckling down and jumping down the rabbit hole that is git's
|
|
CLI.</p>
|
|
|
|
<p>Git doesn't seem to have any equivalent to hg-prompt, but I still wanted to
|
|
have some information in my prompt so I don't get disoriented. oh-my-zsh has a
|
|
bit of support for this, but it wasn't quite enough for me so I <a href="http://github.com/sjl/oh-my-zsh/commit/3d22ee248c6bce357c018a93d31f8d292d2cb4cd">hacked
|
|
something together</a> to add the last bit of functionality I
|
|
wanted.</p>
|
|
|
|
<p>When I'm in a git repository my prompt now shows:</p>
|
|
|
|
<ul>
|
|
<li>The current git branch.</li>
|
|
<li>Whether there are any changes in the index.</li>
|
|
<li>Whether there are any changes <em>not</em> in the index.</li>
|
|
</ul>
|
|
|
|
<p>Adding this to your prompt is very simple because oh-my-zsh has built-in
|
|
support for it. All you need to do is define a few variables in your theme:</p>
|
|
|
|
<pre><code>ZSH_THEME_GIT_PROMPT_PREFIX=" on %{$fg[magenta]%}"
|
|
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
|
|
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[green]%}!"
|
|
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[green]%}?"
|
|
ZSH_THEME_GIT_PROMPT_CLEAN=""</code></pre>
|
|
|
|
<p>Once you do that you can put <code>$(git_prompt_info)</code> into your <code>PROMPT</code> variable
|
|
to make it show up.</p>
|
|
|
|
<p><strong>Note:</strong> The <code>ZSH_THEME_GIT_PROMPT_UNTRACKED</code> variable is the part I added.
|
|
If your want to use that one (to be able to see indexed and unindexed changes
|
|
separately) you'll need to use <a href="http://github.com/sjl/oh-my-zsh/">my fork of oh-my-zsh</a>.</p>
|
|
|
|
<h2 id="s12-the-whole-thing"><a href="index.html#s12-the-whole-thing">The Whole Thing</a></h2>
|
|
|
|
<p>Here's what my new "prose" theme file currently looks like in its entirety:</p>
|
|
|
|
<pre><code>function collapse_pwd {
|
|
echo $(pwd | sed -e "s,^$HOME,~,")
|
|
}
|
|
|
|
function prompt_char {
|
|
git branch >/dev/null 2>/dev/null && echo '±' && return
|
|
hg root >/dev/null 2>/dev/null && echo '☿' && return
|
|
echo '○'
|
|
}
|
|
|
|
function battery_charge {
|
|
echo `$BAT_CHARGE` 2>/dev/null
|
|
}
|
|
|
|
function virtualenv_info {
|
|
[ $VIRTUAL_ENV ] && echo '('`basename $VIRTUAL_ENV`') '
|
|
}
|
|
|
|
function hg_prompt_info {
|
|
hg prompt --angle-brackets "\
|
|
< on %{$fg[magenta]%}<branch>%{$reset_color%}>\
|
|
< at %{$fg[yellow]%}<tags|%{$reset_color%}, %{$fg[yellow]%}>%{$reset_color%}>\
|
|
%{$fg[green]%}<status|modified|unknown><update>%{$reset_color%}<
|
|
patches: <patches|join( → )|pre_applied(%{$fg[yellow]%})|post_applied(%{$reset_color%})|pre_unapplied(%{$fg_bold[black]%})|post_unapplied(%{$reset_color%})>>" 2>/dev/null
|
|
}
|
|
|
|
PROMPT='
|
|
%{$fg[magenta]%}%n%{$reset_color%} at %{$fg[yellow]%}%m%{$reset_color%} in %{$fg_bold[green]%}$(collapse_pwd)%{$reset_color%}$(hg_prompt_info)$(git_prompt_info)
|
|
$(virtualenv_info)$(prompt_char) '
|
|
|
|
RPROMPT='$(battery_charge)'
|
|
|
|
ZSH_THEME_GIT_PROMPT_PREFIX=" on %{$fg[magenta]%}"
|
|
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
|
|
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[green]%}!"
|
|
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[green]%}?"
|
|
ZSH_THEME_GIT_PROMPT_CLEAN=""</code></pre>
|
|
|
|
<p>The file is also <a href="http://github.com/sjl/oh-my-zsh/blob/master/themes/prose.zsh-theme">on GitHub</a>. Remember, you'll need
|
|
<a href="http://github.com/sjl/oh-my-zsh/">my fork of oh-my-zsh</a> to use the <code>ZSH_THEME_GIT_PROMPT_UNTRACKED</code>
|
|
feature.</p>
|
|
|
|
<p>A shell prompt is something that we'll each see thousands of times a day, so
|
|
it's something that you should take the time to customize into a useful tool.
|
|
Feel free to use my prompt as a starting point or just as a source of ideas.</p>
|
|
|
|
<p>If you have any questions, suggestions, or examples of your own please fine me on
|
|
<a href="http://twitter.com/stevelosh/">Twitter</a> — I'd love to hear them!</p>
|
|
</article></main><hr class='main-separator' /><footer><nav><a href='https://github.com/sjl/'>GitHub</a> ・ <a href='https://twitter.com/stevelosh/'>Twitter</a> ・ <a href='https://instagram.com/thirtytwobirds/'>Instagram</a> ・ <a href='https://hg.stevelosh.com/.plan/'>.plan</a></nav></footer></body></html> |