diff options
author | MountainMan <43313373+MountainMan1312@users.noreply.github.com> | 2023-04-02 21:49:37 -0400 |
---|---|---|
committer | MountainMan <43313373+MountainMan1312@users.noreply.github.com> | 2023-04-02 21:49:37 -0400 |
commit | 4b006b55c4c3610812353bc36e18f1d2eb59f56d (patch) | |
tree | d85b803fe7497fa5b4555909ca9c7318bb08c04c /home/.bashrc | |
parent | Fix formatting in `dotfiles/home/.bashrc` (diff) | |
download | dotfiles.old-4b006b55c4c3610812353bc36e18f1d2eb59f56d.tar.gz dotfiles.old-4b006b55c4c3610812353bc36e18f1d2eb59f56d.tar.bz2 dotfiles.old-4b006b55c4c3610812353bc36e18f1d2eb59f56d.zip |
Add git branch to `$PS1` in `dotfiles/home/.bashrc`
It's nice to see which branch you're in at-a-glance. This change makes it
so that, if you are in a git repo, the `$PS1` displays which branch is
active. If not, it is reduced to a single space. I would like to find a
way to conditionally add a space between (BRANCH) and DIR, omitting it if
not in a git repo. This would make it look nicer outside of git repos.
Diffstat (limited to 'home/.bashrc')
-rw-r--r-- | home/.bashrc | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/home/.bashrc b/home/.bashrc index 6610b34..6f6711e 100644 --- a/home/.bashrc +++ b/home/.bashrc | |||
@@ -16,10 +16,10 @@ fi | |||
16 | # conditionally based on what kind of user is logged in. | 16 | # conditionally based on what kind of user is logged in. |
17 | # | 17 | # |
18 | # Breakdown of PS1 components: | 18 | # Breakdown of PS1 components: |
19 | # [TTY#] [DATE TIME] [USER HOST] [DIR] > | 19 | # [TTY#] [DATE TIME] [USER HOST] [(BRANCH) DIR] > |
20 | # | 20 | # |
21 | # Example of what the prompt should look like: | 21 | # Example of what the prompt should look like: |
22 | # [1] [2023-03-28 16:02:55] [user host] [/etc/portage] > | 22 | # [1] [2023-03-28 16:02:55] [user host] [(stable) /etc/portage] > |
23 | ######################################################################### | 23 | ######################################################################### |
24 | # Set colors for easy reading | 24 | # Set colors for easy reading |
25 | PS1_COLOR_RESET="\[\e[0m\]" | 25 | PS1_COLOR_RESET="\[\e[0m\]" |
@@ -59,8 +59,13 @@ PS1+="$PS1_COLOR_GREY@$PS1_COLOR_RESET" # @ | |||
59 | PS1+="$PS1_COLOR_BLUE\h$PS1_COLOR_RESET" # HOST | 59 | PS1+="$PS1_COLOR_BLUE\h$PS1_COLOR_RESET" # HOST |
60 | PS1+="$PS1_COLOR_MAIN] $PS1_COLOR_RESET" # ] | 60 | PS1+="$PS1_COLOR_MAIN] $PS1_COLOR_RESET" # ] |
61 | 61 | ||
62 | # [DIR] > | 62 | # [(BRANCH) DIR] > |
63 | parse_git_branch() { | ||
64 | git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' \ | ||
65 | | awk '{$1=$1;print}' | ||
66 | } | ||
63 | PS1+="$PS1_COLOR_MAIN[$PS1_COLOR_RESET" # [ | 67 | PS1+="$PS1_COLOR_MAIN[$PS1_COLOR_RESET" # [ |
68 | PS1+="\$(parse_git_branch) " # (BRANCH) | ||
64 | PS1+="$PS1_COLOR_CYAN\w$PS1_COLOR_RESET" # DIR | 69 | PS1+="$PS1_COLOR_CYAN\w$PS1_COLOR_RESET" # DIR |
65 | PS1+="$PS1_COLOR_MAIN] > $PS1_COLOR_RESET" # ] > | 70 | PS1+="$PS1_COLOR_MAIN] > $PS1_COLOR_RESET" # ] > |
66 | ######################################################################### | 71 | ######################################################################### |