Skip to content

Instantly share code, notes, and snippets.

@allyouaskfor
Last active October 6, 2022 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allyouaskfor/96e28f18dc761c49e2d6eeafec179b8f to your computer and use it in GitHub Desktop.
Save allyouaskfor/96e28f18dc761c49e2d6eeafec179b8f to your computer and use it in GitHub Desktop.
List contents of directory after changing into it.
#!/bin/bash
# cd & ls with just "cd"
# Original solution found on StackOverflow. I do not have the direct link.
# Modified/adjusted by myself to work in line with my own expectations.
# Tested and used regularly on macOS with ZSH and Raspberry Pi with BASH.
altercd() {
cd() {
unset -f cd
if [[ -z $* ]]; then
cd $HOME
else
cd "$*"
fi
ls
altercd
}
}; altercd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment