├── LICENSE.md ├── README.md └── coal /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016-2017 Dylan Araps 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Coal 2 | 3 | A bash script that takes a list of colors and outputs them in various formats for use in other programs. 4 | 5 | 6 | # Usage 7 | 8 | ```sh 9 | # Convert the list of colors to the given format 10 | coal --colors "#000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000" --xresources 11 | coal --colors "#000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000" --gtk2 12 | 13 | # Output in both firefox and xresources formats 14 | coal --colors "#000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000" --firefox --xresources 15 | 16 | # Send the output to a file 17 | coal --colors "#000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000" --gtk2 > gtk_colors 18 | 19 | ``` 20 | 21 | **Note:** You can list as many or as little colors as you like, the list length above is just an example. 22 | -------------------------------------------------------------------------------- /coal: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # set -x 3 | # vim: fdm=marker:noai:ts=4:sw=4 4 | # 5 | # Coal 6 | # 7 | # Created by Dylan Araps 8 | # 9 | # https://github.com/dylanaraps/coal 10 | 11 | # Speed up script by not using unicode 12 | export LC_ALL=C 13 | export LANG=C 14 | 15 | # Colors from 0-15 16 | c=( 17 | '#232c33' 18 | '#99736e' 19 | '#78a090' 20 | '#bfb7a1' 21 | '#7c9fa6' 22 | '#BF9C86' 23 | '#99BFBA' 24 | '#f0f0f0' 25 | '#70838c' 26 | '#99736e' 27 | '#78a090' 28 | '#bfb7a1' 29 | '#7c9fa6' 30 | '#BF9C86' 31 | '#99BFBA' 32 | '#f0f0f0' 33 | ) 34 | 35 | # Color functions {{{ 36 | 37 | 38 | # Xresources {{{ 39 | 40 | xresources() { 41 | # Special colors 42 | printf "%s\n" "*.foreground: ${c[7]}" 43 | printf "%s\n" "*.background: ${c[0]}" 44 | printf "%s\n" "*.cursorColor: ${c[7]}" 45 | 46 | for col in "${c[@]}"; do 47 | printf "%s\n" "*.color${num:-0}:${space:- } ${col}" 48 | ((num++)) 49 | 50 | # Align the colors 51 | (("${#num}" == 2)) && space=" " 52 | done 53 | } 54 | 55 | # }}} 56 | 57 | # Shell Variables {{{ 58 | 59 | shell() { 60 | for col in "${c[@]}"; do 61 | printf "%s\n" "export color${num:-0}='${col}'" 62 | ((num++)) 63 | done 64 | } 65 | 66 | # }}} 67 | 68 | # GTK2 Theme {{{ 69 | 70 | 71 | gtk2() { 72 | for col in "${c[@]}"; do 73 | printf "%s\n" "gtk_color_scheme = \"color_${num:-0}:${space:- }${col}\"" 74 | ((num++)) 75 | 76 | # Align the colors 77 | (("${#num}" == 2)) && space=" " 78 | done 79 | } 80 | 81 | 82 | # }}} 83 | 84 | # Firefox CSS {{{ 85 | 86 | firefox() { 87 | printf "%s\n" "/* Color variables */" 88 | printf "%s\n" ":root {" 89 | 90 | for col in "${c[@]}"; do 91 | printf "%s\n" " --color${num:-0}:${space:- }${col};" 92 | ((num++)) 93 | 94 | # Align the colors 95 | (("${#num}" == 2)) && space=" " 96 | done 97 | 98 | printf "%s\n" "}" 99 | } 100 | 101 | # }}} 102 | 103 | # iTerm2 Theme {{{ 104 | 105 | iterm() { 106 | printf "%s\n" "" 107 | printf "%s\n" "" 108 | printf "%s\n" "" 109 | printf "%s\n" "" 110 | 111 | div() { 112 | if (("${1}" == 255)); then 113 | printf "%s\n" "1.0" 114 | else 115 | printf "%s\n" "0.$((${1:-0}0000000000000000/255))" 116 | fi 117 | } 118 | 119 | for col in "${c[@]}"; do 120 | red="$(div "$((16#${col:1:2}))")" 121 | green="$(div "$((16#${col:3:2}))")" 122 | blue="$(div "$((16#${col:5:2}))")" 123 | 124 | printf "%s\n" " Ansi ${num:-0} Color" 125 | printf "%s\n" " " 126 | printf "%s\n" " Blue Component" 127 | printf "%s\n" " $blue" 128 | printf "%s\n" " Green Component" 129 | printf "%s\n" " $green" 130 | printf "%s\n" " Red Component" 131 | printf "%s\n" " $red" 132 | printf "%s\n" " " 133 | 134 | ((num++)) 135 | done 136 | 137 | printf "%s\n" "" 138 | printf "%s\n" "" 139 | } 140 | 141 | # }}} 142 | 143 | # Openbox {{{ 144 | 145 | openbox() { 146 | printf "%s\n" "\ 147 | # Titlebar colors 148 | window.active.title.bg.color: ${c[${1:-0}]} 149 | window.inactive.title.bg.color: ${c[${2:-0}]} 150 | window.active.label.text.color: ${c[7]} 151 | window.inactive.label.text.color: ${c[7]} 152 | window.*.button.*.image.color: ${c[7]} 153 | 154 | # Menu colors 155 | menu*.bg.color: ${c[7]} 156 | menu*.text.color: ${c[0]} 157 | menu.border.color: ${c[7]} 158 | menu.separator.color: ${c[7]} 159 | 160 | # Border colors 161 | window.active.border.color: ${c[7]} 162 | window.inactive.border.color: ${c[7]}" 163 | } 164 | 165 | # }}} 166 | 167 | 168 | # }}} 169 | 170 | 171 | # Args {{{ 172 | 173 | # If args are empty. 174 | if (($# == 0)); then 175 | printf "%s\n" "Coal must be run with flags." 176 | exit 1 177 | fi 178 | 179 | while [[ "$1" ]]; do 180 | case "$1" in 181 | --colors) c=(${@//--*}) ;; 182 | --xresources) xresources ;; 183 | --shell) shell ;; 184 | --gtk2) gtk2 ;; 185 | --firefox) firefox ;; 186 | --iterm) iterm ;; 187 | --openbox) openbox "${2//--*}" "${3//--*}" ;; 188 | esac 189 | 190 | shift 191 | done 192 | 193 | # }}} 194 | --------------------------------------------------------------------------------