Created
August 5, 2023 16:24
-
-
Save manila/529af3f312e420817373fb799b8823d4 to your computer and use it in GitHub Desktop.
Source into bash profile for a better prompt for piper | fig | git workspaces
This file contains 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
print_relative_dir() { | |
re="^$HOME(/?.*)" | |
[[ "$PWD" =~ $re ]] && echo "~${BASH_REMATCH[1]}" || echo "$PWD" | |
} | |
is_workspace() { | |
# Path on macOS will begin with /Volumes | |
re="^(/Volumes)?(/google/src/cloud)/(${USER})/([^/]+)(/.*)?" | |
dir="$PWD" | |
[[ "$dir" =~ $re ]] && return 0 || return 1 | |
} | |
parse_workspace() { | |
if ! is_workspace; then | |
print_relative_dir | |
return | |
fi | |
project="${BASH_REMATCH[4]}" | |
wspath="${BASH_REMATCH[5]:-$project}" | |
printf "[%s] %s" "$project" "$(basename $wspath)" | |
} | |
parse_client() { | |
is_workspace || return | |
ws="piper" | |
hg root 2>/dev/null 1>&2 ; [[ "$?" -eq 0 ]] && ws="fig" | |
printf " (%s)" "$ws" | |
} | |
parse_git_branch() { | |
git branch --show-current 2>/dev/null | sed -e 's/\(.*\)/ (\1)/' | |
} | |
prompt_generator() { | |
export PS1="\[\033[01;32m\]\h\[\033[00m\]:\[\033[01;34m\]$(parse_workspace)\[\033[00m\]$(parse_client)$(parse_git_branch)\[\033[00m\]\n$ " | |
} | |
export PROMPT_COMMAND=prompt_generator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment