Love Your Terminal (blog.andrewhays.net)
I'm starting up a new blog about programming and productivity and the things that make my productivity better at my new job.
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.
136 comments
[ 3.2 ms ] story [ 169 ms ] threadMy desktop, however, doesn't use tmux right now. May be something that I look into in the near future because it looks interesting.
Even if you only use terminals, and you have to have a framebuffer that supports that native resolution of your screen, you'll find that Xorg is nearly always more performant.
If you have issues with X11's security model that's a different story, I'd suggest trying http://wayland.freedesktop.org/
(I do notice that within tmux on iterm, i can use the mouse for selection (using Alt), but the mouse does not work in tmux in xterm.)
Also, it doesn't happen frequently, but I have closed terminals which I didn't mean to. tmux/screen means that causes only minor inconvenience, compared to closing the terminal, opening it again, opening all tabs, dealing with swap files, re-running servers, dbconsoles etc.
This allows me to basically just type at any point `work foobar` and I'll either have a clean slate to start working on foobar, or I will be dropped into an existing tmux session 'foobar' that is exactly where I left off last time. Same 'tail -f'/'watch'es, same Vim sessions, same everything.
Besides regular units of work I usually keep a tmux session around just for database connections or the like, and another for messing around with environment stuff (dotfiles, ~/bin/, etc).
Most of this organization is stuff I used to do with virtual desktops, but I find tmux is wildly better suited for it.
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.
tmux for multiple screens instead of Xorg garbage? I think you don't know what Xorg is.
That doesn't make any sense. If you are referring to the screenshot, that's gnome-terminal's tabs.
http://pastie.org/5456546
How is using tmux to manage them is painful?
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.
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.
tmux(and screen) scrollback is absolutely fantastic. Navigate with keyboard(and not just page-up page-down), have vim or emacs bindings, search backward...
> I work on about 6 different machines on a regular basis and don't have the patience to mess around syncing my configs.
As I said elsewhere, it takes about 2 minutes to copy ssh keys and scp dotfiles.
How do you lose your configs? Store them in github/dropbox and sync.
> It also makes me more portable and productive when I am using a new or someone else's machine.
With dedicated work and personal laptops, using a new or someone else's machine isn't a commonly occurring event. I would rather optimize for what I have 99% of the time.
You don't do much work in large corporations I guess. When issued equipment and not having to much control you find it easier to just adapt, which is what I did.
I used to work for one. I still do but now I use my own laptop. But that's not the point. The point is if you have a machine, you don't need special privileges to write to your own home directory. If your org stops you from pulling things from the internet, well, that's a different story.
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.
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!
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?
You know what? I don't care any more. My computer is my computer. It does not need to work for other people and I don't need to work on other people's computers much. My Emacs loads many plugins, my Visual Studio is using ViEmu, I replaced my Finder and I remapped some keys on the keyboard.
This makes for a crazy confusing experience for anyone who sits down at my computer, but it works for me. And as far as compatibility is concerned, my Emacs init.el will automatically download and install all plugins it finds missing, so setting up a new computer is about as complex as copying one file.
Most of the configurations just need to be copied. Just copy your .vim folder and you are setup with everything. Copy your .screenrc and that's that. I sync my dotfiles and then run a small script to set symlinks. That hardly takes 2 minutes.
Servers are a different story, but the ones I work with are all running Linux and have vi, which will do.
http://dotfiles.github.com/
https://github.com/technicalpickles/homesick
Janus and oh-my-zsh were big for me, but I never actually installed either one.
Instead, those were my Vim and Zsh department stores.
I'd get the itch to try something new, so I'd "go shopping" at those projects, find something new to pull into my config, and I'd learn to use that plugin or make sure I knew what that shell option was now doing for me.
Then, eventually, I'd get the itch and go shopping again.
Over time, I built up my dotfiles. As I learned, I naturally found myself ditching some of the plugins I pulled in along the way, and modifying or replacing some of the shell config with my own creation. But those projects we're great sources of some early "wins".
https://github.com/loeschg/ascii-art
what have we done.
A couple of minor differences, otherwise exactly the same...
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).
What shell are you using? Probably bash, right? Well, stop it. Or don’t. Just know why you’re using the shell that you have.
I'm a bash user myself. I've tried zshell but didn't stick with it.
tmux on my local machine does me fine. And as loading tmux inside of tmux is pointless, I don't need to copy configs across.
though what I do have is a number of cheat sheets for each type of server, so I have copy and paste code (most of it is simple enough stuff, but sometimes having a visual reminder is helpful when you're up against tight, stressful, deadlines)
Or Clink - https://code.google.com/p/clink/
PS: There is also a somewhat extended version of Console2 here by a different author: https://github.com/cbucher/console which I like.
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.
I've never had a difficult time telling the difference between where my prompt ends and where the result begins. I think too much grows absurd quickly, but a little bit of information is nice, I think.
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:
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.
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!
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)
My general philosophy is to deal with whatever is the default and not become reliant on customisations because other systems I'll be required to use won't have any of them set up.
Unless you get new systems everyday, multiple systems just mean copying ssh keys followed by scp of dotfiles.
> some of which don't even have bash (let alone zsh),
If it has bash, .bashrc gets executed. If it has neither, I use the system default. Just because sometimes there won't be a shell I use or configure(1%) doesn't mean I am going to put up with whatever the system throws at me(99%).
> 'wi' is just there to remind me where I am once in a while.
Any my "once in a while" is frequent. Multiple machines, multiple projects, multiple branches.
> My general philosophy is to deal with whatever is the default and not become reliant on customisations because other systems I'll be required to use won't have any of them set up.
If I have customized my vim to hell, it generally means I am familiar enough with vim to understand how vim works. Same goes for bash, screen, zsh, what have you. It isn't like when once in an eternity, I am forced to use a machine where I have to type "git branch" instead of "gitb", I am going to forget it.
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.
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.
The fact that my prompt shows additional information is a secondary thing. (It's sometimes nice to scroll back through output and be able to see what directory I was in.) The _important_ thing is that the color and extra space make it exceedingly easy to visually chunk commands and output.
Just something I could run if I switched back to a shell and kinda forgot what or where it was.
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`
[1] - https://github.com/sorin-ionescu/prezto
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.
EDIT: I'm using urxvt btw
sudo chmod ugo-x /usr/libexec/path_helper
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.
http://serverfault.com/q/48769
http://serverfault.com/q/241154
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).
https://github.com/daGrevis/Dotfiles
P.S. If you start to change dotfiles yourself, you won't be able to stop.
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.
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 ;-)
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
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
Check it out :)
https://github.com/Goles/Battery
Linux support is on the roadmap, I would need some beta-testers though
And there's all the other cruft removal.
[1] http://ridiculousfish.com/shell/
Also, note that you can easily copy across your bash settings using:
/usr/local/share/fish/tools/import_bash_settings.py < ~/.bashrc
(from http://ridiculousfish.com/shell/faq.html )
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.
: 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.)
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.
Maybe I will have to run a linux distro in order to share the love.
I'm kind of naive - I figured every application run within command line (not terminal) was restricted to a specific 256 palette.