/
bs
executable file
·60 lines (50 loc) · 1.44 KB
/
bs
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
#!/usr/bin/env bash
# (lemon)bar stuff
# formatting reference: https://github.com/LemonBoy/bar/blob/master/README.pod#formatting
# this script closes tags and manages content wrapping
# example:
# echo some text | bs Bffffff F000000 UFF000000 +o +u
# => "%{B#ffffff}%{F#000000}%{U#FF000000}%{+o}%{+u}some text%{B-}%{F-}%{U-}%{-o}%{-u}"
# note on clicking
# Eg. %{A:reboot:} Click here to reboot %{A}
# The button field is optional, it defaults to the left
# button, and it's a number ranging from 1 to 5 which maps
# to the left, middle, right, scroll up and scroll down
# movements. Your mileage may vary.
prepend=
content=
append=
for item in "$@"; do
first=${item:0:1}
if [[ : == $first ]]; then
content=${item:1}
continue
fi
if [[ O == $first ]]; then
content="${content}%{${item}}"
continue
fi
if [[ BFU == *$first* ]]; then
case "$item" in
${first}#*) color=${item:1} ;;
${first}*) color=\#${item:1} ;;
esac
prepend="${prepend}%{${first}${color}}"
elif [[ A == $first ]]; then
prepend="${prepend}%{${item:0:2}:$(sed 's/:/\\:/g' <<< "${item:2}"):}"
append="${append}%{A}"
else
prepend="${prepend}%{${item}}"
fi
if [[ BTFU == *$first* ]]; then
append="${append}%{${first}-}"
fi
last=${item: -1} # the space is needed
if [[ ou == *$last* ]]; then
append="${append}%{-${last}}"
fi
done
if [ -z "${content}" ]; then
content=$(cat -)
fi
printf '%s' "${prepend}${content}${append}"