Mercurial > index.cgi > dotfiles
annotate .bash_prompt @ 262:93279b4ed0b4
This has been wrong for... a long time. Only realized it today on the chromebook.
author | Steve Huston <huston@srhuston.net> |
---|---|
date | Mon, 01 Apr 2024 17:46:06 -0400 |
parents | 7651a91983cd |
children | c15ff56617a9 |
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. |
259
09e37b590785
A couple changes since some systems use different syntax
Steve Huston <huston@princeton.edu>
parents:
256
diff
changeset
|
45 # Some versions of git say tree, some say directory |
09e37b590785
A couple changes since some systems use different syntax
Steve Huston <huston@princeton.edu>
parents:
256
diff
changeset
|
46 green_pattern="working (tree|directory) clean" |
09e37b590785
A couple changes since some systems use different syntax
Steve Huston <huston@princeton.edu>
parents:
256
diff
changeset
|
47 if [[ ${git_status} =~ ${green_pattern} ]]; then |
256
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
48 state="${GREEN}" |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
49 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
|
50 state="${YELLOW}" |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
51 else |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
52 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
|
53 fi |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
54 |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
55 # Set arrow icon based on status against remote. |
259
09e37b590785
A couple changes since some systems use different syntax
Steve Huston <huston@princeton.edu>
parents:
256
diff
changeset
|
56 remote_pattern="Your branch is (.*)" |
256
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
57 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
|
58 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
|
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 else |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
61 remote="↓" |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
62 fi |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
63 else |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
64 remote="" |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
65 fi |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
66 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
|
67 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
|
68 remote="↕" |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
69 fi |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
70 |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
71 # 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
|
72 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
|
73 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
|
74 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
|
75 else |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
76 branch="?" |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
77 fi |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
78 |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
79 # 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
|
80 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
|
81 return 0 |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
82 } |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
83 |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
84 # 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
|
85 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
|
86 # 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
|
87 # 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
|
88 # 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
|
89 # 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
|
90 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
|
91 |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
92 [[ -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
|
93 |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
94 # 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
|
95 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
|
96 |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
97 # 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
|
98 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
|
99 [[ ${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
|
100 |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
101 # 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
|
102 # 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
|
103 # 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
|
104 # 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 state="${YELLOW}" |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
111 else |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
112 state="${GREEN}" |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
113 fi |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
114 |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
115 #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
|
116 #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
|
117 # bookmarks="/${bookmarks}" |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
118 #fi |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
119 |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
120 # 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
|
121 # 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
|
122 # 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
|
123 # 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
|
124 # .... 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
|
125 # 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
|
126 |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
127 # 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
|
128 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
|
129 } |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
130 |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
131 # 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
|
132 # previous command. |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
133 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
|
134 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
|
135 PROMPT_SYMBOL="\\$" |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
136 else |
261
7651a91983cd
Had to swap the logic on PROMPT_COMMAND, and one more escape slash.
Steve Huston <huston@srhuston.net>
parents:
259
diff
changeset
|
137 PROMPT_SYMBOL="${LIGHT_RED}\\\$${COLOR_NONE}" |
256
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
138 fi |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
139 } |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
140 |
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 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
|
142 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
|
143 # 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
|
144 # 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
|
145 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
|
146 |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
147 # 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
|
148 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
|
149 |
262
93279b4ed0b4
This has been wrong for... a long time. Only realized it today on the chromebook.
Steve Huston <huston@srhuston.net>
parents:
261
diff
changeset
|
150 [[ $TERM =~ (xterm|rxvt) ]] && echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/\~}\007" |
256
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
151 |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
152 # 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
|
153 # 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
|
154 # 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
|
155 # 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
|
156 # 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
|
157 # 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
|
158 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
|
159 0) |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
160 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
|
161 ;; |
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 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
|
164 ;; |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
165 esac |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
166 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
|
167 } |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
168 |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
169 # Tell bash to execute this function just before displaying its prompt. |
261
7651a91983cd
Had to swap the logic on PROMPT_COMMAND, and one more escape slash.
Steve Huston <huston@srhuston.net>
parents:
259
diff
changeset
|
170 PROMPT_COMMAND="set_bash_prompt ; history -a" |