Created
March 3, 2021 08:51
-
-
Save falzm/ec22dd347eeb10336ea35c0ae563abbc to your computer and use it in GitHub Desktop.
Simple Bash function to create a directory and cd to it immediately. Creates a temporary directory by passing flag "-t".
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
mkcd() { | |
local dir="" | |
while getopts "ht" c | |
do | |
case $c in | |
t) dir=$(mktemp -d) ;; | |
h|?) echo "mkcd [-t] [DIRECTORY]" ; return ;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
[[ -n "$dir" ]] || dir="$1" | |
[[ -d "$dir" ]] || mkdir "$dir" | |
cd "$dir" | |
OPTIND=$# | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment