-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplaycolors.sh
executable file
·71 lines (64 loc) · 2.46 KB
/
displaycolors.sh
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
#!/usr/bin/env bash
# displaycolors.sh by :nudge>
unset printf || exit $?
display_info() { printf "\n%-18s -> \e[1;32m%-18s\e[0m\n\n" "$SHELL" "${0##*/}" ; }
display_colors() {
local -r RED="\e[1;31m%s\e[0m"
local -r RESET=$(/usr/bin/tput sgr0)
[[ -n "$1" ]] || { printf "[$RED]: No start (param 1): $RED\n" "ERROR" $1 ; return 1 ; }
[[ -n "$2" ]] || { printf "[$RED]: No end (param 2): $RED\n" "ERROR" $2 ; return 2 ; }
/usr/bin/tput civis
for fgc in $(/usr/bin/seq -f "%03g" $1 $2); do
set_fgc=$(/usr/bin/tput setaf $fgc)
for bgc in $(/usr/bin/seq -f "%03g" $1 $2); do
set_bgc=$(/usr/bin/tput setab $bgc)
printf "%s%s BG:%s FG:%s " $set_bgc $set_fgc $bgc $fgc
done
printf "%s\n" $RESET
done
/usr/bin/tput cnorm
}
without_params(){
local -i column_start=$start
while [[ $column_start -lt $end ]]; do
column_end=$(( column_start + columns - 1 ))
[[ "$column_end" -gt $end ]] && (( column_end = end ))
display_colors $column_start $column_end || exit $?
(( column_start += columns ))
done
}
with_params(){
start=$1
[[ -z "$2" ]] || end=$2
if [[ $(( end - start )) -lt $columns ]]; then
display_colors $start $end
else
local -i column_start=$1
local -i column_end=$(( column_start + columns - 1 ))
[[ "$column_end" -gt $end ]] && (( column_end = end ))
while [[ "$column_start" -lt $end ]]; do
display_colors $column_start $column_end || exit $?
(( column_start += columns ))
[[ "$column_start" -gt $end ]] && (( column_start = end ))
column_end=$(( column_start + columns - 1 ))
[[ "$column_end" -gt $end ]] && (( column_end = end ))
done
fi
}
main() {
local -i txtlen=15
local -i start=0
local -i width=$( /usr/bin/tput cols )
local -i colors=$(/usr/bin/tput colors )
local -i end=$(( colors - 1 ))
local -i columns=$(( width / txtlen ))
local -r YLO="\e[1;33m%d\e[0m"
display_info || exit $?
[[ -z "$1" ]] && without_params \
|| with_params "$@"
printf "\nwidth: $YLO columns: $YLO colors: $YLO start: $YLO end: $YLO\n\n" \
$width $columns $colors $start $end
}
#–––––––––––––––––––––––––––––––––––––––––––∆
[[ ${BASH_SOURCE[0]} = "$0" ]] && main "$@" #
#–––––––––––––––––––––––––––––––––––––––––––Ω