adeab93019c183f05653419d5b6c5ff0921e7ecb
[yaffs-website] / vendor / drush / drush / examples / example.prompt.sh
1 # -*- mode: shell-script; mode: flyspell-prog; ispell-local-dictionary: "american" -*-
2 #
3 # Example PS1 prompt.
4 #
5 # Use `drush init` to copy this to ~/.drush/drush.prompt.sh, and source it in
6 # ~/.bashrc or ~/.bash_profile.
7 #
8 # Note that your Bash session must already have the __git_ps1 function available.
9 # Typically this is provided by git-prompt.sh, see instructions for downloading
10 # and including this file here:
11 # https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
12 #
13 # Features:
14 #
15 # Displays Git repository and Drush alias status in your prompt.
16
17 __drush_ps1() {
18   f="${TMPDIR:-/tmp/}/drush-env-${USER}/drush-drupal-site-$$"
19   if [ -f $f ]
20   then
21     __DRUPAL_SITE=$(cat "$f")
22   else
23     __DRUPAL_SITE="$DRUPAL_SITE"
24   fi
25
26   # Set DRUSH_PS1_SHOWCOLORHINTS to a non-empty value and define a
27   # __drush_ps1_colorize_alias() function for color hints in your Drush PS1
28   # prompt. See example.prompt.sh for an example implementation.
29   if [ -n "${__DRUPAL_SITE-}" ] && [ -n "${DRUSH_PS1_SHOWCOLORHINTS-}" ]; then
30     __drush_ps1_colorize_alias
31   fi
32
33   [[ -n "$__DRUPAL_SITE" ]] && printf "${1:- (%s)}" "$__DRUPAL_SITE"
34 }
35
36 if [ -n "$(type -t __git_ps1)" ] && [ "$(type -t __git_ps1)" = function ] && [ "$(type -t __drush_ps1)" ] && [ "$(type -t __drush_ps1)" = function ]; then
37
38   # This line enables color hints in your Drush prompt. Modify the below
39   # __drush_ps1_colorize_alias() to customize your color theme.
40   DRUSH_PS1_SHOWCOLORHINTS=true
41
42   # Git offers various prompt customization options as well as seen in
43   # https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh.
44   # Adjust the following lines to enable the corresponding features:
45   #
46   GIT_PS1_SHOWDIRTYSTATE=true
47   GIT_PS1_SHOWUPSTREAM=auto
48   # GIT_PS1_SHOWSTASHSTATE=true
49   # GIT_PS1_SHOWUNTRACKEDFILES=true
50   GIT_PS1_SHOWCOLORHINTS=true
51
52   # The following line sets your bash prompt according to this example:
53   #
54   #   username@hostname ~/working-directory (git-branch)[@drush-alias] $
55   #
56   # See http://ss64.com/bash/syntax-prompt.html for customization options.
57   export PROMPT_COMMAND='__git_ps1 "\u@\h \w" "$(__drush_ps1 "[%s]") \\\$ "'
58
59   # PROMPT_COMMAND is used in the example above rather than PS1 because neither
60   # Git nor Drush color hints are compatible with PS1. If you don't want color
61   # hints, however, and prefer to use PS1, you can still do so by commenting out
62   # the PROMPT_COMMAND line above and uncommenting the PS1 line below:
63   #
64   # export PS1='\u@\h \w$(__git_ps1 " (%s)")$(__drush_ps1 "[%s]")\$ '
65
66   __drush_ps1_colorize_alias() {
67     if [[ -n ${ZSH_VERSION-} ]]; then
68       local COLOR_BLUE='%F{blue}'
69       local COLOR_CYAN='%F{cyan}'
70       local COLOR_GREEN='%F{green}'
71       local COLOR_MAGENTA='%F{magenta}'
72       local COLOR_RED='%F{red}'
73       local COLOR_WHITE='%F{white}'
74       local COLOR_YELLOW='%F{yellow}'
75       local COLOR_NONE='%f'
76     else
77       # Using \[ and \] around colors is necessary to prevent issues with
78       # command line editing/browsing/completion.
79       local COLOR_BLUE='\[\e[94m\]'
80       local COLOR_CYAN='\[\e[36m\]'
81       local COLOR_GREEN='\[\e[32m\]'
82       local COLOR_MAGENTA='\[\e[35m\]'
83       local COLOR_RED='\[\e[91m\]'
84       local COLOR_WHITE='\[\e[37m\]'
85       local COLOR_YELLOW='\[\e[93m\]'
86       local COLOR_NONE='\[\e[0m\]'
87     fi
88
89     # Customize your color theme below.
90     case "$__DRUPAL_SITE" in
91       *.live|*.prod) local ENV_COLOR="$COLOR_RED" ;;
92       *.stage|*.test) local ENV_COLOR="$COLOR_YELLOW" ;;
93       *.local) local ENV_COLOR="$COLOR_GREEN" ;;
94       *) local ENV_COLOR="$COLOR_BLUE" ;;
95     esac
96
97     __DRUPAL_SITE="${ENV_COLOR}${__DRUPAL_SITE}${COLOR_NONE}"
98   }
99
100 fi