How to have a lightweight, beautiful, functional terminal

terminal.png

I’ve done a lot over the past few months to make my time spent on the command line a bit more enjoyable and easier to use.  Hopefully you’ll find these steps useful as well.


Install 256-color support for rxvt-unicode (urxvt) in Ubuntu or Arch.

In Ubuntu I have instructions here.

In Arch, you can grab the rxvt-unicode-256color from AUR.

Or if you wish just continue on with xterm which should work nicely out of the box.

To test it out, use this 256colors script.(you must right click and Save Link As in order to access the file).

Download it, set it executable, open a fresh urxvt terminal, and run:


$ ./256colors

or
$ perl 256colors

The output should look like:

256colors

Any program that supports 256 colors that had to fallback to 88 or even 8 colors can now be used in all its glory.

Pick a terminal color scheme for urxvt or xterm and place it in your .Xresources file

I have collected about 30 different themes you can add directly into your .Xresources or .Xdefaults file (remember, only use one of these files, not both).  You’ll have to specify xterm or urxvt before the *color in each of the lines.

http://tuxtraining.com/2009/06/27/terminal-color-schemes-for-xdefaults-or-xresources-file

This one is currently my favorite:


*background:     #121212
!black
*color0:         #353535
*color8:         #666666
!red
*color1:         #AE4747
*color9:         #EE6363
!green
*color2:         #556B2F
*color10:        #9ACD32
!brown/yellow
*color3:         #DAA520
*color11:        #FFC125
!blue
*color4:         #6F99B4
*color12:        #7C96B0
!magenta
*color5:         #8B7B8B
*color13:        #D8BFD8
!cyan
*color6:         #A7A15E
*color14:        #F0E68C
!white
*color7:         #DDDDDD
*color15:        #FFFFFF

*foreground: #DDDDDD

After you’re done with the file simply run:

xrdb -all ~/.Xresources

Have clickable Links in Urxvt

Just add the following to your .Xdefaults:

URxvt.perl-ext-common: default,matcher
URxvt.urlLauncher: firefox
URxvt.matcher.button: 2
URxvt.matcher.pattern.1: \\bwww\\.[\\w-]\\.[\\w./?&@#-]*[\\w/-]

Now you just need to replace firefox with your favorite browsers startup script and choose which mousebutton should be handled. Button 2 is the middle mouse button and clicking a link with it now opens it directly in firefox without copy and paste or other timewasting things

After you’re done with the file simply run:

xrdb -all ~/.Xresources

Customize .bashrc a bit

Put the following in your ~/.bashrc file

# Define a few Colours
BLACK=’\e[0;30m'
BLUE='\e[0;34m'
GREEN='\e[0;32m'
CYAN='\e[0;36m'
RED='\e[0;31m'
PURPLE='\e[0;35m'
BROWN='\e[0;33m'
LIGHTGRAY='\e[0;37m'
DARKGRAY='\e[1;30m'
LIGHTBLUE='\e[1;34m'
LIGHTGREEN='\e[1;32m'
LIGHTCYAN='\e[1;36m'
LIGHTRED='\e[1;31m'
LIGHTPURPLE='\e[1;35m'
YELLOW='\e[1;33m'
WHITE='\e[1;37m'
NC='\e[0m'              # No Color

#######################################################

# WELCOME SCREEN
#######################################################

clear

echo -ne "${LIGHTGREEN}" "Hello, $USER. today is, "; date
echo -e "${LIGHTRED}"; cal ;
echo -ne "${CYAN}";
echo -ne "${LIGHTPURPLE}Sysinfo:";uptime ;echo ""

# MAKE MAN PAGES PRETTY
#######################################################

export LESS_TERMCAP_mb=$'\E[01;31m'             # begin blinking
export LESS_TERMCAP_md=$'\E[01;38;5;74m'        # begin bold
export LESS_TERMCAP_me=$'\E[0m'                 # end mode
export LESS_TERMCAP_se=$'\E[0m'                 # end standout-mode
export LESS_TERMCAP_so=$'\E[38;5;246m'          # begin standout-mode - info box
export LESS_TERMCAP_ue=$'\E[0m'                 # end underline
export LESS_TERMCAP_us=$'\E[04;38;5;146m'       # begin underline

############################## ##################################
# ##### PROMPT SECTION ##### ####################################
############################## ##################################

# color_name='\[\033[ color_code m\]‘

rgb_restore=’\[\033[00m\]‘
rgb_black=’\[\033[00;30m\]‘
rgb_firebrick=’\[\033[00;31m\]‘
rgb_red=’\[\033[01;31m\]‘
rgb_forest=’\[\033[00;32m\]‘
rgb_green=’\[\033[01;32m\]‘
rgb_brown=’\[\033[00;33m\]‘
rgb_yellow=’\[\033[01;33m\]‘
rgb_navy=’\[\033[00;34m\]‘
rgb_blue=’\[\033[01;34m\]‘
rgb_purple=’\[\033[00;35m\]‘
rgb_magenta=’\[\033[01;35m\]‘
rgb_cadet=’\[\033[00;36m\]‘
rgb_cyan=’\[\033[01;36m\]‘
rgb_gray=’\[\033[00;37m\]‘
rgb_white=’\[\033[01;37m\]‘
rgb_host=”${rgb_cyan}”
rgb_std=”${rgb_white}”

if [ `id -u` -eq 0 ]
then
 rgb_usr=”${rgb_red}”
else
 rgb_usr=”${rgb_green}”
fi

#[ -n "$PS1" ] && PS1=”${rgb_usr}`whoami`${rgb_std} \W ${rgb_usr}\\\$${rgb_restore} ”
[ -n "$PS1" ] && PS1=”${rgb_usr}`whoami`${rgb_host}@\h: \W ${rgb_usr}\\\$${rgb_restore} ”

unset   rgb_restore   \
 rgb_black     \
 rgb_firebrick \
 rgb_host      \
 rgb_red       \
 rgb_forest    \
 rgb_green     \
 rgb_brown     \
 rgb_yellow    \
 rgb_navy      \
 rgb_blue      \
 rgb_purple    \
 rgb_magenta   \
 rgb_cadet     \
 rgb_cyan      \
 rgb_gray      \
 rgb_white     \
 rgb_std       \
 rgb_usr

Enable 256 Color Support in Vim

XTerm and most other modern terminal emulaters support 256 colors.

To enable colors on XTerm you will need to run the configure scripts with the --enable-256-color switch.

To enable 256 colors in vim, put this your .vimrc ( see below about picking a color-scheme:

if &t_Co == 256
    colorscheme xoria256
endif

You may also need to add:

set t_AB=^[[48;5;%dm
set t_AF=^[[38;5;%dm

Pick a 256 color Vim theme

For full effect, use a colorscheme that supports 256 colors . Here are some of my favorites:

gardener (script#1348)
desert256 (script#1243)
inkpot (script#1143)
xoria256 (xoria256.vim)

You place these files in ~/.vim/colors directory and specify in your ~/.vimrc

colorscheme <themename>

Here is an example of xoria256

Click for larger

Click for larger

Pick a nice theme for Irssi

If you want to customize your cli irc client, no sweat:

Go here to pick a theme: http://irssi.org/themes

Copy the .theme file to ~/.irssi/ directory, change the theme with /SET theme theme_name

Gmail Checker in Gnu Screen

Want your terminal to display how many unread messages are in your Gmail? No problem:

http://tuxtraining.com/2009/04/29/show-unread-gmails-in-gnu-screen-status-bar

Other scripts for Gnu Screen

get_uptime

uptime | awk '{print $2,$3, $4}'

get_freemem

#!/bin/bash
free -m | grep - | awk '{print $4}'

get_freeswap

#!/bin/bash
free -m | grep Swap | awk '{print $4}'

get_sessionname

#!/bin/sh
screen -ls | grep $PPID | awk '{print $1}' | cut -f2 -d'.'

My .screenrc file

#terminfo and termcap for nice 256 color terminal
# allow bold colors - necessary for some reason
attrcolor b ".I"
# tell screen how to set colors. AB = background, AF=foreground
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
# erase background with current bg color
defbce "on"
#term xterm-256color
term screen-256color
startup_message off

caption always "%{= KW}%-w%{= gW}%n %t%{-}%+w %-="
hardstatus alwayslastline "%{= kW} %-= %{= kB}Session:%u%{= kW} %5` | %{= kB}Host:%{= kW} %H | %1` |%{= kB} MEM:%{= kW} %2`MB /%{= kB} SW: %{= kW}%3`MB | %4` %{= kR}Unread %{= kW}| %m/%d %c"

#caption always "%{= kw}%-w%{= BW}%n %t%{-}%+w %-=   | %1` | %2`MB/%3`MB | %4` Unread | %m/%d %l:%M %p"
vbell off

#Backticks to display information in status bar
backtick 1 60 60 /home/username/bin/get_uptime
backtick 2 60 60 /home/username/bin/get_freemem
backtick 3 60 60 /home/username/bin/get_freeswap
backtick 4 60 60 /home/username/bin/get_gmail
backtick 5 60 60 /home/username/bin/get_sessionname

defscrollback 5000
screen -t root 0 sudo -s
screen -t shell 1 bash
screen -t shell 2 bash
screen -t shell 3 bash
screen -t shell 4 bash
screen -t shell 5 bash
screen -t shell 6  bash
screen -t shell 7  bash
screen -t irc 8 irssi
screen -t home 9 bash
select 1

Automagically set titles to boxes you ssh in screen

when I SSH somewhere I like to set the title of the screen I’m in, so I can easily keep track of loads of them.

To do this I’ve come up with a script which can be executed by SSH when it connects to a remote server.

First download this script:

http://tuxtraining.com/files/screen_ssh.sh (right click, save as)

and make it executable

chmod u+x ~/screen_ssh.sh

You’ll need to edit

/etc/ssh/ssh/config

and add the following line:

PermitLocalCommand Yes 

Then edit the following file:

~/.ssh/config

and set something like this:

Host *
  LocalCommand /path/to/screen_ssh.sh $PPID %n

This will set the screen title to the name of the machine you SSH’d to and do its best to chop off extraneous Top-Level-Domain information (i.e. if you ssh to foo.company.com the title will be “foo”).
If you have a name defined in your .ssh/config and ssh to that, the screensession name will change to that title.  If you ssh to www.server.com it will display www.   If you ssh to an IP address it will display the entire IP address.

Set Terminal Title (For wmii users )

If you would like to display the current directory in your terminal emulator's titlebar, add this to your .bashrc

WMII_IS_RUNNING=`ps a | grep wmii | awk '/tty1/'`
if [ -n "$WMII_IS_RUNNING" ]; then
  PROMPT_COMMAND='dirs | wmiir write /client/sel/label'
fi

End Result

Click for larger

Click for larger

Related Posts

One Comment

  1. admin says:

    The xoria font I would not be able to tell you as the screenshot is off the xoria page on vim.org.

    As for the final result I have this in my .Xresources:

    XTerm*font: xft:DejaVu Sans Mono:size=8
    xterm*faceName: Mono
    xterm*faceSize: 8