[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 #!/bin/sh
# Load helper functions
source "$(dirname "$(rreadlink "$0")")/../lib/utils.sh"
# TODO: detect term or set it globally # TODO: detect term or set it globally
TERM_EMU="kitty" TERM_EMU="kitty"
die() { if ! check_exists wl-paste && [ ! -z "$WAYLAND_DISPLAY" ]; then
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
die "Wayland detected and wl-paste not found" 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" die "xsel not found"
fi fi
@ -61,7 +53,7 @@ case "$choice" in
path="$HOME/mus/$(printf "%s" "$choice" | cut -d " " -f 2-)" path="$HOME/mus/$(printf "%s" "$choice" | cut -d " " -f 2-)"
[ -d "$path" ] || mkdir -p "$path" [ -d "$path" ] || mkdir -p "$path"
cd "$path" || exit 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") "crawl")
path="$HOME/books/" 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(")" out="$(lncrawl --single --all --format epub --filename-only --suppress -s "$urls" | grep -vFe "Input is suppressed" -e "Namespace(")"
errors="$(printf "%s" "$out" | grep -Fe " ❗ ")" errors="$(printf "%s" "$out" | grep -Fe " ❗ ")"
if [ -n "$errors" ]; then if [ -n "$errors" ]; then
printf "%s" "$errors" | xargs -n1 -d "\n" notify-send printf "%s" "$errors" | notify_err
else else
printf "%s" "$out" | sed -ne '/^NOVEL: /s/NOVEL: \(.*\)/Successfully crawled "\1"/p' | xargs -0 -n1 notify-send printf "%s" "$out" | sed -ne '/^NOVEL: /s/NOVEL: \(.*\)/Successfully crawled "\1"/p' | xargs -0 -n1 notify-send
fi fi

View file

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

View file

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

View file

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