Les tribulations d'un octet

← revenir au blog


pimp your shell

Attention cet article à plus de 3 ans ! Les informations peuvent ne plus être d'actualité et les liens peuvent être cassé.

Why should you pimp your shell ? Because it's a tool and as a tool it should fit your needs ! Today, I'll talk about how I configure my shell so that I become more efficient.

I won't present all the things that exist to pimp your shell or tell you what to use. Your shell is your tool and should fit to your needs. I'll present my own choices over time.

What do I need?

The first question I asked myself was "What do I want to do with my shell?".

First thing I did was to find the coolest software and commands for my shell. I downloaded many shell programs: email reader, rss reader, irc chat, weather updates, vim and even a facebook chat! I looked at the Ubuntu list to find stuff. I found really useful programs that I'll tell you about.

But a better first question actually would be "What do I really do with my shell ?". That's because realized that I added lots of stuff that I used only once, just because… I didn't need it !

Vim or Emacs ?

I was surprised to discover that the only right question about the shell was this one ! As if shell didn't evolve since 90's. Those two programs left a huge mark into modern shell system and you will find out that every shell program has to choose between Emacs and vim mechanisms.

I feel more comfortable with vim. Not that it is better than Emacs, but I just learnt vim earlier than Emacs so I prefer to use Vim. In addition, you will see that many programs I use are in vim style. It makes a coherent environment to work with. (yes, I'm exactly talking about hjkl !)

other office and media tools

I used other office tools as cal for calendar (It's all I need, no more), Ranger as a file browser (imagine the Mac Finder for a shell, you got it !) and VLC to play music (if you would like to use vlc to play music and video in your shell, you will have to activate the ncurse vlc interface). In order to use IRC I tried irssi.

While I discover new shell tools, I found out that what I'm looking for is not tools but environment ! Indeed, I know that a tool exists and I will have the set I need to work in a console but I was tired to have a case sensitive auto-completion and a black and white shell !

Let's find the good frame to work with

Here start for me a long journey in the wondershellland. I have been using a stable shell environment for one year now but I had tried many many things before using it. By stable, I mean that the big idea will not change, But some little things change all the time to fit with my attempt and projects.

One shell to rule them all

As anyone who begins with a shell, I use bash. One of the most famous GNU software that you will find on almost every Linux distribution as standard shell. many users still use bash and sysadmin know that they will use bash because it's ready out of the box and it's a powerful universal scripting language.

In order to fit my personal use of the shell (maintenance, coding, music, file management), I looked for existing shell programs and I found lots of them !

  • bash : It's a part of the GNU project. One of the mainstream and one of the most powerful shell. It's easy to have a working and powerful environment with it, but it is not enough for me. It doesn't accept plugins and doesn't have git integration. Most of the time, bash needs hours of configuration to have access to advanced features.
  • ash : forked from bash, it's a minimal POSIX shell.
  • sh : original UNIX shell by Mr. Bourne.
  • fish : Friendly Interactive Shell. The idea of that shell is to learn from you. what do you use the most, what will you type, ... etc. It also provide more advanced functions, features and configuration possibilities, we will talk about it later.
  • zsh : As fish, it provides lots of useful features as advanced auto-completion features, colours, advanced function system and even right information panel.
  • etc... There exists many other shells, you should have a look at others lists if you want to find out how many ;).

I started with zsh. I spent too much time to configure it before I discovered oh-my-zsh. An out of the box script for an every day use of zsh with themes and plug-ins. It makes zsh one of the most good looking and pleasant shells to use. As an example, with zsh (and fish too) you can forget 'cd', if your command is a folder, it finds out by itself that you want to change your directory. Also forget about black and white shell, even the auto-completion is in colour ! As with fish, you have a man page auto-completion and many other features that make your shell friendly.

I switched to fish because it's really more friendly and faster than zsh. Zsh is more than powerful and I really had fun with it but with time and scripts it began to become slow, really slow ! Fish is more reactive.

As for zsh it exists oh-my-fish that brings to you a plug-in and a theme manager. Here is what I use as my fishrc :

# Load oh-my-fish configuration.
. $fish_path/oh-my-fish.fish

# Theme
Theme "agnoster"

Plugin "android-sdk"
Plugin "archlinux"
Plugin "ccache"
Plugin "node"
Plugin "ndenv"
Plugin "php"
Plugin "tmux"
Plugin "git-flow"
Plugin "grc"
Plugin "ssh"
Plugin "gi"
Plugin "extract"
Plugin "vundle"
Plugin "composer"
Plugin "balias"

alias cafe='cat /dev/urandom | hexdump -C | grep "ca fe"'

function fuck
    eval (thefuck $history[1])
end

And that's all ! no complicated things to write nor functions to remember to have convenient results. It makes the job much easier. Now I have colours, good completion (with a search tool into completion results) and many features as git integration, advanced extract function or android tools integration.

shell multiplexer

I got tired of always having to switch between tabs and windows. It happens a lot when using Firefox, I open dozen of tabs and get lost into it. It was common for me to see five or more terminal windows and spend time switching between them just to find which one I wanted to use.

There is a program to get rid of that problem: the terminal multiplexer, or terminal windows manager.

A terminal window manager/multiplexer emulates a terminal for you. That way, It provides many advanced features as pane, tabs and sessions for your terminal. Here is a sysadmin use case, You have a server that you use to work on all day long with many long time running scripts. You execute your script at 2 pm in a terminal multiplexer then you close your ssh session. As your script runs in an emulated environment, you will be able to reconnect through a new ssh session (no matter from where) and get back to your terminal with your running scripts. It's a good way to have a flexible environment on your own terms.

In my use case as an everyday terminal user, I got a script that checks if there is already a session. I get automatically attached to that session or the script creates a new one. With that logic I got only one terminal and if I switch to a tty, I'll retrieve the same terminal and all of that is sync !

There exists three big ones :

  • screen : The historical one, it is a part of GNU project and you can find it on cisco machines or on clusters.
  • byobu : fork of screen. It adds many things to screen and makes it more user friendly but the interesting thing about it is a second information bar at the bottom of the screen.
  • tmux : my favourite and my every day multiplexer.

Tmux have one thing that I don't like… the documentation ! Its man documentation is really disturbing the first time you look at it. By the way, many people share their tmux config files so if you want to know how to configure it, look for examples, there is plenty on the Internet.

As my own conf file is huge I'll not paste it here. I'm thinking of sharing it on github. As you can imagine, I used lots of pasted code from the Internet, so you should be able to easily reproduce my configuration if you like it :).

gimme some sugar !

To complete this article, I would like to talk about power-line and 'fuck'. The first one is an eye candy display into your shell. Indeed, power-line is more beautiful than regular prompts and other tools bar. It's designed for vim but tmux and fish/zsh can also have their power-line tools.

Power-line adds also some plug-ins and produce the tmux bar that you can see in the cover. If you want to use it, I shall let you see it for your own Linux distribution. It's not the same for every distro and can be very tricky.

Fuck, is a really fun and useful script ! Don't you ever makae a mistake like 'fit commit' instead of 'git commit'. It bothers you to use history and correct your command ? Just use 'fuck', it'll look at your last command and correct it ! It's not a big deal but it's a cool feature :).

Conclusion

More than just a geek stylish shell and prompt, my shell is a tool. As a tool I presented to you all the changes I made on it to suit my style. But there is nothing such as the perfect thing so, if you would like to start customizing your own, it's a long journey !

In the end, I'm really happy for taking time to learn more about my shell. It saved me a lot of time and made my work more fun and efficient ! If you have a suggestion about other shell tools that I didn't list or talk about, leave a comment below :). I'm thinking about making other shell articles if I find new interesting stuff about it.