···11# description
22-thm is a shell script that applies colors to a template file.
33-44-# usage
55-thm theme_name
66-77-the theme_name does not include the `.theme` at the end of the file.
88-99-# directories
1010-By default, the config files will be searched for in `$XDG_CONFIG_HOME/thm` or `$HOME/.config/thm`.
1111-The generated files will be placed in either `$XDG_CACHE_HOME/thm` or `$HOME/.cache/thm`. This can
1212-be changed by setting the environment variables `THM_CONFIG_DIR` and `THM_DEST_DIR`. The dest dir
1313-is cleared while running.
1414-1515-# inside config directory
1616-The themes directory holds shell scripts defining the colors. These files should end with `.theme`
1717-if they should be usable with thm. The templates directory holds files for generating the themes.
1818-These files should end with `.template` The scripts directory holds files to be executed after thm
1919-is finished generating all the files. These files should be executable in order for thm to launch
2020-them. Examples of these files can be found in the examples directory of this repository.
22+Random scripts that could be useful outside of my dotfiles
···11+#!/bin/sh
22+# Grab the color of a specific point
33+44+# Required Commands:
55+# convert(imagemagick) - Get the color from the screenshotted point
66+# grim - Take a screenshot of the selected point
77+# slurp - Select a point
88+# mkdir - Create missing directories
99+# notify-send (optional) - Send a screenshot with the color
1010+# wl-copy(wl-clipboard) (optional) - Copy the color into the clipboard
1111+# xdg-open (optional) - Open the screenshot in an image viewer
1212+1313+usage() {
1414+ printf '%s\n' "usage: ${0##*/} [options]" \
1515+ "options:" \
1616+ " -c - copy the color code to the clipboard" \
1717+ " -h - display usage statement" \
1818+ " -n - send a notification with the color code" \
1919+ " -o - open an image with the color and the color code" \
2020+ " -r - display the color code as an rgb value" \
2121+ " -x - display the color code as a hexcode value (default)"
2222+}
2323+2424+# Parse arguments
2525+for flag in "$@"
2626+do
2727+ # Make sure flag begins with '-' and are atleast two characters long
2828+ case $flag in
2929+ - ) continue ;;
3030+ -- ) break ;;
3131+ -* ) ;;
3232+ * ) continue ;;
3333+ esac
3434+3535+ # Split the flags into individual arguments and set variables
3636+ flag=${flag#-}
3737+ while [ "$flag" ]
3838+ do
3939+ a=${flag%${flag#?}}
4040+ case $a in
4141+ c ) copy_to_clipboard=true ;;
4242+ h ) usage; exit 0 ;;
4343+ n ) send_notification=true ;;
4444+ o ) open_color_image=true ;;
4545+ r ) color_type="rgb" ;;
4646+ x ) color_type="hex" ;;
4747+ * ) printf '%s\n' "${0##*/}: -$a invalid argument" 1>&2
4848+ usage 1>&2; exit 1 ;;
4949+ esac
5050+ flag=${flag#?}
5151+ done
5252+done
5353+5454+# Make sure this directory exist before continuing
5555+[ -d "/tmp/${0##*/}" ] || {
5656+ mkdir -p "/tmp/${0##*/}" || \
5757+ printf '%s\n' "${0##*/}: failed to create directory: /tmp/${0##*/}" 1>&2 \
5858+ exit 1
5959+}
6060+6161+# Set color_type if not already set
6262+[ $color_type ] || color_type="hex"
6363+6464+# Get a screenshot of the pixel
6565+grim -s 1 -g "$(slurp -p)" "/tmp/${0##*/}/temp.png"
6666+6767+case $color_type in
6868+ hex ) color=$(convert "/tmp/${0##*/}/temp.png" -format "%[hex:p]\n" info:) ;;
6969+ rgb ) color=$(convert "/tmp/${0##*/}/temp.png" -format "%[pixel:p]\n" info:)
7070+ color=${color#*(}; color=${color%)*} ;;
7171+ * ) printf '%s\n' "${0##*/}: invalid color_type: $color_type" 1>&2; exit 1 ;;
7272+esac
7373+echo "$color"
7474+7575+# Copy color to clipboard
7676+[ $copy_to_clipboard ] && {
7777+ wl-copy -n "$color" || printf '%s\n' "${0##*/}: failed to copy color to clipboard" 1>&2
7878+}
7979+8080+# Open color image in the user's perfered image viewer
8181+[ $open_color_image ] && {
8282+ # Create the color image if it doesn't already exist
8383+ [ -f "/tmp/${0##*/}/o$color.png" ] || {
8484+ case $color_type in
8585+ hex ) ocolor="#$color" ;;
8686+ rgb ) ocolor="rgb($color)";;
8787+ esac
8888+ convert -size 150x150 xc:"$ocolor" +size -gravity center \
8989+ \( -background white pango:"<span font_family=\"monospace\"
9090+ font_weight=\"bold\"> $color </span>" \) \
9191+ -composite "/tmp/${0##*/}/o$color.png"
9292+ }
9393+ xdg-open "/tmp/${0##*/}/o$color.png" > "/tmp/${0##*/}/xdg-open.log" 2>&1 &
9494+}
9595+9696+# Send a notification with an image of the color aswell as the value
9797+[ $send_notification ] && {
9898+ [ -f "/tmp/${0##*/}/n$color.png" ] || {
9999+ case $color_type in
100100+ hex ) ncolor="#$color"; color_prefix="hex:";;
101101+ rgb ) ncolor="rgb($color)"
102102+ color_r="${color%%,*}"
103103+ color_g="${color#*,}"; color_g="${color_g%,*}"
104104+ color_b="${color##*,}"
105105+ color_rgb="$color_r$color_g$color_b"
106106+ color_prefix="rgb:";;
107107+ esac
108108+ convert -size 64x64 xc:"$ncolor" "/tmp/${0##*/}/n$color_rgb.png"
109109+ }
110110+ notify-send -a "${0##*/}" -i "/tmp/${0##*/}/n$color_rgb.png" "$color_prefix $color"
111111+}
+201
scritps/scr
···11+#!/bin/sh
22+# shellcheck disable=SC1090,SC2154
33+44+# SC1090 & SC2154
55+# The files sourced are user generated files that should contain the needed
66+# variables for the script to function correctly. It should be safe to ignore
77+# these warnings.
88+99+# Required Commands
1010+# ffmpeg - needed for aud
1111+# grim - needed for pic
1212+# mkdir - create missing directories
1313+# pactl - create loopback devices for multi-device audio recording in wf-recorder
1414+# slurp - make a selection
1515+# wf-recorder - needed for rec
1616+# wl-copy - copy images to clipboard
1717+1818+# This script is intended for use on wayland; however, `scr aud` should work fine without
1919+# wayland.
2020+2121+# Set required variables if needed
2222+[ "$SCR_CFG_DIR" ] || SCR_CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/scr"
2323+[ "$SCR_CACHE_DIR" ] || SCR_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/scr"
2424+2525+# Source the configuration file
2626+# A sample configuration can be found in my dotfiles at:
2727+# https://github.com/yemouu/setup/blob/master/root/home/cfg/scr/config.sh
2828+. "$SCR_CFG_DIR/config.sh" || \
2929+ { printf '%s\n' "${0##*/}: failed to source $SCR_CONFIG_DIR/config.sh" 1>&2; exit 1; }
3030+3131+# Usage statement for the script
3232+usage() {
3333+ printf '%s\n' "usage: ${0##*/} action [options]" \
3434+ "actions:" \
3535+ " aud - audio" \
3636+ " pic - picture" \
3737+ " rec - record" \
3838+ "options:" \
3939+ " -a - record desktop audio" \
4040+ " -c - copy image to clipboard" \
4141+ " -h - display this message" \
4242+ " -m - record microphone audio"
4343+}
4444+4545+# Determine the action to run
4646+case $1 in
4747+ aud ) action="scr_aud" ;;
4848+ pic ) action="scr_pic" ;;
4949+ rec ) action="scr_rec" ;;
5050+ *h|*help ) usage; exit 0 ;;
5151+ * ) printf '%s\n' "${0##*/}: $1: invalid action" 1>&2; usage 1>&2; exit 1 ;;
5252+esac
5353+shift
5454+5555+# Determine options to run with based on arguments
5656+for flag in "$@"
5757+do
5858+ # Make sure arguments start with '-' and are atleast 2 characters long
5959+ case $flag in
6060+ - ) continue ;;
6161+ -- ) break ;;
6262+ -* ) ;;
6363+ * ) continue;;
6464+ esac
6565+6666+ # Split arguments to be 1 character long and determine options to use
6767+ flag=${flag#-}
6868+ while [ "$flag" ]
6969+ do
7070+ a=${flag%${flag#?}}
7171+ case $a in
7272+ a ) desktop_audio=true ;;
7373+ c ) copy_clipboard=true ;;
7474+ h ) usage; exit 0 ;;
7575+ m ) microphone=true ;;
7676+ * ) printf '%s\n' "${0##*/}: -$a: invalid argument" 1>&2
7777+ usage 1>&2; exit 1 ;;
7878+ esac
7979+ flag=${flag#?}
8080+ done
8181+done
8282+unset args arg
8383+8484+# Simple function to print out an error message and exit
8585+die() {
8686+ printf '%s\n' "${0##*/}: $*" 1>&2
8787+ exit 1
8888+}
8989+9090+# Record Audio
9191+scr_aud() {
9292+ # Create the directory to store audio recordings if it does not already exist
9393+ [ -d "$scr_aud_dir" ] || \
9494+ { mkdir -p "$scr_aud_dir" || die "failed to make directory: $scr_aud_dir"; }
9595+9696+ # Create the directory to store logs if it does not already exist
9797+ [ -d "$SCR_CACHE_DIR" ] || \
9898+ { mkdir -p "$SCR_CACHE_DIR" || \
9999+ die "failed to make directory: $SCR_CACHE_DIR"; }
100100+101101+ filename="$scr_aud_dir/$aud_filename"
102102+103103+ # Require atleast one of the arguments: -a or -m
104104+ [ "$microphone" ] || [ "$desktop_audio" ] || \
105105+ { die "aud: argument -a or -m is required to record audio"; }
106106+107107+ # Set ffmpeg options based on script options
108108+ [ "$microphone" ] && { args="-f pulse -i $aud_source"; }
109109+ [ "$desktop_audio" ] && { args="$args -f pulse -i $aud_sink"; }
110110+ [ "$microphone" ] && [ "$desktop_audio" ] && \
111111+ { args="$args -filter_complex amix=inputs=2"; }
112112+113113+ # Pressing Ctrl+C will exit the script instead of just wf-recorder.
114114+ # Intercept Ctrl+C and exit wf-recorder instead of the script
115115+ trap 'kill -2 $aud_pid' INT
116116+117117+ # shellcheck disable=SC2086
118118+ # Word splitting is favorable here
119119+ ffmpeg $args "$filename" > "$SCR_CACHE_DIR/aud.log" 2>&1 &
120120+ aud_pid=$!
121121+ printf '%s' "Press Ctrl+C to stop recording. " 1>&2
122122+ wait $aud_pid
123123+124124+ # Reset the trap
125125+ trap - INT
126126+127127+ printf '\n%s\n' "$filename"
128128+}
129129+130130+# Take a screenshot
131131+scr_pic() {
132132+ # Create directories if they do not already exist
133133+ [ -d "$scr_pic_dir" ] || \
134134+ { mkdir -p "$scr_pic_dir" || die "failed to make directory: $scr_pic_dir"; }
135135+136136+ [ -d "$SCR_CACHE_DIR" ] || \
137137+ { mkdir -p "$SCR_CACHE_DIR" || \
138138+ die "failed to create directory: $SCR_CACHE_DIR"; }
139139+140140+ filename="$scr_pic_dir/$pic_filename"
141141+142142+ # Get the geometry of the screenshot from the user and take the screenshot
143143+ grim -g "$(slurp)" "$filename" > "$SCR_CACHE_DIR/pic.log" 2>&1
144144+145145+ # Copy the image to the system clipboard
146146+ $copy_clipboard && { wl-copy <"$filename" > "$SCR_CACHE_DIR/copy.log" 2>&1; }
147147+148148+ printf '%s\n' "$filename"
149149+}
150150+151151+scr_rec() {
152152+ # Create directories if they do not already exist
153153+ [ -d "$scr_rec_dir" ] || \
154154+ { mkdir -p "$scr_rec_dir" || die "failed to make directory: $scr_pic_dir"; }
155155+156156+ [ -d "$SCR_CACHE_DIR" ] || \
157157+ { mkdir -p "$SCR_CACHE_DIR" || \
158158+ die "failed to make directory: $SCR_CACHE_DIR"; }
159159+160160+ filename="$scr_rec_dir/$rec_filename"
161161+162162+ # Set wf-recorder arguments based on script options
163163+ [ "$microphone" ] && args="-a$aud_source"
164164+ [ "$desktop_audio" ] && args="-a$aud_sink"
165165+166166+ # If both microphone and desktop_audio is set, create a loopback devices pointing to
167167+ # scr_inputs. wf-record does not support multiple audio devices. This is how they
168168+ # recomend you record two devices at the same time.
169169+ [ "$microphone" ] && [ "$desktop_audio" ] && {
170170+ unload_pulse_modules=true
171171+ null_sink=$(pactl load-module module-null-sink sink_name=aud_both)
172172+ lb_desk=$(pactl load-module module-loopback sink=aud_both source="$aud_sink")
173173+ lb_mic=$(pactl load-module module-loopback sink=aud_both source="$aud_source")
174174+ args="-aaud_both.monitor"
175175+ }
176176+177177+ # Pressing Ctrl+C will exit the script instead of just wf-recorder.
178178+ # Intercept Ctrl+C and exit wf-recorder instead of the script
179179+ trap 'kill -2 $rec_pid' INT
180180+181181+ # Word splitting is favorable here
182182+ # shellcheck disable=SC2086
183183+ wf-recorder $args -g "$(slurp)" -f "$filename" > "$SCR_CACHE_DIR/rec.log" 2>&1 &
184184+ rec_pid=$!
185185+ printf '%s' "Press Ctrl+C to stop recording. " 1>&2
186186+ wait $rec_pid
187187+188188+ # Reset the trap
189189+ trap - INT
190190+191191+ # Clean up pulseaudio modules that the script created
192192+ [ "$unload_pulse_modules" ] && {
193193+ pactl unload-module "$lb_mic"
194194+ pactl unload-module "$lb_desk"
195195+ pactl unload-module "$null_sink"
196196+ }
197197+198198+ printf '\n%s\n' "$filename"
199199+}
200200+201201+$action