A variety of simple automation scripts and enhancements to Sway and i3.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

apply-gruvbox.sh 31KB

vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
vor 8 Monaten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. #!/usr/bin/env bash
  2. # Single theme copy of apply-colors.sh from:
  3. # https://raw.githubusercontent.com/Mayccoll/Gogh
  4. # ====================CONFIG THIS =============================== #
  5. export COLOR_01="#282828" # HOST
  6. export COLOR_02="#cc241d" # SYNTAX_STRING
  7. export COLOR_03="#98971a" # SYNTAX_STRING
  8. export COLOR_04="#d79921" # COMMAND
  9. export COLOR_05="#458588" # COMMAND_COLOR2
  10. export COLOR_06="#b16286" # PATH
  11. export COLOR_07="#68986a" # SYNTAX_VAR
  12. export COLOR_08="#a89984" # PROMP
  13. export COLOR_09="#928374" #
  14. export COLOR_10="#fb4934" #
  15. export COLOR_11="#b8bb26" # COMMAND_ERROR
  16. export COLOR_12="#fabd2f" # EXEC
  17. export COLOR_13="#83a598" #
  18. export COLOR_14="#d3869b" # FOLDER
  19. export COLOR_15="#8ec07c" #
  20. export COLOR_16="#ebdbb2" #
  21. export BACKGROUND_COLOR="#1d2021" # Background Color
  22. export FOREGROUND_COLOR="#ebdbb2" # Text
  23. export CURSOR_COLOR="$FOREGROUND_COLOR" # Cursor
  24. export PROFILE_NAME="Gruvbox"
  25. # | ===========================================
  26. # | Early pre-requisites check
  27. # | ===========================================
  28. UUIDGEN="${UUIDGEN:-$(command -v uuidgen | xargs echo)}"
  29. DCONF="${DCONF:-$(command -v dconf | xargs echo)}"
  30. GCONF="${GCONF:-$(command -v gconftool-2 | xargs echo)}"
  31. GS="${GS:-$(command -v gsettings | xargs echo)}"
  32. # Note: xargs echo is to make the command sucessful even if it was not
  33. # otherwise the script will exit if the command does not exist (elementary os)
  34. # | ===========================================
  35. # | Make sure all exported variables get unset no matter what
  36. # | Defining this in this script because it gets called even if
  37. # | gogh.sh was not called. Exported variables in gogh.sh gets
  38. # | handled there in case there was en error before this script was called
  39. # | ============================================
  40. GLOBAL_VAR_CLEANUP() {
  41. unset PROFILE_NAME
  42. unset PROFILE_SLUG
  43. unset scratchdir
  44. unset TILIX_RES
  45. unset TERMINAL
  46. unset LOOP
  47. unset OPTLENGTH
  48. for c in $(seq -s " " -w 16); do
  49. unset DEMO_COLOR_${c}
  50. unset COLOR_${c}
  51. done
  52. unset BACKGROUND_COLOR
  53. unset FOREGROUND_COLOR
  54. unset CURSOR_COLOR
  55. unset HIGHLIGHT_FG_COLOR
  56. unset HIGHLIGHT_BG_COLOR
  57. unset USE_SYS_TRANSPARENCY
  58. unset PROFILE_NAME
  59. }
  60. # Note: Since all scripts gets invoked in a subshell the traps from the parent
  61. # shell will not get inherited. Hence traps defined in gogh.sh and
  62. # print-themes.sh will still trigger
  63. trap 'GLOBAL_VAR_CLEANUP; trap - EXIT' EXIT HUP INT QUIT PIPE TERM
  64. # | ===========================================
  65. # | Second test for TERMINAL in case user ran
  66. # | theme script directly instead of gogh.sh
  67. # | ============================================
  68. if [[ -z "${TERMINAL:-}" ]]; then
  69. # | ===========================================
  70. # | Check for the terminal name (depening on os)
  71. # | ===========================================
  72. OS="$(uname)"
  73. if [[ "$OS" = "Darwin" ]]; then
  74. TERMINAL=$TERM_PROGRAM
  75. elif [[ "${OS#CYGWIN}" != "${OS}" ]]; then
  76. TERMINAL="mintty"
  77. else
  78. # | ===========================================
  79. # | Depending on how the script was invoked, we need
  80. # | to loop until pid is no longer a subshell
  81. # | ===========================================
  82. pid="$$"
  83. TERMINAL="$(ps -h -o comm -p $pid)"
  84. while [[ "${TERMINAL:(-2)}" == "sh" ]]; do
  85. pid="$(ps -h -o ppid -p $pid)"
  86. TERMINAL="$(ps -h -o comm -p $pid)"
  87. done
  88. fi
  89. fi
  90. case "${TERMINAL}" in
  91. pantheon-terminal|io.elementary.t* )
  92. if [[ -z "${GS}" ]]; then
  93. printf '\n%s\n' "Error gsettings not found"
  94. printf '%s\n' "sudo apt install dconf?"
  95. printf '%s\n\n' "or export GS=/path/to/gsettings"
  96. exit 1
  97. fi
  98. ;;
  99. mintty )
  100. CFGFILE="${HOME}/.minttyrc"
  101. if [[ ! -f "${CFGFILE}" ]]; then
  102. printf '\n%s\n' "Warning: Couldn't find an existing configuration file, \
  103. so one will be created for you."
  104. printf '%s\n\n' "Warning: Are you really running Cygwin's mintty?"
  105. touch "${CFGFILE}"
  106. fi
  107. ;;
  108. guake|tilix|mate-terminal|gnome-terminal* )
  109. case "${TERMINAL}" in
  110. guake|gnome-terminal* )
  111. if [[ -z "${DCONF}" ]] && [[ -z "${GCONF}" ]]; then
  112. printf '\n%s\n' "Error gconftool not found!"
  113. printf '%s\n' "sudo apt install gconftool?"
  114. printf '%s\n\n' "or export GCONF=/path/to/gconftool-2/"
  115. exit 1
  116. fi
  117. ;;
  118. esac
  119. if [[ -z "${DCONF}" ]]; then
  120. printf '\n%s\n' "Error dconf not found"
  121. printf '%s\n' "sudo apt install dconf?"
  122. printf '%s\n\n' "or export DCONF=/path/to/dconf"
  123. exit 1
  124. fi
  125. ;;
  126. esac
  127. # | ===========================================
  128. # | Convert RGB to gnome colors
  129. # | ===========================================
  130. gnome_color () {
  131. AA=${1:1:2}
  132. BB=${1:3:2}
  133. CC=${1:5:2}
  134. echo "#${AA}${AA}${BB}${BB}${CC}${CC}"
  135. }
  136. hexToDec () {
  137. echo "$((16#${1}))"
  138. }
  139. hexRGBtoDecRGB () {
  140. R="$(hexToDec "${1:1:2}")"
  141. G="$(hexToDec "${1:3:2}")"
  142. B="$(hexToDec "${1:5:2}")"
  143. echo "${R}" "${G}" "${B}"
  144. }
  145. convertRGBtoMac () {
  146. local color="${1}"
  147. set --
  148. set -- $(hexRGBtoDecRGB "${color}")
  149. R=${1}; shift; G=${1}; shift; B=${1}; shift
  150. R=$(echo "${R} / 255" | bc -l)
  151. G=$(echo "${G} / 255" | bc -l)
  152. B=$(echo "${B} / 255" | bc -l)
  153. echo "${R}" "${G}" "${B}"
  154. }
  155. createMinttyEntry () {
  156. local name="${1}"
  157. local color="${2}"
  158. set --
  159. set -- $(hexRGBtoDecRGB "${color}")
  160. R=${1}; shift; G=${1}; shift; B=${1}; shift
  161. echo "${name}=${R},${G},${B}"
  162. }
  163. updateMinttyConfig () {
  164. local config="${1}"
  165. local color="${2}"
  166. local name="${3}"
  167. sed -i -r -e "s/^${name}=.+/$(createMinttyEntry "${name}" \
  168. "${color}")/g" "${config}"
  169. }
  170. convertNameAndRGBtoITerm() {
  171. local name="${1}"
  172. local color="${2}"
  173. set --
  174. set -- $(convertRGBtoMac "${color}")
  175. R=${1}; shift; G=${1}; shift; B=${1}; shift
  176. echo "<key>${name}</key><dict><key>Blue Component</key><real>${B}\
  177. </real><key>Green Component</key><real>${G}</real><key>Red Component</key>\
  178. <real>${R}</real></dict>"
  179. }
  180. dset() {
  181. local key="${1}"; shift
  182. local val="${1}"
  183. "${DCONF}" write "${PROFILE_KEY}/${key}" "${val}"
  184. }
  185. # Because dconf still doesn't have "append"
  186. dlist_append() {
  187. local key="${1}"; shift
  188. local val="${1}"; shift
  189. local entries
  190. entries="$(
  191. {
  192. "${DCONF}" read "${key}" | tr -d "[]" | tr , "\n" | \
  193. grep -F -v "${val}"
  194. echo "'${val}'"
  195. } \
  196. | head -c-1 | tr "\n" ,
  197. )"
  198. "${DCONF}" write "${key}" "[${entries}]"
  199. }
  200. gcset() {
  201. local type="${1}"; shift
  202. local key="${1}"; shift
  203. local val="${1}"
  204. "${GCONF}" --set --type "${type}" "${PROFILE_KEY}/${key}" -- "${val}"
  205. }
  206. # Because gconftool doesn't have "append"
  207. glist_append() {
  208. local type="${1}"; shift
  209. local key="${1}"; shift
  210. local val="${1}"; shift
  211. local entries
  212. entries="$(
  213. {
  214. "${GCONF}" --get "${key}" | tr -d "[]" | tr , "\n" | \
  215. grep -F -v "${val}"
  216. echo "${val}"
  217. }\
  218. | head -c-1 | tr "\n" ,
  219. )"
  220. "${GCONF}" --set --type list --list-type "${type}" "${key}" \
  221. "[${entries}]"
  222. }
  223. gset() {
  224. local key="${1}"; shift
  225. local val="${1}"
  226. "${GS}" set "${PROFILE_KEY}" "${key}" "${val}"
  227. }
  228. set_theme() {
  229. dset visible-name "'${PROFILE_NAME}'"
  230. dset background-color "'${BACKGROUND_COLOR}'"
  231. dset foreground-color "'${FOREGROUND_COLOR}'"
  232. if [[ -n "${HIGHLIGHT_BG_COLOR:-}" ]]; then
  233. dset highlight-colors-set "true"
  234. dset highlight-background-color "'${HIGHLIGHT_BG_COLOR}'"
  235. if [[ -n "${HIGHLIGHT_FG_COLOR:-}" ]]; then
  236. dset highlight-foreground-color \
  237. "'${HIGHLIGHT_FG_COLOR}'"
  238. fi
  239. fi
  240. if [[ -n "${BOLD_COLOR:-}" ]]; then
  241. dset bold-color "'${BOLD_COLOR}'"
  242. dset bold-color-same-as-fg "false"
  243. else
  244. dset bold-color "'${FOREGROUND_COLOR}'"
  245. dset bold-color-same-as-fg "true"
  246. fi
  247. dset use-theme-colors "false"
  248. dset use-theme-background "false"
  249. dset use-theme-transparency "${USE_SYS_TRANSPARENCY:-false}"
  250. }
  251. legacy_set_theme() {
  252. gcset string visible_name "${PROFILE_NAME}"
  253. gcset string background_color "${BACKGROUND_COLOR}"
  254. gcset string foreground_color "${FOREGROUND_COLOR}"
  255. if [[ -n "${BOLD_COLOR:-}" ]]; then
  256. gcset string bold_color "${BOLD_COLOR}"
  257. gcset bool bold_color_same_as_fg "false"
  258. else
  259. gcset string bold_color "${FOREGROUND_COLOR}"
  260. gcset bool bold_color_same_as_fg "true"
  261. fi
  262. gcset bool use_theme_colors "false"
  263. gcset bool use_theme_background "false"
  264. }
  265. # | ===========================================
  266. # | If terminal supports truecolor then we can show theme colors without
  267. # | applying the theme
  268. # | ===========================================
  269. if [[ "${COLORTERM:-}" == "truecolor" ]] || [[ "${COLORTERM:-}" == "24bit" ]]
  270. then
  271. # gogh_colors have been moved here to avoid multiple definitions
  272. function gogh_colors () {
  273. # Build up the color string to avoid visual rendering
  274. local color_str
  275. # Note: {01..16} does not work on OSX
  276. for c in $(seq -s " " -w 16); do
  277. local color="COLOR_$c"
  278. set -- $(hexRGBtoDecRGB "${!color}")
  279. color_str+="\033[38;2;${1};${2};${3}m█████$(tput sgr0)"
  280. [[ ${GOGH_DRY_RUN:-0} -eq 1 ]] && \
  281. export "DEMO_COLOR_$c=\033[38;2;${1};${2};${3}m"
  282. [[ "$c" == "08" ]] && \
  283. color_str+="\n" # new line
  284. done
  285. printf '\n%b\n\n\n' "${color_str}"
  286. unset color_str
  287. }
  288. else
  289. function gogh_colors () {
  290. # Build up the color string to avoid visual rendering
  291. local color_str
  292. for c in {0..15}; do
  293. color_str+="$(tput setaf $c)█████$(tput sgr0)"
  294. [[ $c == 7 ]] && color_str+="\n" # new line
  295. done
  296. printf '\n%b\n\n' "${color_str}"
  297. unset color_str
  298. }
  299. fi
  300. # | ===========================================
  301. # | Print theme colors
  302. # | ===========================================
  303. gogh_colors
  304. if [[ ${GOGH_DRY_RUN:-0} -eq 1 ]]; then
  305. color
  306. # End here if dry run was initiated
  307. exit 0
  308. fi
  309. apply_elementary() {
  310. # | ===========================================
  311. # | Applying values on elementary/pantheon terminal
  312. # | ===========================================
  313. gset background "${BACKGROUND_COLOR}"
  314. gset foreground "${FOREGROUND_COLOR}"
  315. gset cursor-color "${CURSOR_COLOR}"
  316. gset palette "${COLOR_01}:${COLOR_02}:${COLOR_03}:${COLOR_04}:${COLOR_05}:${COLOR_06}:${COLOR_07}:${COLOR_08}:${COLOR_09}:${COLOR_10}:${COLOR_11}:${COLOR_12}:${COLOR_13}:${COLOR_14}:${COLOR_15}:${COLOR_16}"
  317. }
  318. apply_cygwin() {
  319. # | ===========================================
  320. # | Applying values on mintty (cygwin)
  321. # | ===========================================
  322. echo "Patching mintty configuration file (${CFGFILE}) with new colors..."
  323. updateMinttyConfig "$CFGFILE" "$COLOR_01" "Black"
  324. updateMinttyConfig "$CFGFILE" "$COLOR_02" "Red"
  325. updateMinttyConfig "$CFGFILE" "$COLOR_03" "Green"
  326. updateMinttyConfig "$CFGFILE" "$COLOR_04" "Yellow"
  327. updateMinttyConfig "$CFGFILE" "$COLOR_05" "Blue"
  328. updateMinttyConfig "$CFGFILE" "$COLOR_06" "Magenta"
  329. updateMinttyConfig "$CFGFILE" "$COLOR_07" "Cyan"
  330. updateMinttyConfig "$CFGFILE" "$COLOR_08" "White"
  331. updateMinttyConfig "$CFGFILE" "$COLOR_09" "BoldBlack"
  332. updateMinttyConfig "$CFGFILE" "$COLOR_10" "BoldRed"
  333. updateMinttyConfig "$CFGFILE" "$COLOR_11" "BoldGreen"
  334. updateMinttyConfig "$CFGFILE" "$COLOR_12" "BoldYellow"
  335. updateMinttyConfig "$CFGFILE" "$COLOR_13" "BoldBlue"
  336. updateMinttyConfig "$CFGFILE" "$COLOR_14" "BoldMagenta"
  337. updateMinttyConfig "$CFGFILE" "$COLOR_15" "BoldCyan"
  338. updateMinttyConfig "$CFGFILE" "$COLOR_16" "BoldWhite"
  339. updateMinttyConfig "$CFGFILE" "$BACKGROUND_COLOR" "Backgroundcolor"
  340. updateMinttyConfig "$CFGFILE" "$FOREGROUND_COLOR" "Foregroundcolor"
  341. updateMinttyConfig "$CFGFILE" "$CURSOR_COLOR" "Cursorcolor"
  342. echo "Done - please reopen your Cygwin terminal to see the changes"
  343. }
  344. apply_darwin() {
  345. # | ===========================================
  346. # | Applying values on iTerm2
  347. # | ===========================================
  348. BACKGROUND_COLOR=$(convertNameAndRGBtoITerm "Background Color" \
  349. "$BACKGROUND_COLOR")
  350. FOREGROUND_COLOR=$(convertNameAndRGBtoITerm "Foreground Color" \
  351. "$FOREGROUND_COLOR")
  352. COLOR_01=$(convertNameAndRGBtoITerm "Ansi 0 Color" \
  353. "$COLOR_01")
  354. COLOR_02=$(convertNameAndRGBtoITerm "Ansi 1 Color" \
  355. "$COLOR_02")
  356. COLOR_03=$(convertNameAndRGBtoITerm "Ansi 2 Color" \
  357. "$COLOR_03")
  358. COLOR_04=$(convertNameAndRGBtoITerm "Ansi 3 Color" \
  359. "$COLOR_04")
  360. COLOR_05=$(convertNameAndRGBtoITerm "Ansi 4 Color" \
  361. "$COLOR_05")
  362. COLOR_06=$(convertNameAndRGBtoITerm "Ansi 5 Color" \
  363. "$COLOR_06")
  364. COLOR_07=$(convertNameAndRGBtoITerm "Ansi 6 Color" \
  365. "$COLOR_07")
  366. COLOR_08=$(convertNameAndRGBtoITerm "Ansi 7 Color" \
  367. "$COLOR_08")
  368. COLOR_09=$(convertNameAndRGBtoITerm "Ansi 8 Color" \
  369. "$COLOR_09")
  370. COLOR_10=$(convertNameAndRGBtoITerm "Ansi 9 Color" \
  371. "$COLOR_10")
  372. COLOR_11=$(convertNameAndRGBtoITerm "Ansi 10 Color" \
  373. "$COLOR_11")
  374. COLOR_12=$(convertNameAndRGBtoITerm "Ansi 11 Color" \
  375. "$COLOR_12")
  376. COLOR_13=$(convertNameAndRGBtoITerm "Ansi 12 Color" \
  377. "$COLOR_13")
  378. COLOR_14=$(convertNameAndRGBtoITerm "Ansi 13 Color" \
  379. "$COLOR_14")
  380. COLOR_15=$(convertNameAndRGBtoITerm "Ansi 14 Color" \
  381. "$COLOR_15")
  382. COLOR_16=$(convertNameAndRGBtoITerm "Ansi 15 Color" \
  383. "$COLOR_16")
  384. # Assemble color scheme file contents
  385. ITERMCOLORS='<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict>'${BACKGROUND_COLOR}${FOREGROUND_COLOR}${COLOR_01}${COLOR_02}${COLOR_03}${COLOR_04}${COLOR_05}${COLOR_06}${COLOR_07}${COLOR_08}${COLOR_09}${COLOR_10}${COLOR_11}${COLOR_12}${COLOR_13}${COLOR_14}${COLOR_15}'</dict></plist>'
  386. # Dump iTerm color scheme to file and import it by opening it
  387. echo "${ITERMCOLORS}" > "${PROFILE_NAME}.itermcolors"
  388. open "${PROFILE_NAME}.itermcolors"
  389. rm "${PROFILE_NAME}.itermcolors"
  390. }
  391. apply_gtk() {
  392. # | ===========================================
  393. # | Applying values to gnome/mate/tilix
  394. # | ===========================================
  395. local legacy="${1:-}"
  396. # This is to avoid doing the profile loop definition twice
  397. if [[ -z "${legacy}" ]]; then
  398. CONFTOOL="${DCONF} read"
  399. VISIBLE_NAME="visible-name"
  400. else
  401. CONFTOOL="${GCONF} --get"
  402. VISIBLE_NAME="visible_name"
  403. fi
  404. # Check first wether profile already exists
  405. profile_hashes=($(${CONFTOOL} "${PROFILE_LIST_KEY}" | tr "[]'," " "))
  406. for profile in "${profile_hashes[@]}"; do
  407. if [[ "$(${CONFTOOL} "${BASE_DIR}${profile}/${VISIBLE_NAME}" | \
  408. tr -d "'")" == "${PROFILE_NAME}" ]]; then
  409. printf '%s\n' "Profile already exists" "Skipping..."
  410. exit 0
  411. fi
  412. done
  413. # Fallback if there is no default profile
  414. set -- $(${CONFTOOL} ${PROFILE_LIST_KEY} | tr "[]'," " ")
  415. : ${DEFAULT_SLUG:="$1"}
  416. : ${PROFILE_NAME:="Default"}
  417. : ${PROFILE_SLUG:="Default"}
  418. DEFAULT_KEY="${BASE_DIR}${DEFAULT_SLUG:-}"
  419. PROFILE_KEY="${BASE_DIR}${PROFILE_SLUG:-}"
  420. if [[ -z "${legacy}" ]]; then
  421. # Provide a user friendly error text if no saved profile exists,
  422. # otherwise it will display "Error gconftool not found!"
  423. # it could happen on a newly installed system
  424. if [[ -z "$(${DCONF} list ${BASE_DIR%:})" ]]; then
  425. printf '%s\n' \
  426. "Error, no saved profiles found!" \
  427. "Possible fix, new a profile (Terminal > Edit > Pref\
  428. erences > Profiles > New, then Close) and try again." \
  429. "You can safely delete the created profile after the\
  430. installation."
  431. exit 1
  432. fi
  433. BACKGROUND_COLOR=$(gnome_color "$BACKGROUND_COLOR")
  434. FOREGROUND_COLOR=$(gnome_color "$FOREGROUND_COLOR")
  435. HIGHLIGHT_BG_COLOR=$(gnome_color "$HIGHLIGHT_BG_COLOR")
  436. HIGHLIGHT_FG_COLOR=$(gnome_color "$HIGHLIGHT_FG_COLOR")
  437. COLOR_01=$(gnome_color "$COLOR_01")
  438. COLOR_02=$(gnome_color "$COLOR_02")
  439. COLOR_03=$(gnome_color "$COLOR_03")
  440. COLOR_04=$(gnome_color "$COLOR_04")
  441. COLOR_05=$(gnome_color "$COLOR_05")
  442. COLOR_06=$(gnome_color "$COLOR_06")
  443. COLOR_07=$(gnome_color "$COLOR_07")
  444. COLOR_08=$(gnome_color "$COLOR_08")
  445. COLOR_09=$(gnome_color "$COLOR_09")
  446. COLOR_10=$(gnome_color "$COLOR_10")
  447. COLOR_11=$(gnome_color "$COLOR_11")
  448. COLOR_12=$(gnome_color "$COLOR_12")
  449. COLOR_13=$(gnome_color "$COLOR_13")
  450. COLOR_14=$(gnome_color "$COLOR_14")
  451. COLOR_15=$(gnome_color "$COLOR_15")
  452. COLOR_16=$(gnome_color "$COLOR_16")
  453. # copy existing settings from default profile
  454. $DCONF dump "${DEFAULT_KEY}/" | \
  455. $DCONF load "${PROFILE_KEY}/"
  456. # add new copy to global list of profiles
  457. dlist_append "${PROFILE_LIST_KEY}" "${PROFILE_SLUG#:}"
  458. set_theme
  459. dset palette "${LEFT_WRAPPER:-}'${COLOR_01}${PALETTE_DELIM}${COLOR_02}${PALETTE_DELIM}${COLOR_03}${PALETTE_DELIM}${COLOR_04}${PALETTE_DELIM}${COLOR_05}${PALETTE_DELIM}${COLOR_06}${PALETTE_DELIM}${COLOR_07}${PALETTE_DELIM}${COLOR_08}${PALETTE_DELIM}${COLOR_09}${PALETTE_DELIM}${COLOR_10}${PALETTE_DELIM}${COLOR_11}${PALETTE_DELIM}${COLOR_12}${PALETTE_DELIM}${COLOR_13}${PALETTE_DELIM}${COLOR_14}${PALETTE_DELIM}${COLOR_15}${PALETTE_DELIM}${COLOR_16}'${RIGHT_WRAPPER:-}"
  460. ${LEGACY_BOLD:-} && dset allow-bold "true" # mate
  461. else
  462. # Append the Base16 profile to the profile list
  463. glist_append string "${PROFILE_LIST_KEY}" "${PROFILE_SLUG}"
  464. legacy_set_theme
  465. gcset string palette "${COLOR_01}:${COLOR_02}:${COLOR_03}:${COLOR_04}:${COLOR_05}:${COLOR_06}:${COLOR_07}:${COLOR_08}:${COLOR_09}:${COLOR_10}:${COLOR_11}:${COLOR_12}:${COLOR_13}:${COLOR_14}:${COLOR_15}:${COLOR_16}"
  466. ${LEGACY_BOLD:-} && gcset bool allow-bold "true"
  467. fi
  468. }
  469. apply_guake() {
  470. # | ===========================================
  471. # | Applying values to guake
  472. # | ===========================================
  473. local legacy="${1:-}"
  474. PROFILE_KEY="/apps/guake/style/font"
  475. if [[ -z "${legacy}" ]]; then
  476. dset palette "'${COLOR_01}:${COLOR_02}:${COLOR_03}:${COLOR_04}:${COLOR_05}:${COLOR_06}:${COLOR_07}:${COLOR_08}:${COLOR_09}:${COLOR_10}:${COLOR_11}:${COLOR_12}:${COLOR_13}:${COLOR_14}:${COLOR_15}:${COLOR_16}:${FOREGROUND_COLOR}:${BACKGROUND_COLOR}'"
  477. dset palette-name "'${PROFILE_NAME}'"
  478. dset allow-bold 'true'
  479. else
  480. gcset string color "${FOREGROUND_COLOR}"
  481. gcset string palette "${COLOR_01}:${COLOR_02}:${COLOR_03}:${COLOR_04}:${COLOR_05}:${COLOR_06}:${COLOR_07}:${COLOR_08}:${COLOR_09}:${COLOR_10}:${COLOR_11}:${COLOR_12}:${COLOR_13}:${COLOR_14}:${COLOR_15}:${COLOR_16}"
  482. gcset string palette-name "${PROFILE_NAME}"
  483. PROFILE_KEY="/apps/guake/style/background"
  484. gcset string color "${BACKGROUND_COLOR}"
  485. fi
  486. }
  487. appy_tilixschemes() {
  488. # | ===========================================
  489. # | Applying values to tilix colorschemes
  490. # | ===========================================
  491. if [[ ${TILIX_RES::1} =~ ^(y|Y)$ ]]; then
  492. [[ -d "${HOME}/.config/tilix/schemes" ]] || mkdir -p "${HOME}/.config/tilix/schemes"
  493. TILIXCOLORS='{\n\t"name": "'${PROFILE_NAME}'",\n\t"comment": "Generated by Gogh",\n\t"foreground-color": "'${FOREGROUND_COLOR}'",\n\t"background-color":"'${BACKGROUND_COLOR}'",\n\t"cursor-background-color": "'${CURSOR_COLOR}'",\n\t"palette": [\n\t\t"'${COLOR_01}'",\n\t\t"'${COLOR_02}'",\n\t\t"'${COLOR_03}'",\n\t\t"'${COLOR_04}'",\n\t\t"'${COLOR_05}'",\n\t\t"'${COLOR_06}'",\n\t\t"'${COLOR_07}'",\n\t\t"'${COLOR_08}'",\n\t\t"'${COLOR_09}'",\n\t\t"'${COLOR_10}'",\n\t\t"'${COLOR_11}'",\n\t\t"'${COLOR_12}'",\n\t\t"'${COLOR_13}'",\n\t\t"'${COLOR_14}'",\n\t\t"'${COLOR_15}'",\n\t\t"'${COLOR_16}'"\n\t],\n\t"use-badge-color": false,\n\t"use-bold-color": false,\n\t"use-cursor-color": false,\n\t"use-highlight-color": false,\n\t"use-theme-colors": false\n}'
  494. echo -e "${TILIXCOLORS}" > "${scratchdir}/${PROFILE_NAME}.json"
  495. # Note: Tilix does not store color scheme name in dconf
  496. # so we have to update color palette for the current profile in order to switch to the new theme
  497. # but only set the palette on the last loop to avoid a flashing terminal
  498. if ((LOOP == OPTLENGTH)); then
  499. cp -f ${scratchdir}/* "$HOME/.config/tilix/schemes/"
  500. rm -rf "${scratchdir}"
  501. read -r -p "All done - apply new theme? [y/N] " -n 1 TILIX_RES
  502. if [[ ${TILIX_RES::1} =~ ^(y|Y)$ ]]; then
  503. PROFILE_KEY="${BASE_DIR}${DEFAULT_SLUG}"
  504. PROFILE_NAME="$(${DCONF} read ${PROFILE_KEY}/visible-name | tr -d \')"
  505. set_theme
  506. dset palette "['${COLOR_01}', '${COLOR_02}', '${COLOR_03}', '${COLOR_04}', '${COLOR_05}', '${COLOR_06}', '${COLOR_07}', '${COLOR_08}', '${COLOR_09}', '${COLOR_10}', '${COLOR_11}', '${COLOR_12}', '${COLOR_13}', '${COLOR_14}', '${COLOR_15}', '${COLOR_16}']"
  507. fi
  508. fi
  509. unset PROFILE_NAME
  510. unset PROFILE_SLUG
  511. unset TILIXCOLORS
  512. exit 0
  513. fi
  514. }
  515. apply_xfce4-terminal() {
  516. # XFCE4 terminal has no profiles, instead it uses color presets
  517. SCHEMEDIR="${HOME}/.local/share/xfce4/terminal/colorschemes"
  518. CONFFILE="${HOME}/.config/xfce4/terminal/terminalrc"
  519. if [[ ! (-w "${CONFFILE}") ]]; then
  520. if [[ -r "${XDG_CONFIG_DIRS%%:*}/Terminal/terminalrc" ]]; then
  521. cp "${XDG_CONFIG_DIRS%%:*}/Terminal/terminalrc" ${CONFFILE}
  522. else
  523. echo "ERROR: config file not present or not writable!"
  524. exit 1
  525. fi
  526. fi
  527. [[ -d "${SCHEMEDIR}" ]] || mkdir -p "${SCHEMEDIR}"
  528. F_NAME=${PROFILE_NAME// /-}
  529. F_NAME=$(echo ${F_NAME} | tr -d ":()")
  530. F_NAME=$(echo "${F_NAME}" | awk '{print tolower($0)}')
  531. FF_NAME="${SCHEMEDIR}/${F_NAME}.theme"
  532. touch "${FF_NAME}"
  533. L_COLORCURSOR="ColorCursor=${CURSOR_COLOR}"
  534. L_COLORPALETTE="ColorPalette=${COLOR_01};${COLOR_02};${COLOR_03};${COLOR_04};${COLOR_05};${COLOR_06};${COLOR_07};${COLOR_08};${COLOR_09};${COLOR_10};${COLOR_11};${COLOR_12};${COLOR_13};${COLOR_14};${COLOR_15};${COLOR_16}"
  535. printf '%s\n' \
  536. "; Generated by Gogh" \
  537. "; https://mayccoll.github.io/Gogh" \
  538. "[Scheme]" \
  539. "Name=${PROFILE_NAME}" \
  540. "ColorForeground=${FOREGROUND_COLOR}" \
  541. "ColorBackground=${BACKGROUND_COLOR}" \
  542. "${L_COLORCURSOR}" \
  543. "${L_COLORPALETTE}" \
  544. "ColorCursorUseDefault=FALSE" > ${FF_NAME}
  545. # apply last theme in queue
  546. # xfce4-terminal monitors its rc file and doesn't reference
  547. # any of the themes in there. The color settings need to
  548. # be written there directly.
  549. if ((LOOP == OPTLENGTH)); then
  550. read -r -p "All done - apply new theme? [y/N] " -n 1 XFCE4_APPLY_CURR_THEME
  551. if [[ ${XFCE4_APPLY_CURR_THEME::1} =~ ^(y|Y)$ ]]; then
  552. if grep -q "^ColorPalette=" "${CONFFILE}"; then
  553. sed -i -r -e "s/^ColorPalette=.*/${L_COLORPALETTE}/" "${CONFFILE}"
  554. else
  555. echo "${L_COLORPALETTE}" >> "${CONFFILE}"
  556. fi
  557. if grep -q "^ColorCursor=" "${CONFFILE}"; then
  558. sed -i -r -e "s/^ColorCursor=.*/${L_COLORCURSOR}/" "${CONFFILE}"
  559. else
  560. echo "${L_COLORCURSOR}" >> "${CONFFILE}"
  561. fi
  562. if grep -q "^ColorForeground=" "${CONFFILE}"; then
  563. sed -i -r -e "s/^ColorForeground=.*/ColorForeground=${FOREGROUND_COLOR}/" "${CONFFILE}"
  564. else
  565. echo "ColorForeground=${FOREGROUND_COLOR}" >> "${CONFFILE}"
  566. fi
  567. if grep -q "^ColorBackground=" "${CONFFILE}"; then
  568. sed -i -r -e "s/^ColorBackground=.*/ColorBackground=${BACKGROUND_COLOR}/" "${CONFFILE}"
  569. else
  570. echo "ColorBackground=${BACKGROUND_COLOR}" >> "${CONFFILE}"
  571. fi
  572. if grep -q "^ColorCursorUseDefault=FALSE" "${CONFFILE}"; then
  573. true
  574. else
  575. echo "ColorCursorUseDefault=FALSE" >> "${CONFFILE}"
  576. fi
  577. fi
  578. fi
  579. unset SCHEMEDIR
  580. unset CONFFILE
  581. unset PROFILE_NAME
  582. unset F_NAME
  583. unset FF_NAME
  584. unset L_COLORCURSOR
  585. unset L_COLORPALETTE
  586. exit 0
  587. }
  588. [[ -n "${UUIDGEN}" ]] && PROFILE_SLUG="$(uuidgen)"
  589. case "${TERMINAL}" in
  590. pantheon-terminal|io.elementary.t* )
  591. if [[ "${TERMINAL}" == "pantheon-terminal" ]]; then
  592. PROFILE_KEY="org.pantheon.terminal.settings"
  593. else
  594. PROFILE_KEY="io.elementary.terminal.settings"
  595. fi
  596. apply_elementary
  597. ;;
  598. iTerm.app )
  599. apply_darwin
  600. ;;
  601. mintty )
  602. apply_cygwin
  603. ;;
  604. guake )
  605. if [[ -n "$(${DCONF} list /apps/guake/style/)" ]]; then
  606. apply_guake
  607. else
  608. apply_guake legacy
  609. fi
  610. ;;
  611. gnome-terminal* )
  612. if [[ -n "$(${DCONF} list /org/gnome/terminal/)" ]]; then
  613. BASE_DIR="/org/gnome/terminal/legacy/profiles:/:"
  614. PROFILE_LIST_KEY="${BASE_DIR%:}list"
  615. PROFILE_SLUG="${PROFILE_SLUG}"
  616. # Note -- ${BASE_DIR%s} is a workaround to avoid doing additional conditional testing for existing profiles
  617. # if terminal is set to gnome-terminal
  618. : ${DEFAULT_SLUG:="$(${DCONF} read ${BASE_DIR%:}default | tr -d \')"}
  619. LEFT_WRAPPER="["
  620. RIGHT_WRAPPER="]"
  621. PALETTE_DELIM="', '"
  622. apply_gtk
  623. else
  624. BASE_DIR="/apps/gnome-terminal/profiles/"
  625. PROFILE_LIST_KEY="${BASE_DIR/profiles/global}profile_list"
  626. LEGACY_BOLD=true
  627. : ${DEFAULT_SLUG:="$(${GCONF} read ${BASE_DIR}default_profile)"}
  628. apply_gtk legacy
  629. fi
  630. ;;
  631. mate-terminal )
  632. BASE_DIR="/org/mate/terminal/profiles/"
  633. PROFILE_LIST_KEY="${BASE_DIR/profiles/global}profile-list"
  634. LEGACY_BOLD=true
  635. : ${DEFAULT_SLUG:="$(${DCONF} read ${BASE_DIR/profiles/global}default-profile | tr -d \')"}
  636. PALETTE_DELIM=":"
  637. apply_gtk
  638. ;;
  639. tilix )
  640. BASE_DIR="/com/gexperts/Tilix/profiles/"
  641. PROFILE_LIST_KEY="${BASE_DIR}list"
  642. : ${DEFAULT_SLUG:="$(${DCONF} read ${BASE_DIR}default | tr -d \')"}
  643. LEFT_WRAPPER="["
  644. RIGHT_WRAPPER="]"
  645. PALETTE_DELIM="', '"
  646. appy_tilixschemes
  647. apply_gtk
  648. ;;
  649. xfce4-terminal )
  650. apply_xfce4-terminal
  651. ;;
  652. * )
  653. printf '%s\n' \
  654. "Unsupported terminal!" \
  655. "" \
  656. "Supported terminals:" \
  657. " mintty and deriviates" \
  658. " guake" \
  659. " iTerm2" \
  660. " elementary terminal (pantheon/elementary)" \
  661. " mate-terminal" \
  662. " gnome-terminal" \
  663. " tilix" \
  664. " xfce4-terminal" \
  665. "" \
  666. "If you believe you have recieved this message in error," \
  667. "try manually setting \`TERMINAL', hint: ps -h -o comm -p \$PPID"
  668. exit 1
  669. ;;
  670. esac
  671. unset PROFILE_NAME
  672. unset PROFILE_SLUG
  673. unset DEFAULT_SLUG