-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathplain.bash
86 lines (69 loc) · 2.38 KB
/
plain.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
SEGMENTS_PROMPT_READY_ICON=${LAYOUTS_PLAIN_PROMPT_READY_ICON:-'➜'}
SEGMENTS_GIT_ICON=${LAYOUTS_PLAIN_GIT_ICON:-' '}
SEGMENTS_GIT_INCOMING_ICON=${LAYOUTS_PLAIN_GIT_INCOMING_ICON:-'↓'}
SEGMENTS_GIT_OUTGOING_ICON=${LAYOUTS_PLAIN_GIT_OUTGOING_ICON:-'↑'}
SEGMENTS_PATH_SPLITTER_DISABLE=${LAYOUTS_PLAIN_PATH_SPLITTER_DISABLE:-1}
PROMPT_COMPACT=${SBP_PROMPT_COMPACT:-false}
print_themed_prompt() {
local left_segments=$1
local right_segments=$2
local line_two_segments=$3
local prompt_gap_size=$4
local reset_color
decorate::print_colors 'reset_color'
if [[ -n $right_segments ]]; then
right_segments="${right_segments} "
prompt_gap_size=$((prompt_gap_size - 1))
right_segments="${right_segments}${reset_color}"
fi
if [[ $PROMPT_COMPACT == false ]]; then
left_segments="\n${left_segments}"
fi
local filler_segment
if [[ -n $right_segments || -n $line_two_segments ]]; then
print_themed_filler 'filler_segment' "$prompt_gap_size"
right_segments="${right_segments}\n"
fi
line_two_segments="${line_two_segments}${reset_color}"
printf '%s' "${left_segments}${filler_segment}${right_segments}${line_two_segments}"
}
print_themed_filler() {
local -n print_themed_filler_result=$1
local filler_size=$2
# Account for seperator and padding
# shellcheck disable=SC2183
padding=$(printf "%*s" "$filler_size")
# shellcheck disable=SC2034
SEGMENT_LINE_POSITION=2
prompt_filler_output="$(print_themed_segment 'filler' "$padding")"
mapfile -t segment_output <<<"$prompt_filler_output"
# shellcheck disable=SC2034
print_themed_filler_result=${segment_output[1]}
}
print_themed_segment() {
local segment_type=$1
shift
local segment_parts=("${@}")
local segment_length=0
local themed_parts
if [[ $segment_type == 'highlight' ]]; then
PRIMARY_COLOR="$PRIMARY_COLOR_HIGHLIGHT"
fi
if [[ $segment_type == 'filler' ]]; then
themed_parts="${segment_parts[0]}"
else
for part in "${segment_parts[@]}"; do
[[ -z ${part// /} ]] && continue
part_length="${#part}"
themed_parts="${themed_parts} ${part}"
segment_length=$((segment_length + part_length + 1))
done
fi
local color
decorate::print_fg_color 'color' "$PRIMARY_COLOR"
full_output="${color}${themed_parts}"
if [[ $segment_type == 'prompt_ready' ]]; then
full_output="${full_output} "
fi
printf '%s\n%s' "$segment_length" "$full_output"
}