bash: per-command history. How does it work?

Posted by romainl on Super User See other posts from Super User or by romainl
Published on 2010-12-26T09:07:29Z Indexed on 2010/12/26 9:56 UTC
Read the original article Hit count: 352

Filed under:
|
|
|

OK. I have an old G5 running Leopard and a Dell running Ubuntu 10.04 at home and a MacPro also running Leopard at work.

I use Terminal.app/bash a lot. On my home G5 it exhibits a nice feature: using ? to navigate history I get the last command starting with the few letters that I've typed.

This is what I mean (| represents the caret):

$ ssh user@server
$ vim /some/file/just/to/populate/history
$ ss|

So, I've typed the two first letters of "ssh", hitting ? results in this:

$ ssh user@server

instead of this, which is the behaviour I get everywhere else :

$ vim /some/file/just/to/populate/history

If I keep on hitting ? or ?, I can navigate through the history of ssh like this:

$ ssh otheruser@otherserver
$ ssh user@server
$ ssh yetanotheruser@yetanotherserver

It works the same for any command like cat, vim or whatever.

That's really cool. Except that I have no idea how to mimic this behaviour on my other machines.

Here is my .profile:

export PATH=/Developer/SDKs/flex_sdk_3.4/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/sw/bin:/sw/sbin:/bin:/sbin:/bin:/sbin:/usr/bin:/usr/sbin:$HOME/Applications/bin:/usr/X11R6/bin
export MANPATH=/usr/local/share/man:/usr/local/man:opt/local/man:sw/share/man
export INFO=/usr/local/share/info
export PERL5LIB=/opt/local/lib/perl5
export PYTHONPATH=/opt/local/bin/python2.7
export EDITOR=/opt/local/bin/vim
export VISUAL=/opt/local/bin/vim
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home

export TERM=xterm-color
export GREP_OPTIONS='--color=auto' GREP_COLOR='1;32'
export CLICOLOR=1
export LS_COLORS='no=00:fi=00:di=01;34:ln=target:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.deb=00;31:*.rpm=00;31:*.TAR=00;31:*.TGZ=00;31:*.ARJ=00;31:*.TAZ=00;31:*.LZH=00;31:*.ZIP=00;31:*.Z=00;31:*.Z=00;31:*.GZ=00;31:*.BZ2=00;31:*.DEB=00;31:*.RPM=00;31:*.jpg=00;35:*.png=00;35:*.gif=00;35:*.bmp=00;35:*.ppm=00;35:*.tga=00;35:*.xbm=00;35:*.xpm=00;35:*.tif=00;35:*.png=00;35:*.fli=00;35:*.gl=00;35:*.dl=00;35:*.psd=00;35:*.JPG=00;35:*.PNG=00;35:*.GIF=00;35:*.BMP=00;35:*.PPM=00;35:*.TGA=00;35:*.XBM=00;35:*.XPM=00;35:*.TIF=00;35:*.PNG=00;35:*.FLI=00;35:*.GL=00;35:*.DL=00;35:*.PSD=00;35:*.mpg=00;36:*.avi=00;36:*.mov=00;36:*.flv=00;36:*.divx=00;36:*.qt=00;36:*.mp4=00;36:*.m4v=00;36:*.MPG=00;36:*.AVI=00;36:*.MOV=00;36:*.FLV=00;36:*.DIVX=00;36:*.QT=00;36:*.MP4=00;36:*.M4V=00;36:*.txt=00;32:*.rtf=00;32:*.doc=00;32:*.odf=00;32:*.rtfd=00;32:*.html=00;32:*.css=00;32:*.js=00;32:*.php=00;32:*.xhtml=00;32:*.TXT=00;32:*.RTF=00;32:*.DOC=00;32:*.ODF=00;32:*.RTFD=00;32:*.HTML=00;32:*.CSS=00;32:*.JS=00;32:*.PHP=00;32:*.XHTML=00;32:'

export LC_ALL=C
export LANG=C

stty cs8 -istrip -parenb
bind 'set convert-meta off'
bind 'set meta-flag on'
bind 'set output-meta on'

alias ip='curl http://www.whatismyip.org | pbcopy'
alias ls='ls -FhLlGp'
alias la='ls -AFhLlGp'
alias couleurs='$HOME/Applications/bin/colors2.sh'
alias td='$HOME/Applications/bin/todo.sh'
alias scale='$HOME/Applications/bin/scale.sh'
alias stree='$HOME/Applications/bin/tree'
alias envoi='$HOME/Applications/bin/envoi.sh'
alias unfoo='$HOME/Applications/bin/unfoo'
alias up='cd ..'
alias size='du -sh'
alias lsvn='svn list -vR'
alias jsc='/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc'
alias asl='sudo rm -f /private/var/log/asl/*.asl'
alias trace='tail -f $HOME/Library/Preferences/Macromedia/Flash\ Player/Logs/flashlog.txt'
alias redis='redis-server /opt/local/etc/redis.conf'

source /Users/johncoltrane/Applications/bin/git-completion.sh
export GIT_PS1_SHOWUNTRACKEDFILES=1
export GIT_PS1_SHOWUPSTREAM="verbose git"
export GIT_PS1_SHOWDIRTYSTATE=1

export PS1='\n\[\033[32m\]\w\[\033[0m\] $(__git_ps1 "[%s]")\n\[\033[1;31m\]\[\033[31m\]\u\[\033[0m\] $ \[\033[0m\]'

mkcd () {
  mkdir -p "$*"
  cd "$*"
}

function cdl {
  cd $1
  la
}

n() {
  $EDITOR ~/Dropbox/nv/"$*".txt
}

nls () { 
  ls -c ~/Dropbox/nv/ | grep "$*"
}

copy(){
  curl -s -F 'sprunge=<-' http://sprunge.us | pbcopy
}

if [ -f /opt/local/etc/profile.d/cdargs-bash.sh ]; then
  source /opt/local/etc/profile.d/cdargs-bash.sh
fi

if [ -f /opt/local/etc/bash_completion ]; then
  . /opt/local/etc/bash_completion
fi

Any idea?

© Super User or respective owner

Related posts about mac

Related posts about bash