-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash-template-builder
More file actions
executable file
·96 lines (84 loc) · 1.91 KB
/
bash-template-builder
File metadata and controls
executable file
·96 lines (84 loc) · 1.91 KB
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
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
set -o errexit -o errtrace -o nounset -o pipefail
readonly ansiEsc='\033'
readonly ansiOsc="${ansiEsc}\135" \
ansiSt="${ansiEsc}\134"
function :printf () {
# shellcheck disable=SC2059
printf -- "$1" "${@:2}"
}
function :printfln () {
# shellcheck disable=SC2059
printf -- "${1}\n" "${@:2}"
}
function :println () {
:printfln '%s' "$@"
}
function :replace:all () {
:println "${1//"$2"/"$3"}"
}
function :join () {
:replace:all "$(:println "${@:2}")" $'\n' "$1"
}
function :ansi:osc () {
:println "${ansiOsc}$(:join ';' "$1" "${@:2}")${ansiSt}"
}
function :print:ansi:osc:color:change () {
: "${@: -1}"
: "printf -- %q '{{${_}-hex-r}}' '{{${_}-hex-g}}' '{{${_}-hex-b}}'"
:printfln "$_" "$(:ansi:osc "${@:1:$#-1}" 'rgb:%s/%s/%s')"
}
cat - <<'EOD'
#!/usr/bin/env bash
# base16-shell (https://github.com/chriskempson/base16-shell)
# Base16 Shell template by Matt Helm (https://github.com/mtthlm)
# {{scheme-name}} scheme by {{scheme-author}}
EOD
readonly -a args=(
# 4-bit Colors
4 0 'base00' # Black
4 1 'base08' # Red
4 2 'base0B' # Green
4 3 'base0A' # Yellow
4 4 'base0D' # Blue
4 5 'base0E' # Magenta
4 6 'base0C' # Cyan
4 7 'base05' # White
# 4-bit Bright Colors
4 8 'base03' # Bright Black
4 9 'base08' # Bright Red
4 10 'base0B' # Bright Green
4 11 'base0A' # Bright Yellow
4 12 'base0D' # Bright Blue
4 13 'base0E' # Bright Magenta
4 14 'base0C' # Bright Cyan
4 15 'base07' # Bright White
# 8-bit Colors
4 16 'base09'
4 17 'base0F'
4 18 'base01'
4 19 'base02'
4 20 'base04'
4 21 'base06'
# Foreground
10 'base05'
# Background
11 'base00'
# Cursor
12 'base05'
)
set -- "${args[@]}"
while [[ $# -gt 1 ]]
do
case "$1"
in
4)
:print:ansi:osc:color:change "${@:1:3}"
shift 1
;;
*)
:print:ansi:osc:color:change "${@:1:2}"
;;
esac
shift 2
done