Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created October 2, 2010 04:18
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitode909/607290 to your computer and use it in GitHub Desktop.
Save hitode909/607290 to your computer and use it in GitHub Desktop.
上に行くcd
#compdef up
segments=$(perl -le '$p=$ENV{PWD};$p =~ tr/\// /; print $p')
_arguments "1:first:($segments)"
function up()
{
to=$(perl -le '$p=$ENV{PWD}."/";$d="/".$ARGV[0]."/";$r=rindex($p,$d);$r>=0 && print substr($p, 0, $r+length($d))' $1)
if [ "$to" = "" ]; then
echo "no such file or directory: $1" 1>&2
return 1
fi
cd $to
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment