Posts Tagged ‘shell’

“En shell dans le texte”

Tuesday, May 27th, 2008

Unix Command Line Kung-Fu is 33 interesting pages with a lot of shell tips (linked today by Larry Wright). My small selection with “customized” examples :


$ !!:p
$ !!


$ iwconfig
zsh: command not found: iwconfig
$ /sbin/!!


$ e app/model/user.rb
$ svn diff !$


$ ./script/generate rspec_controler user
$ ^user^session


$ seq -w 1 12


$ awk '{ print $1 }' access.log | sort | uniq -c | sort -rn | head -5


$ less -r +G log/test.log

Some of my own favorites :


$ sudo du -s /home/* | sort -rn | head


$ echo 2048 | sudo tee /proc/sys/vm/min_free_kbytes


$ sudo sh -c "ls /var/archives/*home*"
$ sudo find /var/archives -name "*home*"


$ pgrep nm-applet | head -n -1 | xargs kill


$ alias ifconfig='/sbin/ifconfig'


$ alias myps='ps -u $USER'

Go to gtk bookmarks in your shell

Wednesday, November 28th, 2007

Gnome (I mean the FileChooser, Nautilus, etc) supports for a few time Bookmarks/Places. You can go back to your favorite folders in a single click. Very usefull in Gedit for example.

But when you’re in your shell ? I use a lot the Ctrl+R search in my zsh history, but it’s a bit tiring to search always the same thing.

First step : a small ruby script to find the wanted path in the gtk boorkmark.

Second step : because a script can’t change the current path of your shell, a function called by an alias is needed. Under zsh, you can make it like that (into your .zshrc) :

function go_impl() {
  target_name=$1
  target=`go-path $target_name`

  if [ -d "$target" ]; then
    cd $target
  else
    echo "target not found : $target_name" 2>&1
  fi
}

alias go='go_impl'

And then ?

[hyppo:~] go freecast
[hyppo:..g/freecast/trunk]

:-)

For the moment, I didn’t manage to setup the zsh completion … The following code :

function go_targets { reply=(`go-path --all`); }
compctl -K go_targets go

… doesn’t nothing