spather

Untitled

Nov 3rd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. # Copyright (C) 2015 Facebook, Inc
  2. # Maintained by Ryan McElroy <[email protected]>
  3. #
  4. # Inspiration and derivation from git-completion.bash by Shawn O. Pearce.
  5. #
  6. # Distributed under the GNU General Public License, version 2.0.
  7. #
  8. # ========================================================================
  9. #
  10. # Quickly determines the and emits some useful information about the state
  11. # of your current mercurial or git repository. Useful for PS1 prompts.
  12. #
  13. # Design goals:
  14. # * Useful for both git and mercurial
  15. # * Portable to both zsh and bash
  16. # * Portable to both Mac (BSD-based utils) and Linux (GNU-based utils)
  17. # * As fast as possible given the above constraints (few command invocations)
  18. # * Avoids invoking git or mercurial, which may be slow on large repositories
  19. #
  20. # To use from zsh:
  21. #
  22. # NOTE! the single quotes are important; if you use double quotes
  23. # then the prompt won't change when you chdir or checkout different
  24. # branches!
  25. #
  26. # setopt PROMPT_SUBST
  27. # source /path/to/scm-prompt
  28. # export PS1='$(_scm_prompt)$USER@%m:%~%% '
  29. #
  30. # To use from bash:
  31. #
  32. # source /path/to/scm-prompt
  33. # export PS1="\$(_scm_prompt)\u@\h:\W\$ "
  34. #
  35. # NOTE! You *EITHER* need to single-quote the whole thing *OR* back-slash
  36. # the $(...) (as above), but not both. Which one you use depends on if
  37. # you need the rest of your PS1 to interpolate variables.
  38. #
  39. # You may additionally pass a format-string to the scm_info command. This
  40. # allows you to control the format of the prompt string without interfering
  41. # with the prompt outside of a mercurial or git repository. For example:
  42. #
  43. # $(_scm_prompt "%s")
  44. #
  45. # The default format string is " (%s)" (note the space)
  46. #
  47. # Options: you may want to set these environment variables
  48. # * HOME_IS_NOT_A_REPO : Stop walking up the filesystem looking for a git or
  49. # hg repo at (but not including) /home instead of /. This helps when /home
  50. # is a remote or autofs mount point.
  51. # * WANT_OLD_SCM_PROMPT : Use '%s' as the formatting for the prompt instead
  52. # of ' (%s)'
  53. #
  54. # Notes to developers:
  55. #
  56. # * Aliases can screw up the default commands. To prevent this issue, use
  57. # the 'builtin' prefix for built-in shell commands (eg, 'cd' and 'echo')
  58. # and use the 'command' prefix for external commands that you do not want
  59. # to invoke aliases for (eg, 'grep', 'cut').
  60. #
  61. # =========================================================================
  62. #
  63.  
  64. _find_most_relevant() {
  65. # We don't want to output all remote bookmarks because there can be many
  66. # of them. This function finds the most relevant remote bookmark using this
  67. # algorithm:
  68. # 1. If 'master' or '@' bookmark is available then output it
  69. # 2. Sort remote bookmarks and output the first in reverse sorted order (
  70. # it's a heuristic that tries to find the newest bookmark. It will work well
  71. # with bookmarks like 'release20160926' and 'release20161010').
  72. relevantbook="$(command grep -m1 -E -o "^[^/] /(master|@)$" <<< "$1")"
  73. if [[ -n $relevantbook ]]; then
  74. builtin echo $relevantbook
  75. return 0
  76. fi
  77.  
  78. builtin echo "$(command sort -r <<< "$1" | command head -n 1)"
  79. }
  80.  
  81. _hg_prompt() {
  82. local hg br extra
  83. hg="$1"
  84.  
  85. if [[ -f "$hg/bisect.state" ]]; then
  86. extra="|BISECT"
  87. elif [[ -f "$hg/histedit-state" ]]; then
  88. extra="|HISTEDIT"
  89. elif [[ -f "$hg/graftstate" ]]; then
  90. extra="|GRAFT"
  91. elif [[ -f "$hg/unshelverebasestate" ]]; then
  92. extra="|UNSHELVE"
  93. elif [[ -f "$hg/rebasestate" ]]; then
  94. extra="|REBASE"
  95. elif [[ -d "$hg/merge" ]]; then
  96. extra="|MERGE"
  97. elif [[ -L "$hg/store/lock" ]]; then
  98. extra="|STORE-LOCKED"
  99. elif [[ -L "$hg/wlock" ]]; then
  100. extra="|WDIR-LOCKED"
  101. fi
  102. local dirstate="$( \
  103. ( [[ -f "$hg/dirstate" ]]
Add Comment
Please, Sign In to add comment