A collection of scripts

Initial Commit

yemou e1ba1ef8

+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
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"
+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