Last active
March 18, 2021 18:40
-
-
Save miyl/b52a716e93990f3205ab02da4c169fc1 to your computer and use it in GitHub Desktop.
Intelligent cd
This file contains hidden or 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
# /usr/bin/env sh | |
# You've heard of exa/lsd, sd and fd. But what about a modern cd? | |
# This isn't really it. Try autojump/z/fasd? | |
# But maybe this does make plain old cd 5% better, on a good day? | |
# Description: Just a vaguely intelligent cd | |
# Specifically it can handle cd'ing to a path even if it has a filename | |
# at the end, in which case it cd's to the directory which contains it | |
cd() { | |
[ -z $1 ] && builtin cd | |
if [ "$(file --brief --dereference "$1")" != "directory" ]; then | |
builtin cd "$(dirname "$1")" | |
else | |
builtin cd "$1" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment