From ac969f7715dfa5b2416a0b1b83d10f60e5fedc3d Mon Sep 17 00:00:00 2001 From: yemou Hannam Date: Sat, 5 Feb 2022 21:12:17 -0500 Subject: [PATCH] misc changes --- scritps/colorgrab | 38 +++++++++++++++------------ scritps/ds4-leds | 10 +++++--- scritps/prefon | 65 +++++++++++++++++++++++++++++------------------ scritps/scr | 3 +++ scritps/thm | 7 ++--- 5 files changed, 75 insertions(+), 48 deletions(-) diff --git a/scritps/colorgrab b/scritps/colorgrab index f0395df..4b25017 100755 --- a/scritps/colorgrab +++ b/scritps/colorgrab @@ -22,7 +22,7 @@ usage() { } # Parse arguments -for flag in "$@" +for flag do # Make sure flag begins with '-' and are atleast two characters long case $flag in @@ -34,9 +34,11 @@ do # Split the flags into individual arguments and set variables flag=${flag#-} + while [ "$flag" ] do - a=${flag%${flag#?}} + a=${flag%"${flag#?}"} + case $a in c ) copy_to_clipboard=true ;; h ) usage; exit 0 ;; @@ -47,16 +49,13 @@ do * ) 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##*/}" || \ - printf '%s\n' "${0##*/}: failed to create directory: /tmp/${0##*/}" 1>&2 \ - exit 1 -} +[ -d "/tmp/${0##*/}" ] || { mkdir -p "/tmp/${0##*/}" || exit 1; } # Set color_type if not already set [ $color_type ] || color_type="hex" @@ -66,8 +65,10 @@ grim -s 1 -g "$(slurp -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%)*} ;; + 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 echo "$color" @@ -83,13 +84,15 @@ echo "$color" [ -f "/tmp/${0##*/}/o$color.png" ] || { case $color_type in hex ) ocolor="#$color" ;; - rgb ) ocolor="rgb($color)";; + rgb ) ocolor="rgb($color)" ;; esac + convert -size 150x150 xc:"$ocolor" +size -gravity center \ \( -background white pango:" $color " \) \ -composite "/tmp/${0##*/}/o$color.png" } + xdg-open "/tmp/${0##*/}/o$color.png" > "/tmp/${0##*/}/xdg-open.log" 2>&1 & } @@ -98,14 +101,17 @@ echo "$color" [ -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:";; + 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" } diff --git a/scritps/ds4-leds b/scritps/ds4-leds index e88f48b..7033af1 100755 --- a/scritps/ds4-leds +++ b/scritps/ds4-leds @@ -13,6 +13,7 @@ hex2rgb() { 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" } @@ -25,12 +26,13 @@ ds4leds() { "$led_path/"*"$vendorid:0BA0"*":global" ) productid="0BA0" ;; esac - IFS=, read -r rgb_r rgb_g rgb_b <<-EOF + IFS=, read -r r g b <<-EOF $1 EOF - printf '%s' "$rgb_r" | tee "$led_path/"*"$vendorid:$productid"*":red/brightness" > /dev/null - printf '%s' "$rgb_g" | tee "$led_path/"*"$vendorid:$productid"*":green/brightness" > /dev/null - printf '%s' "$rgb_b" | tee "$led_path/"*"$vendorid:$productid"*":blue/brightness" > /dev/null + + printf '%s' "$r" | tee "$led_path/"*"$vendorid:$productid"*":red/brightness" > /dev/null + printf '%s' "$g" | tee "$led_path/"*"$vendorid:$productid"*":green/brightness" > /dev/null + printf '%s' "$b" | tee "$led_path/"*"$vendorid:$productid"*":blue/brightness" > /dev/null } case $1 in diff --git a/scritps/prefon b/scritps/prefon index ec06956..2f7d643 100755 --- a/scritps/prefon +++ b/scritps/prefon @@ -33,8 +33,7 @@ info() { w ) prefix=WARNING ;; e ) prefix=ERROR ;; * ) printf '%s\n' "sus!" 1>&2; exit 1 ;; - esac - shift + esac; shift printf "${0##*/}: $prefix: %b\n" "$*" 1>&2 } @@ -58,9 +57,11 @@ do -* ) 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 ;; @@ -72,35 +73,50 @@ do 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 ;; + * ) printf '%s\n' "${0##*/}: -$arg: invalid argument" 1>&2 + usage 1>&2; exit 1 ;; esac + flag=${flag#?} done done -generate_image() { - _gen_img() { - convert -background "#$2" -bordercolor "#$2" -border "$PREFON_BORDER_SIZE" \ - pango:"$4" "$3" - } +_gen_img() { + convert -background "#$2" -bordercolor "#$2" -border "$PREFON_BORDER_SIZE" \ + pango:"$4" "$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; } + _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; } + _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 ;; + * ) 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}" @@ -110,23 +126,22 @@ generate_image() { } read_input() { - _output_file() { - while IFS= read -r line - do - printf '%s\n' "$line" - done < "$PREFON_FILE" - } - 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 ;; + 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 diff --git a/scritps/scr b/scritps/scr index 1135ada..34ebe3f 100755 --- a/scritps/scr +++ b/scritps/scr @@ -69,9 +69,11 @@ do # 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 ;; @@ -84,6 +86,7 @@ do * ) printf '%s\n' "${0##*/}: -$a: invalid argument" 1>&2 usage 1>&2; exit 1 ;; esac + args=${args#?} done done diff --git a/scritps/thm b/scritps/thm index e5aab11..7961f93 100755 --- a/scritps/thm +++ b/scritps/thm @@ -12,6 +12,7 @@ hex2rgb() { 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" } @@ -19,6 +20,7 @@ hex2rgb() { [ "$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_CACHE_HOME:-$HOME/.cache}/thm" @@ -59,7 +61,7 @@ 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" || err "failed to create $dest_dir/thm_old"; } +[ -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 @@ -168,6 +170,5 @@ 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 & +do [ -x "$i" ] && $i > /dev/null 2>&1 & done -- 2.51.2