├── Makefile ├── README └── rpg /Makefile: -------------------------------------------------------------------------------- 1 | PREFIX ?= /usr 2 | BINDIR ?= $(PREFIX)/bin 3 | 4 | all: 5 | @echo RUN \'make install\' to install rpg 6 | 7 | install: 8 | @install -Dm 755 rpg $(DESTDIR)$(BINDIR)/rpg 9 | 10 | uninstall: 11 | @rm -f $(DESTDIR)$(BINDIR)/rpg 12 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | rpg - random palette generator 2 | ============================== 3 | 4 | Generate random palettes for your terminal's colors. 5 | 6 | The palettes are random with the exception that min and max rgb values are 7 | used to achieve somewhat sane colors. 8 | 9 | 10 | screenshots: https://user-images.githubusercontent.com/36552788/94266156-02e57680-ff3a-11ea-8acc-6899816fc24e.png 11 | https://user-images.githubusercontent.com/36552788/94266242-26a8bc80-ff3a-11ea-8e7c-1f917ccc8a07.png 12 | 13 | 14 | Installation 15 | ------------ 16 | 17 | Clone the repo 18 | 19 | $ git clone https://github.com/fehawen/rpg.git 20 | 21 | Change working directory to rpg 22 | 23 | $ cd rpg 24 | 25 | Install rpg 26 | 27 | $ make install 28 | 29 | Persist colors either by adding the following in $SHELL's startup file ... 30 | 31 | rpg reload 32 | 33 | ... Or by adding the following to ~/.Xresources if you use one 34 | 35 | #include ".cache/rpg/colors.Xresources" 36 | 37 | 38 | Usage 39 | ----- 40 | 41 | rpg d, rpg dark - generate dark palette 42 | rpg l, rpg light - generate light palette 43 | rpg r, rpg reload - reload current palette 44 | rpg c, rpg current - print current palette 45 | -------------------------------------------------------------------------------- /rpg: -------------------------------------------------------------------------------- 1 | #!/bin/sh -f 2 | 3 | # 4 | # rpg - random palette generator 5 | # 6 | 7 | exists() { 8 | command -v "$1" >/dev/null 9 | } 10 | 11 | runs() { 12 | pgrep -x "$1" >/dev/null 13 | } 14 | 15 | rgb() { 16 | # shellcheck disable=SC2046 17 | set -- $(shuf -i "$1"-"$2" -n 1) 18 | 19 | printf '%02x\n' "$1" 20 | } 21 | 22 | hex() { 23 | min=100; max=200 24 | 25 | [ "$light" ] && { 26 | min=80 27 | max=180 28 | } 29 | 30 | r=$(rgb "${1:-$min}" "${2:-$max}") 31 | g=$(rgb "${3:-$min}" "${4:-$max}") 32 | b=$(rgb "${5:-$min}" "${6:-$max}") 33 | 34 | printf '#%s%s%s\n' "$r" "$g" "$b" 35 | } 36 | 37 | 38 | palette() { 39 | bg="$(hex "0" "10" "0" "10" "0" "10")" 40 | fg="$(hex "245" "255" "245" "255" "245" "255")" 41 | black="$(hex "70" "80" "70" "80" "70" "80")" 42 | 43 | [ "$light" ] && { 44 | tmp=$bg; bg=$fg; fg=$tmp 45 | black="$(hex "170" "180" "170" "180" "170" "180")" 46 | } 47 | 48 | red="$(hex)" 49 | green="$(hex)" 50 | yellow="$(hex)" 51 | blue="$(hex)" 52 | magenta="$(hex)" 53 | cyan="$(hex)" 54 | } 55 | 56 | seq() { 57 | seqs="$seqs]$1;$2\\"; 58 | 59 | color=${1##*;} 60 | 61 | case $1 in 62 | *";"*) 63 | [ "${color}" -eq 0 ] && { 64 | printf '%s\n' \ 65 | "*background: $2" \ 66 | "*.background: $2" >> "$xresource_file" 67 | } 68 | 69 | [ "${color}" -eq 7 ] && { 70 | printf '%s\n' \ 71 | "*foreground: $2" \ 72 | "*.foreground: $2" \ 73 | "*cursorColor: $2" \ 74 | "*.cursorColor: $2" >> "$xresource_file" 75 | } 76 | 77 | [ "${color}" -lt 16 ] && { 78 | printf '%s\n' "color${color}=\"$2\"" >> "$colors_file" 79 | 80 | printf '%s\n' \ 81 | "*color${color}: $2" \ 82 | "*.color${color}: $2" >> "$xresource_file" 83 | } 84 | ;; 85 | esac 86 | } 87 | 88 | sequences() { 89 | # Regular colors 90 | seq "4;0" "$bg" 91 | seq "4;1" "$red" 92 | seq "4;2" "$green" 93 | seq "4;3" "$yellow" 94 | seq "4;4" "$blue" 95 | seq "4;5" "$magenta" 96 | seq "4;6" "$cyan" 97 | seq "4;7" "$fg" 98 | seq "4;8" "$black" 99 | seq "4;9" "$red" 100 | seq "4;10" "$green" 101 | seq "4;11" "$yellow" 102 | seq "4;12" "$blue" 103 | seq "4;13" "$magenta" 104 | seq "4;14" "$cyan" 105 | seq "4;15" "$fg" 106 | 107 | # Special colors 108 | # 10: Foreground color 109 | # 11: Background color 110 | # 12: Cursor foreground color 111 | # 13: Mouse foreground color 112 | # 17: Highlight background Color 113 | # 19: Highlight foreground Color 114 | # 256: Cursor color 115 | # 257: Reversed cursor color 116 | # 258: Background color 117 | # 259: Foreground color 118 | seq "10" "$fg" 119 | seq "11" "$bg" 120 | seq "12" "$fg" 121 | seq "13" "$fg" 122 | seq "17" "$bg" 123 | seq "19" "$fg" 124 | seq "4;256" "$fg" 125 | seq "4;257" "$bg" 126 | seq "4;258" "$bg" 127 | seq "4;259" "$fg" 128 | 129 | # Unless VTE 130 | # 708: Border color 131 | [ "$VTE_VERSION" ] || seq "708" "$bg" 132 | } 133 | 134 | wallpaper() { 135 | if runs "picom" || runs "compton"; then 136 | exists "hsetroot" && hsetroot -solid "$black" 137 | else 138 | exists "xsetroot" && xsetroot -solid "$black" 139 | fi 140 | } 141 | 142 | activate() { 143 | set +f 144 | set -f -- /dev/pts/[0-9]* 145 | for tty in "$@"; do 146 | [ -w "$tty" ] && printf %b "$seqs" > "$tty" & 147 | done 148 | 149 | printf %b "$seqs" > "$sequence_file" 150 | 151 | exists "xrdb" && xrdb -merge "$xresource_file" 152 | } 153 | 154 | current() { 155 | printf '\n' 156 | 157 | for i in 0 1 2 3 4 5 6 7; do 158 | printf '\033[10%sm \033[m ' "$i" 159 | done 160 | 161 | printf '\n\n' 162 | 163 | exit 164 | } 165 | 166 | main() { 167 | mkdir -p "${cache_dir:=${HOME}/.cache/rpg}" 168 | 169 | sequence_file="$cache_dir/sequences" 170 | colors_file="$cache_dir/colors.sh" 171 | xresource_file="$cache_dir/colors.Xresources" 172 | 173 | case $1 in 174 | d|dark) ;; 175 | l|light) light=1 ;; 176 | r|reload) (cat "$sequence_file" 2>/dev/null &); exit ;; 177 | c|current) current ;; 178 | *) printf '%s\n' \ 179 | "Usage: rpg [OPTION]" \ 180 | " d, dark Generate dark palette" \ 181 | " l, light Generate light palette" \ 182 | " r, reload Reload current palette" \ 183 | " c, current Print current palette" 184 | exit 185 | ;; 186 | esac 187 | 188 | :> "$colors_file" 189 | :> "$xresource_file" 190 | 191 | palette 192 | 193 | sequences 194 | 195 | wallpaper 196 | 197 | activate 198 | 199 | current 200 | } 201 | 202 | main "$@" 203 | --------------------------------------------------------------------------------