Skip to content

Instantly share code, notes, and snippets.

@derekcavaliero
Created April 3, 2025 14:46
Show Gist options
  • Select an option

  • Save derekcavaliero/369231ffa449692dda091d0485a2ff07 to your computer and use it in GitHub Desktop.

Select an option

Save derekcavaliero/369231ffa449692dda091d0485a2ff07 to your computer and use it in GitHub Desktop.
Bash `goto` shortcut/alias.
goToFolder() {
local primary_directory="Sites"
# Default base - change to whatever default folder you want to use inside the primary_directory
local base="Level"
local client=""
# Check if argument contains a slash
if [[ "$1" == */* ]]; then
# Split the argument by the first slash
base_key="${1%%/*}"
client="${1#*/}"
# Map the base key to the actual directory
case "$base_key" in
lvl) base="Level" ;;
wmx) base="WebMechanix" ;;
dsc) base="Personal" ;;
me) base="Personal" ;;
play) base="Playground" ;;
*) echo "Unknown base: $base_key" && return 1 ;;
esac
else
# If no slash, treat the argument as the base key
case "$1" in
lvl) base="Level" ;;
wmx) base="WebMechanix" ;;
dsc) base="Personal" ;;
me) base="Personal" ;;
play) base="Playground" ;;
*)
# If not a known base key, treat as client in default base
client="$1"
;;
esac
fi
BRIGHT_GREEN="\e[92m"
GRAY="\e[90m"
RESET="\e[0m"
echo
# Navigate to the appropriate directory
if [[ -n "$client" ]]; then
cd "$HOME/$primary_directory/$base/$client"
printf "${GRAY}$primary_directory/$base/$client${RESET}\n"
else
cd "$HOME/$primary_directory/$base"
printf "${GRAY}$primary_directory/$base${RESET}\n"
fi
echo
ls
echo
}
alias goto=goToFolder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment