my xfce4 dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

469 lines
19 KiB

3 years ago
  1. # Bash bindings for gitstatus.
  2. [[ $- == *i* ]] || return # non-interactive shell
  3. # Starts gitstatusd in the background. Does nothing and succeeds if gitstatusd
  4. # is already running.
  5. #
  6. # Usage: gitstatus_start [OPTION]...
  7. #
  8. # -t FLOAT Fail the self-check on initialization if not getting a response from
  9. # gitstatusd for this this many seconds. Defaults to 5.
  10. #
  11. # -s INT Report at most this many staged changes; negative value means infinity.
  12. # Defaults to 1.
  13. #
  14. # -u INT Report at most this many unstaged changes; negative value means infinity.
  15. # Defaults to 1.
  16. #
  17. # -c INT Report at most this many conflicted changes; negative value means infinity.
  18. # Defaults to 1.
  19. #
  20. # -d INT Report at most this many untracked files; negative value means infinity.
  21. # Defaults to 1.
  22. #
  23. # -m INT Report -1 unstaged, untracked and conflicted if there are more than this many
  24. # files in the index. Negative value means infinity. Defaults to -1.
  25. #
  26. # -e Count files within untracked directories like `git status --untracked-files`.
  27. #
  28. # -U Unless this option is specified, report zero untracked files for repositories
  29. # with status.showUntrackedFiles = false.
  30. #
  31. # -W Unless this option is specified, report zero untracked files for repositories
  32. # with bash.showUntrackedFiles = false.
  33. #
  34. # -D Unless this option is specified, report zero staged, unstaged and conflicted
  35. # changes for repositories with bash.showDirtyState = false.
  36. #
  37. # -r INT Close git repositories that haven't been used for this many seconds. This is
  38. # meant to release resources such as memory and file descriptors. The next request
  39. # for a repo that's been closed is much slower than for a repo that hasn't been.
  40. # Negative value means infinity. The default is 3600 (one hour).
  41. function gitstatus_start() {
  42. if [[ "$BASH_VERSION" < 4 ]]; then
  43. >&2 printf 'gitstatus_start: need bash version >= 4.0, found %s\n' "$BASH_VERSION"
  44. >&2 printf '\n'
  45. >&2 printf 'To see the version of the current shell, type:\n'
  46. >&2 printf '\n'
  47. >&2 printf ' \033[32mecho\033[0m \033[33m"$BASH_VERSION"\033[0m\n'
  48. >&2 printf '\n'
  49. >&2 printf 'The output of `\033[32mbash\033[0m --version` may be different and is not relevant.\n'
  50. return 1
  51. fi
  52. unset OPTIND
  53. local opt timeout=5 max_dirty=-1 ttl=3600 extra_flags=
  54. local max_num_staged=1 max_num_unstaged=1 max_num_conflicted=1 max_num_untracked=1
  55. while getopts "t:s:u:c:d:m:r:eUWD" opt; do
  56. case "$opt" in
  57. t) timeout=$OPTARG;;
  58. s) max_num_staged=$OPTARG;;
  59. u) max_num_unstaged=$OPTARG;;
  60. c) max_num_conflicted=$OPTARG;;
  61. d) max_num_untracked=$OPTARG;;
  62. m) max_dirty=$OPTARG;;
  63. r) ttl=$OPTARG;;
  64. e) extra_flags+='--recurse-untracked-dirs ';;
  65. U) extra_flags+='--ignore-status-show-untracked-files ';;
  66. W) extra_flags+='--ignore-bash-show-untracked-files ';;
  67. D) extra_flags+='--ignore-bash-show-dirty-state ';;
  68. *) return 1;;
  69. esac
  70. done
  71. (( OPTIND == $# + 1 )) || { echo "usage: gitstatus_start [OPTION]..." >&2; return 1; }
  72. [[ -z "${GITSTATUS_DAEMON_PID:-}" ]] || return 0 # already started
  73. if [[ "${BASH_SOURCE[0]}" == */* ]]; then
  74. local gitstatus_plugin_dir="${BASH_SOURCE[0]%/*}"
  75. if [[ "$gitstatus_plugin_dir" != /* ]]; then
  76. gitstatus_plugin_dir="$PWD"/"$gitstatus_plugin_dir"
  77. fi
  78. else
  79. local gitstatus_plugin_dir="$PWD"
  80. fi
  81. local tmpdir req_fifo resp_fifo culprit
  82. function gitstatus_start_impl() {
  83. local log_level="${GITSTATUS_LOG_LEVEL:-}"
  84. [[ -n "$log_level" || "${GITSTATUS_ENABLE_LOGGING:-0}" != 1 ]] || log_level=INFO
  85. local uname_sm
  86. uname_sm="$(command uname -sm)" || return
  87. uname_sm="${uname_sm,,}"
  88. local uname_s="${uname_sm% *}"
  89. local uname_m="${uname_sm#* }"
  90. if [[ "${GITSTATUS_NUM_THREADS:-0}" -gt 0 ]]; then
  91. local threads="$GITSTATUS_NUM_THREADS"
  92. else
  93. local cpus
  94. if ! command -v sysctl &>/dev/null || [[ "$uname_s" == linux ]] ||
  95. ! cpus="$(command sysctl -n hw.ncpu)"; then
  96. if ! command -v getconf &>/dev/null || ! cpus="$(command getconf _NPROCESSORS_ONLN)"; then
  97. cpus=8
  98. fi
  99. fi
  100. local threads=$((cpus > 16 ? 32 : cpus > 0 ? 2 * cpus : 16))
  101. fi
  102. local daemon_args=(
  103. --parent-pid="$$"
  104. --num-threads="$threads"
  105. --max-num-staged="$max_num_staged"
  106. --max-num-unstaged="$max_num_unstaged"
  107. --max-num-conflicted="$max_num_conflicted"
  108. --max-num-untracked="$max_num_untracked"
  109. --dirty-max-index-size="$max_dirty"
  110. --repo-ttl-seconds="$ttl"
  111. $extra_flags)
  112. tmpdir="$(command mktemp -d "${TMPDIR:-/tmp}"/gitstatus.bash.$$.XXXXXXXXXX)" || return
  113. if [[ -n "$log_level" ]]; then
  114. GITSTATUS_DAEMON_LOG="$tmpdir"/daemon.log
  115. [[ "$log_level" == INFO ]] || daemon_args+=(--log-level="$log_level")
  116. else
  117. GITSTATUS_DAEMON_LOG=/dev/null
  118. fi
  119. req_fifo="$tmpdir"/req.fifo
  120. resp_fifo="$tmpdir"/resp.fifo
  121. command mkfifo -- "$req_fifo" "$resp_fifo" || return
  122. {
  123. (
  124. trap '' INT QUIT TSTP
  125. [[ "$GITSTATUS_DAEMON_LOG" == /dev/null ]] || set -x
  126. builtin cd /
  127. (
  128. local fd_in fd_out
  129. exec {fd_in}<"$req_fifo" {fd_out}>>"$resp_fifo" || exit
  130. echo "$BASHPID" >&"$fd_out"
  131. local _gitstatus_bash_daemon _gitstatus_bash_version _gitstatus_bash_downloaded
  132. function _gitstatus_set_daemon() {
  133. _gitstatus_bash_daemon="$1"
  134. _gitstatus_bash_version="$2"
  135. _gitstatus_bash_downloaded="$3"
  136. }
  137. set -- -d "$gitstatus_plugin_dir" -s "$uname_s" -m "$uname_m" \
  138. -p "printf '.\036' >&$fd_out" -e "$fd_out" -- _gitstatus_set_daemon
  139. [[ "${GITSTATUS_AUTO_INSTALL:-1}" -ne 0 ]] || set -- -n "$@"
  140. source "$gitstatus_plugin_dir"/install || return
  141. [[ -n "$_gitstatus_bash_daemon" ]] || return
  142. [[ -n "$_gitstatus_bash_version" ]] || return
  143. [[ "$_gitstatus_bash_downloaded" == [01] ]] || return
  144. local sig=(TERM ILL PIPE)
  145. if (( UID == EUID )); then
  146. local home=~
  147. else
  148. local user
  149. user="$(command id -un)" || return
  150. [[ "$user" =~ ^[a-zA-Z0-9_,.-]+$ ]] || return
  151. eval "local home=~$user"
  152. [[ -n "$home" ]] || return
  153. fi
  154. if [[ -x "$_gitstatus_bash_daemon" ]]; then
  155. HOME="$home" "$_gitstatus_bash_daemon" \
  156. -G "$_gitstatus_bash_version" "${daemon_args[@]}" <&"$fd_in" >&"$fd_out" &
  157. local pid=$!
  158. trap "trap - ${sig[*]}; kill $pid &>/dev/null" ${sig[@]}
  159. wait "$pid"
  160. local ret=$?
  161. trap - ${sig[@]}
  162. case "$ret" in
  163. 0|129|130|131|137|141|143|159)
  164. echo -nE $'}bye\x1f0\x1e' >&"$fd_out"
  165. exit "$ret"
  166. ;;
  167. esac
  168. fi
  169. (( ! _gitstatus_bash_downloaded )) || return
  170. [[ "${GITSTATUS_AUTO_INSTALL:-1}" -ne 0 ]] || return
  171. [[ "$_gitstatus_bash_daemon" == \
  172. "${GITSTATUS_CACHE_DIR:-${XDG_CACHE_HOME:-$HOME/.cache}/gitstatus}"/* ]] || return
  173. set -- -f "$@"
  174. _gitstatus_bash_daemon=
  175. _gitstatus_bash_version=
  176. _gitstatus_bash_downloaded=
  177. source "$gitstatus_plugin_dir"/install || return
  178. [[ -n "$_gitstatus_bash_daemon" ]] || return
  179. [[ -n "$_gitstatus_bash_version" ]] || return
  180. [[ "$_gitstatus_bash_downloaded" == 1 ]] || return
  181. HOME="$home" "$_gitstatus_bash_daemon" \
  182. -G "$_gitstatus_bash_version" "${daemon_args[@]}" <&"$fd_in" >&"$fd_out" &
  183. local pid=$!
  184. trap "trap - ${sig[*]}; kill $pid &>/dev/null" ${sig[@]}
  185. wait "$pid"
  186. trap - ${sig[@]}
  187. echo -nE $'}bye\x1f0\x1e' >&"$fd_out"
  188. ) & disown
  189. ) & disown
  190. } 0</dev/null &>"$GITSTATUS_DAEMON_LOG"
  191. exec {_GITSTATUS_REQ_FD}>>"$req_fifo" {_GITSTATUS_RESP_FD}<"$resp_fifo" || return
  192. command rm -f -- "$req_fifo" "$resp_fifo" || return
  193. [[ "$GITSTATUS_DAEMON_LOG" != /dev/null ]] || command rmdir -- "$tmpdir" 2>/dev/null
  194. IFS='' read -r -u $_GITSTATUS_RESP_FD GITSTATUS_DAEMON_PID || return
  195. [[ "$GITSTATUS_DAEMON_PID" == [1-9]* ]] || return
  196. local reply
  197. echo -nE $'}hello\x1f\x1e' >&$_GITSTATUS_REQ_FD || return
  198. local dl=
  199. while true; do
  200. reply=
  201. if ! IFS='' read -rd $'\x1e' -u $_GITSTATUS_RESP_FD -t "$timeout" reply; then
  202. culprit="$reply"
  203. return 1
  204. fi
  205. [[ "$reply" == $'}hello\x1f0' ]] && break
  206. if [[ -z "$dl" ]]; then
  207. dl=1
  208. if [[ -t 2 ]]; then
  209. local spinner=('\b\033[33m-\033[0m' '\b\033[33m\\\033[0m' '\b\033[33m|\033[0m' '\b\033[33m/\033[0m')
  210. >&2 printf '[\033[33mgitstatus\033[0m] fetching \033[32mgitstatusd\033[0m .. '
  211. else
  212. local spinner=('.')
  213. >&2 printf '[gitstatus] fetching gitstatusd ..'
  214. fi
  215. fi
  216. >&2 printf "${spinner[0]}"
  217. spinner=("${spinner[@]:1}" "${spinner[0]}")
  218. done
  219. if [[ -n "$dl" ]]; then
  220. if [[ -t 2 ]]; then
  221. >&2 printf '\b[\033[32mok\033[0m]\n'
  222. else
  223. >&2 echo ' [ok]'
  224. fi
  225. fi
  226. _GITSTATUS_DIRTY_MAX_INDEX_SIZE=$max_dirty
  227. _GITSTATUS_CLIENT_PID="$BASHPID"
  228. }
  229. if ! gitstatus_start_impl; then
  230. >&2 printf '\n'
  231. >&2 printf '[\033[31mERROR\033[0m]: gitstatus failed to initialize.\n'
  232. if [[ -n "${culprit-}" ]]; then
  233. >&2 printf '\n%s\n' "$culprit"
  234. fi
  235. [[ -z "${req_fifo:-}" ]] || command rm -f "$req_fifo"
  236. [[ -z "${resp_fifo:-}" ]] || command rm -f "$resp_fifo"
  237. unset -f gitstatus_start_impl
  238. gitstatus_stop
  239. return 1
  240. fi
  241. export _GITSTATUS_CLIENT_PID _GITSTATUS_REQ_FD _GITSTATUS_RESP_FD GITSTATUS_DAEMON_PID
  242. unset -f gitstatus_start_impl
  243. }
  244. # Stops gitstatusd if it's running.
  245. function gitstatus_stop() {
  246. if [[ "${_GITSTATUS_CLIENT_PID:-$BASHPID}" == "$BASHPID" ]]; then
  247. [[ -z "${_GITSTATUS_REQ_FD:-}" ]] || exec {_GITSTATUS_REQ_FD}>&- || true
  248. [[ -z "${_GITSTATUS_RESP_FD:-}" ]] || exec {_GITSTATUS_RESP_FD}>&- || true
  249. [[ -z "${GITSTATUS_DAEMON_PID:-}" ]] || kill "$GITSTATUS_DAEMON_PID" &>/dev/null || true
  250. fi
  251. unset _GITSTATUS_REQ_FD _GITSTATUS_RESP_FD GITSTATUS_DAEMON_PID
  252. unset _GITSTATUS_DIRTY_MAX_INDEX_SIZE _GITSTATUS_CLIENT_PID
  253. }
  254. # Retrives status of a git repository from a directory under its working tree.
  255. #
  256. # Usage: gitstatus_query [OPTION]...
  257. #
  258. # -d STR Directory to query. Defaults to $PWD. Has no effect if GIT_DIR is set.
  259. # -t FLOAT Timeout in seconds. Will block for at most this long. If no results
  260. # are available by then, will return error.
  261. # -p Don't compute anything that requires reading Git index. If this option is used,
  262. # the following parameters will be 0: VCS_STATUS_INDEX_SIZE,
  263. # VCS_STATUS_{NUM,HAS}_{STAGED,UNSTAGED,UNTRACKED,CONFLICTED}.
  264. #
  265. # On success sets VCS_STATUS_RESULT to one of the following values:
  266. #
  267. # norepo-sync The directory doesn't belong to a git repository.
  268. # ok-sync The directory belongs to a git repository.
  269. #
  270. # If VCS_STATUS_RESULT is ok-sync, additional variables are set:
  271. #
  272. # VCS_STATUS_WORKDIR Git repo working directory. Not empty.
  273. # VCS_STATUS_COMMIT Commit hash that HEAD is pointing to. Either 40 hex digits or
  274. # empty if there is no HEAD (empty repo).
  275. # VCS_STATUS_COMMIT_ENCODING Encoding of the HEAD's commit message. Empty value means UTF-8.
  276. # VCS_STATUS_COMMIT_SUMMARY The first paragraph of the HEAD's commit message as one line.
  277. # VCS_STATUS_LOCAL_BRANCH Local branch name or empty if not on a branch.
  278. # VCS_STATUS_REMOTE_NAME The remote name, e.g. "upstream" or "origin".
  279. # VCS_STATUS_REMOTE_BRANCH Upstream branch name. Can be empty.
  280. # VCS_STATUS_REMOTE_URL Remote URL. Can be empty.
  281. # VCS_STATUS_ACTION Repository state, A.K.A. action. Can be empty.
  282. # VCS_STATUS_INDEX_SIZE The number of files in the index.
  283. # VCS_STATUS_NUM_STAGED The number of staged changes.
  284. # VCS_STATUS_NUM_CONFLICTED The number of conflicted changes.
  285. # VCS_STATUS_NUM_UNSTAGED The number of unstaged changes.
  286. # VCS_STATUS_NUM_UNTRACKED The number of untracked files.
  287. # VCS_STATUS_HAS_STAGED 1 if there are staged changes, 0 otherwise.
  288. # VCS_STATUS_HAS_CONFLICTED 1 if there are conflicted changes, 0 otherwise.
  289. # VCS_STATUS_HAS_UNSTAGED 1 if there are unstaged changes, 0 if there aren't, -1 if
  290. # unknown.
  291. # VCS_STATUS_NUM_STAGED_NEW The number of staged new files. Note that renamed files
  292. # are reported as deleted plus new.
  293. # VCS_STATUS_NUM_STAGED_DELETED The number of staged deleted files. Note that renamed files
  294. # are reported as deleted plus new.
  295. # VCS_STATUS_NUM_UNSTAGED_DELETED The number of unstaged deleted files. Note that renamed files
  296. # are reported as deleted plus new.
  297. # VCS_STATUS_HAS_UNTRACKED 1 if there are untracked files, 0 if there aren't, -1 if
  298. # unknown.
  299. # VCS_STATUS_COMMITS_AHEAD Number of commits the current branch is ahead of upstream.
  300. # Non-negative integer.
  301. # VCS_STATUS_COMMITS_BEHIND Number of commits the current branch is behind upstream.
  302. # Non-negative integer.
  303. # VCS_STATUS_STASHES Number of stashes. Non-negative integer.
  304. # VCS_STATUS_TAG The last tag (in lexicographical order) that points to the same
  305. # commit as HEAD.
  306. # VCS_STATUS_PUSH_REMOTE_NAME The push remote name, e.g. "upstream" or "origin".
  307. # VCS_STATUS_PUSH_REMOTE_URL Push remote URL. Can be empty.
  308. # VCS_STATUS_PUSH_COMMITS_AHEAD Number of commits the current branch is ahead of push remote.
  309. # Non-negative integer.
  310. # VCS_STATUS_PUSH_COMMITS_BEHIND Number of commits the current branch is behind push remote.
  311. # Non-negative integer.
  312. # VCS_STATUS_NUM_SKIP_WORKTREE The number of files in the index with skip-worktree bit set.
  313. # Non-negative integer.
  314. # VCS_STATUS_NUM_ASSUME_UNCHANGED The number of files in the index with assume-unchanged bit set.
  315. # Non-negative integer.
  316. #
  317. # The point of reporting -1 via VCS_STATUS_HAS_* is to allow the command to skip scanning files in
  318. # large repos. See -m flag of gitstatus_start.
  319. #
  320. # gitstatus_query returns an error if gitstatus_start hasn't been called in the same
  321. # shell or the call had failed.
  322. function gitstatus_query() {
  323. unset OPTIND
  324. local opt dir= timeout=() no_diff=0
  325. while getopts "d:c:t:p" opt "$@"; do
  326. case "$opt" in
  327. d) dir=$OPTARG;;
  328. t) timeout=(-t "$OPTARG");;
  329. p) no_diff=1;;
  330. *) return 1;;
  331. esac
  332. done
  333. (( OPTIND == $# + 1 )) || { echo "usage: gitstatus_query [OPTION]..." >&2; return 1; }
  334. [[ -n "${GITSTATUS_DAEMON_PID-}" ]] || return # not started
  335. local req_id="$RANDOM.$RANDOM.$RANDOM.$RANDOM"
  336. if [[ -z "${GIT_DIR:-}" ]]; then
  337. [[ "$dir" == /* ]] || dir="$(pwd -P)/$dir" || return
  338. elif [[ "$GIT_DIR" == /* ]]; then
  339. dir=:"$GIT_DIR"
  340. else
  341. dir=:"$(pwd -P)/$GIT_DIR" || return
  342. fi
  343. echo -nE "$req_id"$'\x1f'"$dir"$'\x1f'"$no_diff"$'\x1e' >&$_GITSTATUS_REQ_FD || return
  344. local -a resp
  345. while true; do
  346. IFS=$'\x1f' read -rd $'\x1e' -a resp -u $_GITSTATUS_RESP_FD "${timeout[@]}" || return
  347. [[ "${resp[0]}" == "$req_id" ]] && break
  348. done
  349. if [[ "${resp[1]}" == 1 ]]; then
  350. VCS_STATUS_RESULT=ok-sync
  351. VCS_STATUS_WORKDIR="${resp[2]}"
  352. VCS_STATUS_COMMIT="${resp[3]}"
  353. VCS_STATUS_LOCAL_BRANCH="${resp[4]}"
  354. VCS_STATUS_REMOTE_BRANCH="${resp[5]}"
  355. VCS_STATUS_REMOTE_NAME="${resp[6]}"
  356. VCS_STATUS_REMOTE_URL="${resp[7]}"
  357. VCS_STATUS_ACTION="${resp[8]}"
  358. VCS_STATUS_INDEX_SIZE="${resp[9]}"
  359. VCS_STATUS_NUM_STAGED="${resp[10]}"
  360. VCS_STATUS_NUM_UNSTAGED="${resp[11]}"
  361. VCS_STATUS_NUM_CONFLICTED="${resp[12]}"
  362. VCS_STATUS_NUM_UNTRACKED="${resp[13]}"
  363. VCS_STATUS_COMMITS_AHEAD="${resp[14]}"
  364. VCS_STATUS_COMMITS_BEHIND="${resp[15]}"
  365. VCS_STATUS_STASHES="${resp[16]}"
  366. VCS_STATUS_TAG="${resp[17]}"
  367. VCS_STATUS_NUM_UNSTAGED_DELETED="${resp[18]}"
  368. VCS_STATUS_NUM_STAGED_NEW="${resp[19]:-0}"
  369. VCS_STATUS_NUM_STAGED_DELETED="${resp[20]:-0}"
  370. VCS_STATUS_PUSH_REMOTE_NAME="${resp[21]:-}"
  371. VCS_STATUS_PUSH_REMOTE_URL="${resp[22]:-}"
  372. VCS_STATUS_PUSH_COMMITS_AHEAD="${resp[23]:-0}"
  373. VCS_STATUS_PUSH_COMMITS_BEHIND="${resp[24]:-0}"
  374. VCS_STATUS_NUM_SKIP_WORKTREE="${resp[25]:-0}"
  375. VCS_STATUS_NUM_ASSUME_UNCHANGED="${resp[26]:-0}"
  376. VCS_STATUS_COMMIT_ENCODING="${resp[27]-}"
  377. VCS_STATUS_COMMIT_SUMMARY="${resp[28]-}"
  378. VCS_STATUS_HAS_STAGED=$((VCS_STATUS_NUM_STAGED > 0))
  379. if (( _GITSTATUS_DIRTY_MAX_INDEX_SIZE >= 0 &&
  380. VCS_STATUS_INDEX_SIZE > _GITSTATUS_DIRTY_MAX_INDEX_SIZE_ )); then
  381. VCS_STATUS_HAS_UNSTAGED=-1
  382. VCS_STATUS_HAS_CONFLICTED=-1
  383. VCS_STATUS_HAS_UNTRACKED=-1
  384. else
  385. VCS_STATUS_HAS_UNSTAGED=$((VCS_STATUS_NUM_UNSTAGED > 0))
  386. VCS_STATUS_HAS_CONFLICTED=$((VCS_STATUS_NUM_CONFLICTED > 0))
  387. VCS_STATUS_HAS_UNTRACKED=$((VCS_STATUS_NUM_UNTRACKED > 0))
  388. fi
  389. else
  390. VCS_STATUS_RESULT=norepo-sync
  391. unset VCS_STATUS_WORKDIR
  392. unset VCS_STATUS_COMMIT
  393. unset VCS_STATUS_LOCAL_BRANCH
  394. unset VCS_STATUS_REMOTE_BRANCH
  395. unset VCS_STATUS_REMOTE_NAME
  396. unset VCS_STATUS_REMOTE_URL
  397. unset VCS_STATUS_ACTION
  398. unset VCS_STATUS_INDEX_SIZE
  399. unset VCS_STATUS_NUM_STAGED
  400. unset VCS_STATUS_NUM_UNSTAGED
  401. unset VCS_STATUS_NUM_CONFLICTED
  402. unset VCS_STATUS_NUM_UNTRACKED
  403. unset VCS_STATUS_HAS_STAGED
  404. unset VCS_STATUS_HAS_UNSTAGED
  405. unset VCS_STATUS_HAS_CONFLICTED
  406. unset VCS_STATUS_HAS_UNTRACKED
  407. unset VCS_STATUS_COMMITS_AHEAD
  408. unset VCS_STATUS_COMMITS_BEHIND
  409. unset VCS_STATUS_STASHES
  410. unset VCS_STATUS_TAG
  411. unset VCS_STATUS_NUM_UNSTAGED_DELETED
  412. unset VCS_STATUS_NUM_STAGED_NEW
  413. unset VCS_STATUS_NUM_STAGED_DELETED
  414. unset VCS_STATUS_PUSH_REMOTE_NAME
  415. unset VCS_STATUS_PUSH_REMOTE_URL
  416. unset VCS_STATUS_PUSH_COMMITS_AHEAD
  417. unset VCS_STATUS_PUSH_COMMITS_BEHIND
  418. unset VCS_STATUS_NUM_SKIP_WORKTREE
  419. unset VCS_STATUS_NUM_ASSUME_UNCHANGED
  420. unset VCS_STATUS_COMMIT_ENCODING
  421. unset VCS_STATUS_COMMIT_SUMMARY
  422. fi
  423. }
  424. # Usage: gitstatus_check.
  425. #
  426. # Returns 0 if and only if gitstatus_start has succeeded previously.
  427. # If it returns non-zero, gitstatus_query is guaranteed to return non-zero.
  428. function gitstatus_check() {
  429. [[ -n "$GITSTATUS_DAEMON_PID" ]]
  430. }