Pimp my terminal

We work more and more in different environments on even more servers than I can keep track of, so I started looking into pimping my terminal. I came across a bunch of projects but the one that really stood out me was Powerline. Combining powerline with a bunch of scripts for Nano makes it a lot easier to work in terminal and support you in git.

Powerline

To install we simply git clone the the repository directly from GitHub and install it.

mkdir -p ~/git/
cd git
git clone https://github.com/milkbikis/powerline-shell
cd powerline-shell
cp config.py.dist config.py
./install.py

Now I chose to install it for my user only in ~/bin instead of globally. But you could install it globally by placing in it /usr/local/bin for example.

mkdir -p ~/bin
ln -s ~/git/powerline-shell/powerline-shell.py ~/bin/powerline-shell.py

To fully use it we do need to add a few fonts, otherwise not all icons will be displayed correctly and install powerline-status. All we need to install Powerline-status is pip which is covered in hundreds of posts so I’m not going into that.

wget https://github.com/powerline/powerline/raw/develop/font/10-powerline-symbols.conf 
wget https://github.com/powerline/powerline/blob/develop/font/PowerlineSymbols.otf
sudo mv PowerlineSymbols.otf /usr/share/fonts/
sudo mv 10-powerline-symbols.conf /etc/fonts/conf.d/
fc-cache -vf /usr/share/fonts/
pip install powerline-status

To use it automagically you need to add the run to your bashrc as shown below, you can simply copy paste it to the bottom of it.

# set PATH so it includes user"s private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

function _update_ps1() {
    PS1="$(~/bin/powerline-shell.py $? 2> /dev/null)"
}

if [ "$TERM" != "linux" ]; then
    PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
fi

 

Nano

To add a bunch of colour and markup to Nano all you need is to run the code bellow. The code simply git pulls the repository and adds a reference to the file in your nanorc file. The complete list of supported file are listed on the creators page; https://github.com/scopatz/nanorc

cd ~/git
git clone https://github.com/scopatz/nanorc.git
find ~/git/nanorc -iname "*.nanorc" -exec echo include {} \; >> ~/.nanorc

 

Screen

Screen enables you to run multiple “screens” i.e. terminals in a single terminal and keeping them alive after you disconnect. I added the following on the server side so it automagically spawn or continues with a screen.

if [ "$PS1" != "" -a "${STARTED_SCREEN:-x}" = x -a "${SSH_TTY:-x}" != x ]
then
  STARTED_SCREEN=1 ; export STARTED_SCREEN
  [ -d $HOME/lib/screen-logs ] || mkdir -p $HOME/lib/screen-logs
  sleep 1
  case "/$(ps -p $PPID -o comm=)" in
    */sshd) screen -R -d && exit 0;;
  esac
fi
# [end of auto-screen snippet]