Add cd.sh to behave like normal cd.
This commit is contained in:
parent
1193f11974
commit
8a2dd5e49f
|
@ -0,0 +1,49 @@
|
||||||
|
# Better cd
|
||||||
|
# Usage: cd [full_path|partial_path|path_initials|-]
|
||||||
|
#
|
||||||
|
# Examples:
|
||||||
|
# ~/playground/ $ find . -type d
|
||||||
|
# .
|
||||||
|
# ./slides
|
||||||
|
# ./slides/small
|
||||||
|
# ./slides/huge
|
||||||
|
# ./swings
|
||||||
|
# ./swings/small
|
||||||
|
# ./swings/large
|
||||||
|
# ~/playground/ $ cd sl
|
||||||
|
# ~/playground/slides/ $ cd
|
||||||
|
# ~ $ cd p/s/h
|
||||||
|
# ~/playground/slides/huge $ cd ../..
|
||||||
|
# ~/playground/ $ cd -
|
||||||
|
# ~/playground/slides/huge $ cd -
|
||||||
|
# ~/playground/ $ cd s/s
|
||||||
|
# Warning: Multiple possible paths. Going to first path.
|
||||||
|
# ~/playground/slides/small $
|
||||||
|
|
||||||
|
function cd {
|
||||||
|
if [[ $# -eq 0 ]]; then
|
||||||
|
builtin cd
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $# -gt 1 ]]; then
|
||||||
|
echo "too many arguments" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# cd -
|
||||||
|
if [[ $1 == '-' ]]; then
|
||||||
|
builtin cd -
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check for absolute path first
|
||||||
|
if [[ -d $1 ]]; then
|
||||||
|
builtin cd "$1"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If nothing works
|
||||||
|
echo "$1: No such directory." >&2
|
||||||
|
return 1
|
||||||
|
}
|
Loading…
Reference in New Issue