A collection of scripts

misc changes

Changed files
+75 -48
scritps
+22 -16
scritps/colorgrab
··· 22 22 } 23 23 24 24 # Parse arguments 25 - for flag in "$@" 25 + for flag 26 26 do 27 27 # Make sure flag begins with '-' and are atleast two characters long 28 28 case $flag in ··· 34 34 35 35 # Split the flags into individual arguments and set variables 36 36 flag=${flag#-} 37 + 37 38 while [ "$flag" ] 38 39 do 39 - a=${flag%${flag#?}} 40 + a=${flag%"${flag#?}"} 41 + 40 42 case $a in 41 43 c ) copy_to_clipboard=true ;; 42 44 h ) usage; exit 0 ;; ··· 47 49 * ) printf '%s\n' "${0##*/}: -$a invalid argument" 1>&2 48 50 usage 1>&2; exit 1 ;; 49 51 esac 52 + 50 53 flag=${flag#?} 51 54 done 52 55 done 53 56 54 57 # Make sure this directory exist before continuing 55 - [ -d "/tmp/${0##*/}" ] || { 56 - mkdir -p "/tmp/${0##*/}" || \ 57 - printf '%s\n' "${0##*/}: failed to create directory: /tmp/${0##*/}" 1>&2 \ 58 - exit 1 59 - } 58 + [ -d "/tmp/${0##*/}" ] || { mkdir -p "/tmp/${0##*/}" || exit 1; } 60 59 61 60 # Set color_type if not already set 62 61 [ $color_type ] || color_type="hex" ··· 66 65 67 66 case $color_type in 68 67 hex ) color=$(convert "/tmp/${0##*/}/temp.png" -format "%[hex:p]\n" info:) ;; 69 - rgb ) color=$(convert "/tmp/${0##*/}/temp.png" -format "%[pixel:p]\n" info:) 70 - color=${color#*(}; color=${color%)*} ;; 68 + rgb ) 69 + color=$(convert "/tmp/${0##*/}/temp.png" -format "%[pixel:p]\n" info:) 70 + color=${color#*(}; color=${color%)*} 71 + ;; 71 72 * ) printf '%s\n' "${0##*/}: invalid color_type: $color_type" 1>&2; exit 1 ;; 72 73 esac 73 74 echo "$color" ··· 83 84 [ -f "/tmp/${0##*/}/o$color.png" ] || { 84 85 case $color_type in 85 86 hex ) ocolor="#$color" ;; 86 - rgb ) ocolor="rgb($color)";; 87 + rgb ) ocolor="rgb($color)" ;; 87 88 esac 89 + 88 90 convert -size 150x150 xc:"$ocolor" +size -gravity center \ 89 91 \( -background white pango:"<span font_family=\"monospace\" 90 92 font_weight=\"bold\"> $color </span>" \) \ 91 93 -composite "/tmp/${0##*/}/o$color.png" 92 94 } 95 + 93 96 xdg-open "/tmp/${0##*/}/o$color.png" > "/tmp/${0##*/}/xdg-open.log" 2>&1 & 94 97 } 95 98 ··· 98 101 [ -f "/tmp/${0##*/}/n$color.png" ] || { 99 102 case $color_type in 100 103 hex ) ncolor="#$color"; color_prefix="hex:";; 101 - rgb ) ncolor="rgb($color)" 102 - color_r="${color%%,*}" 103 - color_g="${color#*,}"; color_g="${color_g%,*}" 104 - color_b="${color##*,}" 105 - color_rgb="$color_r$color_g$color_b" 106 - color_prefix="rgb:";; 104 + rgb ) 105 + ncolor="rgb($color)" 106 + color_r="${color%%,*}" 107 + color_g="${color#*,}"; color_g="${color_g%,*}" 108 + color_b="${color##*,}" 109 + color_rgb="$color_r$color_g$color_b" 110 + color_prefix="rgb:";; 107 111 esac 112 + 108 113 convert -size 64x64 xc:"$ncolor" "/tmp/${0##*/}/n$color_rgb.png" 109 114 } 115 + 110 116 notify-send -a "${0##*/}" -i "/tmp/${0##*/}/n$color_rgb.png" "$color_prefix $color" 111 117 }
+6 -4
scritps/ds4-leds
··· 13 13 hex_r=${hex%????} 14 14 hex_g=${hex#??}; hex_g=${hex_g%??} 15 15 hex_b=${hex#????} 16 + 16 17 printf '%d,%d,%d' "0x$hex_r" "0x$hex_g" "0x$hex_b" 17 18 } 18 19 ··· 25 26 "$led_path/"*"$vendorid:0BA0"*":global" ) productid="0BA0" ;; 26 27 esac 27 28 28 - IFS=, read -r rgb_r rgb_g rgb_b <<-EOF 29 + IFS=, read -r r g b <<-EOF 29 30 $1 30 31 EOF 31 - printf '%s' "$rgb_r" | tee "$led_path/"*"$vendorid:$productid"*":red/brightness" > /dev/null 32 - printf '%s' "$rgb_g" | tee "$led_path/"*"$vendorid:$productid"*":green/brightness" > /dev/null 33 - printf '%s' "$rgb_b" | tee "$led_path/"*"$vendorid:$productid"*":blue/brightness" > /dev/null 32 + 33 + printf '%s' "$r" | tee "$led_path/"*"$vendorid:$productid"*":red/brightness" > /dev/null 34 + printf '%s' "$g" | tee "$led_path/"*"$vendorid:$productid"*":green/brightness" > /dev/null 35 + printf '%s' "$b" | tee "$led_path/"*"$vendorid:$productid"*":blue/brightness" > /dev/null 34 36 } 35 37 36 38 case $1 in
+40 -25
scritps/prefon
··· 33 33 w ) prefix=WARNING ;; 34 34 e ) prefix=ERROR ;; 35 35 * ) printf '%s\n' "sus!" 1>&2; exit 1 ;; 36 - esac 37 - shift 36 + esac; shift 38 37 39 38 printf "${0##*/}: $prefix: %b\n" "$*" 1>&2 40 39 } ··· 58 57 -* ) flag=${1#-}; shift ;; 59 58 * ) shift; continue ;; 60 59 esac 60 + 61 61 while [ "$flag" ] 62 62 do 63 63 arg=${flag%${flag#?}} 64 + 64 65 case $arg in 65 66 F ) PREFON_ACTION="file"; PREFON_FILE=$1; shift ;; 66 67 S ) PREFON_ACTION=stdin; PREFON_FILE=/dev/stdin ;; ··· 72 73 o ) PREFON_OUTPUT=$1; shift ;; 73 74 s ) PREFON_SIZE=$1; shift ;; 74 75 t ) PREFON_ACTION=text; PREFON_TEXT=$1; shift ;; 75 - * ) printf '%s\n' "${0##*/}: -$arg: invalid argument" 1>&2; usage 1>&2; exit 1 ;; 76 + * ) printf '%s\n' "${0##*/}: -$arg: invalid argument" 1>&2 77 + usage 1>&2; exit 1 ;; 76 78 esac 79 + 77 80 flag=${flag#?} 78 81 done 79 82 done 80 83 81 - generate_image() { 82 - _gen_img() { 83 - convert -background "#$2" -bordercolor "#$2" -border "$PREFON_BORDER_SIZE" \ 84 - pango:"<span foreground=\"#$1\" font_desc=\"$PREFON_FONT $PREFON_SIZE\">$4</span>" "$3" 85 - } 84 + _gen_img() { 85 + convert -background "#$2" -bordercolor "#$2" -border "$PREFON_BORDER_SIZE" \ 86 + pango:"<span foreground=\"#$1\" font_desc=\"$PREFON_FONT $PREFON_SIZE\">$4</span>" "$3" 87 + } 88 + 89 + _output_file() { 90 + while IFS= read -r line 91 + do printf '%s\n' "$line" 92 + done < "$PREFON_FILE" 93 + } 86 94 95 + generate_image() { 87 96 fgcolor=${PREFON_COLORS%,*} 88 97 bgcolor=${PREFON_COLORS#*,} 89 98 90 - _gen_img "$fgcolor" "$bgcolor" "$PREFON_OUTPUT" "$1" || { info e failed to generate image; exit 1; } 99 + _gen_img "$fgcolor" "$bgcolor" "$PREFON_OUTPUT" "$1" || { 100 + info e failed to generate image 101 + exit 1 102 + } 91 103 92 104 [ "$PREFON_INVERSE" != "none" ] && { 93 105 inverse="${PREFON_OUTPUT%.*}" 94 106 inverse="${inverse}-inverse.${PREFON_OUTPUT##*.}" 95 107 96 - _gen_img "$bgcolor" "$fgcolor" "$inverse" "$1" || { info e failed to generate image; exit 1; } 108 + _gen_img "$bgcolor" "$fgcolor" "$inverse" "$1" || { 109 + info e failed to generate image 110 + exit 1 111 + } 97 112 98 113 case $PREFON_INVERSE in 99 114 horizontal ) convert "$PREFON_OUTPUT" "$inverse" +append "$PREFON_OUTPUT" \ 100 115 || { info e failed to generate image; exit 1; } ;; 101 116 vertical ) convert "$PREFON_OUTPUT" "$inverse" -append "$PREFON_OUTPUT" \ 102 117 || { info e failed to generate image; exit 1; } ;; 103 - * ) info e "${PREFON_INVERSE}: is not a valid value for PREFON_INVERSE"; exit 1 ;; 118 + * ) info e "${PREFON_INVERSE}: is not a valid value for PREFON_INVERSE" 119 + exit 1 ;; 104 120 esac 105 121 106 122 rm "$inverse" || info w failed to remove temporary file: "${inverse}" ··· 110 126 } 111 127 112 128 read_input() { 113 - _output_file() { 114 - while IFS= read -r line 115 - do 116 - printf '%s\n' "$line" 117 - done < "$PREFON_FILE" 118 - } 119 - 120 129 input="$(_output_file)" 121 130 generate_image "$input" 122 131 } 123 132 124 133 case $PREFON_ACTION in 125 - file ) [ -e "$PREFON_FILE" ] || { info e "'$PREFON_FILE' does not exist"; exit 1; } 126 - read_input ;; 127 - stdin ) [ -e /dev/stdin ] || { info e "/dev/stdin does not exist"; exit 1; } 128 - read_input ;; 129 - text ) [ "$PREFON_TEXT" ] || { info e "string not provided"; exit 1; } 130 - generate_image "$PREFON_TEXT" ;; 131 - * ) info e invalid action: $PREFON_ACTION; exit 1 ;; 134 + file ) 135 + [ -e "$PREFON_FILE" ] || { info e "'$PREFON_FILE' does not exist"; exit 1; } 136 + read_input 137 + ;; 138 + stdin ) 139 + [ -e /dev/stdin ] || { info e "/dev/stdin does not exist"; exit 1; } 140 + read_input 141 + ;; 142 + text ) 143 + [ "$PREFON_TEXT" ] || { info e "string not provided"; exit 1; } 144 + generate_image "$PREFON_TEXT" 145 + ;; 146 + * ) info e invalid action: $PREFON_ACTION; exit 1 ;; 132 147 esac
+3
scritps/scr
··· 69 69 70 70 # Split arguments to be 1 character long and determine options to use 71 71 args=${flag#-} 72 + 72 73 while [ "$args" ] 73 74 do 74 75 a=${args%${args#?}} 76 + 75 77 case $a in 76 78 a ) desktop_audio=true ;; 77 79 c ) copy_clipboard=true ;; ··· 84 86 * ) printf '%s\n' "${0##*/}: -$a: invalid argument" 1>&2 85 87 usage 1>&2; exit 1 ;; 86 88 esac 89 + 87 90 args=${args#?} 88 91 done 89 92 done
+4 -3
scritps/thm
··· 12 12 hex_r=${hex%????} 13 13 hex_g=${hex#??}; hex_g=${hex_g%??} 14 14 hex_b=${hex#????} 15 + 15 16 printf '%d,%d,%d' "0x$hex_r" "0x$hex_g" "0x$hex_b" 16 17 } 17 18 ··· 19 20 [ "$THM_CONFIG_DIR" ] \ 20 21 && conf_dir="$THM_CONFIG_DIR" \ 21 22 || conf_dir="${XDG_CONFIG_HOME:-$HOME/.config}/thm" 23 + 22 24 [ "$THM_DEST_DIR" ] \ 23 25 && dest_dir="$THM_DEST_DIR" \ 24 26 || dest_dir="${XDG_CACHE_HOME:-$HOME/.cache}/thm" ··· 59 61 color15_rgb="$(hex2rgb "$color15")" 60 62 61 63 # Make sure the dest_dir and dest_dir/thm_old exist 62 - [ -d "$dest_dir/thm_old" ] || { mkdir -p "$dest_dir/thm_old" || err "failed to create $dest_dir/thm_old"; } 64 + [ -d "$dest_dir/thm_old" ] || mkdir -p "$dest_dir/thm_old" 63 65 64 66 # Try and empty the dest_dir before populating it 65 67 mv "$dest_dir/"* "$dest_dir/thm_old" 2> /dev/null ··· 168 170 # Run extra user scripts 169 171 [ -d "$conf_dir/scripts" ] || exit 0 170 172 for i in "$conf_dir/scripts/"* 171 - do 172 - [ -x "$i" ] && $i > /dev/null 2>&1 & 173 + do [ -x "$i" ] && $i > /dev/null 2>&1 & 173 174 done