kindwolf.org Git repositories xavierg-snippets / master how-about-a-smarter-cd-builtin-command / cd-function.sh
master

Tree @master (Download .tar.gz)

cd-function.sh @masterraw · history · blame

# Override the "cd" keyword with a copy/paste friendly function.
function cd() {
	if [ $# -eq 0 ]; then
		builtin cd
	else
		if [ -f "$1" ]; then
			builtin cd "$(dirname "$1")"
		else
			builtin cd "$1"
		fi
	fi
}