Modernizing the Command Line

One of the greatest features of Linux is the command line. Sadly, it has been somewhat neglected as of late. The purpose of this “Blog Entry” is to point out some command line features and possibilities that are not often taken advantage of.

The explanations provided are intended for an Ubuntu user using BASH as a shell, but could easily be modified for others. Some of the things mentioned in this entry are well known while other are not. The well known ones are here in case someone doesn’t know.

Color Arguments

Several programs produce color output when given certain arguments. To make this default, add the following to ~/.bashrc.

#Add to .bashrc
    alias ls="ls --color=auto"
    alias grep="grep --color=auto"
    alias less="less -R"

Color Versions

Using the programs colormake colorgcc and colordiff instead of their non-color equivalent can be pleasant. Install the color versions and alias them.

#Run to install
 sudo apt-get install colormake colorgcc colordiff
#Add to ~/.bashrc
alias make="colormake"
alias diff="colordiff"
alias gcc="colorgcc"

Variables

The PS1 variable is printed as the prompt in bash. It can contain escape sequences and commands. One suggestion would be mine:

#Add to the end of ~/.bashrc
PS1="\[33[0;34m\]$(date +"%H:%M")\[33[0;32m\]\w\[33[0;31m\]\$ \[33[00m\]"

Which results in:

blue:21:31 green:~ red:$

Some other suggestions and resources for PS1 variable can be found at the CLUG wiki.

Individuals may also be interested in adding colorful man pages by adding the following:

#Add to  ~/.bashrc
#note that the variables could easily be other
#escape sequences.
# For colourful man pages (CLUG-Wiki style)
export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;31m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'

as suggested by the CLUG wiki

Compare:

Escape Codes in Raw Text Files

One Idea (that I haven’t seen anywhere else yet… UPDATE: I found another site with this…) is to put escape codes in files like /etc/motd or /etc/issue.

The following is my /etc/motd.tail (which forms /etc/motd on startup on Ubuntu systems). It is based on the normal Ubuntu one.

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

To access official Ubuntu documentation, please visit
http://help.ubuntu.com/

It renders as:


The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.

To access official Ubuntu documentation, please visit
http://help.ubuntu.com/

One could do the same with /etc/issue which is printed right before login starts.

Others

One interesting thing to do is use lesspipe. There is a detailed entry about this on another blog.

It is also interesting to change the text printed out by the init functions. More information on this can be found on Ubuntu Forums.

Readers may also wish to look into framebuffers, which allow the displaying of pictures ( and pdfs, etc… once installed see fbi and links2 -g) and smaller fonts in the ttys. A good tutorial can be found on Ubuntu Forums.

I would advise readers to install gpm (general purpose mouse) which allows the use of a mouse in a tty.

It is also worth making sure that the readers are aware that vim, emacs and nano can all do syntax highlighting.

Advertisements

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: