summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/dmenuhandler40
-rwxr-xr-xscripts/dmenuoff15
-rwxr-xr-xscripts/dmenusearch100
-rwxr-xr-xscripts/dmenutimer6
-rwxr-xr-xscripts/music30
-rwxr-xr-xscripts/musiccmd116
-rwxr-xr-xscripts/screenshot11
-rwxr-xr-xscripts/selectopt5
-rwxr-xr-xscripts/speedtest8
-rw-r--r--scripts/test1
-rwxr-xr-xscripts/ytdl33
11 files changed, 365 insertions, 0 deletions
diff --git a/scripts/dmenuhandler b/scripts/dmenuhandler
new file mode 100755
index 0000000..b3eb9c8
--- /dev/null
+++ b/scripts/dmenuhandler
@@ -0,0 +1,40 @@
+#!/bin/sh
+# Feed this script a link and it will give dmenu
+# some choice programs to use to open it.
+
+FEED="${1:-$(printf "" | dmenu -p 'Paste URL or file path')}"
+
+[ -z "$FEED" ] && exit
+
+case "$(printf '%s\nbrowser\nmusic\nmpv\nmpv loop\nnsxiv\nPDF\nvim\nyt-dlp\nmusic-dlp' "$FEED" | dmenu -i -p "Open with ")" in
+ "$FEED")
+ printf '%s\n' "$FEED" | xclip -selection clipboard ;; # Copy URL
+ browser)
+ setsid -f "$BROWSER" "$FEED" >/dev/null 2>&1 ;;
+ music)
+ setsid -f music "$FEED" >/dev/null 2>&1 ;;
+ mpv)
+ setsid -f mpv --quiet --ytdl-format="bv,ba" "$FEED" >/dev/null 2>&1 ;;
+ "mpv loop")
+ setsid -f mpv --quiet --ytdl-format="bv,ba" --loop "$FEED" >/dev/null 2>&1 ;;
+ nsxiv)
+ curl -sL "$FEED" > "/tmp/$(echo "$FEED" | sed "s/.*\///;s/%20/ /g")" &&
+ nsxiv -a "/tmp/$(echo "$FEED" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 ;;
+ PDF)
+ curl -sL "$FEED" > "/tmp/$(echo "$FEED" | sed "s/.*\///;s/%20/ /g")" &&
+ zathura "/tmp/$(echo "$FEED" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 ;;
+ vim)
+ curl -sL "$FEED" > "/tmp/$(echo "$FEED" | sed "s/.*\///;s/%20/ /g")" &&
+ setsid -f "$TERMINAL" -e "$EDITOR" "/tmp/$(echo "$FEED" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 ;;
+ yt-dlp)
+ setsid -f ytdl v "$FEED" >/dev/null 2>&1 ;;
+ music-dlp)
+ if [ "$(printf 'no\nyes' | dmenu -i -p 'Playlist?')" = "yes" ]; then
+ setsid -f ytdl p "$FEED" >/dev/null 2>&1
+ else
+ setsid -f ytdl m "$FEED" >/dev/null 2>&1
+ fi
+ #setbg)
+ # curl -sL "$FEED" > "$XDG_CACHE_HOME/pic" &&
+ # hsetroot -cover "$XDG_CACHE_HOME/pic" >/dev/null 2>&1 ;;
+esac \ No newline at end of file
diff --git a/scripts/dmenuoff b/scripts/dmenuoff
new file mode 100755
index 0000000..e278c8a
--- /dev/null
+++ b/scripts/dmenuoff
@@ -0,0 +1,15 @@
+#!/bin/sh
+# menu for shutdown or lock
+# require nopass for poweroff and reboot and my build of dmenu for -hf
+
+QUERY=$(printf 'no\nlock\npoweroff\nreboot' | dmenu -i -sb '#cc241d' -hf '#689d6a' -p 'Shutdown?')
+ROOTCMD="${ROOTCMD:-$(command -v doas || command -v sudo)}"
+
+case "$QUERY" in
+"lock")
+ slock ;;
+"poweroff")
+ "$ROOTCMD" poweroff ;;
+"reboot")
+ "$ROOTCMD" reboot ;;
+esac \ No newline at end of file
diff --git a/scripts/dmenusearch b/scripts/dmenusearch
new file mode 100755
index 0000000..b1ed9d6
--- /dev/null
+++ b/scripts/dmenusearch
@@ -0,0 +1,100 @@
+#!/bin/sh
+# search web, arch wiki, aur, youtube man pages or emoji with dmenu
+# websearch dependencies : shuf, curl, /tmp needs to be temporary
+# wiki dependency: arch-wiki-docs
+# youtube dependency: ytfzf
+# man dependencies: man-db, zathura
+# emoji dependency: xclip
+
+set -e
+
+web() {
+ NETWORK=clearnet # clearnet, tor or i2p
+ if [ ! -f "/tmp/instances" ]; then
+ curl -s "https://librex.ratakor.com/instances.json" > /tmp/instances.json ||
+ (notify-send "No internet connection"; exit 1)
+
+ strip() {
+ tmp="${1##" \"$NETWORK\": \""}"
+ printf '%s\n' "${tmp%%"\","}"
+ }
+
+ while IFS= read -r line || [ -n "$line" ]; do
+ case $line in
+ *"$NETWORK"*null,)
+ continue ;;
+ *"$NETWORK"*)
+ strip "$line" >> /tmp/instances ;;
+ esac
+ done < /tmp/instances.json
+ fi
+
+ instance="$(shuf -n 1 /tmp/instances)"
+ query="${instance}search.php?q=${1:-$(printf "" | dmenu -p "Search:" -l 0)}&t=0"
+}
+
+wiki() {
+ WIKIDIR="/usr/share/doc/arch-wiki/html/en"
+
+ strip() {
+ tmp="${1##"$WIKIDIR/"}"
+ printf '\n%s' "${tmp%%".html"}"
+ }
+
+ for file in "$WIKIDIR"/*.html; do
+ [ -f "$file" ] || continue
+ wikidocs="$wikidocs$(strip "$file")"
+ done
+
+ wikidocs="${wikidocs#*
+}" # remove a trailing newline
+
+ query="$WIKIDIR/$(printf '%s\n' "$wikidocs" | sed -e 's/_/ /g' | sort |\
+ dmenu -i -l 10 -p 'Search Wiki: ').html"
+ query="$(printf '%s\n' "$query" | sed 's/ /_/g')" # separate otherwise set -e fails
+}
+
+aur() {
+ AURSITE="https://aur.archlinux.org/packages?O=0&K="
+ query="$AURSITE$(printf "" | dmenu -p "AUR:" -l 0)"
+}
+
+manpdf() {
+ INPUT=${1:-$(/usr/bin/man -k . | dmenu -i -l 20 | awk '{print $1}')}
+ [ -n "$INPUT" ] && /usr/bin/man -Tpdf "$INPUT" | zathura -
+}
+
+emoji() {
+ CHOSEN=$(cut -d ';' -f1 "$XDG_DATA_HOME/emoji" | dmenu -i -l 30 | sed "s/ .*//")
+
+ [ -z "$CHOSEN" ] && return 1
+
+ printf '%s' "$CHOSEN" | xclip -selection clipboard
+ # notify-send "'$CHOSEN' copied to clipboard."
+}
+
+main() {
+ case ${1:-$(printf 'web\naur\nyoutube\nman\nemoji' | dmenu -i)} in
+ web)
+ web "$2" ;;
+ #wiki)
+ # wiki ;;
+ aur)
+ aur ;;
+ youtube)
+ ytfzf -D
+ return ;;
+ man)
+ manpdf "$2"
+ return ;;
+ emoji)
+ emoji
+ return ;;
+ *)
+ return 1 ;;
+ esac
+
+ "$BROWSER" "$query" 2> /dev/null
+}
+
+main "$@" \ No newline at end of file
diff --git a/scripts/dmenutimer b/scripts/dmenutimer
new file mode 100755
index 0000000..00ccb4e
--- /dev/null
+++ b/scripts/dmenutimer
@@ -0,0 +1,6 @@
+#!/bin/sh
+# dmenu script for an arttime timer
+
+TIME=$(printf '' | dmenu -i -sb '#4E3524' -p 'New timer: ')
+
+st -c "arttime" -o - -e arttime --nolearn --random all --style 1 -t "Timer" -g $TIME 2>/dev/null | grep goal
diff --git a/scripts/music b/scripts/music
new file mode 100755
index 0000000..42ceeeb
--- /dev/null
+++ b/scripts/music
@@ -0,0 +1,30 @@
+#!/bin/sh
+# simple music selector with dmenu that uses and interacts with mpv
+# have a look at musiccmd, dwmblocks/sb_music and .local/etc/mpv/music
+# shellcheck disable=SC2012
+
+MUSICDIR="${XDG_MUSIC_DIR:-$HOME/music}"
+
+if [ "$1" = "--shuffle" ]; then
+ SHUFFLE=yes
+ shift
+fi
+
+MUSIC="${1:-$MUSICDIR/$(ls "$MUSICDIR" | dmenu -i -p "Play ")}"
+SCRIPT="$XDG_CONFIG_HOME/mpv/music/local.lua"
+
+if [ "$MUSIC" = "$MUSICDIR/urls" ]; then
+ MUSIC="$(cat "$MUSICDIR/urls/$(ls "$MUSICDIR/urls" | dmenu -i -p "Play ")")"
+ SCRIPT="$XDG_CONFIG_HOME/mpv/music/online.lua"
+fi
+
+[ "$MUSIC" = "$MUSICDIR/" ] || [ -z "$MUSIC" ] && exit 1
+
+if [ -z "$SHUFFLE" ] && [ -d "$MUSIC" ] || printf '%s' "$MUSIC" | grep -q playlist; then
+ SHUFFLE="$(printf 'yes\nno' | dmenu -i -p 'Shuffle?')"
+ [ -z "$SHUFFLE" ] && exit 1
+fi
+
+printf 'stop\n' | socat - /tmp/mpvsocket 2> /dev/null
+mpv --vid=no --input-ipc-server=/tmp/mpvsocket --loop-playlist --volume=75\
+ --ytdl-format="wv*+ba" --script="$SCRIPT" --shuffle="$SHUFFLE" "$MUSIC"
diff --git a/scripts/musiccmd b/scripts/musiccmd
new file mode 100755
index 0000000..ecaf437
--- /dev/null
+++ b/scripts/musiccmd
@@ -0,0 +1,116 @@
+#!/bin/sh
+# helper for the music script
+# dependencies: music, mpv, socat, yt-dlp, ffmpeg, imagemagick
+# optional dependencies: dwmblocks, libnotify, herbe
+
+FAVDIR="${XDG_MUSIC_DIR:-$HOME/music}/favorite"
+DLDIR="${XDG_MUSIC_DIR:-$HOME/music}/download"
+CACHE="${XDG_CACHE_HOME:-$HOME/.cache}"
+IMG="nsxiv"
+
+getpath() {
+ tmp="$(printf '{ "command": ["get_property", "path"] }\n'\
+ | socat - /tmp/mpvsocket)"
+ tmp="${tmp#{\"data\":\"}"
+ path="${tmp%\",\"request_id\":0,\"error\":\"success\"\}}"
+}
+
+getvol() {
+ tmp="$(printf '{ "command": ["get_property", "volume"] }\n'\
+ | socat - /tmp/mpvsocket)"
+ tmp="${tmp#{\"data\":}"
+ printf '%s\n' "${tmp%.000000,\"request_id\":0,\"error\":\"success\"\}}"
+}
+
+download() {
+ mkdir -p "$1"
+ notify-send "Downloading '$path' to '$1'"
+ if yt-dlp -f "ba" -x --embed-thumbnail --audio-format mp3\
+ -o"%(title)s [%(id)s].%(ext)s" -P "$1" "$path"; then
+ notify-send "'$path' successfuly downloaded to '$2'"
+ return 0
+ else
+ notify-send "Error: '$path' couldn't be downloaded"
+ return 1
+ fi
+}
+
+addtofav() {
+ case $path in
+ *youtube.com*)
+ download "$FAVDIR" ;;
+ *)
+ mkdir -p "$FAVDIR"
+ if cp "$path" "$FAVDIR"; then
+ notify-send "'$path' was copied to '$FAVDIR'"
+ return 0
+ else
+ notify-send "'$path' couldn't be copied to '$FAVDIR'"
+ return 1
+ fi ;;
+ esac
+}
+
+getthumbnail() {
+ mkdir -p "$CACHE"
+ case $path in
+ *youtube.com*)
+ yt-dlp --skip-download --force-overwrites --write-thumbnail\
+ -o "$CACHE/thumbnail" "$path" > /dev/null 2>&1 &&\
+ magick "$CACHE/thumbnail.webp" "$CACHE/thumbnail.jpg" ;;
+ *)
+ ffmpeg -y -i "$path" "$CACHE/thumbnail.jpg" 2> /dev/null ;;
+ esac
+}
+
+
+main() {
+ if ! pgrep -x music >/dev/null; then
+ kill -35 "$(pidof dwmblocks)"
+ herbe "Error: There is no music playing"\
+ "Do you want to play some ?" &&
+ music
+ return 1
+ fi
+
+ cmd="${1:-$(printf '⏯️pause/play\n⏭️next\n⏮️prev\n📢volume\n🔳stop
+⭐favorite\n⬇️download\n🖼️thumbnail' | dmenu -i -p "musiccmd")}"
+
+ case "$cmd" in
+ cycle|*pause|*play)
+ printf 'cycle pause\n' | socat - /tmp/mpvsocket
+ kill -35 "$(pidof dwmblocks)" ;;
+ *next)
+ printf 'playlist-next\n' | socat - /tmp/mpvsocket ;;
+ *prev)
+ printf 'playlist-prev\n' | socat - /tmp/mpvsocket ;;
+ *volume)
+ printf '{ "command": ["set_property", "volume", %s] }\n'\
+ "${2:-$(true | dmenu -p "Current volume: $(getvol)")}"\
+ | socat - /tmp/mpvsocket 1> /dev/null ;;
+ *stop)
+ printf 'stop\n' | socat - /tmp/mpvsocket
+ kill -35 "$(pidof dwmblocks)" ;;
+ *favorite|fav)
+ getpath
+ addtofav ;;
+ *download)
+ getpath
+ download "$DLDIR" ;;
+ *thumbnail)
+ getpath
+ if getthumbnail; then
+ $IMG "$CACHE/thumbnail.jpg"
+ else
+ notify-send "Error: can't get thumbnail"
+ return 1
+ fi ;;
+ path)
+ getpath
+ printf '%s\n' "$path" ;;
+ vol)
+ getvol ;;
+ esac
+}
+
+main "$@"
diff --git a/scripts/screenshot b/scripts/screenshot
new file mode 100755
index 0000000..8226205
--- /dev/null
+++ b/scripts/screenshot
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+OUTPUT="$XDG_PICTURES_DIR/screenshots/$(date '+%Y-%m-%d_%H:%M:%S').png"
+XCLIPCMD="xclip -sel clip -t image/png"
+
+case "$(printf "save select\nsave screen\ncopy select\ncopy screen" | dmenu -i -p "Screenshot")" in
+ "copy screen") maim -q -u -d 0.5 | $XCLIPCMD ;;
+ "save select") maim -u -s "$OUTPUT" ;;
+ "save screen") maim -q -u -d 0.5 "$OUTPUT" ;;
+ "copy select") maim -u -s | $XCLIPCMD ;;
+esac
diff --git a/scripts/selectopt b/scripts/selectopt
new file mode 100755
index 0000000..eff605f
--- /dev/null
+++ b/scripts/selectopt
@@ -0,0 +1,5 @@
+# !/bin/sh
+# a script to select whether music or musiccmd should be called,
+# depending on whether mpv is already running or not
+
+pidof mpv >/dev/null && musiccmd || music \ No newline at end of file
diff --git a/scripts/speedtest b/scripts/speedtest
new file mode 100755
index 0000000..a93b63a
--- /dev/null
+++ b/scripts/speedtest
@@ -0,0 +1,8 @@
+#!/bin/sh
+# usage: time speedtest cmd
+
+i=0
+while [ $i -lt 100000 ]; do
+ "$@"
+ i=$((i+1))
+done
diff --git a/scripts/test b/scripts/test
new file mode 100644
index 0000000..999bef1
--- /dev/null
+++ b/scripts/test
@@ -0,0 +1 @@
+fzdlfhzdk \ No newline at end of file
diff --git a/scripts/ytdl b/scripts/ytdl
new file mode 100755
index 0000000..e69cf26
--- /dev/null
+++ b/scripts/ytdl
@@ -0,0 +1,33 @@
+#!/bin/sh
+# wrapper for yt-dlp
+
+MUSICDIR="${XDG_MUSIC_DIR:-$HOME/Music}"
+VIDEODIR="${XDG_VIDEOS_DIR:-$HOME/Videos}"
+
+case $1 in
+v)
+ mkdir -p "$VIDEODIR"
+ notify-send "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) ;;
+m)
+ mkdir -p "$MUSICDIR/download"
+ notify-send "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) ;;
+p)
+ NAME=$(printf '' | dmenu -p 'Name ')
+ mkdir -p "$MUSICDIR/$NAME"
+ notify-send "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) ;;
+*)
+ exit 1 ;;
+esac \ No newline at end of file