Skip to content

Instantly share code, notes, and snippets.

@hogelog
Created August 12, 2011 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hogelog/1141378 to your computer and use it in GitHub Desktop.
Save hogelog/1141378 to your computer and use it in GitHub Desktop.
cdd
#!/bin/sh
cdddir=$HOME/.cdd
cddfile=$cdddir/cddfile
cddtmp=$cdddir/cddtmp
cddmax=20
function cdd_init() {
if [ ! -d $cdddir ]; then
mkdir $cdddir
fi
if [ ! -f $cddfile ]; then
for i in `seq $cddmax`
do
echo >> $cddfile
done
fi
touch $cddfile
touch $cddtmp
}
function cdd_cd() {
dir=`head -\`perl -e"print \"$1\"+1"\` $cddfile |tail -1`
builtin cd $dir
}
function cdd_ls() {
perl -nle 'print "\t", $n++, " $_"' $cddfile
}
function cdd_rec() {
perl -nle "\$c=\$i++;if(\$c==$1){print'$2'}else{print}" $cddfile > $cddtmp
cp $cddtmp $cddfile
}
function cdd() {
cdd_init
if [ $1 ]; then
cdd_cd $1
if [ $WINDOW ]; then
cdd_rec $WINDOW `pwd`
fi
else
cdd_ls
fi
}
function cd() {
cdd_init
builtin cd $@
if [ $WINDOW ]; then
cdd_rec $WINDOW `pwd`
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment