Mercurial > index.cgi > dotfiles
annotate .bash_prompt @ 264:bb69763716a7
Buncha changes for floyd thanks to RHEL8
| author | Steve Huston <huston@princeton.edu> | 
|---|---|
| date | Thu, 18 Apr 2024 13:37:00 -0400 | 
| parents | 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: 
256diff
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: 
256diff
changeset | 46 green_pattern="working (tree|directory) clean" | 
| 
09e37b590785
A couple changes since some systems use different syntax
 Steve Huston <huston@princeton.edu> parents: 
256diff
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: 
262diff
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: 
262diff
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: 
262diff
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 { | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 88 # 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 | 89 # 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 | 90 # 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 | 91 # 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 | 92 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 | 93 | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 94 [[ -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 | 95 | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 96 # 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 | 97 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 | 98 | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 99 # 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 | 100 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 | 101 [[ ${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 | 102 | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 103 # 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 | 104 # 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 | 105 # 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 | 106 # 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 | 107 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 | 108 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 | 109 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 | 110 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 | 111 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 | 112 state="${YELLOW}" | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 113 else | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 114 state="${GREEN}" | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 115 fi | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 116 | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 117 #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 | 118 #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 | 119 # bookmarks="/${bookmarks}" | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 120 #fi | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 121 | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 122 # 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 | 123 # 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 | 124 # 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 | 125 # 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 | 126 # .... 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 | 127 # 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 | 128 | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 129 # 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 | 130 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 | 131 } | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 132 | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 133 # 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 | 134 # previous command. | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 135 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 | 136 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 | 137 PROMPT_SYMBOL="\\$" | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 138 else | 
| 261 
7651a91983cd
Had to swap the logic on PROMPT_COMMAND, and one more escape slash.
 Steve Huston <huston@srhuston.net> parents: 
259diff
changeset | 139 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 | 140 fi | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 141 } | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 142 | 
| 
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 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 | 144 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 | 145 # 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 | 146 # 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 | 147 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 | 148 | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 149 # 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 | 150 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 | 151 | 
| 262 
93279b4ed0b4
This has been wrong for... a long time.  Only realized it today on the chromebook.
 Steve Huston <huston@srhuston.net> parents: 
261diff
changeset | 152 [[ $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 | 153 | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 154 # 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 | 155 # 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 | 156 # 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 | 157 # 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 | 158 # 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 | 159 # 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 | 160 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 | 161 0) | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 162 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 | 163 ;; | 
| 
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 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 | 166 ;; | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 167 esac | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 168 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 | 169 } | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 170 | 
| 
d868be3816bf
New prompt settings to test out, works well on the Mac so far.
 Steve Huston <huston@srhuston.net> parents: diff
changeset | 171 # 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: 
259diff
changeset | 172 PROMPT_COMMAND="set_bash_prompt ; history -a" | 
