OXYGENHUB
◆ v0.10.0 oxygen / contrib / oh-my-bash / oxy.sh
2.0 KiB · Bourne Again Shell (bash) · last changed Shell completions, man pages, and help for every argument 1 month ago source blame history raw
694805cc Andy McCall ↶ 1
#! bash oh-my-bash.module
2
# Oxygen segment for the oh-my-bash powerline themes.
3
#
4
# Install: copy this file to "$OSH_CUSTOM/oxy.sh" (default ~/.oh-my-bash/custom/)
5
# and open a new shell. Custom files load before the theme, so the
6
# POWERLINE_PROMPT default below adds the "oxy" segment next to the Git one;
7
# set POWERLINE_PROMPT yourself to arrange segments differently.
8
#
9
# The segment shows: icon, bookmark, working-copy change id, a state glyph
10
# (✔ clean, ✎ uncommitted changes, ‼ conflicts), and ↑n/↓n against origin.
11
# Its colour follows the state. It costs one `oxy prompt` call, a few
12
# milliseconds, and prints nothing outside an Oxygen repository.
13
14
: "${POWERLINE_PROMPT:=user_info scm oxy python_venv ruby cwd}"
15
16
OXY_CHAR=${POWERLINE_OXY_CHAR:="⚛ "}
17
OXY_THEME_PROMPT_CLEAN_COLOR=${OXY_THEME_PROMPT_CLEAN_COLOR:=25}
18
OXY_THEME_PROMPT_DIRTY_COLOR=${OXY_THEME_PROMPT_DIRTY_COLOR:=88}
19
OXY_THEME_PROMPT_CONFLICT_COLOR=${OXY_THEME_PROMPT_CONFLICT_COLOR:=160}
20
OXY_THEME_PROMPT_CLEAN_GLYPH=${OXY_THEME_PROMPT_CLEAN_GLYPH:="✔"}
21
OXY_THEME_PROMPT_DIRTY_GLYPH=${OXY_THEME_PROMPT_DIRTY_GLYPH:="✎"}
22
OXY_THEME_PROMPT_CONFLICT_GLYPH=${OXY_THEME_PROMPT_CONFLICT_GLYPH:="‼"}
23
24
function __powerline_oxy_prompt {
25
  command -v oxy >/dev/null 2>&1 || return
26
  local info
27
  info=$(oxy prompt --format '%b|%c|%d|%x|%U|%O' 2>/dev/null) || return
28
  [[ -n "$info" ]] || return
29
  local bookmark change dirty conflict up down
30
  IFS='|' read -r bookmark change dirty conflict up down <<< "$info"
31
  local color glyph
32
  if [[ -n "$conflict" ]]; then
33
    color=$OXY_THEME_PROMPT_CONFLICT_COLOR glyph=$OXY_THEME_PROMPT_CONFLICT_GLYPH
34
  elif [[ -n "$dirty" ]]; then
35
    color=$OXY_THEME_PROMPT_DIRTY_COLOR glyph=$OXY_THEME_PROMPT_DIRTY_GLYPH
36
  else
37
    color=$OXY_THEME_PROMPT_CLEAN_COLOR glyph=$OXY_THEME_PROMPT_CLEAN_GLYPH
38
  fi
39
  _omb_util_print "${OXY_CHAR}${bookmark} ${change} ${glyph}${up}${down}|${color}"
40
}
d42369ab Andy McCall 41
42
# Tab completion for oxy's commands and options.
43
if command -v oxy >/dev/null 2>&1; then
44
  # shellcheck disable=SC1090
45
  source <(oxy completions bash 2>/dev/null)
46
fi