-
Notifications
You must be signed in to change notification settings - Fork 0
/
mxcolr
executable file
·72 lines (60 loc) · 1.52 KB
/
mxcolr
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
#!/bin/bash
### FLAGS ##############################
set -o noclobber # Avoid overlay files
set -o errexit # Avoid cascading errors
set -o pipefail # Unveil hidden failures
set -o nounset # Expose unset variables
set -o errtrace # Trace error LINENO
trap 'echo Error at $LINENO' ERR
### PRE CHECKS #########################
if ! command -v pastel &> /dev/null; then
echo "pastel not found."
echo " ==> https://github.com/sharkdp/pastel#installation"
exit 1
fi
if ! command -v bc &> /dev/null; then
echo "bc not found."
echo " ==> https://www.gnu.org/software/bc"
exit 1
fi
echo ---
### VARIABLES ##########################
INTERACTIVE=0
STRATEGY=vivid
BASE_PATH=$(dirname "$(realpath "$0")")
### ARGUMENTS ##########################
usage() { echo "Usage: $0 [-s <vivid|lch>] [-i]" 1>&2; exit 1; }
while getopts "is:" o; do
case "${o}" in
s)
STRATEGY=${OPTARG:-vivid}
[[ $STRATEGY == "vivid" || $STRATEGY == "lch" ]] || usage
[ $STRATEGY == 'lch' ] && STRATEGY=lch_hue
;;
i) INTERACTIVE=1 ;;
*) STRATEGY=vivid ;;
esac
done
shift $((OPTIND-1))
### SOURCE #############################
for src in $BASE_PATH/src/*.sh; do . "$src"; done
### START ##############################
main () {
generate_seed
generate_palette
generate_shade
save
save_preview_terminal
demo
if (( "$INTERACTIVE" )); then
prompt_menu
case $REPLY in
n) main ;;
u) save; plugins_apply ;;
*) demo_full ;;
esac
else
prompt_confirm && save && plugins_apply
fi
}
main