aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Contributions/brew_bash_completion.sh
diff options
context:
space:
mode:
authorJack Nagel2011-11-10 23:47:04 -0600
committerJack Nagel2011-11-11 00:01:05 -0600
commit0474fa11cd88ef04c3e3d77d37bd440e2790984b (patch)
tree6b5d41d207db698f9617a55064207651fa2ad26a /Library/Contributions/brew_bash_completion.sh
parent6b9fa0b818117bbc5221bd38594bbb10d507a1f8 (diff)
downloadbrew-0474fa11cd88ef04c3e3d77d37bd440e2790984b.tar.bz2
completion: add __brew_ps1 to annotate $PS1
It is often useful to be reminded that you are, in fact, in the middle of a debug or interactive install. We provided this reminder in the form of HOMEBREW_DEBUG_INSTALL, but we can make this even easier for the end user to consume by exposing it in the form of a shell function. When HOMEBREW_DEBUG_INSTALL is set, the __brew_ps1() function returns the string "(formula_name|DEBUG)" by default (much like the __git_ps1() output when performing some long-running operation, e.g. "(branch|REBASE-i)". The formatting around "formula_name|DEBUG" can be customized by passing a format string to the function. Signed-off-by: Jack Nagel <jacknagel@gmail.com>
Diffstat (limited to 'Library/Contributions/brew_bash_completion.sh')
-rw-r--r--Library/Contributions/brew_bash_completion.sh26
1 files changed, 26 insertions, 0 deletions
diff --git a/Library/Contributions/brew_bash_completion.sh b/Library/Contributions/brew_bash_completion.sh
index 32ff8d421..3488dc6f2 100644
--- a/Library/Contributions/brew_bash_completion.sh
+++ b/Library/Contributions/brew_bash_completion.sh
@@ -2,6 +2,26 @@
#
# To use, edit your .bashrc and add:
# source `brew --prefix`/Library/Contributions/brew_bash_completion.sh
+#
+# The __brew_ps1() function can be used to annotate your PS1 with
+# Homebrew debugging information; it behaves similarly to the __git_ps1()
+# function provided by the git's bash completion script.
+#
+# For example, the prompt string
+# PS1='\u@\h \W $(__brew_ps1 "(%s)") $'
+#
+# would result in a prompt like
+# user@hostname cwd $
+#
+# but if you are currently engaged in an interactive or debug install,
+# (i.e., you invoked `brew install` with either '-i' or '-d'), then the
+# prompt would look like
+# user@hostname cwd (formula_name|DEBUG) $
+#
+# You can customize the output string, e.g. $(__brew_ps1 "[%s]") would
+# output "[formula_name|DEBUG]". The default (if you do not provide a
+# format argument) is to print "(formula_name|DEBUG)" prefixed with a
+# single space.
_brew_to_completion()
{
@@ -206,4 +226,10 @@ _brew_to_completion()
esac
}
+__brew_ps1 ()
+{
+ [[ -n $HOMEBREW_DEBUG_INSTALL ]] &&
+ printf "${1:- (%s)}" "$HOMEBREW_DEBUG_INSTALL|DEBUG"
+}
+
complete -o bashdefault -o default -F _brew_to_completion brew