Skip to content

Commit 3e0835f

Browse files
committed
feat(themes): add a new theme "shxll"
1 parent 05e6d03 commit 3e0835f

3 files changed

Lines changed: 151 additions & 0 deletions

File tree

themes/THEMES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@
280280

281281
[![](sexy/sexy-dark.png)](sexy/sexy-dark.png)
282282

283+
## `shxll`
284+
285+
[![](shxll/shxll-dark.png)](shxll/shxll-dark.png)
286+
283287
## `simple`
284288

285289
[![](simple/simple-dark.png)](simple/simple-dark.png)

themes/shxll/shxll-dark.png

62.1 KB
Loading

themes/shxll/shxll.theme.sh

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#! bash oh-my-bash.module
2+
3+
SHXLL_CHAR="λ"
4+
5+
__omb_theme_cmd_started=0
6+
__omb_theme_cmd_start=0
7+
__omb_theme_cmd_armed=1
8+
__omb_theme_prev_debug_trap=""
9+
10+
__omb_theme_last_clock=""
11+
__omb_theme_force_clock=1
12+
13+
__omb_theme_in_prompt=0
14+
__omb_theme_last_venv=""
15+
__omb_theme_cached_venv=""
16+
17+
__omb_theme_prev_debug_trap_src="$(trap -p DEBUG)"
18+
if [[ $__omb_theme_prev_debug_trap_src =~ ^trap\ --\ \'(.*)\'\ DEBUG$ ]]; then
19+
__omb_theme_prev_debug_trap="${BASH_REMATCH[1]}"
20+
fi
21+
unset __omb_theme_prev_debug_trap_src
22+
23+
_omb_theme_now() {
24+
if [[ -n ${EPOCHREALTIME-} ]]; then
25+
local sec frac
26+
sec=${EPOCHREALTIME%%[.,]*}
27+
frac=${EPOCHREALTIME#*[.,]}
28+
frac=${frac:0:3}
29+
printf '%s%03d' "$sec" "$((10#${frac:-0}))"
30+
else
31+
printf '%(%s%3N)T' -1x
32+
fi
33+
}
34+
35+
_omb_theme_print_clock() {
36+
local clock_now
37+
clock_now=$(date +%H:%M)
38+
39+
if [[ $__omb_theme_force_clock -eq 1 || $clock_now != $__omb_theme_last_clock ]]; then
40+
printf '\033[90m⌞ %s ⌟\033[0m\n' "$clock_now"
41+
__omb_theme_last_clock="$clock_now"
42+
fi
43+
44+
__omb_theme_force_clock=0
45+
}
46+
47+
_omb_theme_debug_trap() {
48+
[[ $__omb_theme_in_prompt -eq 1 ]] && return
49+
50+
if [[ $BASH_COMMAND == clear || $BASH_COMMAND == reset || $BASH_COMMAND == cls ]]; then
51+
__omb_theme_force_clock=1
52+
fi
53+
54+
if [[ $__omb_theme_cmd_armed -eq 1 && $__omb_theme_cmd_started -eq 0 ]]; then
55+
__omb_theme_cmd_start=$(_omb_theme_now)
56+
__omb_theme_cmd_started=1
57+
__omb_theme_cmd_armed=0
58+
fi
59+
60+
if [[ -n $__omb_theme_prev_debug_trap ]]; then
61+
eval -- "$__omb_theme_prev_debug_trap"
62+
fi
63+
}
64+
65+
trap '_omb_theme_debug_trap' DEBUG
66+
67+
_omb_theme_shxll_way_prompt_scm() {
68+
local CHAR branch dirty color
69+
CHAR=$(scm_char)
70+
71+
if [[ $CHAR != "$SCM_NONE_CHAR" ]]; then
72+
branch=$(git_clean_branch)
73+
dirty=$(git status --porcelain 2>/dev/null)
74+
75+
if [[ -n "$dirty" ]]; then
76+
color="${_omb_prompt_yellow}"
77+
else
78+
color="${_omb_prompt_blue}"
79+
fi
80+
81+
printf '%s' " ϟ ${color}${branch}${_omb_prompt_normal}"
82+
fi
83+
}
84+
85+
_omb_theme_get_venv() {
86+
local venv=${VIRTUAL_ENV-}
87+
if [[ $venv == "$__omb_theme_last_venv" ]]; then
88+
printf '%s' "$__omb_theme_cached_venv"
89+
return
90+
fi
91+
92+
local out=""
93+
_omb_prompt_get_python_venv
94+
out=$python_venv
95+
96+
__omb_theme_last_venv=$venv
97+
__omb_theme_cached_venv=$out
98+
printf '%s' "$out"
99+
}
100+
101+
function _omb_theme_PROMPT_COMMAND {
102+
local exit_code=$?
103+
local scm_segment=""
104+
local python_venv=""
105+
local ps_username=""
106+
local ps_path=""
107+
local ps_user_mark=""
108+
local status=""
109+
local time_str=""
110+
111+
__omb_theme_in_prompt=1
112+
113+
_omb_theme_print_clock
114+
115+
if [[ $__omb_theme_cmd_started -eq 1 ]]; then
116+
local now elapsed_ms
117+
now=$(_omb_theme_now)
118+
elapsed_ms=$((now - __omb_theme_cmd_start))
119+
120+
if ((elapsed_ms > 500)); then
121+
time_str="${_omb_prompt_gray}${elapsed_ms}ms${_omb_prompt_normal} "
122+
fi
123+
fi
124+
125+
__omb_theme_cmd_started=0
126+
127+
python_venv=$(_omb_theme_get_venv)
128+
scm_segment=$(_omb_theme_shxll_way_prompt_scm)
129+
130+
ps_username="${_omb_prompt_purple}\u${_omb_prompt_normal}"
131+
ps_path="${_omb_prompt_green}\w${_omb_prompt_normal}"
132+
ps_user_mark="${_omb_prompt_red}${SHXLL_CHAR}${_omb_prompt_normal}"
133+
134+
if [[ $exit_code -ne 0 ]]; then
135+
status="${_omb_prompt_red}(${exit_code})${_omb_prompt_normal} "
136+
fi
137+
138+
PS1="$python_venv$ps_username:$ps_path$scm_segment $time_str$status$ps_user_mark "
139+
140+
__omb_theme_cmd_armed=1
141+
__omb_theme_in_prompt=0
142+
}
143+
144+
OMB_PROMPT_SHOW_PYTHON_VENV=${OMB_PROMPT_SHOW_PYTHON_VENV:-false}
145+
OMB_PROMPT_VIRTUALENV_FORMAT="${_omb_prompt_olive}(%s)${_omb_prompt_reset_color} "
146+
147+
_omb_util_add_prompt_command _omb_theme_PROMPT_COMMAND

0 commit comments

Comments
 (0)