My terminal setup

In my workflow v3 screencast last week I gave a flash of my terminal, and (as I did when I saw it first), many people asked me about my set up.

TL;DR: it’s zsh with a customised version of agnoster running with iTerm 2.

Remy Sharp's terminal settings

Terminal application tweaks

If you’re running a Mac, and you’re using Terminal, stop it. Right now. Just close it, remove the shortcuts and do yourself a favour, and install iTerm 2. Future you will thank both you and me.

Here are the customisations:

Note that I’ve also sometimes tweak the “Minimum contrast” to around 1/5th on the slider in iTerm, this is to get around some dark colours used in Grunt and Yeoman (though may have been long resolved).

Shell tweaks

Like I said, I’m using the Agnoster theme with a few small tweaks.

Firstly here’s my complete theme file. One key difference is that I put the cursor on a line by itself so I don’t have to change where I’m looking to find my cursor.

This makes use of a battery capacity script from stevelosh.com’s blog (a good overall read too) with a small tweak (I use rectangles): batcharge.py.

Finally I have an online indicator, green for active connection, and red for not. I found that when I travel with a 3G dongle attached, it was useful to get a glance status. It’s done by a cronjob touching or removing a file to indicate status every minute, and the file is checked by the prompt: online-check.sh.

34 Responses to “My terminal setup”

  1. Wondering what are the main pros of zsh, agnoster and iTerm 2 you find useful?

  2. @Simon: iterm handles split windows really, really, REALLY well. Agnoster (and thus zsh) gives me instant information about the git repo I’m working out of. If you saw the screenshot at the top of the post it tells me:

    a. I’m in the master banch
    b. ± means the working directory is dirty (there’s files that git doesn’t know about)
    c. as it’s blue, I know there’s nothing waiting to be staged

    zsh also gives me the right hand prompt (which I’m sure there’s some other shells that have it, but the point is all these features are useful to me).

    It’s also got a very good history extension.

    So I can type `z jsbin` anywhere and I’ll change to the /Users/remy/Sites/jsbin/ directory.

    Or I can type the beginning of a command, like `cat` and cursor upwards and it’ll only show me the history of commands starting with “cat”.

  3. Remy, thanks for posting this! I have seen this set-up elsewhere and could not find a good explanation on Google.

  4. Many thanks for this! When I saw a presentation you did, I wanted to copy your iTerm setup, but I couldn’t find the right powerline font, and the one I had wasn’t giving me the arrowheads and other non-ASCII characters.

    Great setup! <3

  5. What’s the character used for SEGMENT_SEPARATOR?
    this one ? doesn’t look good

  6. I just spent about an hour googling about trying to figure out what to do with the gist you have shared. Where do I put this file or how do I import it? I imported the solarized colours through the profile editor, but I can’t get it to accept the remy.zsh-theme file.

    I think I am being a major dumbass!

  7. @patrick91 – I think whatever character you entered got lost in the comment. Can you try again (maybe check if you need to escape it)

    @Ben – you need to go through the setup process to use zsh: https://github.com/robbyrussell/oh-my-zsh (it was in the TL;DR bit). Once you’ve got oh-my-zsh installed, you’ll have a directory in your home directory ~ called .oh-my-zsh/themes/. Put the theme in there, and edit ~/.zshrc to point the theme to that file. All this install process should be in the link I’ve posted (I just checked myself and it looks to be there).

  8. I have an extremely similar terminal setup for myself, using zsh, Solarized (on a light background, I code in well-lit coffeeshops during the day), and Powerline. I haven’t been sold on iTerm2 yet, mostly because its another software package to install and configure, and I work across a lot of different OSX and Linux machines.

    I feel like I should take 15 minutes now and see what its going to take to get iTerm2 working with Visor/TotalTerminal.

  9. @Charles – I used to be a big fan of visor, but I’ve now got iTerm hooked up to cmd+esc to show and hide. It’s total muscle memory now, if nothing happens (when I’m on someone else’s machine), I’m totally confused!

  10. Thanks for sharing the setup. I was trying to do the setup for myself and I have a problem with the batcharge.py

    My os is 10.8.4, I have both the default python version and 3.3.
    All setup is good (I can see the green light for connection, etc) except for the batcharge.py. When I open a iterm2 terminal it shows the following error messages:

    ~/batcharge.py: line 6: import: command not found
    ~batcharge.py: line 8: syntax error near unexpected token `(‘
    ~/batcharge.py: line 8: `p = subprocess.Popen(["ioreg", "-rc", "AppleSmartBattery"], stdout=subprocess.PIPE)’

    Any clue on what might be wrong? I tried with python3.3 but that throws different set of errors.
    Thanks.

  11. @remy here is the screenshoot: http://sht.tl/PILBS

    The character unicode code is U+25BA, let me know if is the same as yours :)

    Thanks

  12. love it! thanks!

  13. @Sarah I had the same problem on OS 10.7.5. I went to replace remy’s code with the one from Steve Losh ( http://stevelosh.com/blog/2010/02/my-extravagant-zsh-prompt/#my-right-prompt-battery-capacity ) and replaced the arrows with remy’s squares and it worked for me.

  14. @patrick91 – Looks like a different character:

    You want U+E0B0.

  15. @remy, thanks for reply, I’m not able to show that character: http://sht.tl/6Tlp7

    I’m investigating

  16. Hey Remy,
    Thanks for sharing this. I have got it working after spending 20 min. Only thing is battery charge display. It is kind of overshooting on the next line and showing me some weird numbers also. such as
    1;33m??????????[00m

    I am trying to figure out but still no success, can you please help?

  17. @patrick91 I have the same problem, this is how I see the separator character: http://i.imgur.com/tJ5sHbs.png

  18. I’m personally a fan of ys terminal. Pretty much all of the different themes show the same basic information. Mine, for example, is pretty self explanatory (the green circle before the timestamp turns to a red x if I have uncommitted changes).

    I find the timestamp useless, I just haven’t had the time to customize exactly how I’d like (nor the features I want). Unfortunately, my rMBP is primarily used as a desktop replacement, so a battery indicator doesn’t provide much added value… unless it was for my Logitech K800 and Performance MX! So, I’m looking forward to digging through Unifying drivers one day in search of what I need.

    @Varun: My guess would be you are missing the leading escape character before those random characters you see (which would be color-codes, if the escape character was there).

  19. @Sarah, it looks like you’ve copied the whole file, but the first line must be #!/usr/bin/env python

    (I made the same error) :)

  20. I’m with @patrick91, got everything working except I can’t figure out how to get the cool arrow for the SEGMENT_SEPARATOR, which is the coolest part! I installed the Powerline font, but I don’t see symbols in the font book…

  21. Of course now I figured it out, when setting the font in iTerm2 I was picking the font family, but failing to the select the one typeface. Doh.

  22. @remy just fixed! thanks to @gnachman! I didn’t set the right font for Non-ASCII font.

  23. so which font is the right non-ASCII font?

  24. oh.. that font.

  25. Thanks so much Remy! This helped me lots in finally making the move to iTerm2.

  26. Thanks for the tip, Remy!

    I took me a while it figure out I needed .oh-my-zsh to get themes working, but it’s up and running now.

  27. Great tips…

    Would be interesting to see what shortcut functions you have under .zshrc

  28. Thanks for detailing this, Remy! I’d heard of zsh/oh-my-zsh but hadn’t felt inspired to check them out. The nice coloured prompt was really appealing. Having (finally) got it working, I am uncertain I’ve made the right choice for me.

    Does zsh change the autocomplete actions at different parts of a command? In bash I could supply a path to a git command and have bash autocomplete the parts of the path I couldn’t remember or be bothered to type. Zsh (or the theme?) seems to turn off autocomplete for paths as arguments. That’s a significant hinderance to my productivity until I can work out how to change the behaviour.

  29. SEPARATOR CHARACTER NOT RENDERING PROPERLY: SOLUTION

    To get this to render properly, you need to install all 3 of the Powerline fonts in the gist that Remy references in line 9 of the theme:

    https://gist.github.com/1595572

    It’s one of these that has the separator character in it and from what I can tell this character is unrelated to the font that you specify in your iterm profile.

    HTH

    Robin

  30. I still cannot get the special character in SEGMENT_SEPARATOR to show up. I have installed all the powerline fonts and set my non-ascii font to Source Code Pro for Powerline, Medium, 14pt. I have also set TextWrangler’s font to this and I see a character that looks like a square with a circle in it when viewing the theme code instead of the cool branched arrow. I also cannot find it when I look through the character map.

  31. To get the Powerline symbols working, I ended up installing the Powerline Symbol font, opening it in FontBook and copying and pasting the icon into my theme file

  32. Great post! I finally got the theme working but now I’m getting this:

    battery_charge:1: permission denied: /Users/Darren/bin/batcharge.py

    any idea what’s happening?

  33. @Darren
    I had the same issue and I couldn’t sleep for 2 nights without fix it :)
    Here is what I have done to get it work, and hope it helps you.

    - Check the permission. From terminal within ‘bin’ folder run ’ls -l’. For me I got:
    -rwxr-xr-x@ 1 ahmed staff 1161 30 Dec 12:56 batcharge.py
    Which means I have the privilege to read, write and execute that file.
    - Using ‘chmod +rwx batcharge.py’ changes the file mode and its permission.

    - I thought I’m done and ready to sleep, but now way I got a syntax error:

    File “/Users/ahmed/bin/batcharge.py”, line 25
    SyntaxError: Non-ASCII character ‘\xe2′ in file /Users/ahmed/bin/batcharge.py on line 25, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

    - Reading through the provided link I found I need to add ‘# coding=UTF-8’ as after ‘#!/usr/bin/env python’

    After that it’s done and now I can sleep :)

  34. Thanks for this @remy — having an issue though in the battery colors and getting the proper symbols to display in the prompt for ‘dirty’ git repo.

    Also for whatever reason my cursor sits on the prompt not next to it.

    Any ideas what I missed — I read through all the comments and can’t see what I missed.

    https://www.dropbox.com/s/7f4woxnhhert4id/Screenshot%202014-01-29%2011.52.55.png
    and
    https://www.dropbox.com/s/u8ufn02fjuao554/Screenshot%202014-01-29%2011.57.30.png

Leave a Reply
Not required

CODE: Please escape code and wrap in <pre><code>, doing so will automatically syntax highlight