[bin] Update scripts to use lib functions

This commit is contained in:
lara 2020-12-23 16:43:24 +01:00
parent c643728d2d
commit 2f6039abad
4 changed files with 22 additions and 34 deletions

View file

@ -1,22 +1,14 @@
#!/bin/sh
# Load helper functions
source "$(dirname "$(rreadlink "$0")")/../lib/utils.sh"
# TODO: detect term or set it globally
TERM_EMU="kitty"
die() {
notify-send "$@"
exit 1
}
check_exists() {
for c in $@; do
which "$c" > /dev/null 2>&1 || return 1
done
}
if ! which wl-paste > /dev/null 2>&1 && [ ! -z "$WAYLAND_DISPLAY" ]; then
if ! check_exists wl-paste && [ ! -z "$WAYLAND_DISPLAY" ]; then
die "Wayland detected and wl-paste not found"
elif ! which xsel > /dev/null 2>&1 && [ -z "$WAYLAND_DISPLAY" ]; then
elif ! check_exists xsel && [ -z "$WAYLAND_DISPLAY" ]; then
die "xsel not found"
fi
@ -61,7 +53,7 @@ case "$choice" in
path="$HOME/mus/$(printf "%s" "$choice" | cut -d " " -f 2-)"
[ -d "$path" ] || mkdir -p "$path"
cd "$path" || exit
youtube-dl -x --audio-format mp3 --no-playlist -o "%(title)s.%(ext)s" "$urls" 2>&1 | grep 'ERROR:' | tee /dev/fd/2 | xargs -n1 -d "\n" notify-send
youtube-dl -x --audio-format mp3 --no-playlist -o "%(title)s.%(ext)s" "$urls" 2>&1 | grep 'ERROR:' | notify_err
;;
"crawl")
path="$HOME/books/"
@ -70,7 +62,7 @@ case "$choice" in
out="$(lncrawl --single --all --format epub --filename-only --suppress -s "$urls" | grep -vFe "Input is suppressed" -e "Namespace(")"
errors="$(printf "%s" "$out" | grep -Fe " ❗ ")"
if [ -n "$errors" ]; then
printf "%s" "$errors" | xargs -n1 -d "\n" notify-send
printf "%s" "$errors" | notify_err
else
printf "%s" "$out" | sed -ne '/^NOVEL: /s/NOVEL: \(.*\)/Successfully crawled "\1"/p' | xargs -0 -n1 notify-send
fi

View file

@ -3,8 +3,9 @@
# We use a script instead of an alias because we want this utility in our path,
# usable from dmenu
if ! which dragon-drag-and-drop > /dev/null 2>&1; then
echo "Error: dragon-drag-and-drop isn't installed!" | tee /dev/fd/2 | xargs -n1 -d "\n" notify-send
fi
# Load helper functions
source "$(dirname "$(rreadlink "$0")")/../lib/utils.sh"
dragon-drag-and-drop $*
assert_exists dragon-drag-and-drop
dragon-drag-and-drop "$@"

View file

@ -1,7 +1,10 @@
#!/bin/sh
if [ "$1" = "-h" ] || [ "$#" -ne "1" ]; then
>&2 echo "Usage: $0 <input.mp4> <output.gif>"
# Load helper functions
source "$(dirname "$(rreadlink "$0")")/../lib/utils.sh"
if [ "$1" = "-h" ] || [ "$#" -lt "1" ]; then
>&2 echo "Usage: $0 [-l] <video url>"
exit 1
fi

View file

@ -1,15 +1,8 @@
#!/bin/sh
die() {
# When run from WM, $TERM appear to be set to "linux"
# TODO: find a less brittle solution
[ "$TERM" = "linux" ] && notify-send "$@" || echo "$@"
exit 1
}
check_exists() {
which "$1" > /dev/null 2>&1 || die "$1 doesn't appear to be installed"
}
# Load helper functions
bin_path="$(dirname "$(rreadlink "$0")")"
source "$bin_path/../lib/utils.sh"
if [ -z "$1" ]; then
NAME="shot_$(date '+%Y%m%d%H%M%S').png"
@ -21,13 +14,12 @@ SCREEN_DIR="$HOME/img/screenshots"
mkdir -p "$SCREEN_DIR"
# Let's try to detect Wayland running
if [ -z "$WAYLAND_DISPLAY" ]; then
check_exists "maim"
assert_exists "maim"
maim --hidecursor --select "$SCREEN_DIR/$NAME"
# Fail silently if xsel isn't installed, the clipboard feature isn't critical
echo "$SCREEN_DIR/$NAME" | xsel --clipboard --input > /dev/null 2>&1
else
check_exists "grim"
check_exists "slop"
assert_exists "grim" "slop"
slop | awk -F '[x+]' '{printf "%s,%s %sx%s",$3,$4,$1,$2}' | grim -g - "$SCREEN_DIR/$NAME"
# Same as xsel
wl-copy -n "$SCREEN_DIR/$NAME" > /dev/null 2>&1