-
-
Save hogelog/1141378 to your computer and use it in GitHub Desktop.
cdd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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