example.prompt.sh

  1. 8.0.x examples/example.prompt.sh
  2. master examples/example.prompt.sh
# -*- mode: shell-script; mode: flyspell-prog; ispell-local-dictionary: "american" -*-
#
# Example PS1 prompt.
#
# Use `drush init` to copy this to ~/.drush/drush.prompt.sh, and source it in ~/.bashrc
#
# Features:
#
# Displays Git repository and Drush alias status in your prompt.
if [ -n "$(type -t __git_ps1)" ] && [ "$(type -t __git_ps1)" = function ] && [ "$(type -t __drush_ps1)" ] && [ "$(type -t __drush_ps1)" = function ]; then

  # This line enables color hints in your Drush prompt. Modify the below
  # __drush_ps1_colorize_alias() to customize your color theme.
  DRUSH_PS1_SHOWCOLORHINTS=true

  # Git offers various prompt customization options as well as seen in
  # https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh.
  # Adjust the following lines to enable the corresponding features:
  #
  GIT_PS1_SHOWDIRTYSTATE=true
  GIT_PS1_SHOWUPSTREAM=auto
  # GIT_PS1_SHOWSTASHSTATE=true
  # GIT_PS1_SHOWUNTRACKEDFILES=true
  GIT_PS1_SHOWCOLORHINTS=true

  # The following line sets your bash prompt according to this example:
  #
  #   username@hostname ~/working-directory (git-branch)[@drush-alias] $
  #
  # See http://ss64.com/bash/syntax-prompt.html for customization options.
  export PROMPT_COMMAND='__git_ps1 "\u@\h \w" "$(__drush_ps1 "[%s]") \\\$ "'

  # PROMPT_COMMAND is used in the example above rather than PS1 because neither
  # Git nor Drush color hints are compatible with PS1. If you don't want color
  # hints, however, and prefer to use PS1, you can still do so by commenting out
  # the PROMPT_COMMAND line above and uncommenting the PS1 line below:
  #
  # export PS1='\u@\h \w$(__git_ps1 " (%s)")$(__drush_ps1 "[%s]")\$ '

  __drush_ps1_colorize_alias() {
    if [[ -n ${ZSH_VERSION-} ]]; then
      local COLOR_BLUE='%F{blue}'
      local COLOR_CYAN='%F{cyan}'
      local COLOR_GREEN='%F{green}'
      local COLOR_MAGENTA='%F{magenta}'
      local COLOR_RED='%F{red}'
      local COLOR_WHITE='%F{white}'
      local COLOR_YELLOW='%F{yellow}'
      local COLOR_NONE='%f'
    else
      # Using \[ and \] around colors is necessary to prevent issues with
      # command line editing/browsing/completion.
      local COLOR_BLUE='\[\e[94m\]'
      local COLOR_CYAN='\[\e[36m\]'
      local COLOR_GREEN='\[\e[32m\]'
      local COLOR_MAGENTA='\[\e[35m\]'
      local COLOR_RED='\[\e[91m\]'
      local COLOR_WHITE='\[\e[37m\]'
      local COLOR_YELLOW='\[\e[93m\]'
      local COLOR_NONE='\[\e[0m\]'
    fi

    # Customize your color theme below.
    case "$__DRUPAL_SITE" in
      *.live|*.prod) local ENV_COLOR="$COLOR_RED" ;;
      *.stage|*.test) local ENV_COLOR="$COLOR_YELLOW" ;;
      *.local) local ENV_COLOR="$COLOR_GREEN" ;;
      *) local ENV_COLOR="$COLOR_BLUE" ;;
    esac

    __DRUPAL_SITE="${ENV_COLOR}${__DRUPAL_SITE}${COLOR_NONE}"
  }

fi

File

examples/example.prompt.sh
View source
  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 ~/.bashrc
  6. #
  7. # Features:
  8. #
  9. # Displays Git repository and Drush alias status in your prompt.
  10. if [ -n "$(type -t __git_ps1)" ] && [ "$(type -t __git_ps1)" = function ] && [ "$(type -t __drush_ps1)" ] && [ "$(type -t __drush_ps1)" = function ]; then
  11. # This line enables color hints in your Drush prompt. Modify the below
  12. # __drush_ps1_colorize_alias() to customize your color theme.
  13. DRUSH_PS1_SHOWCOLORHINTS=true
  14. # Git offers various prompt customization options as well as seen in
  15. # https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh.
  16. # Adjust the following lines to enable the corresponding features:
  17. #
  18. GIT_PS1_SHOWDIRTYSTATE=true
  19. GIT_PS1_SHOWUPSTREAM=auto
  20. # GIT_PS1_SHOWSTASHSTATE=true
  21. # GIT_PS1_SHOWUNTRACKEDFILES=true
  22. GIT_PS1_SHOWCOLORHINTS=true
  23. # The following line sets your bash prompt according to this example:
  24. #
  25. # username@hostname ~/working-directory (git-branch)[@drush-alias] $
  26. #
  27. # See http://ss64.com/bash/syntax-prompt.html for customization options.
  28. export PROMPT_COMMAND='__git_ps1 "\u@\h \w" "$(__drush_ps1 "[%s]") \\\$ "'
  29. # PROMPT_COMMAND is used in the example above rather than PS1 because neither
  30. # Git nor Drush color hints are compatible with PS1. If you don't want color
  31. # hints, however, and prefer to use PS1, you can still do so by commenting out
  32. # the PROMPT_COMMAND line above and uncommenting the PS1 line below:
  33. #
  34. # export PS1='\u@\h \w$(__git_ps1 " (%s)")$(__drush_ps1 "[%s]")\$ '
  35. __drush_ps1_colorize_alias() {
  36. if [[ -n ${ZSH_VERSION-} ]]; then
  37. local COLOR_BLUE='%F{blue}'
  38. local COLOR_CYAN='%F{cyan}'
  39. local COLOR_GREEN='%F{green}'
  40. local COLOR_MAGENTA='%F{magenta}'
  41. local COLOR_RED='%F{red}'
  42. local COLOR_WHITE='%F{white}'
  43. local COLOR_YELLOW='%F{yellow}'
  44. local COLOR_NONE='%f'
  45. else
  46. # Using \[ and \] around colors is necessary to prevent issues with
  47. # command line editing/browsing/completion.
  48. local COLOR_BLUE='\[\e[94m\]'
  49. local COLOR_CYAN='\[\e[36m\]'
  50. local COLOR_GREEN='\[\e[32m\]'
  51. local COLOR_MAGENTA='\[\e[35m\]'
  52. local COLOR_RED='\[\e[91m\]'
  53. local COLOR_WHITE='\[\e[37m\]'
  54. local COLOR_YELLOW='\[\e[93m\]'
  55. local COLOR_NONE='\[\e[0m\]'
  56. fi
  57. # Customize your color theme below.
  58. case "$__DRUPAL_SITE" in
  59. *.live|*.prod) local ENV_COLOR="$COLOR_RED" ;;
  60. *.stage|*.test) local ENV_COLOR="$COLOR_YELLOW" ;;
  61. *.local) local ENV_COLOR="$COLOR_GREEN" ;;
  62. *) local ENV_COLOR="$COLOR_BLUE" ;;
  63. esac
  64. __DRUPAL_SITE="${ENV_COLOR}${__DRUPAL_SITE}${COLOR_NONE}"
  65. }
  66. fi