Skip to content

Instantly share code, notes, and snippets.

@qutek
Created April 16, 2019 18:25
Show Gist options
  • Save qutek/df599064e89de0f88718c1cb72bd451b to your computer and use it in GitHub Desktop.
Save qutek/df599064e89de0f88718c1cb72bd451b to your computer and use it in GitHub Desktop.
[Custom cd function] Custom bash function to cd in my local server directory with autocomplete
# Use it with `goto project`
goto () {
# cancel if no arguments
if [ -z "$1" ]; then
echo "Mau goto kemana??"
return 0
fi
local UPPER=$(printf "%s" "$1" | tr '[:lower:]' '[:upper:]');
local P_DIR="/Users/qutek/LocalServer/_$UPPER";
# if directory exists
if [ -d "$P_DIR" ]; then
cd "$P_DIR";
else
echo "$P_DIR gak ada!!";
return 0;
fi
}
complete -W "project mayven deft" goto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment