11 ms·
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.
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.
- kecebongsoft 14y agoIn 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 14y ago> using only tmux to manage them is painful and ugly: How is using tmux to manage them is painful?
- jlgreco 14y agoI'm wondering that too. Tmux enables a hell of a lot more than just panes/windows, and looks pretty spiffy while doing it I think. A terminal with no menubars or chrome with tmux inside it is the most elegant, adaptable, and capable configuration I've ever had the pleasure to use.
- kecebongsoft 14y agoIf 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 14y ago> 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.
- jff 14y agotmux turns scrollback from "pretty simple" on a stock xterm or other terminal, to "absolute goddamn bullshit". That, combined with the fact that I quite like using "^b" to move my cursor around, means I don't use tmux as much as I possibly should. Yes, I know I could fix the ^b problem in a config file, but as I've said elsewhere, I work on about 6 different machines on a regular basis and don't have the patience to mess around syncing my configs.
- irahul 14y ago> tmux turns scrollback from "pretty simple" on a stock xterm or other terminal, to "absolute goddamn bullshit" 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.
- Derpsec 14y agouse tmux for multiple screens and ditch that xorg garbage.
- Dru89 14y agothat first screenshot is actually just pulled from the internet. the third one (it was broken at first, then I fixed it) is from my laptop. My desktop, however, doesn't use tmux right now. May be something that I look into in the near future because it looks interesting.
- jameyc 14y agoSince you're on osx, you might look into iTerm2, which wraps tmux nicely and brings a few bells and whistles to the table.
- richo 14y agoCalling Xorg garbage is naive. 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/ http://wayland.freedesktop.org/
- jlgreco 14y agoUsing tmux in an X terminal emulator really gets you the best of all worlds. Good mouse support, performant as you mention, and if X really starts to give you hassle for some reason you can always seamlessly continue working in a VT or with putty if you really want to.
- crazydiamond 14y agoCould someone elaborate how x11/xterm compares to iTerm2? I've been using tmux in iTerm. After reading this discussion, i installed x11 and quartz-wm. Why would I switch to X11 ? (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.)
- downey 14y ago"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
- dirkk0 14y agoThat's another neat trick I found useful - add a seperator between your commands: http://lifehacker.com/5840450/add-a-handy-separator-between-commands-in-your-terminal-on-mac-os-x-and-linux http://lifehacker.com/5840450/add-a-handy-separator-between-...
- rewtraw 14y agoAnyone have something similar for zsh? I can't seem to get it to work with my current prompt. http://pastie.org/5456546 http://pastie.org/5456546
- wonnage 14y agoCool 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.
- Dru89 14y agoThat's a good tip. I try to keep my .vimrc down to about 20 lines and a couple of plugins (NERDTree and solarized, mostly). My .zshrc is probably a bit more dense, but I actually have it orgnized into separate files, and just source them from .zshrc.
- boyter 14y agoThat'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.
- irahul 14y ago> losing my config's was too painful. 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.
- boyter 14y agoBeing lazy usually. Also a mixture of devices and machines long before dropbox. So I became used to the defaults before there was a good solution to sync. 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.
- irahul 14y ago
- loeschg 14y agoJust 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 https://github.com/loeschg/ascii-art
- flexd 14y agoYou could kick that up a notch with something I just threw together. http://npmjs.org/motd http://npmjs.org/motd :)
- carlisle_ 14y agoYet another article proclaiming bash as garbage and zsh as the best thing since sliced bread.
- viseztrance 14y agoMy thoughts exactly. Everything mentioned there is just as doable in bash.
- aes256 14y agoHe referred readers to the Wikipedia comparison page, so I went there and duly compared bash to zsh in all the comparison tables. A couple of minor differences, otherwise exactly the same...
- Dru89 14y agoI 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 14y agoBash is ugly and horrible but I know it well and have bad Stockholm syndrome so it's too late.
- chanux 14y agoHe did put it in a 'mild enough' way though. 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.
- Firehed 14y agoMeh. I use bash on my laptop and zsh on my VM, and barely notice a difference between the two other than my different prompt. That tells me I'm not getting the most out of it, but it also tells me that the out-of-the-box improvements are pretty minimal. Given how many machines I need to attempt to keep my customizations in sync across (git is barely an option, let alone something like dropbox - this is inside a PCI Level 1 environment), stuff that requires a ton of plugins to really be useful is typically more trouble than its worth. Simply managing my SSH keys is bad enough.
- ogrim 14y agoI 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.
- positr0n 14y agoI use cygwin with screen (no tmux on windows sadly), vim, and a smattering of grep/sed/awk/etc.
- shocks 14y agoCygwin, with mintty and all the trimmings. Or Clink - https://code.google.com/p/clink/ https://code.google.com/p/clink/
- bjourne 14y agoI'm using Console2 (http://www.hanselman.com/blog/Console2ABetterWindowsCommandPrompt.aspx http://www.hanselman.com/blog/Console2ABetterWindowsCommandP...) and Powershell. Not as nice as a real Linux environment, but Console2 has tabs which makes it bearable.
- shadowfox 14y agoBesides Console2 mentioned in another comment, there is also ConEmu (https://code.google.com/p/conemu-maximus5/ https://code.google.com/p/conemu-maximus5/), which incidentally has support for Clink (again mentioned in another comment!) PS: There is also a somewhat extended version of Console2 here by a different author: https://github.com/cbucher/console https://github.com/cbucher/console which I like.
- philfreo 14y agoThis 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.
- jff 14y agoIf 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.
- vacri 14y agoA friend of mine has an extremely simple prompt. It just shows as $ or # (for root) and has a single field before that - the exit status of the previous command.
- masklinn 14y agoStill way too complex, simplicity means subscribing to the ed school of prompts: neither `$` nor `#`, just `?` when the previous command returned a non-zero status.
- Dru89 14y agoI understand using that because it was what you had, but why would you choose to strip your prompt of useful information? (I'm not trying to degrade the idea here, just wondering what use case it provides. It could have a very good one.) 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.
- irahul 14y ago> 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.
- irahul 14y agoWhatever the terminal you are using, configure it so that it doesn't eat your alt/ctrl key and then learn readline bindings.
- j-kidd 14y agoKinda 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 14y ago> 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`
- vially 14y agoprezto [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 https://github.com/sorin-ionescu/prezto
- wildranter 14y agoIs 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 14y agoSeems 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
- purge 14y agoBe sure to read the documentation when installing zprezto on OSX. If you don't run the following, your PATH will be screwed up. sudo chmod ugo-x /usr/libexec/path_helper
- idupree 14y ago"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 14y agoMine is set _somewhat_ ridiculously large. Just not that large. And it seems like it just gets to be obscene at some point.
- pooriaazimi 14y agoYou're probably aware of it, but anyway... Put HISTCONTROL='ignoreboth:erasedups' In your .bashrc - now duplicate commands (two consecutive commands that were the same) are not included in HISTFILE, and also if you type " some-sensitive-command username password host" (note the extra space at the beginning), they too won't be include in HISTFILE. http://serverfault.com/q/48769 http://serverfault.com/q/48769 http://serverfault.com/q/241154 http://serverfault.com/q/241154
- skriticos2 14y agoI 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 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).
- daGrevis 14y agoI'm maniac with this so called system configuration. Just take a look on my _.vimrc_, for example. :) https://github.com/daGrevis/Dotfiles https://github.com/daGrevis/Dotfiles P.S. If you start to change dotfiles yourself, you won't be able to stop.
- pjmlp 14y agoNice 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 14y agoSecond 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.
- zobzu 14y agoYA 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 ;-)
- laumars 14y agoI'm largely the same. The only terminal app I did play around with the configs for was tmux because I really hated the defaults on that. And as I only ever need to run tmux from my client PC (it's a bit pointless running tmux inside of tmux), i don't have to arse about with copying config files about.
- adimitrov 14y agoYup. 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 http://a-dimit.blogspot.de/2010/12/perfect-prompt.html
- Arelius 14y agoI 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.
- joshuahornby 14y agoI 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 14y agoI 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 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 14y agobrilliant. Thank you
- tambourine_man 14y agohttp://news.ycombinator.com/item?id=4839877 http://news.ycombinator.com/item?id=4839877
- MrGando 14y agoI 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 https://github.com/Goles/Battery
- theskumar 14y agoWould have loved it, if worked on linux too.
- MrGando 14y agoYou can always pull request on it. Linux support is on the roadmap, I would need some beta-testers though
- jff 14y agoYou 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 14y agoWill add Linux support asap :)
- shurane 14y agoThere's also `acpi -b`, which I think is available on most linux distros.
- jff 14y agoIt'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.
- Symmetry 14y agoThis 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/ http://ridiculousfish.com/shell/
- Osmium 14y agoI'd just like to second this. Though bear in mind that many things assume you're running bash on OS X, e.g. the homebrew installation one-liner doesn't work with fish. 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 http://ridiculousfish.com/shell/faq.html )
- laumars 14y agoI'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 14y agoFish is not a POSIX shell. For example, instead of $? there is $status.
- LiveTheDream 14y agoI'm not familiar with fish, but highlighting search phrases from grep is a standard grep option (`--color`, or `--color=auto`)
- jedahan 14y agoYou can get fish syntax highlighting in zsh by installing zsh-syntax-highlighting ( https://github.com/zsh-users/zsh-syntax-highlighting https://github.com/zsh-users/zsh-syntax-highlighting ). I prefer just enabling it in prezto though (which is a fork of oh-my-zsh that is a lot lighter weight and more modular https://github.com/sorin-ionescu/prezto https://github.com/sorin-ionescu/prezto )
- xyzzyb 14y agoThe best prompt I've found for zsh is agnoster. I highly recommend it: https://gist.github.com/3712874 https://gist.github.com/3712874
- kps 14y agoThe 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.)
- jff 14y agoThis is the best post in the thread so far. I use ";" as a prompt sometimes, because it makes copy-paste easy (like you mention, just triple-click), but I often like to keep track of what directory I'm in. I typically just leave my prompt alone because I work on so many different machines, but this is pretty slick and simple.
- irahul 14y ago> 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.
- JimmaDaRustla 14y agoI 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 14y agoActually, applications can control colors in the same way over SSH as they can on a local distro.
- JimmaDaRustla 14y agoSo, 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 14y agoSSH doesn't care about colours. You can use the colours of whatever terminal emulator you're using.
- jfb 14y agoI so dearly wish I didn't have to.
- wting 14y agoI'm going to plug a small CLI program I maintain -- autojump: https://github.com/joelthelion/autojump/#name 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 14y agoThis 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.
- ddunkin 14y agoGet crazy with your colors too, random and fashionable vim/emacs/textmate themes here: http://sweyla.com/themes/ http://sweyla.com/themes/
- stevenspasbo 14y agoHere'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"`