Created
August 14, 2014 20:09
-
-
Save jesboat/10e56636c2f0d9a6197a to your computer and use it in GitHub Desktop.
Better version of the enhanced `cd` described in the `iselect(1)` man page
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
#!bash | |
# database scan for enhanced cd command | |
cds() { | |
( | |
set -o pipefail | |
# XXX: handle directories with newlines in their names? | |
find "$HOME" -type d -print \ | |
| sort -u > "$HOME/.cdpaths" | |
exit $? | |
) & | |
} | |
# definition of the enhanced cd command | |
cd() { | |
if [ $# = 0 || -d "$1" ]; then | |
builtin cd "$@" | |
else | |
builtin cd "$( | |
# XXX: do we want to treat $1 as a regex? | |
egrep "/$1[^/]*$" "$HOME/.cdpaths" \ | |
| iselect -a -Q "$1" -n "chdir" -t "Change directory to..." | |
)" | |
fi | |
local ec=$? | |
PS1='\u@\h:$PWD\n:> ' | |
return $ec | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(Entirely untested.)