annotate .bash_prompt @ 258:7b3dbc32eac5

gvim windows should be fullscreen, methinks
author Steve Huston <huston@srhuston.net>
date Thu, 28 Mar 2024 19:37:38 -0400
parents d868be3816bf
children 09e37b590785
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
256
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
1 #!/bin/bash
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
2 #
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
3 # DESCRIPTION:
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
4 #
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
5 # Set the bash prompt according to:
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
6 # * the branch/status of the current Git or Mercurial repository
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
7 # * the return value of the previous command
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
8 #
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
9 # USAGE:
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
10 #
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
11 # 1. Save this file as ~/.bash_prompt
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
12 # 2. Add the following line to the end of your ~/.bashrc or ~/.bash_profile:
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
13 # . ~/.bash_prompt
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
14 #
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
15 # LINEAGE:
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
16 #
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
17 # https://gist.github.com/2959821
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
18 # https://gist.github.com/31967
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
19 # https://gist.github.com/2394150
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
20 # Overhauled by Steve Huston 2024/03/28 to reduce delays and adapt to my personal style
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
21
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
22 # The various escape codes that we can use to color our prompt.
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
23 RED="\[\e[0;31m\]"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
24 YELLOW="\[\e[1;33m\]"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
25 GREEN="\[\e[0;32m\]"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
26 BLUE="\[\e[1;34m\]"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
27 LIGHT_BLUE="\[\e[1;36m\]"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
28 LIGHT_RED="\[\e[1;31m\]"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
29 LIGHT_GREEN="\[\e[1;32m\]"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
30 WHITE="\[\e[1;37m\]"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
31 LIGHT_GRAY="\[\e[0;37m\]"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
32 COLOR_NONE="\[\e[0m\]"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
33
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
34 # Determine if this is a Git repo and get the branch/state information.
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
35 function set_git_branch {
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
36 # Capture the output of the "git status" command.
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
37 git_status="$(git status 2> /dev/null)"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
38
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
39 # Short circuit if this isn't a git repo
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
40 if [ -z "$git_status" ]; then
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
41 return 1
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
42 fi
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
43
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
44 # Set color based on clean/staged/dirty.
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
45 if [[ ${git_status} =~ "working tree clean" ]]; then
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
46 state="${GREEN}"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
47 elif [[ ${git_status} =~ "Changes to be committed" ]]; then
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
48 state="${YELLOW}"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
49 else
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
50 state="${LIGHT_RED}"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
51 fi
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
52
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
53 # Set arrow icon based on status against remote.
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
54 remote_pattern="Your branch is (.*) of"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
55 if [[ ${git_status} =~ ${remote_pattern} ]]; then
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
56 if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
57 remote="↑"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
58 else
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
59 remote="↓"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
60 fi
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
61 else
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
62 remote=""
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
63 fi
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
64 diverge_pattern="Your branch and (.*) have diverged"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
65 if [[ ${git_status} =~ ${diverge_pattern} ]]; then
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
66 remote="↕"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
67 fi
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
68
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
69 # Get the name of the branch.
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
70 branch_pattern="^(#\s+)?On branch ([^${IFS}]*)"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
71 if [[ ${git_status} =~ ${branch_pattern} ]]; then
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
72 branch=${BASH_REMATCH[2]}
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
73 else
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
74 branch="?"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
75 fi
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
76
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
77 # Set the final branch string.
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
78 BRANCH=" ${state}(git:${branch})${remote}${COLOR_NONE}"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
79 return 0
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
80 }
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
81
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
82 # Determine if this is a Mercurial repo, and get the branch/state accordingly.
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
83 function set_mercurial_branch {
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
84 # See if this is a repo we care about - the one rooted in $HOME is for my
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
85 # dotfiles, so if that's what's detected just abort as other processes warn
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
86 # me about dirty repos and otherwise I would "always" be considered to be in
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
87 # a hg repo
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
88 root=$(hg root 2>/dev/null)
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
89
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
90 [[ -z "$root" || "$root" == "$HOME" ]] && return 1
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
91
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
92 # Get all the details
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
93 hg_summary=$(hg summary)
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
94
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
95 # Get the name of the branch.
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
96 branch_pattern="branch: ([^${IFS}]*)"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
97 [[ ${hg_summary} =~ ${branch_pattern} ]] && branch=${BASH_REMATCH[1]} || branch="?"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
98
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
99 # Set color based on clean/staged/dirty.
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
100 # This doesn't make a distinction between untracked files and uncommitted
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
101 # changes, anything that isn't right is dirty and red. If the working
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
102 # directory is not at the tip that's a caution.
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
103 state_pattern="commit: \(clean\)"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
104 update_pattern="update: \(current\)"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
105 if [[ ! ${hg_summary} =~ ${state_pattern} ]]; then
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
106 state="${LIGHT_RED}"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
107 elif [[ ! ${hg_summary} =~ ${update_pattern} ]]; then
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
108 state="${YELLOW}"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
109 else
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
110 state="${GREEN}"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
111 fi
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
112
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
113 #bookmarks=$(hg summary | grep "^bookmarks" | sed -e "s/^bookmarks: //" -e "s/ /,/")
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
114 #if [ -n "${bookmarks}" ]; then
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
115 # bookmarks="/${bookmarks}"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
116 #fi
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
117
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
118 # Maybe a better way using 'hg sum' for everything... that outputs:
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
119 # branch: [branch name]
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
120 # commit: [(clean) or number added/deleted/modified]
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
121 # update: [(current) or changesets to update]
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
122 # .... if I can get the root from that, that's everything needed. If not it
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
123 # still shrinks the number of calls to two from four.
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
124
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
125 # Set the final branch string.
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
126 BRANCH=" ${state}(hg:${branch}$bookmarks)${COLOR_NONE}"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
127 }
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
128
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
129 # Return the prompt symbol to use, colorized based on the return value of the
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
130 # previous command.
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
131 function set_prompt_symbol () {
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
132 if test $1 -eq 0 ; then
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
133 PROMPT_SYMBOL="\\$"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
134 else
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
135 PROMPT_SYMBOL="${LIGHT_RED}\\$${COLOR_NONE}"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
136 fi
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
137 }
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
138
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
139 # Set the full bash prompt.
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
140 function set_bash_prompt () {
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
141 # Set the PROMPT_SYMBOL variable. We do this first so we don't lose the
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
142 # return value of the last command.
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
143 set_prompt_symbol $?
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
144
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
145 # Set the BRANCH variable.
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
146 set_git_branch || set_mercurial_branch || BRANCH=''
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
147
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
148 [[ $TERM =~ (xterm|rxvt) ]] && echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
149
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
150 # Set the bash prompt variable.
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
151 # This part isn't going to work with the way it's going currently because of
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
152 # how they're evaluated. I need to think about how to do it the way it was,
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
153 # on the other hand that means if I'm in a repo when I 'su' then it'll
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
154 # always have the repo information printed there which isn't right either.
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
155 # Maybe I need to source my .bashrc when I 'su'...
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
156 case $EUID in
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
157 0)
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
158 U="\u@${LIGHT_RED}"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
159 ;;
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
160 *)
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
161 U="${LIGHT_GREEN}"
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
162 ;;
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
163 esac
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
164 export PS1="${debian_chroot:+($debian_chroot)}${U}\h${COLOR_NONE}:${LIGHT_BLUE}\w${COLOR_NONE}${BRANCH}${PROMPT_SYMBOL} "
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
165 }
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
166
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
167 # Tell bash to execute this function just before displaying its prompt.
d868be3816bf New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff changeset
168 PROMPT_COMMAND="history -a ; set_bash_prompt"