Last active
December 28, 2020 05:02
-
-
Save gojimmypi/3b92f3a33d51252252976fba7bae407b to your computer and use it in GitHub Desktop.
show user, host, current path, git upstream origin, branch, and last exit code as bash prompt
This file contains hidden or 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
#!/bin/bash | |
# intially generated from http://bashrcgenerator.com/ with additional modificationas | |
# | |
# creates prompt like this with username and directory path on one line, then most recent error code number and $ on next line: | |
# gojimmypi@ubuntu : ~ | |
# 0 $ | |
# | |
# prior version, no GitHub branch | |
# export PS1="\[\033[38;5;2m\]\u@\h\[$(tput sgr0)\]\[\033[38;5;15m\] : \[$(tput sgr0)\]\[\033[38;5;11m\]\w\[$(tput sgr0)\]\[\033[38;5;15m\]\n\$? \\$ \[$(tput sgr0)\]" | |
# prior version, only show branch | |
# export PS1='\[\033[38;5;2m\]\u@\h\[$(tput sgr0)\]\[\033[38;5;15m\](WSL): \[$(tput sgr0)\]\[\033[38;5;11m\]\w\[$(tput sgr0)\]\[\033[38;5;15m\] ($(__git_ps1 "%s")) \n\n'"$?"' \\$ \[$(tput sgr0)\]' | |
## current prompt example: | |
# | |
# gojimmypi@DESKTOP(WSL): /mnt/c/workspace-vs/fujprog/build/x86-debug (Visual-Studio-Build * u=) gojimmypi/fujprog | |
# | |
# 0 $ | |
# | |
# thanks: | |
# http://bashrcgenerator.com/ | |
# https://stackoverflow.com/questions/15883416/adding-git-branch-on-the-bash-command-prompt | |
# https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh | |
source ~/.git-prompt.sh | |
GIT_PS1_SHOWUPSTREAM="bit" | |
GIT_PS1_SHOWCOLORHINTS="true" | |
GIT_PS1_SHOWDIRTYSTATE="true" | |
GIT_PS1_SHOWUPSTREAM="verbose" | |
# string ' | |
# color \[\033[38;5;2m\] \[$(tput sgr0)\] | |
# User \u | |
# literal @ | |
# host \h | |
# literal (WSL): | |
# color \[$(tput sgr0)\]\[\033[38;5;11m\] \[$(tput sgr0)\]\[\033[38;5;15m\] | |
# working directory \w | |
# literal ( | |
# git branch $(__git_ps1 "%s") | |
# show remote origin git config --get remote.origin.url | |
# pipe results of above show | | |
# replace "https://github.com/" with empty strig sed -e "s/^https:\/\/github.com\///" | |
# replace ".git" with empty strig sed -e "s/.git//" | |
# literal ) | |
# new line \n | |
# new line (blank) \n | |
# prior command error code '"$?"' | |
# literal (space) | |
# literal bash prompt $ \\$ | |
# space | |
export PS1='\[\033[38;5;2m\]\u@\h\[$(tput sgr0)\]\[\033[38;5;15m\](WSL): \[$(tput sgr0)\]\[\033[38;5;11m\]\w\[$(tput sgr0)\]\[\033[38;5;15m\] ($(__git_ps1 "%s")) $(git config --get remote.origin.url | sed -e "s/^https:\/\/github.com\///" | sed -e "s/.git//" ) \n\n'"$?"' \\$ \[$(tput sgr0)\] ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment