summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/icstocal3
-rwxr-xr-xscripts/lfub23
-rwxr-xr-xscripts/plumber209
-rwxr-xr-xscripts/rotdir13
-rwxr-xr-xscripts/ytdl22
5 files changed, 258 insertions, 12 deletions
diff --git a/scripts/icstocal b/scripts/icstocal
index 3d086ca..9bff2be 100755
--- a/scripts/icstocal
+++ b/scripts/icstocal
@@ -68,7 +68,8 @@ while line != "END:VCALENDAR\n":
starts.append([year, month, day, hour, min])
elif line.startswith("DTEND"):
end = line.lstrip("DTEND")
- while start[n] != ":":
+ n = 0
+ while end[n] != ":":
n+=1
hour = ""
min = ""
diff --git a/scripts/lfub b/scripts/lfub
new file mode 100755
index 0000000..0d8b7fe
--- /dev/null
+++ b/scripts/lfub
@@ -0,0 +1,23 @@
+#!/bin/sh
+# This is a wrapper script for lf that allows it to create image previews with
+# ueberzug. This works in concert with the lf configuration file and the
+# lf-cleaner script.
+
+set -e
+
+cleanup() {
+ exec 3>&-
+ rm "$FIFO_UEBERZUG"
+}
+
+if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
+ lf "$@"
+else
+ [ ! -d "$XDG_CACHE_HOME/lf" ] && mkdir -p "$XDG_CACHE_HOME/lf"
+ export FIFO_UEBERZUG="$XDG_CACHE_HOME/lf/ueberzug-$$"
+ mkfifo "$FIFO_UEBERZUG"
+ ueberzug layer -s <"$FIFO_UEBERZUG" -p json &
+ exec 3>"$FIFO_UEBERZUG"
+ trap cleanup HUP INT QUIT TERM PWR EXIT
+ lf "$@" 3>&-
+fi
diff --git a/scripts/plumber b/scripts/plumber
new file mode 100755
index 0000000..b6931a1
--- /dev/null
+++ b/scripts/plumber
@@ -0,0 +1,209 @@
+#!/bin/sh
+# Copywrong © 2023 Ratakor. Under ISC License.
+# plumber 🪠
+# dependencies:
+# - default programs
+# - xdo
+# - xclip or xsel
+# - (optional) herbe and dmenusearch web
+# - (optional) dmenu_path
+# - (optional) st with plumber patch
+# shellcheck disable=SC2086
+
+# default programs
+WEB="xdg-open"
+TEXT="$TERMINAL -e $EDITOR"
+VIDEO="mpv --ytdl-format=22 --loop"
+AUDIO="music --shuffle"
+PIC="nsxiv -a"
+DOC="zathura"
+DIR="$TERMINAL -e lfub"
+
+openlink() {
+ case "$1" in
+ *.mkv|*.webm|*.mp4|*.mov|*youtube.com/watch*|*youtube.com/playlist*|\
+ *youtube.com/shorts*|*youtu.be*|*inv*/playlist*|*inv*/watch*)
+ setsid -f $VIDEO "$1" >/dev/null 2>&1 ;;
+ *.mp3|*.flac|*.opus|*mp3?source*|*.ogg|*.wav|*soundcloud.com*)
+ setsid -f $AUDIO "$1" >/dev/null 2>&1 ;;
+ *.png|*.jpg|*.jpeg|*.gif|*.webp)
+ file=$(printf '%s' "$1" | sed "s/.*\///;s/%20/ /g")
+ curl -sL "$1" > "/tmp/$file" &&
+ $PIC "/tmp/$file" >/dev/null 2>&1 & ;;
+ *.pdf|*.ps|*.cbz|*.cbr|*.djvu|*.epub)
+ file=$(printf '%s' "$1" | sed "s/.*\///;s/%20/ /g")
+ curl -sL "$1" > "/tmp/$file" &&
+ $DOC "/tmp/$file" >/dev/null 2>&1 & ;;
+ *wp.com/stonetoss.com*)
+ file=$(printf '%s' "${1%"?resize=150%2C150&ssl=1"}" |\
+ sed "s/.*\///;s/%20/ /g")
+ curl -sL "${1%"?resize=150%2C150&ssl=1"}" > "/tmp/$file" &&
+ $PIC "/tmp/$file" >/dev/null 2>&1 & ;;
+ git://*|git@*|*.git)
+ "$TERMINAL" -e git clone "$1" ;;
+ *)
+ setsid -f $WEB "$1" >/dev/null 2>&1 ;;
+ esac
+}
+
+openfile() {
+ if [ -d "$1" ]; then
+ setsid -f $DIR "$1" >/dev/null 2>&1
+ return
+ fi
+
+ if [ ! -f "$1" ]; then
+ printf '\033[31mError:\033[m %s is not a valid file\n' "$1" >&2
+ return 1
+ fi
+
+ case "$1" in
+ *.mkv|*.webm|*.mp4|*.mov)
+ setsid -f $VIDEO "$1" >/dev/null 2>&1 ;;
+ *.mp3|*.flac|*.opus|*.ogg|*.wav)
+ setsid -f $AUDIO "$1" >/dev/null 2>&1 ;;
+ *.png|*.jpg|*.jpeg|*.gif|*.webp)
+ setsid -f $PIC "$1" >/dev/null 2>&1 ;;
+ *.pdf|*.ps|*.cbz|*.cbr|*.djvu|*.epub)
+ setsid -f $DOC "$1" >/dev/null 2>&1 ;;
+ *)
+ setsid -f $TEXT "$1" >/dev/null 2>&1 ;;
+ esac
+}
+
+checksel() {
+ case "$1" in
+ http://*|https://*|irc://*|ircs://*|git://*|git@*)
+ openlink "$1" ;;
+ /*)
+ opensel "$1" "$1" ;;
+
+ *)
+ pid=$(pstree -lpA "$(xdo pid)" | tail -n 1 |\
+ awk -F '---' '{print $NF}' | sed -re 's/[^0-9]//g')
+ opensel "$(readlink "/proc/$pid/cwd")/$1" "$1" ;;
+ esac
+}
+
+opensel() {
+ if [ -d "$1" ]; then
+ case $1 in
+ "$XDG_MUSIC_DIR"/*)
+ setsid -f $AUDIO "$1" >/dev/null 2>&1 ;;
+ *)
+ xdo kill
+ $TERMINAL -e sh -c "cd $1; $SHELL" ;;
+ esac
+ return
+ fi
+
+ if [ ! -f "$1" ]; then
+ progname=${2%\ *}
+ for prog in $(dmenu_path); do
+ case $prog in
+ "$progname")
+ $TERMINAL -e sh -c\
+ "cd ${1%"$2"}; echo \$ $2; $2; $SHELL"
+ return ;;
+ esac
+ done
+ herbe "Do you want to search for '$2' ?" && dmenusearch web "$2"
+ return
+ fi
+
+ case "$1" in
+ *.mkv|*.webm|*.mp4|*.mov)
+ setsid -f $VIDEO "$1" >/dev/null 2>&1 ;;
+ *.mp3|*.flac|*.opus|*.ogg|*.wav)
+ setsid -f $AUDIO "$1" >/dev/null 2>&1 ;;
+ *.png|*.jpg|*.jpeg|*.gif|*.webp)
+ setsid -f $PIC "$1" >/dev/null 2>&1 ;;
+ *.pdf|*.ps|*.cbz|*.cbr|*.djvu|*.epub)
+ setsid -f $DOC "$1" >/dev/null 2>&1 ;;
+ *)
+ pid=$(xdo pid)
+ xdo hide -p "$pid"
+ $TEXT "$1" >/dev/null 2>&1
+ xdo show -p "$pid" ;;
+ esac
+}
+
+
+usage() {
+ cat << EOF >&2
+Usage: ${0##*/} [options] [arg]
+
+Options:
+ no option [arg] | Try to guess what to do
+ -l|--link [link] | Open the link
+ -f|--file [file] | Open the file or the folder
+ -s|--sel | Use the selection buffer instead, Plan9's way
+ -t|--term | To be used only when invoking through a patched st
+ -h|--help │ Print this help message
+
+Config:
+ browser = $WEB
+ editor = $TEXT
+ video = $VIDEO
+ audio = $AUDIO
+ picture = $PIC
+ document = $DOC
+ file manager = $DIR
+EOF
+}
+
+main() {
+ case "$1" in
+ -l|--link)
+ if [ -z "$2" ]; then
+ printf '\033[31mError:\033[m no argument given\n' >&2
+ usage
+ return 1
+ fi
+ openlink "$2" ;;
+ -f|--file)
+ if [ -z "$2" ]; then
+ printf '\033[31mError:\033[m no argument given\n' >&2
+ usage
+ return 1
+ fi
+ openfile "$2" ;;
+ -s|--sel|'')
+ sel=$(xclip -o -sel 2>/dev/null || xsel -opn 2>/dev/null)
+ sel=${sel#"${sel%%[![:space:]]*}"}
+
+ # clear clipboard
+ true | xclip 2>/dev/null || true | xsel 2>/dev/null
+
+ if [ -z "$sel" ]; then
+ printf '\033[31mError:\033[m selection buffer is empty\n' >&2
+ usage
+ return 1
+ fi
+
+ checksel "$sel" ;;
+ -t|--term)
+ #if [ "$(ps -o comm= $PPID)" != "st" ]; then
+ # printf '\033[31mError:\033[m --term option used outside of st\n' >&2
+ # usage
+ # return 1
+ #fi
+ [ -n "$2" ] && checksel "$2" ;;
+ -h|--help)
+ usage
+ return 0 ;;
+ -*)
+ printf '\033[31mError:\033[m unknown option\n' >&2
+ usage
+ return 1 ;;
+ *)
+ case "$1" in
+ http://*|https://*|git://*|irc://*|ircs://*)
+ openlink "$1" ;;
+ *)
+ openfile "$1" ;;
+ esac
+ esac
+}
+
+main "$@"
diff --git a/scripts/rotdir b/scripts/rotdir
new file mode 100755
index 0000000..3b3f39d
--- /dev/null
+++ b/scripts/rotdir
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+# When I open an image from the file manager in sxiv (the image viewer), I want
+# to be able to press the next/previous keys to key through the rest of the
+# images in the same directory. This script "rotates" the content of a
+# directory based on the first chosen file, so that if I open the 15th image,
+# if I press next, it will go to the 16th etc. Autistic, I know, but this is
+# one of the reasons that sxiv is great for being able to read standard input.
+# ^ this is Luke's toughts and I approve them
+
+[ -z "$1" ] && echo "usage: rotdir regex 2>&1" && exit 1
+base="$(basename "$1")"
+ls "$PWD" | awk -v BASE="$base" 'BEGIN { lines = ""; m = 0; } { if ($0 == BASE) { m = 1; } } { if (!m) { if (lines) { lines = lines"\n"; } lines = lines""$0; } else { print $0; } } END { print lines; }'
diff --git a/scripts/ytdl b/scripts/ytdl
index e69cf26..9aafb42 100755
--- a/scripts/ytdl
+++ b/scripts/ytdl
@@ -1,33 +1,33 @@
#!/bin/sh
# wrapper for yt-dlp
-MUSICDIR="${XDG_MUSIC_DIR:-$HOME/Music}"
+MUSICDIR="${XDG_MUSIC_DIR:-$HOME/music}"
VIDEODIR="${XDG_VIDEOS_DIR:-$HOME/Videos}"
case $1 in
v)
mkdir -p "$VIDEODIR"
- notify-send "Video download started"
+ herbe "Video download started"
yt-dlp -f 'bv,ba' -o '%(title)s [%(id)s].%(ext)s'\
-P "$VIDEODIR" "$2" &&
- notify-send "Video downloaded" ||
- (notify-send "Error: No internet connection" && exit 1) ;;
+ herbe "Video downloaded" ||
+ (herbe "Error: No internet connection" && exit 1) ;;
m)
mkdir -p "$MUSICDIR/download"
- notify-send "Music download started"
+ herbe "Music download started"
yt-dlp -f 'ba' -x --embed-thumbnail --audio-format mp3\
-o '%(title)s [%(id)s].%(ext)s' -P "$MUSICDIR/download" "$2" &&
- notify-send "Music downloaded" ||
- (notify-send "Error: No internet connection" && exit 1) ;;
+ herbe "Music downloaded" ||
+ (herbe "Error: No internet connection" && exit 1) ;;
p)
NAME=$(printf '' | dmenu -p 'Name ')
mkdir -p "$MUSICDIR/$NAME"
- notify-send "Playlist download started"
+ herbe "Playlist download started"
yt-dlp -f 'ba' -x --embed-thumbnail --audio-format mp3\
-o '%(playlist_index)s - %(title)s [%(id)s].%(ext)s'\
-P "$MUSICDIR/$NAME" "$2" &&
- notify-send "Playlist downloaded" ||
- (notify-send "Error: No internet connection" && exit 1) ;;
+ herbe "Playlist downloaded" ||
+ (herbe "Error: No internet connection" && exit 1) ;;
*)
exit 1 ;;
-esac \ No newline at end of file
+esac