|
1 | 1 | # 2023-07-10 - Microeinstein
|
2 | 2 |
|
3 |
| -# Features: |
4 |
| -# - dynamic prompt based on terminal |
5 |
| -# - colors: |
6 |
| -# - full, 256, 8 |
7 |
| -# - rainbow colors |
8 |
| -# - user=green root=red |
9 |
| -# - (hack) detect light theme |
10 |
| -# - styles: |
11 |
| -# - {powerline, basic} x {long,short} |
12 |
| -# - detect return code |
13 |
| -# - compact current directory based on terminal size |
14 |
| -# - stay on previous line with no command given |
15 |
| -# - detect if last command did not end with newline |
16 |
| -# |
17 |
| -# Unimplemented (technical limitations): |
18 |
| -# - cannot reprint prompt right after resize |
| 3 | + |
| 4 | +gen_rgb_rainbow() { |
| 5 | + # call by hand |
| 6 | + local py="$(cat <<EOF |
| 7 | +from sys import argv |
| 8 | +from colorsys import hsv_to_rgb |
| 9 | +l = 30 |
| 10 | +f = lambda n: str(round(n*255)) |
| 11 | +for n in range(0,l): |
| 12 | + c = map(f, hsv_to_rgb(n/l, float(argv[1]), float(argv[2]))) |
| 13 | + c = ';'.join(c) |
| 14 | + # print(f"\x1b[0;30;48;2;{c}mlorem ipsum\x1b[0m") |
| 15 | + # print(f"'{c}'", end=' ') |
| 16 | + print(c) |
| 17 | +EOF |
| 18 | +)" |
| 19 | + mapfile -t __RAINBOW < <(python -c "$py" "$@") |
| 20 | + printf "'%s' " "${__RAINBOW[@]}" | fold -s |
| 21 | + echo |
| 22 | +} |
19 | 23 |
|
20 | 24 |
|
21 | 25 | setup_PS1() {
|
@@ -74,29 +78,29 @@ setup_PS1() {
|
74 | 78 |
|
75 | 79 |
|
76 | 80 | # rainbow and specific
|
77 |
| - local py="$(cat <<EOF |
78 |
| -from sys import argv |
79 |
| -from colorsys import hsv_to_rgb |
80 |
| -l = 30 |
81 |
| -f = lambda n: str(round(n*255)) |
82 |
| -for n in range(0,l): |
83 |
| - c = map(f, hsv_to_rgb(n/l, float(argv[1]), float(argv[2]))) |
84 |
| - c = ';'.join(c) |
85 |
| - # print(f"\x1b[0;30;48;2;{c}mlorem ipsum\x1b[0m") |
86 |
| - # print(f"'{c}'", end=' ') |
87 |
| - print(c) |
88 |
| -EOF |
89 |
| -)" |
90 |
| - |
91 | 81 | local gray
|
92 | 82 | if ((rgb)); then
|
93 | 83 | C[fc]='38;2;%s' # truecolor
|
94 | 84 | C[bc]='48;2;%s'
|
95 | 85 | if ((light)); then
|
96 |
| - mapfile -t __RAINBOW < <(python -c "$py" .5 .7) |
| 86 | + __RAINBOW=( |
| 87 | + '178;89;89' '178;107;89' '178;125;89' '178;143;89' '178;161;89' |
| 88 | + '178;178;89' '161;178;89' '143;178;89' '125;178;89' '107;178;89' |
| 89 | + '89;178;89' '89;178;107' '89;178;125' '89;178;143' '89;178;161' |
| 90 | + '89;178;178' '89;161;178' '89;143;178' '89;125;178' '89;107;178' |
| 91 | + '89;89;178' '107;89;178' '125;89;178' '143;89;178' '161;89;178' |
| 92 | + '178;89;178' '178;89;161' '178;89;143' '178;89;125' '178;89;107' |
| 93 | + ) |
97 | 94 | gray='218;218;218'
|
98 | 95 | else
|
99 |
| - mapfile -t __RAINBOW < <(python -c "$py" .5 .9) |
| 96 | + __RAINBOW=( # .5 .95 |
| 97 | + '242;121;121' '242;145;121' '242;170;121' '242;194;121' '242;218;121' |
| 98 | + '242;242;121' '218;242;121' '194;242;121' '170;242;121' '145;242;121' |
| 99 | + '121;242;121' '121;242;145' '121;242;170' '121;242;194' '121;242;218' |
| 100 | + '121;242;242' '121;218;242' '121;194;242' '121;170;242' '121;145;242' |
| 101 | + '121;121;242' '145;121;242' '170;121;242' '194;121;242' '218;121;242' |
| 102 | + '242;121;242' '242;121;218' '242;121;194' '242;121;170' '242;121;145' |
| 103 | + ) |
100 | 104 | gray='78;78;78'
|
101 | 105 | fi
|
102 | 106 | else
|
|
261 | 265 | $(FMT bc="$stil" fdbla ) ${B[user]}
|
262 | 266 | $(FMT fc="$stil" bc="$gray") ''
|
263 | 267 | $(FMT fr ) ' $(__MYPWD) '
|
264 |
| - $(FMT blusr fc="$gray") '' |
265 |
| - $(FMT flusr br ) '' |
| 268 | + $(FMT bdusr fc="$gray") '' |
| 269 | + $(FMT fdusr br ) '' |
266 | 270 | )
|
267 | 271 | fi
|
268 | 272 | ps1+=($(FMT r) ' ')
|
|
0 commit comments