aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustine Smithies <justine@smithies.me.uk>2023-08-22 19:35:23 +0100
committerJustine Smithies <justine@smithies.me.uk>2023-08-22 19:35:23 +0100
commit3058d6df77817de298a207d36b8b0871893c417a (patch)
tree2f3cbb973751e0f829ad3e00dd52bc5a081936d5
parent1125d4a4ee25de42f3223d612a50a1256bd222d3 (diff)
Initial commit
-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/qtile-window-switcher.py92
-rwxr-xr-x.local/bin/screenshot.sh28
-rwxr-xr-x.local/bin/ssh-askpass14
8 files changed, 317 insertions, 0 deletions
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..aeded37
--- /dev/null
+++ b/.local/bin/powermenu
@@ -0,0 +1,39 @@
+#!/bin/bash
+lock="swaylock -f -i ~/.cache/wallpaper"
+
+#lock="swaylock -f -i ~/.cache/wallpaper --effect-blur 10x5 --clock --indicator"
+
+#### 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")
+ $lock
+ ;;
+ "$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-}"
+ ;;
+esac
diff --git a/.local/bin/qtile-window-switcher.py b/.local/bin/qtile-window-switcher.py
new file mode 100755
index 0000000..000a176
--- /dev/null
+++ b/.local/bin/qtile-window-switcher.py
@@ -0,0 +1,92 @@
+#!/usr/bin/env python
+#
+# Qtile window switcher for Wayland only
+#
+# Justine Smithies - 2021
+#
+# Requirements are: qtile running under Wayland and fuzzel-git
+
+import subprocess
+import os
+import re
+from libqtile.command.client import InteractiveCommandClient
+
+client = InteractiveCommandClient()
+windows = client.windows()
+# Get the number of open windows
+lines = (len(windows))
+x = 0
+names = []
+ids = []
+groups = []
+appids = []
+while x < lines:
+ # client.window[window_id].focus() etc
+ win = windows[x]
+ name = win.get("name")
+ names.append(name)
+ id = win.get("id")
+ ids.append(id)
+ group = win.get("group")
+ groups.append(group)
+ appid = win.get("wm_class")[0]
+ appids.append(appid)
+ print(name, id, group, appid)
+ x += 1
+print(windows)
+
+# Reverse the tuples
+ids = ids[::-1]
+groups = groups[::-1]
+names = names[::-1]
+appids = appids[::-1]
+
+# Combine all the information into a string to be piped through rofi -dmenu
+d = dict(os.environ)
+outputs = []
+output = []
+icon = []
+x = 0
+print(lines)
+while x < lines:
+ id = ids[x]
+ id = str(id)
+ appid = (appids[x]).strip('\n')
+ name = names[x]
+ # If name is > 40 characters then shorten it to max 40 and append ...
+ if len(name) > 40:
+ name = name[:40] + '...'
+ group = groups[x]
+ # Hacky fix to get correct icon for appids that begin with org.
+ if 'org.' in appid:
+ icon = appid.split(".")
+ icon = str(icon[2].lower())
+ else:
+ icon = appid
+ output = ' ' + appid + ' - ' + name + ' on group: ' + group + ' (' + id + ')' + r'\0icon\x1f' + icon + '\n'
+ outputs.append(str(output))
+ x += 1
+
+outputs = ''.join(outputs)
+# Remove last blank line
+outputs = os.linesep.join([s for s in outputs.splitlines() if s])
+print(outputs)
+
+# Send options to rofi
+d["OPTIONS"] = outputs
+d["LINES"] = str(lines)
+result = subprocess.Popen('echo -e "$OPTIONS" | fuzzel -d -w 100 -l $LINES', shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=d)
+
+# Get selected option and process
+selected_option = str(result.communicate())
+print(selected_option)
+# Search for the content between the last set of brackets
+selected_option = re.sub('^.*\((.*?)\)[^\(]*$', '\g<1>', selected_option)
+print(selected_option)
+if True in [char.isdigit() for char in selected_option]:
+ selected_option = int(selected_option)
+ client.window[selected_option].group.toscreen()
+ client.window[selected_option].focus()
+ exit()
+else:
+ exit()
diff --git a/.local/bin/screenshot.sh b/.local/bin/screenshot.sh
new file mode 100755
index 0000000..bb4bdb6
--- /dev/null
+++ b/.local/bin/screenshot.sh
@@ -0,0 +1,28 @@
+#!/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
+ ;;
+ selected-window)
+ pos=$(qtile cmd-obj -o window -f get_position | awk '{ print $1" "$2}' | tr -dc '0-9 ')
+ xpos=$(echo $pos | awk '{ print $1 }')
+ ypos=$(echo $pos | awk '{ print $2 }')
+ size=$(qtile cmd-obj -o window -f get_size | awk '{ print $1" "$2}' | 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="$(qtile cmd-obj -o core -f eval -a "self._current_output.wlr_output.name" | awk -F"['']" '/,/{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