-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-color-codes
executable file
·72 lines (61 loc) · 1.56 KB
/
generate-color-codes
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
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
print <<EOF;
#!/bin/sh
declare -A color
declare -A pcolor
EOF
my %general = (
'reset' => 0,
'fgDefault' => 39,
'bgDefault' => 49,
'bold' => 1,
'resetBold' => 22,
'underline' => 4,
'resetUnderline' => 24,
'blink' => 5,
'resetBlink' => 25,
'reverse' => 7,
'resetReverse' => 27
);
my @indices;
foreach (sort keys %general) {
print "color[$_]='\\e[$general{$_}m'\n";
push @indices, $_;
}
print "\n";
my @color_names = ('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'gray');
for (my $i = 0; $i < @color_names; ++$i) {
my $color_name = ucfirst $color_names[$i];
my $name_fg="fg${color_name}";
my $name_fgLight="fgLight${color_name}";
my $name_bg="bg${color_name}";
my $name_bgLight="bgLight${color_name}";
# change Black/LightBlack and Gray/LightGray
# to Black/DarkGray and LightGray/White
if ($i == 0) {
$name_fgLight = "fgDarkGray";
$name_bgLight = "bgDarkGray";
}
if ($i == 7) {
$name_fg="fgLightGray";
$name_fgLight="fgWhite";
$name_bg="bgLightGray";
$name_bgLight="bgWhite";
}
print <<EOF;
color[fg$i]='\\e[3${i}m'
color[$name_fg]='\\e[3${i}m'
color[$name_fgLight]='\\e[9${i}m'
color[bg$i]='\\e[4${i}m'
color[$name_bg]='\\e[4${i}m'
color[$name_bgLight]='\\e[10${i}m'
EOF
push @indices, $name_fg, $name_fgLight, $name_bg, $name_bgLight, "fg$i", "bg$i";
}
print "# prompt colors: color codes wrapped in \\[...\\] for use in PS1 etc.\n";
foreach my $index (sort @indices) {
print "pcolor[$index]=\"\\[\${color[$index]}\\]\"\n";
}