aboutsummaryrefslogtreecommitdiff
path: root/.local
diff options
context:
space:
mode:
authorJustine Smithies <justine@smithies.me.uk>2025-11-04 20:40:38 +0000
committerJustine Smithies <justine@smithies.me.uk>2025-11-04 20:40:38 +0000
commitaa66d791c82e02e6e5529d906d4009daf8bb34f9 (patch)
tree7f8d7b1d519a6e6ded08cd37146c371f04fbc5cb /.local
parentb347fc3db35ef68103beb4b735a5e9df04b3a082 (diff)
Initial commit
Diffstat (limited to '.local')
-rwxr-xr-x.local/bin/bar-toggle.sh61
-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
6 files changed, 258 insertions, 0 deletions
diff --git a/.local/bin/bar-toggle.sh b/.local/bin/bar-toggle.sh
new file mode 100755
index 0000000..c39de27
--- /dev/null
+++ b/.local/bin/bar-toggle.sh
@@ -0,0 +1,61 @@
+#!/bin/sh
+# Toggle Polybar on the currently focused monitor under bspwm
+
+get_polybar_id() {
+# List monitors and extract names
+monitors=$(polybar --list-monitors | cut -d":" -f1)
+
+# Get PIDs of polybar processes
+pids=$(pgrep polybar)
+
+# Get the currently focused monitor name
+focused=$(bspc query -M -m focused --names)
+
+# Convert monitors to an array
+set -- "$monitors"
+mon_count=$# # Number of monitors
+
+# Initialize index
+ind=0
+
+# Find the index of the focused monitor
+for monitor in $monitors; do
+ ind=$((ind + 1))
+ if [ "$monitor" = "$focused" ]; then
+ break
+ fi
+done
+
+# Extract the correct PID based on the index
+# Convert pids into an array using space as a delimiter
+pid_array=$(echo "$pids" | tr ' ' '\n')
+poly_id=$(echo "$pid_array" | sed -n "${ind}p")
+
+# Check if poly_id is set; if not, exit with an error
+if [ -z "$poly_id" ]; then
+ echo "No PID found for the focused monitor."
+ exit 1
+fi
+}
+
+get_polybar_id
+
+# Define the state file
+STATE_FILE="/tmp/polybar_toggle_state.$poly_id"
+
+# Check if the state file exists, create it if it doesn't
+if [ ! -f "$STATE_FILE" ]; then
+ echo "show" > "$STATE_FILE" # Default state
+fi
+
+# Read the current state
+CURRENT_STATE=$(cat "$STATE_FILE")
+
+# Toggle the state
+if [ "$CURRENT_STATE" == "show" ]; then
+ echo "hide" > "$STATE_FILE"
+ polybar-msg -p "$poly_id" cmd hide | bspc config -m "$focused" top_padding 0
+else
+ echo "show" > "$STATE_FILE"
+ polybar-msg -p "$poly_id" cmd show
+fi
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..b717267
--- /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")
+ bspc 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