aboutsummaryrefslogtreecommitdiff
path: root/.local/bin
diff options
context:
space:
mode:
authorJustine Smithies <justine@smithies.me.uk>2024-11-08 20:43:20 +0000
committerJustine Smithies <justine@smithies.me.uk>2024-11-08 20:43:20 +0000
commit8d0bdf6bef075ea538f05759528e58bad166b924 (patch)
treefe823b1ef3ca8f041d37c480b0c99ae4393a48f8 /.local/bin
parent47f3bc8e0a8784f849cce23c9dfa72d1ea1d22b0 (diff)
Initial commit
Diffstat (limited to '.local/bin')
-rwxr-xr-x.local/bin/emoji-menu19
-rwxr-xr-x.local/bin/linkhandler23
-rwxr-xr-x.local/bin/msmtp-enqueue.sh44
-rwxr-xr-x.local/bin/msmtp-listqueue.sh8
-rwxr-xr-x.local/bin/msmtp-runqueue.sh69
-rwxr-xr-x.local/bin/powermenu39
-rwxr-xr-x.local/bin/screenshot.sh31
-rwxr-xr-x.local/bin/ssh-askpass14
8 files changed, 247 insertions, 0 deletions
diff --git a/.local/bin/emoji-menu b/.local/bin/emoji-menu
new file mode 100755
index 0000000..6b20513
--- /dev/null
+++ b/.local/bin/emoji-menu
@@ -0,0 +1,19 @@
+#!/bin/sh -eu
+# From: https://git.sr.ht/~emersion/dotfiles/tree/6575f89856d012c2c31e9e7d2c807f350c7503d4/item/bin/emoji-menu
+# This version uses `fuzzel` instead of `menu`.
+
+default_cache_home=~/.cache
+cache_home="${XDG_CACHE_HOME:-$default_cache_home}"
+mkdir -p "$cache_home"
+data_file="$cache_home/emoji-menu.json"
+
+if ! [ -f "$data_file" ]; then
+ curl -o "$data_file" -L "https://github.com/github/gemoji/raw/master/db/emoji.json"
+fi
+
+filter='.[] | (.emoji + " " + .description + " (" + (.aliases | join(", ")) + ")")'
+sel="$(jq -r "$filter" <"$data_file" | fuzzel --no-exit-on-keyboard-focus-loss -d | cut -d ' ' -f 1 | tr -d '\n')"
+if [ -n "$sel" ]; then
+ # wl-ime-type "$sel"
+ wl-copy "$sel"
+fi
diff --git a/.local/bin/linkhandler b/.local/bin/linkhandler
new file mode 100755
index 0000000..044c71b
--- /dev/null
+++ b/.local/bin/linkhandler
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+# Feed script a url or file location.
+# If an image, it will view in sxiv,
+# if a video or gif, it will view in mpv
+# if a music file or pdf, it will download,
+# otherwise it opens link in browser.
+
+# If no url given. Opens browser. For using script as $BROWSER.
+[ -z "$1" ] && { "$BROWSER"; exit; }
+
+case "$1" in
+ *mkv|*webm|*mp4|*youtube.com/watch*|*youtube.com/playlist*|*youtu.be*|*hooktube.com*|*bitchute.com*|*videos.lukesmith.xyz*)
+ setsid -f mpv -quiet "$1" >/dev/null 2>&1 ;;
+ *png|*jpg|*jpe|*jpeg|*gif)
+ curl -sL "$1" > "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" && imv "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 & ;;
+ *pdf|*cbz|*cbr)
+ curl -sL "$1" > "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" && zathura "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 & ;;
+ *mp3|*flac|*opus|*mp3?source*)
+ qndl "$1" 'curl -LO' >/dev/null 2>&1 ;;
+ *)
+ [ -f "$1" ] && setsid -f "$TERMINAL" -e "$EDITOR" "$1" >/dev/null 2>&1 || setsid -f "$BROWSER" --target window "$1" >/dev/null 2>&1
+esac
diff --git a/.local/bin/msmtp-enqueue.sh b/.local/bin/msmtp-enqueue.sh
new file mode 100755
index 0000000..c9beaca
--- /dev/null
+++ b/.local/bin/msmtp-enqueue.sh
@@ -0,0 +1,44 @@
+#!/usr/bin/env sh
+
+QUEUEDIR=$HOME/.msmtpqueue
+
+# Set secure permissions on created directories and files
+umask 077
+
+# Change to queue directory (create it if necessary)
+if [ ! -d "$QUEUEDIR" ]; then
+ mkdir -p "$QUEUEDIR" || exit 1
+fi
+cd "$QUEUEDIR" || exit 1
+
+# Create new unique filenames of the form
+# MAILFILE: ccyy-mm-dd-hh.mm.ss[-x].mail
+# MSMTPFILE: ccyy-mm-dd-hh.mm.ss[-x].msmtp
+# where x is a consecutive number only appended if you send more than one
+# mail per second.
+BASE="$(date +%Y-%m-%d-%H.%M.%S)"
+if [ -f "$BASE.mail" ] || [ -f "$BASE.msmtp" ]; then
+ TMP="$BASE"
+ i=1
+ while [ -f "$TMP-$i.mail" ] || [ -f "$TMP-$i.msmtp" ]; do
+ i=$((i + 1))
+ done
+ BASE="$BASE-$i"
+fi
+MAILFILE="$BASE.mail"
+MSMTPFILE="$BASE.msmtp"
+
+# Write command line to $MSMTPFILE
+echo "$@" > "$MSMTPFILE" || exit 1
+
+# Write the mail to $MAILFILE
+cat > "$MAILFILE" || exit 1
+
+# If we are online, run the queue immediately.
+# Replace the test with something suitable for your site.
+#ping -c 1 -w 2 SOME-IP-ADDRESS > /dev/null
+#if [ $? -eq 0 ]; then
+# msmtp-runqueue.sh > /dev/null &
+#fi
+
+exit 0
diff --git a/.local/bin/msmtp-listqueue.sh b/.local/bin/msmtp-listqueue.sh
new file mode 100755
index 0000000..cc97c58
--- /dev/null
+++ b/.local/bin/msmtp-listqueue.sh
@@ -0,0 +1,8 @@
+#!/usr/bin/env sh
+
+QUEUEDIR=$HOME/.msmtpqueue
+
+for i in $QUEUEDIR/*.mail; do
+ grep -E -s --colour -h '(^From:|^To:|^Subject:)' "$i" || echo "No mail in queue";
+ echo " "
+done
diff --git a/.local/bin/msmtp-runqueue.sh b/.local/bin/msmtp-runqueue.sh
new file mode 100755
index 0000000..1200610
--- /dev/null
+++ b/.local/bin/msmtp-runqueue.sh
@@ -0,0 +1,69 @@
+#!/usr/bin/env sh
+
+QUEUEDIR="$HOME/.msmtpqueue"
+LOCKFILE="$QUEUEDIR/.lock"
+MAXWAIT=120
+
+OPTIONS=$*
+
+# eat some options that would cause msmtp to return 0 without sendmail mail
+case "$OPTIONS" in
+ *--help*)
+ echo "$0: send mails in $QUEUEDIR"
+ echo "Options are passed to msmtp"
+ exit 0
+ ;;
+ *--version*)
+ echo "$0: unknown version"
+ exit 0
+ ;;
+esac
+
+# wait for a lock that another instance has set
+WAIT=0
+while [ -e "$LOCKFILE" ] && [ "$WAIT" -lt "$MAXWAIT" ]; do
+ sleep 1
+ WAIT="$((WAIT + 1))"
+done
+if [ -e "$LOCKFILE" ]; then
+ echo "Cannot use $QUEUEDIR: waited $MAXWAIT seconds for"
+ echo "lockfile $LOCKFILE to vanish, giving up."
+ echo "If you are sure that no other instance of this script is"
+ echo "running, then delete the lock file."
+ exit 1
+fi
+
+# change into $QUEUEDIR
+cd "$QUEUEDIR" || exit 1
+
+# check for empty queuedir
+if [ "$(echo ./*.mail)" = './*.mail' ]; then
+ echo "No mails in $QUEUEDIR"
+ exit 0
+fi
+
+# lock the $QUEUEDIR
+touch "$LOCKFILE" || exit 1
+
+# process all mails
+for MAILFILE in *.mail; do
+ MSMTPFILE="$(echo $MAILFILE | sed -e 's/mail/msmtp/')"
+ echo "*** Sending $MAILFILE to $(sed -e 's/^.*-- \(.*$\)/\1/' $MSMTPFILE) ..."
+ if [ ! -f "$MSMTPFILE" ]; then
+ echo "No corresponding file $MSMTPFILE found"
+ echo "FAILURE"
+ continue
+ fi
+ msmtp $OPTIONS $(cat "$MSMTPFILE") < "$MAILFILE"
+ if [ $? -eq 0 ]; then
+ rm "$MAILFILE" "$MSMTPFILE"
+ echo "$MAILFILE sent successfully"
+ else
+ echo "FAILURE"
+ fi
+done
+
+# remove the lock
+rm -f "$LOCKFILE"
+
+exit 0
diff --git a/.local/bin/powermenu b/.local/bin/powermenu
new file mode 100755
index 0000000..31a8f8a
--- /dev/null
+++ b/.local/bin/powermenu
@@ -0,0 +1,39 @@
+#!/usr/bin/env bash
+
+read -r wallpaper<~/.cache/wallpaper
+
+#### Options ###
+power_off=" Shutdown"
+reboot="󰜉 Reboot"
+lock_screen=" Lock Screen"
+suspend=" Suspend"
+hibernate="󰒲 Hibernate"
+log_out="󰍃﫼 Log Out"
+
+# Options passed to fuzzel
+options="$power_off\n$reboot\n$suspend\n$hibernate\n$log_out\n$lock_screen"
+lines="$(echo "$options" | grep -oF '\n' | wc -l)"
+rofi_command="fuzzel -d -w 14 -l $((lines+1))"
+chosen="$(echo -e "$options" | $rofi_command )"
+case $chosen in
+ "$lock_screen")
+ swaylock -f -i "$wallpaper"
+ ;;
+ "$power_off")
+ loginctl poweroff
+ ;;
+ "$reboot")
+ loginctl reboot
+ ;;
+ "$suspend")
+ $lock && loginctl suspend
+ ;;
+ "$hibernate")
+ $lock && loginctl hibernate
+ ;;
+ "$log_out")
+ #swaymsg exit
+ #loginctl terminate-session "${XDG_SESSION_ID-}"
+ riverctl exit
+ ;;
+esac
diff --git a/.local/bin/screenshot.sh b/.local/bin/screenshot.sh
new file mode 100755
index 0000000..cc9d3a6
--- /dev/null
+++ b/.local/bin/screenshot.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+case $1 in
+ selected-region)
+ # Take a screenshot of the selected region
+ grim -t jpeg -g "$(slurp)" ~/Pictures/Screenshots/"$(date +%Y-%m-%d_%H-%m-%s)".jpg
+ ;;
+ save-to-clipboard)
+ # Take a screenshot and save it to the clipboard
+ grim -g "$(slurp -d)" - | wl-copy
+ ;;
+ focused-window)
+ # Take a screenshot of the focused window
+ pos=$(hyprctl -j activewindow | grep 'at' | tr -dc '0-9 ')
+ xpos=$(echo "$pos" | awk '{ print $1 }')
+ xpos=$((xpos-2))
+ ypos=$(echo "$pos" | awk '{ print $2 }')
+ ypos=$((ypos-2))
+ size=$(hyprctl -j activewindow | grep 'size' | tr -dc '0-9 ')
+ xsize=$(echo "$size" | awk '{ print $1 }')
+ ysize=$(echo "$size" | awk '{ print $2 }')
+ xsize=$((xsize+4)) # Value added is 2 times the border width
+ ysize=$((ysize+4)) # Value added is 2 times the border width
+ grim -g "$xpos"",""$ypos $xsize""x""$ysize" -t jpeg ~/Pictures/Screenshots/"$(date +%Y-%m-%d_%H-%m-%s)".jpg
+ ;;
+ *)
+ # Take a screenshot of the currently focused output and save it into screenshots
+ output="$(hyprctl monitors | grep -B 12 'focused: yes' | grep 'Monitor' | awk '{ print $2 }')"
+ grim -o "$output" -t jpeg ~/Pictures/Screenshots/"$(date +%Y-%m-%d_%H-%m-%s)".jpg
+ ;;
+esac
diff --git a/.local/bin/ssh-askpass b/.local/bin/ssh-askpass
new file mode 100755
index 0000000..d3bbc91
--- /dev/null
+++ b/.local/bin/ssh-askpass
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+# Remember to export SSH_ASKPASS=~/.local/bin/ssh-askpass in your .bashrc
+RESULT=$(pinentry-curses --ttytype=xterm-color --lc-ctype=en_US.UTF8 --ttyname=/dev/tty <<END | grep -E '^(D|ERR)'
+SETDESC Enter your SSH password:
+SETPROMPT
+GETPIN
+END
+)
+
+if [ "$RESULT" == "ERR 111 canceled" ]; then
+ exit 255
+else
+ echo ${RESULT:2:${#RESULT}-2}
+fi