Lightly Customized Bash Terminal

Lightly Customized Bash Terminal
Photo by Markus Spiske / Unsplash

A comfortable working environment is beyond important for a productive developer or sysadmin. Developers use a wide variety of tools to actualize their tasks. All of these tools provide some sort of interface. Some of them allow heavy customization and some of them don't. If you are a developer working with remote servers, chances are high that you have been using Vim or its derivatives (neovim, vi, etc.). Vim is a terminal-based text editor that comes with enormous power and a very steep learning curve. It can be a file explorer, it can be an editor, or it can be a full-fledged IDE.

In addition to text editing, a sysadmin deals with multiple terminals at the same time most of the time. At those times, opening several terminal emulator windows can be quite frustrating and hard to manage. Tmux or Screen are two examples of terminal multiplexers. They can manage multiple terminal sessions in one parent terminal. Tmux is the modern one and the one that we will talk about.

Tmux and Vim, when they are together, are very powerful. They can be customized into almost any shape and function. In this post, I am going to explain my terminal setup for my remote servers. This post is also a note to my future self.

Installing the Tools

The necessary tools to create the environment include, not surprisingly, Vim, Tmux, and Git. Both of them are available in the package managers of all popular distros. The code snippets below assume Ubuntu is the OS of the examples with Bash as the default shell. First things first, we need to install these packages.

$ sudo apt update && sudo apt upgrade
$ sudo apt install git vim tmux curl

The dollar sign ($) in the above snippet represents the bash shell. In the first command, we update the repositories and apply the updates that are available. In the second command, we install Git, Vim, and Tmux.

Getting the Dotfiles

I store my dotfiles in a repo called dotfiles on Github. You can access them here. We need to clone the repo somewhere on our computer. I generally clone the dotfiles into my home directory. To do that:

$ cd
$ git clone https://github.com/tustunkok/dotfiles.git

Now, you should see a directory called dotfiles in your home directory.

Getting Ready for the Dotfiles

These dotfiles require some pre-configuration. First, we need to create symbolic links to our dotfiles. To do that:

$ ln -s /home/<user>/dotfiles/.tmux.conf /home/<user>/
$ ln -s /home/<user>/dotfiles/.vimrc /home/<user>/

After running the above snippet, both Vim and Tmux will use the configuration inside them. The Tmux configuration uses a package manager called tpm (short for Tmux Package Manager). Therefore, we need to install it. Fortunately, it is very easy to install it.

$ git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

This line installs tpm. The full documentation gives every detail that you might wonder about.

Tmux

After installing tpm, we can now activate the extensions that are already on the dotfiles by opening a Tmux session in the terminal and using the prefix + I (capital I). If your font supports certain symbols, your Tmux taskbar should be pretty good.

Vim

Vim is a little bit more complicated than Tmux. We start with installing a plugin manager for Vim. In our case, I use vim-plug. Its installation is simple enough.

$ curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

After running the code snippet, open up a Vim session and type :PlugInstall. This will install all the plugins that are added to the .vimrc file. Now, the only thing to install is Powerline. We can easily install it with the following command:

$ sudo apt install powerline

Powerline requires certain changes in our .bashrc file. Open up the .bashrc file in Vim and append the following snippet at the end of it.

powerline-daemon -q
POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
. /usr/share/powerline/bindings/bash/powerline.sh

Close the terminal and open it again. A pretty-looking bash accompanied by Tmux and Dracula-themed Vim should greet you.

See ya...

Mastodon