aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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/powermenu.sh39
-rwxr-xr-x.local/bin/screenshot.sh37
5 files changed, 197 insertions, 0 deletions
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.sh b/.local/bin/powermenu.sh
new file mode 100755
index 0000000..fabc31a
--- /dev/null
+++ b/.local/bin/powermenu.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+# read -r wallpaper<~/.cache/wallpaper
+
+#### Options ###
+power_off=" Shutdown"
+reboot="󰜉 Reboot"
+lock_screen=" Lock Screen"
+suspend=" Suspend"
+hibernate="󰒲 Hibernate"
+log_out="󰍃 Log Out"
+
+lock="swaylock -f -i "$wallpaper""
+
+# Options passed to rofi
+# options="$power_off\n$reboot\n$suspend\n$hibernate\n$log_out\n$lock_screen"
+options="$power_off\n$reboot\n$log_out\n$lock_screen"
+rofi_command="rofi -theme themes/power-menu.rasi -i "
+chosen="$(echo -e "$options" | $rofi_command -dmenu -mesg "Power Menu" )"
+case $chosen in
+ "$lock_screen")
+ xlock -mode julia
+ ;;
+ "$power_off")
+ doas halt -p
+ ;;
+ "$reboot")
+ doas reboot
+ ;;
+ # "$suspend")
+ # $lock && zzz
+ # ;;
+ # "$hibernate")
+ # # $lock && WIP
+ # ;;
+ "$log_out")
+ herbstclient quit
+ ;;
+esac
diff --git a/.local/bin/screenshot.sh b/.local/bin/screenshot.sh
new file mode 100755
index 0000000..dff8701
--- /dev/null
+++ b/.local/bin/screenshot.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+img_path=~/Pictures/Screenshots/"$(date +%Y-%m-%d_%H-%m-%s)".png
+
+current_screen() {
+ MONITORS=$(xrandr | grep -o '[0-9]*x[0-9]*[+-][0-9]*[+-][0-9]*')
+ for mon in ${MONITORS}; do
+ # Parse the geometry of the monitor
+ MONW=$(echo "${mon}" | awk -F "[x+]" '{print $1}')
+ MONH=$(echo "${mon}" | awk -F "[x+]" '{print $2}')
+ MONX=$(echo "${mon}" | awk -F "[x+]" '{print $3}')
+ MONY=$(echo "${mon}" | awk -F "[x+]" '{print $4}')
+ done
+}
+
+case $1 in
+ selected-region)
+ # Take a screenshot of the selected region
+ maim -s "${img_path}"
+ ;;
+ selected-window)
+ # Take a screenshot of the selected window
+ maim -i $(xdotool getactivewindow) "${img_path}"
+ ;;
+ save-to-clipboard)
+ # Take a screenshot and save it to the clipboard
+ current_screen
+ maim -g "${MONW}x${MONH}+${MONX}+${MONY}" | xclip -selection clipboard -t image/png
+ exit 0
+ ;;
+ *)
+ # Take a screenshot of the currently focused output and save it into screenshots
+ current_screen
+ maim -g "${MONW}x${MONH}+${MONX}+${MONY}" "${img_path}"
+ exit 0
+ ;;
+esac