Skip to content

Instantly share code, notes, and snippets.

@rupa
Created June 10, 2009 14:39
Show Gist options
  • Select an option

  • Save rupa/127250 to your computer and use it in GitHub Desktop.

Select an option

Save rupa/127250 to your computer and use it in GitHub Desktop.
function rat {
# change part of pwd path, and cd to it
# example:
# /usr/lib/foo$ rat li src
# /usr/src/foo$
local cd=$(echo $PWD | awk -v q="$*" -F\/ '
BEGIN { l = split(q,a," ") }
{
for( i=1;i<=NF;i++ ) {
for( j=1;j<=l;j=j+2 ) {
if( !a[j] || $i !~ a[j] ) continue
$i = a[j+1]
delete a[j]
}
}
for( i=1;i<=NF;i++ ) printf $i "/"
}
')
[ -d "$cd" ] && cd $cd
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment