git-prompt-help.sh 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env bash
  2. # git-prompt-help -- show useful info to help new users with the information
  3. # being displayed.
  4. git_prompt_help() {
  5. source "${__GIT_PROMPT_DIR}/prompt-colors.sh"
  6. source "${__GIT_PROMPT_DIR}/themes/Default.bgptheme"
  7. cat <<EOF | sed 's/\\\[\\033//g' | sed 's/\\\]//g'
  8. The git prompt format is ${GIT_PROMPT_PREFIX}<BRANCH><TRACKING>${GIT_PROMPT_SEPARATOR}<LOCALSTATUS>${GIT_PROMPT_SUFFIX}
  9. BRANCH is a branch name, such as "master" or "stage", a tag name, or commit
  10. hash prefixed with ':'.
  11. TRACKING indicates how the local branch differs from the
  12. remote branch. It can be empty, or one of:
  13. ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_AHEAD}N${ResetColor} - ahead of remote by N commits
  14. ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_BEHIND}M${ResetColor} - behind remote by M commits
  15. ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_AHEAD}N${GIT_PROMPT_SYMBOLS_BEHIND}M${ResetColor} - branches diverged, other by M commits, yours by N commits
  16. LOCALSTATUS is one of the following:
  17. ${GIT_PROMPT_CLEAN}${ResetColor} - repository clean
  18. ${GIT_PROMPT_STAGED}N${ResetColor} - N staged files
  19. ${GIT_PROMPT_CONFLICTS}N${ResetColor} - N files with merge conflicts
  20. ${GIT_PROMPT_CHANGED}N${ResetColor} - N changed but *unstaged* files
  21. ${GIT_PROMPT_UNTRACKED}N${ResetColor} - N untracked files
  22. ${GIT_PROMPT_STASHED}N${ResetColor} - N stash entries
  23. See "git_prompt_examples" for examples.
  24. EOF
  25. }
  26. help_git_prompt() { git_prompt_help ; }
  27. git_prompt_examples() {
  28. cat <<EOF | sed 's/\\\[\\033//g' | sed 's/\\\]//g'
  29. These are examples of the git prompt:
  30. [${GIT_PROMPT_BRANCH}master${ResetColor}${GIT_PROMPT_REMOTE}↑·3${ResetColor}|${GIT_PROMPT_CHANGED}1${ResetColor}] - on branch "master", ahead of remote by 3 commits, 1
  31. file changed but not staged
  32. [${GIT_PROMPT_BRANCH}status${ResetColor}|${GIT_PROMPT_STAGED}2${ResetColor}] - on branch "status", 2 files staged
  33. [${GIT_PROMPT_BRANCH}master${ResetColor}|${GIT_PROMPT_CHANGED}7${GIT_PROMPT_UNTRACKED}${ResetColor}] - on branch "master", 7 files changed, some files untracked
  34. [${GIT_PROMPT_BRANCH}master${ResetColor}|${GIT_PROMPT_CONFLICTS}2${GIT_PROMPT_CHANGED}3${ResetColor}] - on branch "master", 2 conflicts, 3 files changed
  35. [${GIT_PROMPT_BRANCH}master${ResetColor}|${GIT_PROMPT_STASHED}2${ResetColor}] - on branch "master", 2 stash entries
  36. [${GIT_PROMPT_BRANCH}experimental${ResetColor}${GIT_PROMPT_REMOTE}↓·2↑·3${ResetColor}|${GIT_PROMPT_CLEAN}${ResetColor}]
  37. - on branch "experimental"; your branch has diverged
  38. by 3 commits, remote by 2 commits; the repository is
  39. otherwise clean
  40. [${GIT_PROMPT_BRANCH}:70c2952${ResetColor}|${GIT_PROMPT_CLEAN}${ResetColor}] - not on any branch; parent commit has hash "70c2952"; the
  41. repository is otherwise clean
  42. EOF
  43. }
  44. git_prompt_color_samples() {
  45. showColor() {
  46. local color=$(eval echo "\${${1}}")
  47. echo -e "${color}${1}${ResetColor}" | sed 's/\\\]//g' | sed 's/\\\[//g'
  48. }
  49. local x=0
  50. while (( x < 8 )) ; do
  51. showColor "${ColorNames[x]}"
  52. showColor "Dim${ColorNames[x]}"
  53. showColor "Bold${ColorNames[x]}"
  54. showColor "Bright${ColorNames[x]}"
  55. (( x++ ))
  56. done
  57. }