Skip to content

Instantly share code, notes, and snippets.

@ashaindlin
Last active August 29, 2015 14:04
Show Gist options
  • Save ashaindlin/0d9a71fa9b831b6da3b7 to your computer and use it in GitHub Desktop.
Save ashaindlin/0d9a71fa9b831b6da3b7 to your computer and use it in GitHub Desktop.
Seriously, stop typing `cd $_`
#!/bin/sh
# The alias to call this script needs to source it, not just execute it in a
# new shell, or you'll make the directory but not cd to it in the parent shell.
# Like this: alias mcd='source ~/.scripts/mkdir_and_cd.sh'
if [ "$#" -ne 1 ]; then
echo "Please pass exactly one directory name."
else
mkdir "$1"
cd "$1"
fi
#!/bin/sh
# Just like `mkdir_and_cd.sh`, but it will create you a randomly-named directory
# if you don't give it any arguments.
#
# The alias to call this script needs to source it, not just execute it in a
# new shell, or you'll make the directory but not cd to it in the parent shell.
# Like this: alias mcda='source ~/.scripts/mkdir_and_cd_adventurous.sh'
case "$#" in
0)
DIR="$(shuf /usr/share/dict/words | head -n 1 | tr -dc 'a-zA-Z0-9')"
mkdir "$DIR" && cd "$DIR"
;;
1)
mkdir "$1" && cd "$1"
;;
*)
echo "Don't you know I only take one argument?"
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment