aboutsummaryrefslogtreecommitdiff
path: root/.local
diff options
context:
space:
mode:
Diffstat (limited to '.local')
-rwxr-xr-x.local/bin/emoji-menu.sh18
-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/power-menu-fuzzel.sh42
-rwxr-xr-x.local/bin/power-menu-rofi.sh47
-rwxr-xr-x.local/bin/screenshot.sh31
-rwxr-xr-x.local/bin/ssh-askpass.sh16
9 files changed, 298 insertions, 0 deletions
diff --git a/.local/bin/emoji-menu.sh b/.local/bin/emoji-menu.sh
new file mode 100755
index 0000000..ec6711b
--- /dev/null
+++ b/.local/bin/emoji-menu.sh
@@ -0,0 +1,18 @@
+#!/bin/sh -eu
+# From: https://git.sr.ht/~emersion/dotfiles/tree/6575f89856d012c2c31e9e7d2c807f350c7503d4/item/bin/emoji-menu
+# This version uses `fuzzel` instead of `rofi`.
+
+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-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/power-menu-fuzzel.sh b/.local/bin/power-menu-fuzzel.sh
new file mode 100755
index 0000000..a182d31
--- /dev/null
+++ b/.local/bin/power-menu-fuzzel.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+# Get current set wallpaper for the lockscreen option
+read -r wallpaper<~/.cache/wallpaper
+
+# Option text to display
+power_off=" Shutdown"
+reboot="󰜉 Reboot"
+lock_screen=" Lock Screen"
+suspend=" Suspend"
+hibernate="󰒲 Hibernate"
+log_out="󰍃 Log Out"
+
+#lock="swaylock -f -i "$wallpaper""
+lock="swaylock -f -i $wallpaper --effect-blur 10x5 --clock --datestr '%a %d %b %Y' --indicator"
+
+# 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" --effect-blur 10x5 --clock --datestr "%a %d %b %Y" --indicator
+ ;;
+ "$power_off")
+ doas poweroff
+ ;;
+ "$reboot")
+ doas reboot
+ ;;
+ "$suspend")
+ $lock && doas zzz
+ ;;
+ "$hibernate")
+ # $lock && WIP
+ ;;
+ "$log_out")
+ mmsg -d quit
+ ;;
+esac
diff --git a/.local/bin/power-menu-rofi.sh b/.local/bin/power-menu-rofi.sh
new file mode 100755
index 0000000..a1de712
--- /dev/null
+++ b/.local/bin/power-menu-rofi.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+# Get current set wallpaper for the lockscreen option
+read -r wallpaper<~/.cache/wallpaper
+
+lock="swaylock -f -i $wallpaper --effect-blur 10x5 --clock --datestr '%a %d %b %Y' --indicator"
+
+# Option text to Display
+power_off=" Shutdown"
+reboot="󰜉 Reboot"
+lock_screen=" Lock Screen"
+suspend=" Suspend"
+hibernate="󰒲 Hibernate"
+log_out="󰍃 Log Out"
+
+# Menu display order
+options="$power_off\n$reboot\n$suspend\n$hibernate\n$log_out\n$lock_screen"
+
+case "$@" in
+ "$power_off")
+ doas poweroff
+ exit 0
+ ;;
+ "$reboot")
+ doas reboot
+ exit 0
+ ;;
+ "$suspend")
+ $lock && doas zzz
+ exit 0
+ ;;
+ "$hibernate")
+ # $lock && WIP
+ exit 0
+ ;;
+ "$log_out")
+ mmsg -d quit
+ exit 0
+ ;;
+ "$lock_screen")
+ swaylock -f -i "$wallpaper" --effect-blur 10x5 --clock --datestr "%a %d %b %Y" --indicator
+ exit 0
+ ;;
+esac
+
+# Display all options in menu
+echo -e "$options"
diff --git a/.local/bin/screenshot.sh b/.local/bin/screenshot.sh
new file mode 100755
index 0000000..9481323
--- /dev/null
+++ b/.local/bin/screenshot.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+# Get focused output
+output="$(mmsg -g | grep "selmon 1" | awk '{print$1}')"
+
+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
+ xpos=$(mmsg -g -x -o "$output" | grep "x" | awk '{print$2}')
+ xpos=$((xpos-2))
+ ypos=$(mmsg -g -x -o "$output" | grep "y" | awk '{print$2}')
+ ypos=$((ypos-2))
+ xsize=$(mmsg -g -x -o "$output" | grep "width" | awk '{print$2}')
+ ysize=$(mmsg -g -x -o "$output" | grep "height" | 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
+ grim -o "$output" -t jpeg ~/Pictures/Screenshots/"$(date +%Y-%m-%d_%H-%m-%s)".jpg
+ ;;
+esac
diff --git a/.local/bin/ssh-askpass.sh b/.local/bin/ssh-askpass.sh
new file mode 100755
index 0000000..234457a
--- /dev/null
+++ b/.local/bin/ssh-askpass.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+# Remember to export SSH_ASKPASS=~/.local/bin/ssh-askpass.sh
+RESULT=$(pinentry-qt --ttytype=xterm-color --lc-ctype=en_US.UTF8 --ttyname=/dev/tty <<END | grep -E '^(D|ERR)'
+SETDESC Enter your passphrase for key:
+SETPROMPT
+GETPIN
+END
+)
+
+if [ "$RESULT" = "ERR 111 canceled" ]; then
+ exit 255
+else
+ length=$(printf "%s" "$RESULT" | wc -c)
+ length=$((length))
+ echo "$RESULT" : '..' | cut -c 3-"$length"
+fi