Skip to content

Instantly share code, notes, and snippets.

@jesboat
Created August 14, 2014 20:09
Show Gist options
  • Save jesboat/10e56636c2f0d9a6197a to your computer and use it in GitHub Desktop.
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
#!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
}
@jesboat
Copy link
Author

jesboat commented Aug 14, 2014

(Entirely untested.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment