A collection of scripts

Compare changes

Choose any two refs to compare.

+1
.gitignore
···
···
+
result*
+37
.nix/colorgrab.nix
···
···
+
{ writeScriptBin
+
, bash
+
, coreutils
+
, grim
+
, imagemagick
+
, libnotify
+
, slurp
+
, wl-clipboard
+
, xdg-utils
+
, ...
+
}:
+
+
writeScriptBin "colorgrab" (builtins.replaceStrings
+
[
+
"#!/bin/sh"
+
"mkdir"
+
"printf"
+
"grim"
+
"slurp"
+
"convert"
+
"wl-copy"
+
"xdg-open "
+
"notify-send"
+
]
+
[
+
"#!${bash}/bin/sh"
+
"${coreutils}/bin/mkdir"
+
"${coreutils}/bin/printf"
+
"${grim}/bin/grim"
+
"${slurp}/bin/slurp"
+
"${imagemagick}/bin/convert"
+
"${wl-clipboard}/bin/wl-copy"
+
"${xdg-utils}/bin/xdg-open "
+
"${libnotify}/bin/notify-send"
+
]
+
(builtins.readFile ../scritps/colorgrab)
+
)
+22
.nix/prefon.nix
···
···
+
{ writeScriptBin
+
, bash
+
, coreutils
+
, imagemagick
+
, ...
+
}:
+
+
writeScriptBin "prefon" (builtins.replaceStrings
+
[
+
"#!/bin/sh"
+
"printf"
+
"convert"
+
"rm"
+
]
+
[
+
"#!${bash}/bin/sh"
+
"${coreutils}/bin/printf"
+
"${imagemagick}/bin/convert"
+
"${coreutils}/bin/rm"
+
]
+
(builtins.readFile ../scritps/prefon)
+
)
+37
.nix/scr.nix
···
···
+
{ writeScriptBin
+
, bash
+
, coreutils
+
, ffmpeg
+
, grim
+
, pulseaudio
+
, slurp
+
, wf-recorder
+
, wl-clipboard
+
, ...
+
}:
+
+
writeScriptBin "scr" (builtins.replaceStrings
+
[
+
"#!/bin/sh"
+
"printf"
+
"mkdir"
+
"ffmpeg"
+
"grim"
+
"slurp"
+
"wl-copy"
+
"pactl"
+
"wf-recorder"
+
]
+
[
+
"#!${bash}/bin/sh"
+
"${coreutils}/bin/printf"
+
"${coreutils}/bin/mkdir"
+
"${ffmpeg}/bin/ffmpeg"
+
"${grim}/bin/grim"
+
"${slurp}/bin/slurp"
+
"${wl-clipboard}/bin/wl-copy"
+
"${pulseaudio}/bin/pactl"
+
"${wf-recorder}/bin/wf-recorder"
+
]
+
(builtins.readFile ../scritps/scr)
+
)
+24
.nix/thm.nix
···
···
+
{ writeScriptBin
+
, bash
+
, coreutils
+
, gnused
+
, ...
+
}:
+
+
writeScriptBin "thm" (builtins.replaceStrings
+
[
+
"#!/bin/sh"
+
"printf"
+
"mkdir"
+
"mv"
+
"sed"
+
]
+
[
+
"#!${bash}/bin/sh"
+
"${coreutils}/bin/printf"
+
"${coreutils}/bin/mkdir"
+
"${coreutils}/bin/mv"
+
"${gnused}/bin/sed"
+
]
+
(builtins.readFile ../scritps/thm)
+
)
-24
LICENSE
···
-
This is free and unencumbered software released into the public domain.
-
-
Anyone is free to copy, modify, publish, use, compile, sell, or
-
distribute this software, either in source code form or as a compiled
-
binary, for any purpose, commercial or non-commercial, and by any
-
means.
-
-
In jurisdictions that recognize copyright laws, the author or authors
-
of this software dedicate any and all copyright interest in the
-
software to the public domain. We make this dedication for the benefit
-
of the public at large and to the detriment of our heirs and
-
successors. We intend this dedication to be an overt act of
-
relinquishment in perpetuity of all present and future rights to this
-
software under copyright law.
-
-
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 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.
-
-
For more information, please refer to <http://unlicense.org/>
···
-20
README
···
-
# description
-
thm is a shell script that applies colors to a template file.
-
-
# usage
-
thm theme_name
-
-
the theme_name does not include the `.theme` at the end of the file.
-
-
# directories
-
By default, the config files will be searched for in `$XDG_CONFIG_HOME/thm` or `$HOME/.config/thm`.
-
The generated files will be placed in either `$XDG_CACHE_HOME/thm` or `$HOME/.cache/thm`. This can
-
be changed by setting the environment variables `THM_CONFIG_DIR` and `THM_DEST_DIR`. The dest dir
-
is cleared while running.
-
-
# inside config directory
-
The themes directory holds shell scripts defining the colors. These files should end with `.theme`
-
if they should be usable with thm. The templates directory holds files for generating the themes.
-
These files should end with `.template` The scripts directory holds files to be executed after thm
-
is finished generating all the files. These files should be executable in order for thm to launch
-
them. Examples of these files can be found in the examples directory of this repository.
···
+2
examples/thm/scripts/reload-mako
···
···
+
#!/bin/sh
+
makoctl reload
+2
examples/thm/scripts/reload-sway
···
···
+
#!/bin/sh
+
swaymsg reload
+32
examples/thm/templates/alacritty-colors.yml.template
···
···
+
colors:
+
primary:
+
background: '#{bg_color}'
+
foreground: '#{fg_color}'
+
+
cursor:
+
text: '#{bg_color}'
+
cursor: '#{fg_color}'
+
+
selection:
+
text: '#{bg_color}'
+
background: '#{fg_color}'
+
+
normal:
+
black: '#{color0}'
+
red: '#{color1}'
+
green: '#{color2}'
+
yellow: '#{color3}'
+
blue: '#{color4}'
+
magenta: '#{color5}'
+
cyan: '#{color6}'
+
white: '#{color7}'
+
+
bright:
+
black: '#{color8}'
+
red: '#{color9}'
+
green: '#{color10}'
+
yellow: '#{color11}'
+
blue: '#{color12}'
+
magenta: '#{color13}'
+
cyan: '#{color14}'
+
white: '#{color15}'
+43
examples/thm/templates/colors.css.template
···
···
+
:root {
+
/* HEX */
+
--bg-color: #{bg_color};
+
--fg-color: #{fg_color};
+
+
--color0: #{color0};
+
--color1: #{color1};
+
--color2: #{color2};
+
--color3: #{color3};
+
--color4: #{color4};
+
--color5: #{color5};
+
--color6: #{color6};
+
--color7: #{color7};
+
--color8: #{color8};
+
--color9: #{color9};
+
--color10: #{color10};
+
--color11: #{color11};
+
--color12: #{color12};
+
--color13: #{color13};
+
--color14: #{color14};
+
--color15: #{color15};
+
+
/* RGB */
+
--bg-color-rgb: rgb({bg_color.rgb});
+
--fg-color-rgb: rgb({fg_color.rgb});
+
+
--color0-rgb: rgb({color0.rgb});
+
--color1-rgb: rgb({color1.rgb});
+
--color2-rgb: rgb({color2.rgb});
+
--color3-rgb: rgb({color3.rgb});
+
--color4-rgb: rgb({color4.rgb});
+
--color5-rgb: rgb({color5.rgb});
+
--color6-rgb: rgb({color6.rgb});
+
--color7-rgb: rgb({color7.rgb});
+
--color8-rgb: rgb({color8.rgb});
+
--color9-rgb: rgb({color9.rgb});
+
--color10-rgb: rgb({color10.rgb});
+
--color11-rgb: rgb({color11.rgb});
+
--color12-rgb: rgb({color12.rgb});
+
--color13-rgb: rgb({color13.rgb});
+
--color14-rgb: rgb({color14.rgb});
+
--color15-rgb: rgb({color15.rgb});
+
}
+45
examples/thm/templates/colors.sh.template
···
···
+
#!/bin/sh
+
+
# Hex
+
bg_color='{bg_color}'
+
fg_color='{fg_color}'
+
+
color0='{color0}'
+
color1='{color1}'
+
color2='{color2}'
+
color3='{color3}'
+
color4='{color4}'
+
color5='{color5}'
+
color6='{color6}'
+
color7='{color7}'
+
+
color8='{color8}'
+
color9='{color9}'
+
color10='{color10}'
+
color11='{color11}'
+
color12='{color12}'
+
color13='{color13}'
+
color14='{color14}'
+
color15='{color15}'
+
+
# RGB
+
bg_color_rgb='{bg_color.rgb}'
+
fg_color_rgb='{fg_color.rgb}'
+
+
color0_rgb='{color0.rgb}'
+
color1_rgb='{color1.rgb}'
+
color2_rgb='{color2.rgb}'
+
color3_rgb='{color3.rgb}'
+
color4_rgb='{color4.rgb}'
+
color5_rgb='{color5.rgb}'
+
color6_rgb='{color6.rgb}'
+
color7_rgb='{color7.rgb}'
+
+
color8_rgb='{color8.rgb}'
+
color9_rgb='{color9.rgb}'
+
color10_rgb='{color10.rgb}'
+
color11_rgb='{color11.rgb}'
+
color12_rgb='{color12.rgb}'
+
color13_rgb='{color13.rgb}'
+
color14_rgb='{color14.rgb}'
+
color15_rgb='{color15.rgb}'
+20
examples/thm/templates/colors.template
···
···
+
# Puts the hex and rgb values of the same color on the same line in order
+
+
{bg_color} {bg_color.rgb}
+
{fg_color} {fg_color.rgb}
+
{color0} {color0.rgb}
+
{color1} {color1.rgb}
+
{color2} {color2.rgb}
+
{color3} {color3.rgb}
+
{color4} {color4.rgb}
+
{color5} {color5.rgb}
+
{color6} {color6.rgb}
+
{color7} {color7.rgb}
+
{color8} {color8.rgb}
+
{color9} {color9.rgb}
+
{color10} {color10.rgb}
+
{color11} {color11.rgb}
+
{color12} {color12.rgb}
+
{color13} {color13.rgb}
+
{color14} {color14.rgb}
+
{color1} {color1.rgb}
+38
examples/thm/templates/dark/sway-appearance.template
···
···
+
# class border background text indicator child_border
+
client.focused #{color5} #{color13} #{fg_color} #{color5} #{color5}
+
client.focused_inactive #{color4} #{color12} #{fg_color} #{color4} #{color4}
+
client.unfocused #{color8} #{color8} #{fg_color} #{color8} #{color8}
+
client.urgent #{color1} #{color9} #{fg_color} #{color1} #{color1}
+
+
default_border normal 2
+
default_floating_border normal 2
+
titlebar_border_thickness 2
+
+
font pango:monospace 10
+
+
hide_edge_borders both
+
+
title_align center
+
+
set {
+
$bg_color {bg_color}
+
$fg_color {fg_color}
+
+
$color0 {color0}
+
$color1 {color1}
+
$color2 {color2}
+
$color3 {color3}
+
$color4 {color4}
+
$color5 {color5}
+
$color6 {color6}
+
$color7 {color7}
+
$color8 {color8}
+
$color9 {color9}
+
+
$color10 {color10}
+
$color11 {color11}
+
$color12 {color12}
+
$color13 {color13}
+
$color14 {color14}
+
$color15 {color15}
+
}
+43
examples/thm/templates/foot.ini.template
···
···
+
font=monospace:size=10
+
dpi-aware=yes
+
pad=8x8
+
initial-window-size-chars=120x36
+
+
[scrollback]
+
lines=2000
+
indicator-position=none
+
+
[cursor]
+
style=bar
+
color={bg_color} {fg_color}
+
+
[colors]
+
background={bg_color}
+
foreground={fg_color}
+
regular0={color0}
+
regular1={color1}
+
regular2={color2}
+
regular3={color3}
+
regular4={color4}
+
regular5={color5}
+
regular6={color6}
+
regular7={color7}
+
bright0={color8}
+
bright1={color9}
+
bright2={color10}
+
bright3={color11}
+
bright4={color12}
+
bright5={color13}
+
bright6={color14}
+
bright7={color15}
+
# selection-foreground=<inverse foreground/background>
+
# selection-background=<inverse foreground/background>
+
+
[csd]
+
preferred=client
+
size=32
+
color=ff{fg_color}
+
button-width=32
+
button-minimize-color={color4}
+
button-maximize-color={color2}
+
button-close-color={color1}
+41
examples/thm/templates/gtk.css.template
···
···
+
/* HEX */
+
@define-color bg-color #{bg_color};
+
@define-color fg-color #{fg_color};
+
+
@define-color color0 #{color0};
+
@define-color color1 #{color1};
+
@define-color color2 #{color2};
+
@define-color color3 #{color3};
+
@define-color color4 #{color4};
+
@define-color color5 #{color5};
+
@define-color color6 #{color6};
+
@define-color color7 #{color7};
+
@define-color color8 #{color8};
+
@define-color color9 #{color9};
+
@define-color color10 #{color10};
+
@define-color color11 #{color11};
+
@define-color color12 #{color12};
+
@define-color color13 #{color13};
+
@define-color color14 #{color14};
+
@define-color color15 #{color15};
+
+
/* RGB */
+
@define-color bg-color-rgb rgb ({bg_color.rgb});
+
@define-color fg-color-rgb rgb ({fg_color.rgb});
+
+
@define-color color0-rgb rgb ({color0.rgb});
+
@define-color color1-rgb rgb ({color1.rgb});
+
@define-color color2-rgb rgb ({color2.rgb});
+
@define-color color3-rgb rgb ({color3.rgb});
+
@define-color color4-rgb rgb ({color4.rgb});
+
@define-color color5-rgb rgb ({color5.rgb});
+
@define-color color6-rgb rgb ({color6.rgb});
+
@define-color color7-rgb rgb ({color7.rgb});
+
@define-color color8-rgb rgb ({color8.rgb});
+
@define-color color9-rgb rgb ({color9.rgb});
+
@define-color color10-rgb rgb ({color10.rgb});
+
@define-color color11-rgb rgb ({color11.rgb});
+
@define-color color12-rgb rgb ({color12.rgb});
+
@define-color color13-rgb rgb ({color13.rgb});
+
@define-color color14-rgb rgb ({color14.rgb});
+
@define-color color15-rgb rgb ({color15.rgb});
+38
examples/thm/templates/light/sway-appearance.template
···
···
+
# class border background text indicator child_border
+
client.focused #{color5} #{color13} #{bg_color} #{color5} #{color5}
+
client.focused_inactive #{color4} #{color12} #{bg_color} #{color4} #{color4}
+
client.unfocused #{color8} #{color8} #{bg_color} #{color8} #{color8}
+
client.urgent #{color1} #{color9} #{bg_color} #{color1} #{color1}
+
+
default_border normal 2
+
default_floating_border normal 2
+
titlebar_border_thickness 2
+
+
font pango:monospace 10
+
+
hide_edge_borders both
+
+
title_align center
+
+
set {
+
$bg_color {bg_color}
+
$fg_color {fg_color}
+
+
$color0 {color0}
+
$color1 {color1}
+
$color2 {color2}
+
$color3 {color3}
+
$color4 {color4}
+
$color5 {color5}
+
$color6 {color6}
+
$color7 {color7}
+
$color8 {color8}
+
$color9 {color9}
+
+
$color10 {color10}
+
$color11 {color11}
+
$color12 {color12}
+
$color13 {color13}
+
$color14 {color14}
+
$color15 {color15}
+
}
+47
examples/thm/templates/mako.template
···
···
+
# Global Config
+
max-visible=2
+
sort=-time
+
output=DP-1
+
layer=top
+
anchor=top-right
+
+
# All Notifcations
+
font=monospace 10
+
background-color=#{bg_color}
+
text-color=#{fg_color}
+
width=400
+
height=200
+
margin=8,8
+
padding=8,8
+
border-size=4
+
border-color=#{fg_color}
+
max-icon-size=48
+
actions=1
+
format=<b>%a</b>\n%s\n%b
+
default-timeout=8000
+
group-by=app-name
+
+
# Low Urgency Notifcations
+
[urgency=low]
+
border-color=#{color8}
+
default-timeout=4000
+
+
# Normal Ugency Notifcations
+
[urgency=normal]
+
border-color=#{fg_color}
+
default-timeout=8000
+
+
# High Urgency Notifcations
+
[urgency=high]
+
border-color=#{color1}
+
default-timeout=0
+
+
[grouped]
+
format=<b>%a</b>\n%s\n%b
+
+
# Hidden Notification
+
[hidden]
+
width=0
+
height=0
+
border-size=0
+
format=
+32
examples/thm/templates/swaylock.template
···
···
+
# Functionality
+
ignore-empty-password
+
daemonize
+
+
# Appearance
+
disable-caps-lock-text
+
indicator-caps-lock
+
color={color8}
+
bs-hl-color={color1}
+
caps-lock-bs-hl-color={color1}
+
caps-lock-key-hl-color={color3}
+
font=monospace
+
indicator-radius=64
+
indicator-thickness=16
+
inside-color={color2}
+
inside-clear-color={color5}
+
inside-caps-lock-color={color3}
+
inside-ver-color={color4}
+
inside-wrong-color={color1}
+
key-hl-color={color2}
+
line-uses-inside
+
ring-color={color10}
+
ring-clear-color={color13}
+
ring-caps-lock-color={color11}
+
ring-ver-color={color12}
+
ring-wrong-color={color9}
+
separator-color={color7}00
+
text-color={color15}
+
text-clear-color={color15}
+
text-caps-lock-color={color15}
+
text-ver-color={color15}
+
text-wrong-color={color15}
+23
examples/thm/themes/dark.theme
···
···
+
#!/bin/sh
+
+
theme_type="dark"
+
+
bg_color="1f1f1f"
+
fg_color="efefef"
+
+
color0="1f1f1f"
+
color1="e67b7b"
+
color2="80ba63"
+
color3="f5a868"
+
color4="849ce6"
+
color5="b37fe3"
+
color6="6ebdc4"
+
color7="b0b0b0"
+
color8="3f3f3f"
+
color9="ed9a9a"
+
color10="a3d989"
+
color11="f7c297"
+
color12="a6baf5"
+
color13="d1adf2"
+
color14="bedcde"
+
color15="efefef"
+23
examples/thm/themes/default-dark.theme
···
···
+
#!/bin/sh
+
+
theme_type="dark"
+
+
bg_color="000000"
+
fg_color="ffffff"
+
+
color0="000000"
+
color1="800000"
+
color2="008000"
+
color3="808000"
+
color4="000080"
+
color5="800080"
+
color6="008080"
+
color7="c0c0c0"
+
color8="808080"
+
color9="ff0000"
+
color10="00ff00"
+
color11="ffff00"
+
color12="0000ff"
+
color13="ff00ff"
+
color14="00ffff"
+
color15="ffffff"
+23
examples/thm/themes/default-light.theme
···
···
+
#!/bin/sh
+
+
theme_type="light"
+
+
bg_color="ffffff"
+
fg_color="000000"
+
+
color0="ffffff"
+
color1="800000"
+
color2="008000"
+
color3="808000"
+
color4="000080"
+
color5="800080"
+
color6="008080"
+
color7="808080"
+
color8="c0c0c0"
+
color9="ff0000"
+
color10="00ff00"
+
color11="ffff00"
+
color12="0000ff"
+
color13="ff00ff"
+
color14="00ffff"
+
color15="000000"
+23
examples/thm/themes/grayscale-light.theme
···
···
+
#!/bin/sh
+
+
theme_type="light"
+
+
bg_color="efefef"
+
fg_color="1f1f1f"
+
+
color0="efefef"
+
color1="b0b0b0"
+
color2="9d9d9d"
+
color3="8a8a8a"
+
color4="787878"
+
color5="656565"
+
color6="525252"
+
color7="3f3f3f"
+
color9="808080"
+
color8="bfbfbf"
+
color10="707070"
+
color11="606060"
+
color12="505050"
+
color13="3f3f3f"
+
color14="2f2f2f"
+
color15="1f1f1f"
+23
examples/thm/themes/light.theme
···
···
+
#!/bin/sh
+
+
theme_type="light"
+
+
bg_color="efefef"
+
fg_color="1f1f1f"
+
+
color0="efefef"
+
color1="e67b7b"
+
color2="80ba63"
+
color3="f5a868"
+
color4="849ce6"
+
color5="b37fe3"
+
color6="6ebdc4"
+
color7="3f3f3f"
+
color8="b0b0b0"
+
color9="ed9a9a"
+
color10="a3d989"
+
color11="f7c297"
+
color12="a6baf5"
+
color13="d1adf2"
+
color14="bedcde"
+
color15="1f1f1f"
-2
exmaples/scripts/reload-sway
···
-
#!/bin/sh
-
swaymsg reload
···
-22
exmaples/templates/colors.sh.template
···
-
#!/bin/sh
-
-
bg_color='{bg_color}'
-
fg_color='{fg_color}'
-
-
color0='{color0}'
-
color1='{color1}'
-
color2='{color2}'
-
color3='{color3}'
-
color4='{color4}'
-
color5='{color5}'
-
color6='{color6}'
-
color7='{color7}'
-
-
color8='{color8}'
-
color9='{color9}'
-
color10='{color10}'
-
color11='{color11}'
-
color12='{color12}'
-
color13='{color13}'
-
color14='{color14}'
-
color15='{color15}'
···
-29
exmaples/templates/sway-colors.template
···
-
# class border background text indicator child_border
-
client.focused #{color5} #{color13} #{bg_color} #{color5} #{color5}
-
client.focused_inactive #{color4} #{color12} #{bg_color} #{color4} #{color4}
-
client.unfocused #{color8} #{color8} #{bg_color} #{color8} #{color8}
-
client.urgent #{color1} #{color9} #{bg_color} #{color1} #{color1}
-
-
# set variables
-
set {
-
$bg_color {bg_color}
-
$fg_color {fg_color}
-
-
$color0 {color0}
-
$color1 {color1}
-
$color2 {color2}
-
$color3 {color3}
-
$color4 {color4}
-
$color5 {color5}
-
$color6 {color6}
-
$color7 {color7}
-
$color8 {color8}
-
$color9 {color9}
-
-
$color10 {color10}
-
$color11 {color11}
-
$color12 {color12}
-
$color13 {color13}
-
$color14 {color14}
-
$color15 {color15}
-
}
···
-21
exmaples/themes/default-dark.theme
···
-
#!/bin/sh
-
-
bg_color="000000"
-
fg_color="ffffff"
-
-
color0="000000"
-
color1="800000"
-
color2="008000"
-
color3="808000"
-
color4="000080"
-
color5="800080"
-
color6="008080"
-
color7="c0c0c0"
-
color8="808080"
-
color9="ff0000"
-
color10="00ff00"
-
color11="ffff00"
-
color12="0000ff"
-
color13="ff00ff"
-
color14="00ffff"
-
color15="ffffff"
···
-21
exmaples/themes/default-light.theme
···
-
#!/bin/sh
-
-
bg_color="ffffff"
-
fg_color="000000"
-
-
color0="ffffff"
-
color1="800000"
-
color2="008000"
-
color3="808000"
-
color4="000080"
-
color5="800080"
-
color6="008080"
-
color7="808080"
-
color8="c0c0c0"
-
color9="ff0000"
-
color10="00ff00"
-
color11="ffff00"
-
color12="0000ff"
-
color13="ff00ff"
-
color14="00ffff"
-
color15="000000"
···
-20
exmaples/themes/grayscale-light.theme
···
-
#!/bin/sh
-
bg_color="efefef"
-
fg_color="1f1f1f"
-
-
color0="efefef"
-
color1="b0b0b0"
-
color2="9d9d9d"
-
color3="8a8a8a"
-
color4="787878"
-
color5="656565"
-
color6="525252"
-
color7="3f3f3f"
-
color9="808080"
-
color8="bfbfbf"
-
color10="707070"
-
color11="606060"
-
color12="505050"
-
color13="3f3f3f"
-
color14="2f2f2f"
-
color15="1f1f1f"
···
-21
exmaples/themes/light.theme
···
-
#!/bin/sh
-
-
bg_color="efefef"
-
fg_color="1f1f1f"
-
-
color0="efefef"
-
color1="e67b7b"
-
color2="80ba63"
-
color3="f5a868"
-
color4="849ce6"
-
color5="b37fe3"
-
color6="6ebdc4"
-
color7="3f3f3f"
-
color8="b0b0b0"
-
color9="ed9a9a"
-
color10="a3d989"
-
color11="f7c297"
-
color12="a6baf5"
-
color13="d1adf2"
-
color14="bedcde"
-
color15="1f1f1f"
···
+27
flake.lock
···
···
+
{
+
"nodes": {
+
"nixpkgs": {
+
"locked": {
+
"lastModified": 1726062873,
+
"narHash": "sha256-IiA3jfbR7K/B5+9byVi9BZGWTD4VSbWe8VLpp9B/iYk=",
+
"owner": "NixOS",
+
"repo": "nixpkgs",
+
"rev": "4f807e8940284ad7925ebd0a0993d2a1791acb2f",
+
"type": "github"
+
},
+
"original": {
+
"owner": "NixOS",
+
"ref": "nixos-unstable",
+
"repo": "nixpkgs",
+
"type": "github"
+
}
+
},
+
"root": {
+
"inputs": {
+
"nixpkgs": "nixpkgs"
+
}
+
}
+
},
+
"root": "root",
+
"version": 7
+
}
+35
flake.nix
···
···
+
{
+
inputs = {
+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
+
};
+
+
outputs = { self, nixpkgs, ... }:
+
let
+
forAllSystems = function: nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" ]
+
(system: function (import nixpkgs {
+
inherit system;
+
overlays = [ self.overlays.default ];
+
}));
+
in
+
{
+
overlays.default = final: prev: rec {
+
colorgrab = final.callPackage ./.nix/colorgrab.nix { };
+
prefon = final.callPackage ./.nix/prefon.nix { };
+
scr = final.callPackage ./.nix/scr.nix { };
+
thm = final.callPackage ./.nix/thm.nix { };
+
yemou-scripts = final.symlinkJoin {
+
name = "yemou-scripts";
+
paths = [ colorgrab prefon scr thm ];
+
};
+
};
+
+
packages = forAllSystems (pkgs: {
+
colorgrab = pkgs.colorgrab;
+
default = pkgs.yemou-scripts;
+
prefon = pkgs.prefon;
+
scr = pkgs.scr;
+
thm = pkgs.thm;
+
yemou-scripts = pkgs.yemou-scripts;
+
});
+
};
+
}
+24
license
···
···
+
This is free and unencumbered software released into the public domain.
+
+
Anyone is free to copy, modify, publish, use, compile, sell, or
+
distribute this software, either in source code form or as a compiled
+
binary, for any purpose, commercial or non-commercial, and by any
+
means.
+
+
In jurisdictions that recognize copyright laws, the author or authors
+
of this software dedicate any and all copyright interest in the
+
software to the public domain. We make this dedication for the benefit
+
of the public at large and to the detriment of our heirs and
+
successors. We intend this dedication to be an overt act of
+
relinquishment in perpetuity of all present and future rights to this
+
software under copyright law.
+
+
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 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.
+
+
For more information, please refer to <http://unlicense.org/>
+6
readme.md
···
···
+
# haiku readme
+
random shell scripts that
+
+
are potentially useful
+
+
for various tasks
+118
scritps/colorgrab
···
···
+
#!/bin/sh
+
# Grab the color of a specific point
+
+
# Required Commands:
+
# convert(imagemagick) - Get the color from the screenshotted point
+
# grim - Take a screenshot of the selected point
+
# slurp - Select a point
+
# mkdir - Create missing directories
+
# notify-send (optional) - Send a screenshot with the color
+
# wl-copy(wl-clipboard) (optional) - Copy the color into the clipboard
+
# xdg-open (optional) - Open the screenshot in an image viewer
+
+
usage() {
+
printf '%s\n' "usage: ${0##*/} [options]" \
+
"options:" \
+
" -c - copy to clipboard" \
+
" -h - display usage statement" \
+
" -n - send a notification with the color" \
+
" -o - open the color as an image" \
+
" -r - display the color as an rgb value" \
+
" -x - display the color as a hexcode value (default)"
+
}
+
+
# Parse arguments
+
for flag
+
do
+
# Make sure flag begins with '-' and are atleast two characters long
+
case $flag in
+
- ) continue ;;
+
-- ) break ;;
+
-* ) ;;
+
* ) continue ;;
+
esac
+
+
# Split the flags into individual arguments and set variables
+
flag=${flag#-}
+
+
while [ "$flag" ]
+
do
+
a=${flag%"${flag#?}"}
+
+
case $a in
+
c ) copy_to_clipboard=true ;;
+
h ) usage; exit 0 ;;
+
n ) send_notification=true ;;
+
o ) open_color_image=true ;;
+
r ) color_type="rgb" ;;
+
x ) color_type="hex" ;;
+
* ) printf '%s\n' "${0##*/}: -$a invalid argument" 1>&2
+
usage 1>&2; exit 1 ;;
+
esac
+
+
flag=${flag#?}
+
done
+
done
+
+
# Make sure this directory exist before continuing
+
[ -d "/tmp/${0##*/}" ] || { mkdir -p "/tmp/${0##*/}" || exit 1; }
+
+
# Set color_type if not already set
+
[ "$color_type" ] || color_type="hex"
+
+
# Get a screenshot of the pixel
+
# shellcheck disable=SC2086
+
grim -s 1 -g "$(slurp ${SLURP_ARGS} -b 00000000 -s 00000000 -w -1 -p)" "/tmp/${0##*/}/temp.png"
+
+
case $color_type in
+
hex ) color=$(convert "/tmp/${0##*/}/temp.png" -format "%[hex:p]\n" info:) ;;
+
rgb )
+
color=$(convert "/tmp/${0##*/}/temp.png" -format "%[pixel:p]\n" info:)
+
color=${color#*(}; color=${color%)*}
+
;;
+
* ) printf '%s\n' "${0##*/}: invalid color_type: $color_type" 1>&2; exit 1 ;;
+
esac
+
printf '%s\n' "$color"
+
+
# Copy color to clipboard
+
[ "$copy_to_clipboard" ] && {
+
wl-copy -n "$color" || printf '%s\n' "${0##*/}: failed to copy color to clipboard" 1>&2
+
}
+
+
# Open color image in the user's perfered image viewer
+
[ "$open_color_image" ] && {
+
# Create the color image if it doesn't already exist
+
[ -f "/tmp/${0##*/}/o$color.png" ] || {
+
case $color_type in
+
hex ) ocolor="#$color" ;;
+
rgb ) ocolor="rgb($color)" ;;
+
esac
+
+
convert -size 150x150 xc:"$ocolor" +size -gravity center \
+
\( -background white pango:"<span font_family=\"monospace\"
+
font_weight=\"bold\"> $color </span>" \) \
+
-composite "/tmp/${0##*/}/o$color.png"
+
}
+
+
xdg-open "/tmp/${0##*/}/o$color.png" > "/tmp/${0##*/}/xdg-open.log" 2>&1 &
+
}
+
+
# Send a notification with an image of the color aswell as the value
+
[ "$send_notification" ] && {
+
[ -f "/tmp/${0##*/}/n$color.png" ] || {
+
case $color_type in
+
hex ) ncolor="#$color"; color_prefix="hex:";;
+
rgb )
+
ncolor="rgb($color)"
+
color_r="${color%%,*}"
+
color_g="${color#*,}"; color_g="${color_g%,*}"
+
color_b="${color##*,}"
+
color_rgb="$color_r$color_g$color_b"
+
color_prefix="rgb:";;
+
esac
+
+
convert -size 64x64 xc:"$ncolor" "/tmp/${0##*/}/n$color_rgb.png"
+
}
+
+
notify-send -a "${0##*/}" -i "/tmp/${0##*/}/n$color_rgb.png" "$color_prefix $color"
+
}
+147
scritps/prefon
···
···
+
#!/bin/sh
+
# Script to preview fonts
+
+
usage() {
+
printf '%b\n' "${0##*/} [-F FILE | -S | -t STRING] [OPTIONS]" \
+
"actions:" \
+
"\t-F FILE - read from file" \
+
"\t-S - read from stdin" \
+
"\t-t STRING - use a string" \
+
"\noptions:" \
+
"\t-b SIZE - border size" \
+
"\t-c COLORS - set the color of the text and background" \
+
"\t-f FONT - which font to preview" \
+
"\t-h - display this message" \
+
"\t-i - generate the inverse image (horizontal, vertical, none)" \
+
"\t-o FILE - output file for the generated image" \
+
"\t-s SIZE - size of the font" \
+
"\ndefault values:" \
+
"These values can be set before execution to change default values" \
+
"\tPREFON_ACTION=text (file, stdin, or text)" \
+
"\tPREFON_BORDER_SIZE=16" \
+
"\tPREFON_COLORS=\"000000,ffffff\"" \
+
"\tPREFON_FONT=\"monospace\"" \
+
"\tPREFON_OUTPUT=\"/tmp/prefon.png\"" \
+
"\tPREFON_SIZE=16" \
+
"\tPREFON_TEXT=\"The quick brown fox jumps\\\n over the lazy dog\"" \
+
"\tPREFON_INVERSE=vertical (horizontal, vertical, none)"
+
}
+
+
info() {
+
case $1 in
+
i ) prefix=INFO ;;
+
w ) prefix=WARNING ;;
+
e ) prefix=ERROR ;;
+
* ) printf '%s\n' "sus!" 1>&2; exit 1 ;;
+
esac; shift
+
+
printf "${0##*/}: $prefix: %b\n" "$*" 1>&2
+
}
+
+
# Default values
+
PREFON_ACTION=${PREFON_ACTION:-text}
+
PREFON_BORDER_SIZE=${PREFON_BORDER_SIZE:-16}
+
PREFON_COLORS=${PREFON_COLORS:-000000,ffffff}
+
PREFON_FONT="${PREFON_FONT:-monospace}"
+
PREFON_OUTPUT="${PREFON_OUTPUT:-/tmp/prefon.png}"
+
PREFON_SIZE=${PREFON_SIZE:-16}
+
PREFON_TEXT="${PREFON_TEXT:-The quick brown fox jumps\n over the lazy dog}"
+
PREFON_INVERSE=${PREFON_WITHOUT_INVERSE:-vertical}
+
+
# Handle arguments
+
while [ "$*" ]
+
do
+
case $1 in
+
- ) shift; continue ;;
+
-- ) shift; break ;;
+
-* ) flag=${1#-}; shift ;;
+
* ) shift; continue ;;
+
esac
+
+
while [ "$flag" ]
+
do
+
arg=${flag%${flag#?}}
+
+
case $arg in
+
F ) PREFON_ACTION="file"; PREFON_FILE=$1; shift ;;
+
S ) PREFON_ACTION=stdin; PREFON_FILE=/dev/stdin ;;
+
b ) PREFON_BORDER_SIZE=$1; shift ;;
+
c ) PREFON_COLORS=$1; shift ;;
+
f ) PREFON_FONT=$1; shift ;;
+
h ) usage; exit 0 ;;
+
i ) PREFON_INVERSE=$1; shift ;;
+
o ) PREFON_OUTPUT=$1; shift ;;
+
s ) PREFON_SIZE=$1; shift ;;
+
t ) PREFON_ACTION=text; PREFON_TEXT=$1; shift ;;
+
* ) printf '%s\n' "${0##*/}: -$arg: invalid argument" 1>&2
+
usage 1>&2; exit 1 ;;
+
esac
+
+
flag=${flag#?}
+
done
+
done
+
+
_gen_img() {
+
convert -background "#$2" -bordercolor "#$2" -border "$PREFON_BORDER_SIZE" \
+
pango:"<span foreground=\"#$1\" font_desc=\"$PREFON_FONT $PREFON_SIZE\">$4</span>" "$3"
+
}
+
+
_output_file() {
+
while IFS= read -r line
+
do printf '%s\n' "$line"
+
done < "$PREFON_FILE"
+
}
+
+
generate_image() {
+
fgcolor=${PREFON_COLORS%,*}
+
bgcolor=${PREFON_COLORS#*,}
+
+
_gen_img "$fgcolor" "$bgcolor" "$PREFON_OUTPUT" "$1" || {
+
info e failed to generate image
+
exit 1
+
}
+
+
[ "$PREFON_INVERSE" != "none" ] && {
+
inverse="${PREFON_OUTPUT%.*}"
+
inverse="${inverse}-inverse.${PREFON_OUTPUT##*.}"
+
+
_gen_img "$bgcolor" "$fgcolor" "$inverse" "$1" || {
+
info e failed to generate image
+
exit 1
+
}
+
+
case $PREFON_INVERSE in
+
horizontal ) convert "$PREFON_OUTPUT" "$inverse" +append "$PREFON_OUTPUT" \
+
|| { info e failed to generate image; exit 1; } ;;
+
vertical ) convert "$PREFON_OUTPUT" "$inverse" -append "$PREFON_OUTPUT" \
+
|| { info e failed to generate image; exit 1; } ;;
+
* ) info e "${PREFON_INVERSE}: is not a valid value for PREFON_INVERSE"
+
exit 1 ;;
+
esac
+
+
rm "$inverse" || info w failed to remove temporary file: "${inverse}"
+
}
+
+
printf '%s\n' "$PREFON_OUTPUT"
+
}
+
+
read_input() {
+
input="$(_output_file)"
+
generate_image "$input"
+
}
+
+
case $PREFON_ACTION in
+
file )
+
[ -e "$PREFON_FILE" ] || { info e "'$PREFON_FILE' does not exist"; exit 1; }
+
read_input
+
;;
+
stdin )
+
[ -e /dev/stdin ] || { info e "/dev/stdin does not exist"; exit 1; }
+
read_input
+
;;
+
text )
+
[ "$PREFON_TEXT" ] || { info e "string not provided"; exit 1; }
+
generate_image "$PREFON_TEXT"
+
;;
+
* ) info e invalid action: $PREFON_ACTION; exit 1 ;;
+
esac
+237
scritps/scr
···
···
+
#!/bin/sh
+
# shellcheck disable=SC1090,SC1091,SC2154
+
+
# SC1090 & SC2154
+
# The files sourced are user generated files that should contain the needed
+
# variables for the script to function correctly. It should be safe to ignore
+
# these warnings.
+
+
# Required Commands
+
# ffmpeg - needed for aud
+
# grim - needed for pic
+
# mkdir - create missing directories
+
# pactl - create loopback devices for multi-device audio recording in wf-recorder
+
# slurp - make a selection
+
# wf-recorder - needed for rec
+
# wl-copy - copy images to clipboard
+
+
# This script is intended for use on wayland; however, `scr aud` should work fine without
+
# wayland.
+
+
# Set required variables if needed
+
[ "$SCR_CFG_DIR" ] || SCR_CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/scr"
+
[ "$SCR_CACHE_DIR" ] || SCR_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/scr"
+
+
# Source the configuration file
+
# A sample configuration can be found in my dotfiles at:
+
# https://github.com/yemouu/setup/blob/master/home/cfg/scr/config.sh
+
# TODO: put an example cofiguration in this repo
+
. "$SCR_CFG_DIR/config.sh" || {
+
printf '%s\n' "${0##*/}: failed to source $SCR_CFG_DIR/config.sh" 1>&2; exit 1
+
}
+
+
# Usage statement for the script
+
usage() {
+
printf '%b\n' "usage: ${0##*/} action [options]" \
+
"actions:" \
+
"\taud - audio" \
+
"\tpic - picture" \
+
"\trec - record" \
+
"options:" \
+
"\t-a - record desktop audio (aud,rec)" \
+
"\t-c - copy image to clipboard (pic)" \
+
"\t-h - display this message" \
+
"\t-m - record microphone audio (aud,rec)" \
+
"\t-o - output to use (pic,rec)" \
+
"\t-d - all displays (pic)"
+
}
+
+
# Determine the action to run
+
case $1 in
+
aud ) action="scr_aud" ;;
+
pic ) action="scr_pic" ;;
+
rec ) action="scr_rec" ;;
+
*h|*help ) usage; exit 0 ;;
+
* ) printf '%s\n' "${0##*/}: $1: invalid action" 1>&2; usage 1>&2; exit 1 ;;
+
esac
+
shift
+
+
# Determine options to run with based on arguments
+
# (I need to stop)
+
for flag in "$@"
+
do
+
# Make sure arguments start with '-' and are atleast 2 characters long
+
case $flag in
+
- ) continue ;;
+
-- ) break ;;
+
-* ) ;;
+
* ) continue;;
+
esac
+
+
# Split arguments to be 1 character long and determine options to use
+
args=${flag#-}
+
+
while [ "$args" ]
+
do
+
a=${args%"${args#?}"}
+
+
case $a in
+
a ) desktop_audio=true ;;
+
c ) copy_clipboard=true ;;
+
d ) output=all ;; # Kinda redundent lol
+
h ) usage; exit 0 ;;
+
m ) microphone=true ;;
+
o ) aargs=$*
+
output=${aargs##*"${flag}"}; output=${output#\ }; output=${output%%\ *}
+
[ "${output}" ] || printf '%s\n' "${0##*/}: -o: missing output" 1>&2 ;;
+
* ) printf '%s\n' "${0##*/}: -$a: invalid argument" 1>&2
+
usage 1>&2; exit 1 ;;
+
esac
+
+
args=${args#?}
+
done
+
done
+
unset args arg
+
+
# Simple function to print out an error message and exit
+
die() {
+
printf '%s\n' "${0##*/}: $*" 1>&2
+
exit 1
+
}
+
+
# Record Audio
+
scr_aud() {
+
# Create the directory to store audio recordings if it does not already exist
+
[ -d "$scr_aud_dir" ] || \
+
{ mkdir -p "$scr_aud_dir" || die "failed to make directory: $scr_aud_dir"; }
+
+
# Create the directory to store logs if it does not already exist
+
[ -d "$SCR_CACHE_DIR" ] || \
+
{ mkdir -p "$SCR_CACHE_DIR" || \
+
die "failed to make directory: $SCR_CACHE_DIR"; }
+
+
filename="$scr_aud_dir/$aud_filename"
+
+
# Require atleast one of the arguments: -a or -m
+
[ "$microphone" ] || [ "$desktop_audio" ] || \
+
{ die "aud: argument -a or -m is required to record audio"; }
+
+
# Set ffmpeg options based on script options
+
[ "$microphone" ] && { args="-f pulse -i $aud_source"; }
+
[ "$desktop_audio" ] && { args="$args -f pulse -i $aud_sink"; }
+
[ "$microphone" ] && [ "$desktop_audio" ] && \
+
{ args="$args -filter_complex amix=inputs=2"; }
+
+
# Pressing Ctrl+C will exit the script instead of just ffmpeg.
+
# Intercept Ctrl+C and do nothing.
+
trap '' INT
+
+
# shellcheck disable=SC2086
+
# Word splitting is favorable here
+
ffmpeg $args "$filename" > "$SCR_CACHE_DIR/aud.log" 2>&1 &
+
aud_pid=$!
+
printf '%s' "Press Ctrl+C to stop recording. " 1>&2
+
wait $aud_pid
+
+
# Reset the trap
+
trap - INT
+
+
printf '\n%s\n' "$filename"
+
}
+
+
# Take a screenshot
+
scr_pic() {
+
# Create directories if they do not already exist
+
[ -d "$scr_pic_dir" ] || \
+
{ mkdir -p "$scr_pic_dir" || die "failed to make directory: $scr_pic_dir"; }
+
+
[ -d "$SCR_CACHE_DIR" ] || \
+
{ mkdir -p "$SCR_CACHE_DIR" || \
+
die "failed to create directory: $SCR_CACHE_DIR"; }
+
+
filename="$scr_pic_dir/$pic_filename"
+
+
if [ "$output" = "all" ]
+
then
+
# Grim will screenshot all monitors by default
+
grim "$filename" > "$SCR_CACHE_DIR/pic.log" 2>&1
+
else
+
# Get the geometry of the screenshot from the user and take the screenshot
+
# shellcheck disable=SC2086
+
if [ "$output" ]; then set -- -o "$output"; else set -- -g "$(slurp ${SLURP_ARGS})"; fi
+
grim "$@" "$filename" > "$SCR_CACHE_DIR/pic.log" 2>&1
+
fi
+
+
# Copy the image to the system clipboard
+
$copy_clipboard && { wl-copy <"$filename" > "$SCR_CACHE_DIR/copy.log" 2>&1; }
+
+
printf '%s\n' "$filename"
+
}
+
+
scr_rec() {
+
# Create directories if they do not already exist
+
[ -d "$scr_rec_dir" ] || \
+
{ mkdir -p "$scr_rec_dir" || die "failed to make directory: $scr_pic_dir"; }
+
+
[ -d "$SCR_CACHE_DIR" ] || \
+
{ mkdir -p "$SCR_CACHE_DIR" || \
+
die "failed to make directory: $SCR_CACHE_DIR"; }
+
+
filename="$scr_rec_dir/$rec_filename"
+
+
# Set wf-recorder arguments based on script options
+
[ "$microphone" ] && args="-a$aud_source"
+
[ "$desktop_audio" ] && args="-a$aud_sink"
+
+
# If both microphone and desktop_audio is set, create a loopback devices pointing to
+
# scr_inputs. wf-record does not support multiple audio devices. This is how they
+
# recomend you record two devices at the same time.
+
[ "$microphone" ] && [ "$desktop_audio" ] && {
+
unload_pulse_modules=true
+
null_sink=$(pactl load-module module-null-sink sink_name=aud_both)
+
lb_desk=$(pactl load-module module-loopback sink=aud_both source="$aud_sink")
+
lb_mic=$(pactl load-module module-loopback sink=aud_both source="$aud_source")
+
args="-aaud_both.monitor"
+
}
+
+
# Pressing Ctrl+C will exit the script instead of just wf-recorder.
+
# Intercept Ctrl+C and exit wf-recorder instead of the script
+
trap '' INT
+
+
# shellcheck disable=SC2086
+
if [ "$output" ]; then set -- -o "$output"; else set -- -g "$(slurp ${SLURP_ARGS})"; fi
+
# Word splitting is favorable here
+
# shellcheck disable=SC2086
+
wf-recorder $args $rec_extraflags "$@" -f "$filename" > "$SCR_CACHE_DIR/rec.log" 2>&1 &
+
rec_pid=$!
+
printf '%s' "Press Ctrl+C to stop recording. " 1>&2
+
wait $rec_pid
+
+
# Reset the trap
+
trap - INT
+
+
# Clean up pulseaudio modules that the script created
+
[ "$unload_pulse_modules" ] && {
+
pactl unload-module "$lb_mic"
+
pactl unload-module "$lb_desk"
+
pactl unload-module "$null_sink"
+
}
+
+
printf '\n%s\n' "$filename"
+
}
+
+
$action
+
+
# Run post scripts
+
# Scripts in the directory `$SCR_CFG_DIR/scripts` will
+
# take in `$action` as `$1` and `$filename` as `$2`.
+
# Sample scripts can be found in my dotfiles at:
+
# https://github.com/yemouu/setup/blob/master/home/cfg/scr/scripts
+
for i in "$SCR_CFG_DIR/scripts/"*
+
do
+
[ -x "$i" ] && {
+
printf '%s\n' "# $i --- START" >> "$SCR_CACHE_DIR/scripts.log"
+
$i "$action" "$filename" > "$SCR_CACHE_DIR/scripts.log" 2>&1
+
printf '%s\n' "# $i --- END" >> "$SCR_CACHE_DIR/scripts.log"
+
}
+
done
+174
scritps/thm
···
···
+
#!/bin/sh
+
# shellcheck disable=SC1090,SC2154
+
+
# Usage statement
+
usage() {
+
printf '%s\n' "usage: ${0##*/} theme"
+
}
+
+
# Convert hex colors into rgb
+
hex2rgb() {
+
hex=$1
+
hex_r=${hex%????}
+
hex_g=${hex#??}; hex_g=${hex_g%??}
+
hex_b=${hex#????}
+
+
printf '%d,%d,%d' "0x$hex_r" "0x$hex_g" "0x$hex_b"
+
}
+
+
# Set directory variables
+
[ "$THM_CONFIG_DIR" ] \
+
&& conf_dir="$THM_CONFIG_DIR" \
+
|| conf_dir="${XDG_CONFIG_HOME:-$HOME/.config}/thm"
+
+
[ "$THM_DEST_DIR" ] \
+
&& dest_dir="$THM_DEST_DIR" \
+
|| dest_dir="${XDG_STATE_HOME:-$HOME/.local/state}/thm"
+
+
err() {
+
[ "$*" ] && err_msg="$*" || err_msg="error"
+
printf '%s%b' "${0##*/}: " "$err_msg\n" 1>&2
+
exit 1
+
}
+
+
# Ensure the theme file exist and source it
+
case $1 in
+
-h|h|--help|help ) usage; exit 0 ;;
+
* ) [ "$1" ] || err "missing argument"
+
[ -f "$conf_dir/themes/$1.theme" ] || err "$1: theme not found"
+
theme_file="$conf_dir/themes/$1.theme"
+
. "$theme_file" ;;
+
esac
+
+
# Create RGB colors from the hex colors
+
bg_color_rgb="$(hex2rgb "$bg_color")"
+
fg_color_rgb="$(hex2rgb "$fg_color")"
+
color0_rgb="$(hex2rgb "$color0")"
+
color1_rgb="$(hex2rgb "$color1")"
+
color2_rgb="$(hex2rgb "$color2")"
+
color3_rgb="$(hex2rgb "$color3")"
+
color4_rgb="$(hex2rgb "$color4")"
+
color5_rgb="$(hex2rgb "$color5")"
+
color6_rgb="$(hex2rgb "$color6")"
+
color7_rgb="$(hex2rgb "$color7")"
+
color8_rgb="$(hex2rgb "$color8")"
+
color9_rgb="$(hex2rgb "$color9")"
+
color10_rgb="$(hex2rgb "$color10")"
+
color11_rgb="$(hex2rgb "$color11")"
+
color12_rgb="$(hex2rgb "$color12")"
+
color13_rgb="$(hex2rgb "$color13")"
+
color14_rgb="$(hex2rgb "$color14")"
+
color15_rgb="$(hex2rgb "$color15")"
+
+
# Make sure the dest_dir and dest_dir/thm_old exist
+
[ -d "$dest_dir/thm_old" ] || mkdir -p "$dest_dir/thm_old"
+
+
# Try and empty the dest_dir before populating it
+
mv "$dest_dir/"* "$dest_dir/thm_old" 2> /dev/null
+
+
# Make a file with the name of the new theme
+
printf '%s\n' "$theme_file" > "$dest_dir/current_thm"
+
+
# Repalce template syntax with the actual colors
+
for t in "${conf_dir}/templates/"*".template"
+
do
+
file_name=${t##*/}
+
file_name=${file_name%.template}
+
+
sed "
+
s/{bg_color}/$bg_color/g
+
s/{fg_color}/$fg_color/g
+
s/{color0}/$color0/g
+
s/{color1}/$color1/g
+
s/{color2}/$color2/g
+
s/{color3}/$color3/g
+
s/{color4}/$color4/g
+
s/{color5}/$color5/g
+
s/{color6}/$color6/g
+
s/{color7}/$color7/g
+
s/{color8}/$color8/g
+
s/{color9}/$color9/g
+
s/{color10}/$color10/g
+
s/{color11}/$color11/g
+
s/{color12}/$color12/g
+
s/{color13}/$color13/g
+
s/{color14}/$color14/g
+
s/{color15}/$color15/g
+
s/{bg_color.rgb}/$bg_color_rgb/g
+
s/{fg_color.rgb}/$fg_color_rgb/g
+
s/{color0.rgb}/$color0_rgb/g
+
s/{color1.rgb}/$color1_rgb/g
+
s/{color2.rgb}/$color2_rgb/g
+
s/{color3.rgb}/$color3_rgb/g
+
s/{color4.rgb}/$color4_rgb/g
+
s/{color5.rgb}/$color5_rgb/g
+
s/{color6.rgb}/$color6_rgb/g
+
s/{color7.rgb}/$color7_rgb/g
+
s/{color8.rgb}/$color8_rgb/g
+
s/{color9.rgb}/$color9_rgb/g
+
s/{color10.rgb}/$color10_rgb/g
+
s/{color11.rgb}/$color11_rgb/g
+
s/{color12.rgb}/$color12_rgb/g
+
s/{color13.rgb}/$color13_rgb/g
+
s/{color14.rgb}/$color14_rgb/g
+
s/{color15.rgb}/$color15_rgb/g
+
" "$t" > "${dest_dir}/${file_name}"
+
done
+
+
# This allows for different configuration for different color schemes.
+
# Configuration for one theme may not work very well for another theme. To use
+
# this set theme_type in the theme file to any string and place theme specific
+
# configuration in `${XDG_CONFIG_HOME:-$HOME/.config}/thm/templates/$theme_type`.
+
# If not specified, only templates in the base template directory will be generated.
+
# This will overwrite previously generated template files.
+
[ "$theme_type" ] && [ -d "${conf_dir}/templates/$theme_type" ] && \
+
for t in "${conf_dir}/templates/$theme_type/"*".template"
+
do
+
file_name=${t##*/}
+
file_name=${file_name%.template}
+
+
sed "
+
s/{bg_color}/$bg_color/g
+
s/{fg_color}/$fg_color/g
+
s/{color0}/$color0/g
+
s/{color1}/$color1/g
+
s/{color2}/$color2/g
+
s/{color3}/$color3/g
+
s/{color4}/$color4/g
+
s/{color5}/$color5/g
+
s/{color6}/$color6/g
+
s/{color7}/$color7/g
+
s/{color8}/$color8/g
+
s/{color9}/$color9/g
+
s/{color10}/$color10/g
+
s/{color11}/$color11/g
+
s/{color12}/$color12/g
+
s/{color13}/$color13/g
+
s/{color14}/$color14/g
+
s/{color15}/$color15/g
+
s/{bg_color.rgb}/$bg_color_rgb/g
+
s/{fg_color.rgb}/$fg_color_rgb/g
+
s/{color0.rgb}/$color0_rgb/g
+
s/{color1.rgb}/$color1_rgb/g
+
s/{color2.rgb}/$color2_rgb/g
+
s/{color3.rgb}/$color3_rgb/g
+
s/{color4.rgb}/$color4_rgb/g
+
s/{color5.rgb}/$color5_rgb/g
+
s/{color6.rgb}/$color6_rgb/g
+
s/{color7.rgb}/$color7_rgb/g
+
s/{color8.rgb}/$color8_rgb/g
+
s/{color9.rgb}/$color9_rgb/g
+
s/{color10.rgb}/$color10_rgb/g
+
s/{color11.rgb}/$color11_rgb/g
+
s/{color12.rgb}/$color12_rgb/g
+
s/{color13.rgb}/$color13_rgb/g
+
s/{color14.rgb}/$color14_rgb/g
+
s/{color15.rgb}/$color15_rgb/g
+
" "$t" > "${dest_dir}/${file_name}"
+
done
+
+
# Run extra user scripts
+
[ -d "$conf_dir/scripts" ] || exit 0
+
for i in "$conf_dir/scripts/"*
+
do [ -x "$i" ] && $i > /dev/null 2>&1 &
+
done
-122
thm
···
-
#!/bin/sh
-
# shellcheck disable=SC1090,SC2154
-
-
# Usage statement
-
usage() {
-
printf '%s\n' "usage: ${0##*/} theme"
-
}
-
-
# Convert hex colors into rgb
-
hex2rgb() {
-
hex=$1
-
hex_r=${hex%????}
-
hex_g=${hex#??}
-
hex_g=${hex_g%??}
-
hex_b=${hex%????}
-
printf '%d,%d,%d' "0x$hex_r" "0x$hex_g" "0x$hex_b"
-
}
-
-
# Set directory variables
-
[ "$THM_CONFIG_DIR" ] \
-
&& conf_dir="$THM_CONFIG_DIR" \
-
|| conf_dir="${XDG_CONFIG_HOME:-$HOME/.config}/thm"
-
[ "$THM_DEST_DIR" ] \
-
&& conf_dir="$THM_DEST_DIR" \
-
|| dest_dir="${XDG_CACHE_HOME:-$HOME/.cache}/thm"
-
-
err() {
-
[ "$*" ] && err_msg="$*" || err_msg="error"
-
printf '%s%b' "${0##*/}: " "$err_msg\n" 1>&2
-
exit 1
-
}
-
-
# Ensure the theme file exist and source it
-
case $1 in
-
-h|h|--help|help ) usage; exit 0 ;;
-
* ) [ "$1" ] || err "missing argument"
-
[ -f "$conf_dir/themes/$1.theme" ] || err "$1: theme not found"
-
theme_file="$conf_dir/themes/$1.theme"
-
. "$theme_file" ;;
-
esac
-
-
# Create RGB colors from the hex colors
-
bg_color_rgb="$(hex2rgb "$bg_color")"
-
fg_color_rgb="$(hex2rgb "$fg_color")"
-
color0_rgb="$(hex2rgb "$color0")"
-
color1_rgb="$(hex2rgb "$color1")"
-
color2_rgb="$(hex2rgb "$color2")"
-
color3_rgb="$(hex2rgb "$color3")"
-
color4_rgb="$(hex2rgb "$color4")"
-
color5_rgb="$(hex2rgb "$color5")"
-
color6_rgb="$(hex2rgb "$color6")"
-
color7_rgb="$(hex2rgb "$color7")"
-
color8_rgb="$(hex2rgb "$color8")"
-
color9_rgb="$(hex2rgb "$color9")"
-
color10_rgb="$(hex2rgb "$color10")"
-
color11_rgb="$(hex2rgb "$color11")"
-
color12_rgb="$(hex2rgb "$color12")"
-
color13_rgb="$(hex2rgb "$color13")"
-
color14_rgb="$(hex2rgb "$color14")"
-
color15_rgb="$(hex2rgb "$color15")"
-
-
# Make sure the dest_dir exist
-
[ -d "$dest_dir" ] || { mkdir -p "$dest_dir" || err "failed to create $dest_dir"; }
-
-
# Ensure the dest_dir is empty before populating it
-
rm "$dest_dir/"*
-
-
# Make a file with the name of the new theme
-
printf '%s\n' "$theme_file" > "$dest_dir/current_thm"
-
-
# Repalce template syntax with the actual colors
-
for t in "${conf_dir}/templates/"*".template"
-
do
-
file_name=${t##*/}
-
file_name=${file_name%.template}
-
-
sed "
-
s/{bg_color}/$bg_color/g
-
s/{fg_color}/$fg_color/g
-
s/{color0}/$color0/g
-
s/{color1}/$color1/g
-
s/{color2}/$color2/g
-
s/{color3}/$color3/g
-
s/{color4}/$color4/g
-
s/{color5}/$color5/g
-
s/{color6}/$color6/g
-
s/{color7}/$color7/g
-
s/{color8}/$color8/g
-
s/{color9}/$color9/g
-
s/{color10}/$color10/g
-
s/{color11}/$color11/g
-
s/{color12}/$color12/g
-
s/{color13}/$color13/g
-
s/{color14}/$color14/g
-
s/{color15}/$color15/g
-
s/{bg_color.rgb}/$bg_color_rgb/g
-
s/{fg_color.rgb}/$fg_color_rgb/g
-
s/{color0.rgb}/$color0_rgb/g
-
s/{color1.rgb}/$color1_rgb/g
-
s/{color2.rgb}/$color2_rgb/g
-
s/{color3.rgb}/$color3_rgb/g
-
s/{color4.rgb}/$color4_rgb/g
-
s/{color5.rgb}/$color5_rgb/g
-
s/{color6.rgb}/$color6_rgb/g
-
s/{color7.rgb}/$color7_rgb/g
-
s/{color8.rgb}/$color8_rgb/g
-
s/{color9.rgb}/$color9_rgb/g
-
s/{color10.rgb}/$color10_rgb/g
-
s/{color11.rgb}/$color11_rgb/g
-
s/{color12.rgb}/$color12_rgb/g
-
s/{color13.rgb}/$color13_rgb/g
-
s/{color14.rgb}/$color14_rgb/g
-
s/{color15.rgb}/$color15_rgb/g
-
" "$t" > "${dest_dir}/${file_name}"
-
done
-
-
# Run extra user scripts
-
[ -d "$conf_dir/scripts" ] || return 0
-
for i in "$conf_dir/scripts/"*
-
do
-
[ -x "$i" ] && $i > /dev/null 2>&1 &
-
done
···