Boosting your console skills

In this little blog post I will share my tips on improving the console with:
  • Better history management
  • Much better completion

These tips work on any Mac OS X, BSD or Linux system. They are aimed towards Bash - which is a standard on most UNIX systems.

Improving the history

The problem with default Bash configuration is that the history is written only when you close a console window. This is a problem if you have 2 windows: They won't share the history and they will eventually override each others history.

This is a quick fix, open up your ~/.bashrc (or ~/.bash_profile) and add this:

#Bash should append rather than overwrite the history
shopt -s histappend

#When displaying the prompt, write the previous line to disk
PROMPT_COMMAND='history -a'

That's it for history.

If you want real comfort here is some extra configuration that I also use:

#Ignore small typos in directory names
shopt -s cdspell

#Ignore case when completing
set completion-ignore-case on

#When listing possible file completions, put / after directory names and * on files
set visible-stats on

Setting up smart completion

You can search in your history by pressing CTRL-R, here is an example of that:

CTRL-R off

One can do much better completion than CTRL-R. Here is an example of how I use up and down arrows to complete from history:

UpDown off

To get this functionality, paste this into your .inputrc:

#Move in history using up and down arrows
"\e[A": history-search-backward
"\e[B": history-search-forward                                                    

#On tab show completion
set show-all-if-ambiguous on

Update your ~/.inputrc and launch a new terminal window, now you can use up and down arrows smartly!

If you have any kick-ass console-improvement tips, then post them as comments.

Code · Tips 15. Nov 2006
8 comments so far

I use the following alias on my remote host, to attach my irssi (irc) screen by typing a single letter and pressing return:

alias i="if ! screen -dr irssi; then cd ~/ && screen -S irssi /usr/local/bin/irssi ; fi && cd -"

pretty much self explaining, but it checks if theres a screen running already, if theres not, it launches one with irssi - and if theres a screen running already, it attaches it instead.

Less than a month ago I switched from bash to zsh. Programmable completion in zsh absolutely rocks! It's much faster than bash. And I should say I got used to new shell in a day. Aslo, it starts very useful interactive setup wizard when you run it for the first time. Nice!

Timur:
How does the completion work in zsh?

Maybe one should dig into zsh.

Zsh is a very powerful shell which I highly recommend. To start, put this in your ~/.zshrc:

# ~/.zshrc
# Aliases are defined here.

if [ $TERM != "dump" ]; then
    alias ls='ls -hv --color=auto'
else
    alias ls='ls -hv'
fi

alias ll='ls -l'
alias diff='diff -u'
alias less='zless'

# Sets up completion.
autoload -U compinit
compinit

This last two lines will set up the intelligent completion (such as only files ending in .pdf after acroread, directories after cd, etc.).

For your environmental variables I have this in my ~/.zshenv:

# ~/.zshenv
# Important environmental variables are defined here.

HISTSIZE=5000
SAVEHIST=5000

HISTFILE=~/.history
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_FIND_NO_DUPS
setopt HIST_REDUCE_BLANKS

setopt INC_APPEND_HISTORY

setopt EXTENDED_GLOB
setopt NUMERIC_GLOB_SORT

if [ $TERM != "dump" ]; then
    PROMPT='%{^[[1;32m%}[%{^[[36m%}%n@%m%{^[[1;32m%}]%{^[[00m%}%# '
    RPROMPT='%{^[[1;32m%}(%{^[[36m%}%~%{^[[1;32m%})%{^[[00m%}%'
fi

The prompts (in plural!) are particular nice: the RPROMPT variable defines a prompt on the right-hand side of the terminal. I use it to show the present working directory. Watch out with the prompts: the character "^[" is *one* character, the escape character. Insert it using Emacs with C-q ESC. I have no clue as to how one can insert it with Vim... :-)

The glob options are nice, they make it possible to have "*.foo" expand into "1.foo 10.foo 100.foo", in that order and to have "*.foo~10.foo" turn into "1.foo 100.foo" where the 10.foo has been subtracted. Zsh gives you tons of ways to do stuff which you would normally do using other programs such as find and awk.

Interesting post. Thanks!

my shell skills are rudimental but i'll try it!

My opinion, its very useful for me... 7/10

عقارات السعودية - عقارات الرياض - عقارات الخرج - عقارات مكة المكرمة - عقارات جدة - عقارات الطائف - عقارات المدينة المنورة - عقارات ينبع - عقارات الدمام - عقارات الخبر - عقارات الأحساء - عقارات القصيم - عقارات عسير - عقارات حائل - عقارات تبوك - عقارات الباحة - عقارات الحدود الشمالية - عقارات الجوف - عقارات جازان - عقارات نجران - عقارات مصر - عقارات القاهرة - عقارات الجيزة - عقارات حلوان - عقارات 6 اكتوبر - عقارات الاسكندرية - عقارات الساحل الشمالي - عقارات البحيرة - عقارات السويس - عقارات الاسماعلية - عقارات بورسعيد - عقارات البحر الاحمر - عقارات مطروح - عقارات جنوب سيناء - عقارات شمال سيناء - عقارات دمياط - عقارات الدقهلية - عقارات كفر الشيخ - عقارات الشرقية - عقارات الغربية - عقارات القليوبية - عقارات المنوفبة - عقارات الفيوم - عقارات قنا - عقارات المنيا - عقارات اسيوط - عقارات بني سويف - عقارات سوهاج - عقارات الوادي الجديد - عقارات الأقصر - عقارات اسوان - عقارات الامارات - عقارات ابوظبي - عقارات العين - عقارات دبي - عقارات جبل علي - عقارات الشارقة - عقارات رأس الخيمة - عقارات عجمان - عقارات أم القيوين - عقارات الفجيرة - الوطن العربي - عقارات الكويت - عقارات عمان - عقارات قطر - عقارات البحرين - عقارات الاردن - عقارات لبنان - عقارات المغرب - عقارات السودان - عقارات سوريا - وظائف - وظائف في السعودية - وظائف في الامارات - وظائف في مصر - وظائف في الكويت - وظائف في عمان - وظائف في قطر - وظائف في البحرين - وظائف في الاردن - وظائف في لبنان - وظائف في المغرب - وظائف في السودان - وظائف في سوريا - خدمات - العروض الجديدة - الرعاية و الإعلان - الدعم الفني - العقارات العام - شراء شقق - شراء شقة - شقق بالتقسيط - شقة بالتقسيط - شقق تمليك - شقة تمليك - شقق سكنية - شقة سكنية - شقق فندقية - شقة فندقية - شقق للايجار - شقة للايجار - شقق للبيع - شقة للبيع - شقق مفروشة - شقة مفروشة - غير مصنف - مطلوب شقق - مطلوب شقة
اهداف الدوري الأنجليزي
اهداف الدوري الأسباني
اهداف دوري ابطال اوروبا
مهارات ولقطات منوعة
اهداف الدوري السعودي
اهداف تصفيات كأس العالم
اهداف الدوري المصري
اهداف الدوري الالماني
أهداف كأس الخليج
هدف تيوب

Post a comment
Commenting on this post has expired.
© 2000-2009 amix. Powered by Skeletonz.