A collection of scripts

misc changes

Changed files
+75 -48
scritps
+22 -16
scritps/colorgrab
···
}
# Parse arguments
-
for flag in "$@"
do
# Make sure flag begins with '-' and are atleast two characters long
case $flag in
···
# 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 ;;
···
* ) 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
-
}
# Set color_type if not already set
[ $color_type ] || color_type="hex"
···
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
echo "$color"
···
[ -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 &
}
···
[ -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"
}
···
}
# Parse arguments
+
for flag
do
# Make sure flag begins with '-' and are atleast two characters long
case $flag in
···
# 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 ;;
···
* ) 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"
···
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
echo "$color"
···
[ -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 &
}
···
[ -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"
}
+6 -4
scritps/ds4-leds
···
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"
}
···
"$led_path/"*"$vendorid:0BA0"*":global" ) productid="0BA0" ;;
esac
-
IFS=, read -r rgb_r rgb_g rgb_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
}
case $1 in
···
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"
}
···
"$led_path/"*"$vendorid:0BA0"*":global" ) productid="0BA0" ;;
esac
+
IFS=, read -r r g b <<-EOF
$1
EOF
+
+
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
+40 -25
scritps/prefon
···
w ) prefix=WARNING ;;
e ) prefix=ERROR ;;
* ) printf '%s\n' "sus!" 1>&2; exit 1 ;;
-
esac
-
shift
printf "${0##*/}: $prefix: %b\n" "$*" 1>&2
}
···
-* ) 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 ;;
···
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
-
generate_image() {
-
_gen_img() {
-
convert -background "#$2" -bordercolor "#$2" -border "$PREFON_BORDER_SIZE" \
-
pango:"<span foreground=\"#$1\" font_desc=\"$PREFON_FONT $PREFON_SIZE\">$4</span>" "$3"
-
}
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}"
···
}
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 ;;
esac
···
w ) prefix=WARNING ;;
e ) prefix=ERROR ;;
* ) printf '%s\n' "sus!" 1>&2; exit 1 ;;
+
esac; shift
printf "${0##*/}: $prefix: %b\n" "$*" 1>&2
}
···
-* ) 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 ;;
···
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}"
···
}
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
+3
scritps/scr
···
# 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 ;;
···
* ) printf '%s\n' "${0##*/}: -$a: invalid argument" 1>&2
usage 1>&2; exit 1 ;;
esac
args=${args#?}
done
done
···
# 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 ;;
···
* ) printf '%s\n' "${0##*/}: -$a: invalid argument" 1>&2
usage 1>&2; exit 1 ;;
esac
+
args=${args#?}
done
done
+4 -3
scritps/thm
···
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"
}
···
[ "$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"
···
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"; }
# Try and empty the dest_dir before populating it
mv "$dest_dir/"* "$dest_dir/thm_old" 2> /dev/null
···
# 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
···
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"
}
···
[ "$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"
···
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
···
# 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