Mercurial > index.cgi > dotfiles
annotate .shared/bash_prompt @ 265:df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
through an SSH connection to be used and cleaned up when finished.
author | Steve Huston <huston@srhuston.net> |
---|---|
date | Wed, 24 Apr 2024 16:15:40 -0400 |
parents | .bash_prompt@c15ff56617a9 |
children |
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. |
263
c15ff56617a9
Have to catch things a little differently, newer git output isn't the same
Steve Huston <huston@princeton.edu>
parents:
262
diff
changeset
|
56 remote_pattern="Your branch is ([^${IFS}]*)" |
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="↑" |
263
c15ff56617a9
Have to catch things a little differently, newer git output isn't the same
Steve Huston <huston@princeton.edu>
parents:
262
diff
changeset
|
60 elif [[ ${BASH_REMATCH[1]} == "up" ]]; then |
c15ff56617a9
Have to catch things a little differently, newer git output isn't the same
Steve Huston <huston@princeton.edu>
parents:
262
diff
changeset
|
61 remote="" |
256
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
62 else |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
63 remote="↓" |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
64 fi |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
65 else |
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 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
|
69 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
|
70 remote="↕" |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
71 fi |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
72 |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
73 # 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
|
74 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
|
75 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
|
76 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
|
77 else |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
78 branch="?" |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
79 fi |
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 # 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
|
82 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
|
83 return 0 |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
84 } |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
85 |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
86 # 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
|
87 function set_mercurial_branch { |
265
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
263
diff
changeset
|
88 # I keep my dotfiles in a mercurial repo rooted in $HOME, so if that's |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
263
diff
changeset
|
89 # what's detected just abort as other processes warn me about dirty repos |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
263
diff
changeset
|
90 # and otherwise I would "always" be considered to be in a hg repo |
256
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
91 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
|
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 |
265
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
263
diff
changeset
|
115 # I still have to incorporate this part, or decide not to |
256
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
116 #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
|
117 #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
|
118 # bookmarks="/${bookmarks}" |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
119 #fi |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
120 |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
121 # 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
|
122 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
|
123 } |
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 # 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
|
126 # previous command. |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
127 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
|
128 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
|
129 PROMPT_SYMBOL="\\$" |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
130 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
|
131 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
|
132 fi |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
133 } |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
134 |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
135 # 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
|
136 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
|
137 # 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
|
138 # 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
|
139 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
|
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 BRANCH variable. |
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
142 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
|
143 |
265
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
263
diff
changeset
|
144 # Only change the terminal title bar if it's really an xterm - don't want it |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
263
diff
changeset
|
145 # set on screen window names, that's annoying. |
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
|
146 [[ $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
|
147 |
265
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
263
diff
changeset
|
148 # If we're root, we'd like to call attention to that. |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
263
diff
changeset
|
149 case $EUID in |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
263
diff
changeset
|
150 0) |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
263
diff
changeset
|
151 U="${LIGHT_RED}\u@" |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
263
diff
changeset
|
152 ;; |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
263
diff
changeset
|
153 *) |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
263
diff
changeset
|
154 U="\u@${LIGHT_GREEN}" |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
263
diff
changeset
|
155 ;; |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
263
diff
changeset
|
156 esac |
df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
Steve Huston <huston@srhuston.net>
parents:
263
diff
changeset
|
157 |
256
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
Steve Huston <huston@srhuston.net>
parents:
diff
changeset
|
158 # 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
|
159 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
|
160 } |
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 # 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
|
163 PROMPT_COMMAND="set_bash_prompt ; history -a" |