

Love Your Terminal - Dru89
http://blog.andrewhays.net/love-your-terminal
I'm starting up a new blog about programming and productivity and the things that make my productivity better at my new job.<p>This particular post is about getting my terminal perfect for me.  I've been using these settings for about a week and I can feel everything getting easier.  Most of my work that isn't answering emails and going to meetings involves me using a terminal. Between vim and a set of zsh commands, my terminal becomes my best friend.
======
zobzu
YA post about making fancy prompts - at least its not about how to make a ssh
tunnel ;-)

Personally I'm never using anything, or adding any fancy setting, if it
doesn't serve any direct purpose and/or is not clear, simple and efficient.

It's not because I believe "simple" and "efficient" are "cool" or "better".
It's just because it's always what made _me_ efficient. I don't lose much time
digging configs either, and I scan man's pretty quickly every time I need
something.

In the end that means my shell looks boring. White on black. Username, host,
current directory, VCS info if any. Colored output for tools that support it
in a sane fashion. Merged shell history. That's it.

Defaults are in general sane. That's why they're defaults after all. Oh and
redoing my dotfile is ~ 2min from memory and work everywhere obviously. I
don't need to care if I'm going to spin a VM, it'll work the way I expect it
without having to copy stuff and tinker around.

I do the same for the gui so i generally just run KDE or MATE. Tinkering 3
days with awesomewm or using someone's "super cool" but useless configs..
nope, not my thing ;-)

~~~
adimitrov
Yup. Everybody and their dog want fancy prompts with lots and lots of info,
and I never understood why. Most of the time I don't need _any_ information on
my bloody prompt. I just need it to sit there and alert me if something is
unusual, maybe, but not to get into my hair otherwise.

A couple of years ago I settled on one minimalist prompt, and I've used it
ever since. I've even written my own post about fancy prompts[1] … I guess
everybody has to have one!

[1] <http://a-dimit.blogspot.de/2010/12/perfect-prompt.html>

~~~
Arelius
I agree. In fact, reading your post, I'd nearly call your prompt fancy, mine
just tells me user, and directory, everything else I'll runn a command for.

------
wonnage
Cool guide. For beginners I'd also suggest restraint with your dotfiles. It's
easy to rush into installing oh-my-zsh and using vim with every plugin you can
find, but I found that made for a really confusing learning experience,
especially if your config ever breaks.

~~~
boyter
That's actually why I stopped tweaking things to hell and back, losing my
config's was too painful. I usually just go for basic colour tweaks these
days. It also makes me more portable and productive when I am using a new or
someone else's machine.

~~~
h2s
I used to take this approach. One day I found I had no choice but to remap
CapsLock as a second Ctrl key because my little finger was in constant agony
otherwise.

I've never had a second's trouble from the finger since then, but you should
see me try to type on other peoples' computers now. I TEND TO WRITE IN ALL-
CAPS A LOT BY ACCIDENT!

So for me there's no longer much point in caring about portability, and I have
aliases and keyboard shortcuts and fancy PS1s to spare.

~~~
tammer
I've run into the same issues. My solution is to reach a sort of balance
between portability and usability.

My xmodmap + XMonad config is designed to be reproducible on Windows via
AutoHotkey and OS X via SizeUp + PCKeyboardHack, that way I'm always in my
home environment no matter the OS!

~~~
gridaphobe
How do you handle window-switching on OSX? I haven't found anything that
satisfactorily reproduces the simple mod-j/k keys of xmonad.

~~~
tammer
I'm not on a Mac at the moment so I can't tell you the exact wording of the
preference, but I just set it up through the hotkeys section of the keyboard
system preferences pane.

One of the options allows switching window focus, and another allows switching
through windows in the active application. There's no option for switching
backwards, however. The way I deal with that is to separate any xmonad
specific functionality behind a prefix-key submap in my XMonad config.

Any hotkeys that don't take the prefix I can use on any OS, the ones that do
are xmoand specific. To me this keeps things nice and organized, while still
letting me exploit the xmonad-contrib stuff to the full extent.

For example, instead of mod-j/mod-k, I use the window navigation extension
behind the prefix so I get finer control over focus navigation, _and_ this
makes xmonad function precisely like tmux just with a different prefix key.

Can you tell I hate context switching?

------
jff
If you're using git, I suggest fixing up your prompts so it doesn't display
the sign for Mercury when in a git repo.

So much junk in a prompt... I clicked on the link to Steve Losh's page and had
a heck of a time figuring out what commands he had actually typed.

The bash defaults are pretty reasonable: show your working directory, maybe
your username, and a $ to end the prompt. If you're root, you get a # instead.
It stays out of the way; if you want to get fancy, colorize it so lines you
entered stand out. These days, I even turn off ls's colorizing half the time;
then again, I always thought wibbley-wobbley 3d windows with glowing buttons
were a little silly compared to, say, FVWM or i3.

~~~
irahul
> So much junk in a prompt... I clicked on the link to Steve Losh's page and
> had a heck of a time figuring out what commands he had actually typed

The point of configuring your prompt is it has to be easy for you to read.
Whether someone else finds it readable or not is a non issue. Though not as
verbose as Steve Losh's, I use a similar prompt which looks like this:

    
    
        rahul@mean-machine: ~/musings (git::master)
        ± $
    

There is nothing in that prompt which I would remove. I login on different
hosts with different usernames(rahul@mean-machine); working directory is
obvious; I use git, svn, hg and switch branches a lot(git::master).

Of course why do I need rahul@mean-machine - I can run 'who' and 'hostname',
why do I need working directory - it's not like 'pwd' hasn't been invented
yet; why would I need the branch name - 'git branch' is where it is at. But
"if there is this painful long way you can do it, why would you do it the easy
way" doesn't make sense to me.

> These days, I even turn off ls's colorizing half the time;

I am curious. What purpose that solves? Colorizing it helps me differentiate
directories, files, executables, broken links.

> then again, I always thought wibbley-wobbley 3d windows with glowing buttons
> were a little silly compared to, say, FVWM or i3.

I don't think 'ls --color=auto' is comparable to woobly window.

~~~
Nursie
A whole extra line above the working prompt? That just seems unnecessary.

If you need that info at any particular moment, make a command. I used to have
one called wi (short for Where am I?) that threw out similar info. But
displayed constantly? Yuck!

~~~
masklinn
> A whole extra line above the working prompt?

Because it's frequently useful, and thus the tradeoff of a bit of space for
simplicity, speed and familiarity is worth it.

> If you need that info at any particular moment, make a command.

Right, so your prompt is composed of nothing but the hardcoded character `>`?
(you obviously don't need the $/# toggle as you can use `whoami`, and you
don't need the previous command's status as that's what `$?` is for)

~~~
columbo
> Right, so your prompt is composed of nothing but the hardcoded character `>`

Hey that's what mine is! Actually it is simply the ')' character. I went from
full on prompt-porn to nothing. For the most part this was just to see how
much of the prompt I really needed on a daily basis (how often do I really
type git branch because I don't know what branch I'm on, how often do I type
pwd... stuff like that). Turns out I rarely use those commands, but to each
their own.

~~~
ansgri
It's an interesting approach! I want to try it in combination with some custom
1-or 2-letter command that would display all this 'prompt-porn' in a single
line on demand.

Maybe a 1 or 2-letter indicator on what host I am (e.g. nothing for local, P
for production, C for cluster head...), got confused too often.

And, of course, fuzzy completions of zsh.

------
Symmetry
This seems like a good place to once again plug fish[1]. Exactly those goodies
I want in a shell and the autocomplete is so convenient I no longer know how I
lived without it.

And there's all the other cruft removal.

[1] <http://ridiculousfish.com/shell/>

~~~
laumars
I've just installed fish and it doesn't support bang (!) history nor some
basic scripting tools (eg $?) which makes it pretty useless for power users.

I can see how the colours and suggestions are great to those who are new to
the command line though and there were some cool features (eg highlight search
phrases from grep). But most of that stuff is just emphasising stuff you'd
learn to spot anyway, after using the CLI for years.

So as cool as it is, I really would find it more of a hindrance than a help.

~~~
qznc
Fish is not a POSIX shell. For example, instead of $? there is $status.

------
carlisle_
Yet another article proclaiming bash as garbage and zsh as the best thing
since sliced bread.

~~~
Dru89
I used bash for years, I was just forced into zsh at work and loved it.

Bash is fine, but I didn't know any of its intricacies. I'm not saying don't
use bash. I'm saying don't use bash without learning about how to make it work
for you (and probably trying other things).

~~~
steve-howard
Bash is ugly and horrible but I know it well and have bad Stockholm syndrome
so it's too late.

------
kps
The prompt style I use was invented, IIRC, by one of the Bell Labs Unix guys
in the early days of windowing terminals.

: _text_ ;

Why? Because you can select entire lines (triple-click in most terminal
emulators) and paste them directly into another shell. “:” is equivalent to
true(1), and it ignores its arguments, the _text_.

(In my case, the _text_ is the base of the host name, but anything compatible
with shell quoting rules will work.)

~~~
irahul
> The prompt style I use was invented, IIRC, by one of the Bell Labs Unix guys
> in the early days of windowing terminals. : text;

My prompt is two lines. The first line is info line followed by $ prompt on
the next line. If I were so inclined, I would simply change the $ to ; or
blank. I don't have to choose only one of them, but if that were the case, the
verbose prompt would have stayed and ; would have gotten the boot.

------
dirkk0
That's another neat trick I found useful - add a seperator between your
commands: [http://lifehacker.com/5840450/add-a-handy-separator-
between-...](http://lifehacker.com/5840450/add-a-handy-separator-between-
commands-in-your-terminal-on-mac-os-x-and-linux)

~~~
rewtraw
Anyone have something similar for zsh? I can't seem to get it to work with my
current prompt.

<http://pastie.org/5456546>

------
loeschg
Just spent some time putting some Star Wars in my terminal greeting. In case
anyone is interested, I threw a .sh and .txt up at github :)

<https://github.com/loeschg/ascii-art>

~~~
flexd
You could kick that up a notch with something I just threw together.
<http://npmjs.org/motd> :)

~~~
mh-
If you told me 10 years ago that people would be auto-executing JavaScript
upon SSHing to a server..

 _what have we done._

~~~
flexd
Haha, true. I do not actually use it at the moment either, I just figured it
could be fun.

------
philfreo
This is more of a git tip... but you should probably change your "ggpnp" alias
to use "pull --rebase" instead of "pull" to avoid an unnecessary merge commit
in your history.

------
skriticos2
I also spend most of my time in the terminal, but actually quit little in the
shell.

Most of my time I'm in Vim, editing code, so most of the configuration is
there (though I keep it down to ~ 50 lines), minor tweaks now and then.

my vimrc: <http://ubuntuone.com/4wmrwsU64KEgj9S0zEH3Ct>

My latest configuration add-on is syncing my config files when they change. I
just do a hardlink (same inode) to my Ubuntu One folder (on system setup). Now
if I change a configuration, it get's synced to my all my other devices when
they are next online.

I found that quite useful. Syncing vimrc, gitconfig, vimprojects and some
other. Basically only use my machines as cache. With this I can get up to be
productive with a new installation very quickly and work with several machines
without configuration miss-match headache.

For sources I use git push to a remote server (+ U1 for convenience, but it's
inconsistent while syncing multiple files, so bad for push target).

------
irahul
Whatever the terminal you are using, configure it so that it doesn't eat your
alt/ctrl key and then learn readline bindings.

~~~
j-kidd
Kinda weird that the author mentions Ctrl-R but not readline. History
searching actually works for everything that supports readline, e.g. bash,
ipython, psql, henplus, etc, although personally I use page-up / page-down
with:

    
    
        "\e[5~": history-search-backward
        "\e[6~": history-search-forward
    

The terminal experience becomes crappy when there is no readline support, e.g.
everything on Windows, sqlplus, db2, etc. When there is no readline, I really
can't love the terminal.

~~~
irahul
> I use page-up / page-down with

I use ctrl-r because it is easier to type.

> experience becomes crappy when there is no readline support, e.g. everything
> on Windows, sqlplus, db2, etc.

If you have rlwrap, you can generally do `rlwrap -r app-that-doesn't-play-
well`

------
kecebongsoft
In my scenario, I have to work on several tabs and splits for one topic/work
(say it's Python work), and I usually have 2-3 topics in a day (office
related, playing around, and maybe side-project stuff). I'm using tmux, and I
tend to have 2-3 tabs for each topic, using only tmux to manage them is
painful and ugly: there's too many tabs in the current display, and the
default gnome terminal doesn't mix with the looks of everything else. So I'm
using urxvt to manage the tabs, it's fast (sometimes I love verbosity), it can
handle tabs beautifully, highly customizable, and the default shortcuts are
good.

~~~
irahul
> using only tmux to manage them is painful and ugly:

How is using tmux to manage them is painful?

~~~
kecebongsoft
If say I have 2 topics with 3 tabs each, and I want to switch to different
topic, I need to move to the 4th tab either by switching tab few times, or
knowing the index of the tab to get a faster shortcut. Both, in my opinion,
are not simple.

If I combine tmux with urxvt, I can have 3 tmux tabs in a urxvt tab, and
another 3 tmux tabs in second urxvt tab, and I can switch context just by
pressit shift+left/right, I can also easily realign context with
ctrl+left/right.

tmux is awesome, but in my case, it's not so awesome when I have to handle
many tabs with totally different context, which is why I combined it with
urxvt.

~~~
irahul
> If I combine tmux with urxvt, I can have 3 tmux tabs in a urxvt tab, and
> another 3 tmux tabs in second urxvt tab, and I can switch context just by
> pressit shift+left/right, I can also easily realign context with
> ctrl+left/right.

I see what you mean. Generally I open a new urxvt/terminator for a new
grouping. A rails project is in its own terminal, a django project in another.

> I need to move to the 4th tab either by switching tab few times, or knowing
> the index of the tab to get a faster shortcut. Both, in my opinion, are not
> simple.

I have this in my conf:

unbind '"' bind '"' choose-window

I generally have more than 10 tmux windows open. Either I know which index is
which(rails project - 0 is vim, 1 is server, 2 is console, 3 is dbconsole, 4
is tail logs, 5 is for running tests...), or I select the windows. Switching
tabs few times isn't an ideal way to switch to the desired window.

> which is why I combined it with urxvt.

urxvt has tabs? Mine doesn't. Anyway I have moved to terminator. I find it
easier to configure(the pains I took to configure urxvt for copy-paste),
performant and standard compliant.

------
MrGando
I wrote a little script to display the battery status (in a nice format) that
should work on Bash & ZSH. I use it on my Tmux bar too...

Check it out :)

<https://github.com/Goles/Battery>

~~~
theskumar
Would have loved it, if worked on linux too.

~~~
MrGando
You can always pull request on it.

Linux support is on the roadmap, I would need some beta-testers though

~~~
jff
You can check Linux battery status by just reading from a certain file
somewhere under /proc; being Linux, I'm certain there's an equivalent buried
somewhere in /sys as well. You just read the file, it gives you back ASCII
text, you're all set.

~~~
MrGando
Will add Linux support asap :)

~~~
shurane
There's also `acpi -b`, which I think is available on most linux distros.

~~~
jff
It's not necessarily installed by default, though. If your Linux system can
read the battery with acpi, it _will_ show up in /sys. Although the 'acpi'
program is convenient, it adds another dependency. Also, if you run 'acpi'
under strace, you'll see that it just opens up /sys/class/power_supply and
parses files under that.

------
wting
I'm going to plug a small CLI program I maintain -- autojump:
<https://github.com/joelthelion/autojump/#name>

It tracks which directories used most often so you can simply use `j <dir>` to
jump to that directory rather than type / tab-complete the full path name. It
also does some fuzzy matching for mistyped names. For example:

    
    
        ~ $ j au
        ~/code/autojump $ j donw
        ~/Download $ j scra
        /scratch/03158/wting $

~~~
yunong
This plugin is great. I'd definitely recommend others to check it out. It's
been a boon to my productivity since I've discovered it.

------
downey
"Art for Art’s sake is an empty phrase. Art for the sake of code, art for the
sake of the terminal and the OS, that is the faith I am searching for." -
Salvador Dali

------
idupree
"While $HISTORY is great, it only retails a certain amount of data."

Unless you have HISTSIZE=100000000; SAVEHIST=100000000 or some such nonsense (
_-hides-_ ). Using Ctrl-R for history doesn't seem to be slowed down at all by
my huge histfile. There are privacy implications if you're hacked/subpoenaed,
but it's hella convenient.

~~~
Dru89
Mine is set _somewhat_ ridiculously large. Just not that large. And it seems
like it just gets to be obscene at some point.

~~~
jlgreco
Every few months I wipe out all of the `ls`, `clear`, `cd` and similar entries
from my history file. Usually knocks the size down by a decent double-digit
percentage.

~~~
netfeed
the history size becomes a bit smaller if you add: export
HISTCONTROL="ignoredups"

------
daGrevis
I'm maniac with this so called system configuration. Just take a look on my
_.vimrc_, for example. :)

<https://github.com/daGrevis/Dotfiles>

P.S. If you start to change dotfiles yourself, you won't be able to stop.

------
pjmlp
Nice guide.

For those on Windows, just move to Powershell if you are still using the plain
old terminal.

Sure it can be a bit verbose, but it is surely way better, specially for the
cases when doing Windows specific projects.

~~~
mrcrassic
Second to this, I don't recommend using the built-in script editor. It's slow
as all hell and not that helpful when learning how to write your first
scripts. Instead, I recommend the Script Editor that comes with PowerGUI. It
has IntelliSense (sort of), which is kind of a crutch in the beginning but
displays the sheer amount of power Powershell has.

------
vially
prezto [1] is a nice alternative to oh-my-zsh. I find it to be faster and it's
more modular.

[1] - <https://github.com/sorin-ionescu/prezto>

~~~
wildranter
Is it working properly now? Last time I've tried it I had to go back to oh-my-
zsh because prezto screwed my terminal.

By the way, one of these days debugging the slow startup time of oh-my-zsh I
found the culprit, virtualenvwrapper. Again I didn't have the time to good
deep into that, so I just edited out that line from my .zshrc.

~~~
vially
Seems to be using properly for me. I've been using it for a month now and I
didn't have any issues with it. But that may be because I'm only using the
basic plugins which are enabled by default, nothing fancy.

EDIT: I'm using urxvt btw

------
JimmaDaRustla
I typically SSH into my boxes, but it isn't really a shell - you don't have
dynamic fonts/colors per application and stuck to 256 colors.

Maybe I will have to run a linux distro in order to share the love.

~~~
mintplant
Actually, applications can control colors in the same way over SSH as they can
on a local distro.

~~~
JimmaDaRustla
So, would my SSH client just map the colors to the closest available one in
its' palette?

I'm kind of naive - I figured every application run within command line (not
terminal) was restricted to a specific 256 palette.

~~~
danellis
SSH doesn't care about colours. You can use the colours of whatever terminal
emulator you're using.

------
joshuahornby
I am just starting out and what to learn how to get the most out of my
terminal. I have zsh installed what is the best site/book in learning how to
unlock its full power?

~~~
alanctgardner2
I would recommend getting used to BASH first if you're just starting out. Some
people here are zsh zealots, but if you plan to work on remote systems, you're
going to encounter BASH. You'll also appreciate whatever fancy benefits zsh
offers more.

<http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html>

A good start for leveraging common bash features. You'll find a lot of the
ckncepts , if not syntax, useful in any *sh

~~~
joshuahornby
brilliant. Thank you

------
ddunkin
Get crazy with your colors too, random and fashionable vim/emacs/textmate
themes here: <http://sweyla.com/themes/>

------
xyzzyb
The best prompt I've found for zsh is agnoster. I highly recommend it:
<https://gist.github.com/3712874>

------
stevenspasbo
Here's a fun tip: If you want to have an awesome lightening bolt (⚡) instead
of a boring $ in your prompt, put this in your PS1 environment variable:

`echo -e "\xE2\x9A\xA1\x03"`

------
ogrim
I am curious what terminal people use on Windows. I find MSYS to be very good,
since it lets me work just as I would on Linux with Emacs-style editing.

~~~
shocks
Cygwin, with mintty and all the trimmings.

Or Clink - <https://code.google.com/p/clink/>

~~~
ogrim
Clink is just what I need for those times I ahve to use cmd.exe - thank you
for the tip!

~~~
shocks
Thank my brother, he's the author! :)

------
tambourine_man
<http://news.ycombinator.com/item?id=4839877>

------
jfb
I so dearly wish I didn't have to.

------
Derpsec
use tmux for multiple screens and ditch that xorg garbage.

~~~
__david__
I don't understand why I'd want to use tmux locally. I'm a huge believer in
tmux on remote machines though. Why would I want to use it on my local laptop?

~~~
Spakman
I've only ever seen people advocate for tmux locally who can't (or don't want
to) run something like xmonad as their window manager.

~~~
th
I would recommend a primarily tmux-based workflow unless you use a number of
graphical programs that benefit greatly from the tiling paradigm.

I used to use Xmonad with tmux (and still do sometimes). I primarily use Unity
with tmux now. I came to the realization that tmux had nearly nullified my
need for a tiling window manager after I switched from gVim to terminal vim
and noticing how much easier it made my workflow. My "ah ha" moment was the
discovery of the distinction between sessions, windows, and panes and how each
could interact with (or sometimes transform into) the each other.

