aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/dot-local/bin/alanvim3
-rwxr-xr-xscripts/dot-local/bin/aligncol41
-rwxr-xr-xscripts/dot-local/bin/batctl61
-rw-r--r--scripts/dot-local/bin/dot-editorconfig7
-rwxr-xr-xscripts/dot-local/bin/mailsync54
-rwxr-xr-xscripts/dot-local/bin/print.sh178
-rwxr-xr-xscripts/dot-local/bin/viml2
7 files changed, 346 insertions, 0 deletions
diff --git a/scripts/dot-local/bin/alanvim b/scripts/dot-local/bin/alanvim
new file mode 100755
index 0000000..5262939
--- /dev/null
+++ b/scripts/dot-local/bin/alanvim
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec runapp -- alacritty -e nvim "$@"
diff --git a/scripts/dot-local/bin/aligncol b/scripts/dot-local/bin/aligncol
new file mode 100755
index 0000000..5e7e375
--- /dev/null
+++ b/scripts/dot-local/bin/aligncol
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+usage() {
+ echo "Usage: $0 [-s specialchar] [-h] colmark [colmark ...]"
+}
+
+sflag=
+sep=
+
+while getopts "hs:" opt; do
+ case $opt in
+ s)
+ sflag=1
+ sep="$OPTARG"
+ ;;
+ h)
+ usage
+ exit 0
+ ;;
+ ?)
+ usage
+ exit 1
+ ;;
+ esac
+done
+if [ -z "$sflag" ]; then
+ sep='%'
+fi
+shift $((OPTIND - 1))
+
+sep_escaped=$(printf '%s\n' "$sep" | sed 's/[\/&]/\\&/g')
+
+sed_args=()
+for arg in "$@"; do
+ arg_escaped=$(printf '%s\n' "$arg" | sed 's/[\/&]/\\&/g')
+ sed_args+=(-e "s/$arg_escaped/$sep_escaped&/g")
+done
+
+sed "${sed_args[@]}" | column -t -s"$sep_escaped" -o' '
diff --git a/scripts/dot-local/bin/batctl b/scripts/dot-local/bin/batctl
new file mode 100755
index 0000000..d6fcaa1
--- /dev/null
+++ b/scripts/dot-local/bin/batctl
@@ -0,0 +1,61 @@
+#!/usr/bin/env bash
+
+set -eo pipefail
+
+DEFAULT_START_THRESHOLD=75
+DEFAULT_STOP_THRESHOLD=85
+
+BAT_DIR=/sys/class/power_supply/BAT0
+START_FILE="$BAT_DIR/charge_start_threshold"
+STOP_FILE="$BAT_DIR/charge_stop_threshold"
+
+setcharge()
+{
+ start=$1
+ stop=$2
+ cur_start=$(cat "$START_FILE")
+ cur_stop=$(cat "$STOP_FILE")
+
+ if ((cur_stop > stop)); then
+ echo "$start" | sudo tee "$START_FILE" >/dev/null
+ echo "$stop" | sudo tee "$STOP_FILE" >/dev/null
+ else
+ echo "$stop" | sudo tee "$STOP_FILE" >/dev/null
+ echo "$start" | sudo tee "$START_FILE" >/dev/null
+ fi
+ echo "Charging set:"
+ echo " start=$start"
+ echo " stop=$stop"
+}
+
+cmd=$1
+
+shift || true
+
+case "$cmd" in
+ show)
+ start=$(cat "$START_FILE")
+ stop=$(cat "$STOP_FILE")
+ echo "Current thresholds:"
+ echo " start=$start"
+ echo " stop=$stop"
+ ;;
+
+ set)
+ start=${1:-$DEFAULT_START_THRESHOLD}
+ stop=${2:-$DEFAULT_STOP_THRESHOLD}
+ setcharge "$start" "$stop"
+ ;;
+
+ fullcharge)
+ start=95
+ stop=100
+ echo "Fullcharge. Keep AC on!"
+ setcharge "$start" "$stop"
+ ;;
+
+ *)
+ echo "Usage: $0 {show|set [start=$DEFAULT_START_THRESHOLD] [stop=$DEFAULT_STOP_THRESHOLD]|fullcharge}" >&2
+ exit 1
+ ;;
+esac
diff --git a/scripts/dot-local/bin/dot-editorconfig b/scripts/dot-local/bin/dot-editorconfig
new file mode 100644
index 0000000..a882442
--- /dev/null
+++ b/scripts/dot-local/bin/dot-editorconfig
@@ -0,0 +1,7 @@
+root = true
+
+[*]
+end_of_line = lf
+insert_final_newline = true
+indent_style = space
+indent_size = 4
diff --git a/scripts/dot-local/bin/mailsync b/scripts/dot-local/bin/mailsync
new file mode 100755
index 0000000..8029444
--- /dev/null
+++ b/scripts/dot-local/bin/mailsync
@@ -0,0 +1,54 @@
+#!/usr/bin/env sh
+
+# Run only if not already running in other instance
+pgrep mbsync >/dev/null && {
+ echo "mbsync is already running."
+ exit
+}
+
+notify()
+{
+ notify-send --app-name="Mail" -- "$1" "$2"
+}
+
+# export GPG_TTY="$(tty)"
+# export DISPLAY=":0"
+# export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/"$(id -u)"/bus
+export MAILDIR="$XDG_DATA_HOME/mail"
+lastrun="$XDG_CACHE_HOME/.mailsynclastrun"
+# export PYTHONWARNINGS="ignore::UserWarning"
+
+# afew --move-mails --all
+mbsync -q mit
+
+new=$(find "$MAILDIR/mit/INBOX/new/" "$MAILDIR/mit/INBOX/cur/" -type f -newer "$lastrun" 2>/dev/null)
+newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l)
+
+case 1 in
+ $((newcount > 5)))
+ echo "$newcount new mail for mit."
+ notify "New Mail!" "$newcount new mail(s)."
+ ;;
+ $((newcount > 0)))
+ echo "$newcount new mail for mit."
+ for file in $new; do
+ # Extract and decode subject and sender from mail.
+ subject=$(awk '/^Subject: / && ++n == 1,/^.*: / && ++i == 2' "$file" | head -n-1 |
+ perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' |
+ sed 's/^Subject: //' | tr -d '\n\t')
+ from="$(sed -n "/^From:/ s|From: *|| p" "$file" |
+ perl -CS -MEncode -ne 'print decode("MIME-Header", $_)')"
+ from="${from% *}"
+ from="${from%\"}"
+ from="${from#\"}"
+ notify "$from:" "$subject"
+ done
+ ;;
+ *) echo "No new mail for mit." ;;
+esac
+
+# notmuch new
+# afew --tag --new
+
+#Create a touch file that indicates the time of the last run of mailsync
+touch "$lastrun"
diff --git a/scripts/dot-local/bin/print.sh b/scripts/dot-local/bin/print.sh
new file mode 100755
index 0000000..8e56519
--- /dev/null
+++ b/scripts/dot-local/bin/print.sh
@@ -0,0 +1,178 @@
+#!/usr/bin/env bash
+
+# Print Menu System
+# Interactive printer selection and options configuration
+
+set -euo pipefail
+
+TEMP_DIR="/tmp/rofi-print-$$"
+mkdir -p "$TEMP_DIR"
+
+trap 'rm -rf "$TEMP_DIR"' EXIT
+
+# Function to get list of printers
+get_printers() {
+ lpstat -p 2>/dev/null | awk '{print $2}' | sort
+}
+
+# Function to get printer options using lpoptions
+get_printer_options() {
+ local printer="$1"
+ lpoptions -p "$printer" -l 2>/dev/null || echo ""
+}
+
+# Function to parse option values
+parse_option_line() {
+ local line="$1"
+ local option_name=$(echo "$line" | cut -d'/' -f1 | tr -d ' ')
+ local values=$(echo "$line" | sed 's/^[^:]*: //')
+ echo "$option_name|$values"
+}
+
+# Function to get current default value
+get_default_value() {
+ local values="$1"
+ echo "$values" | grep -o '\*[^ ]*' | tr -d '*' || echo ""
+}
+
+# Function to get all available values
+get_available_values() {
+ local values="$1"
+ echo "$values" | tr ' ' '\n' | tr -d '*'
+}
+
+# Main script
+main() {
+ FILE="$1"
+
+ if [ ! -f "$FILE" ]; then
+ echo "File not provided or not found: $FILE" >&2
+ exit 1
+ fi
+
+ # Get available printers
+ PRINTERS=$(get_printers)
+ if [ -z "$PRINTERS" ]; then
+ echo "No printers found" >&2
+ exit 1
+ fi
+
+ # Select printer
+ PRINTER=$(echo "$PRINTERS" | fuzzel --dmenu -i -p "Select printer")
+ if [ -z "$PRINTER" ]; then
+ echo "No printer selected" >&2
+ exit 1
+ fi
+
+ # Get printer options
+ OPTIONS=$(get_printer_options "$PRINTER")
+
+ # Build lp command
+ LP_OPTS=()
+
+ # Process each option
+ declare -A selected_options
+
+ while IFS= read -r line; do
+ if [ -z "$line" ]; then continue; fi
+
+ # Parse option line
+ IFS='|' read -r opt_name values <<< "$(parse_option_line "$line")"
+
+ if [ -z "$opt_name" ] || [ -z "$values" ]; then continue; fi
+
+ # Get default and available values
+ default=$(get_default_value "$values")
+ available=$(get_available_values "$values")
+
+ # Create friendly names for common options
+ case "$opt_name" in
+ *Duplex*|*Sided*)
+ friendly_name="Duplex (Double-sided)"
+ ;;
+ *Staple*)
+ friendly_name="Stapling"
+ ;;
+ *MediaType*)
+ friendly_name="Paper Type"
+ ;;
+ *PageSize*|*media*)
+ friendly_name="Paper Size"
+ ;;
+ *OutputBin*)
+ friendly_name="Output Tray"
+ ;;
+ *Collate*)
+ friendly_name="Collate"
+ ;;
+ *ColorModel*|*Color*)
+ friendly_name="Color Mode"
+ ;;
+ *Resolution*)
+ friendly_name="Print Quality"
+ ;;
+ *)
+ friendly_name="$opt_name"
+ ;;
+ esac
+
+ # Present options to user with default highlighted
+ available_with_default=$(echo "$available" | sed "s/^${default}$/${default} (default)/")
+
+ selected=$(echo "$available_with_default" | fuzzel --dmenu -i -p "$friendly_name")
+
+ if [ -n "$selected" ]; then
+ # Remove " (default)" suffix if present
+ selected=$(echo "$selected" | sed 's/ (default)$//')
+
+ # Only add if different from default
+ if [ "$selected" != "$default" ]; then
+ selected_options["$opt_name"]="$selected"
+ fi
+ fi
+
+ done <<< "$OPTIONS"
+
+ # Ask for number of copies
+ COPIES=$(echo -e "1\n2\n3\n4\n5\n10\n20" | fuzzel --dmenu -i -p "Number of copies")
+ COPIES=${COPIES:-1}
+
+ # Build final lp command options
+ for opt in "${!selected_options[@]}"; do
+ LP_OPTS+=("-o" "${opt}=${selected_options[$opt]}")
+ done
+
+ if [ "$COPIES" -gt 1 ]; then
+ LP_OPTS+=("-n" "$COPIES")
+ fi
+
+ # Confirmation
+ OPTS_SUMMARY="Printer: $PRINTER\nFile: $(basename "$FILE")\nCopies: $COPIES"
+ if [ ${#selected_options[@]} -gt 0 ]; then
+ OPTS_SUMMARY+="\n\nOptions:"
+ for opt in "${!selected_options[@]}"; do
+ OPTS_SUMMARY+="\n $opt = ${selected_options[$opt]}"
+ done
+ fi
+
+ echo lp -d "$PRINTER" "${LP_OPTS[@]}" "$FILE" 2>"$TEMP_DIR/error.log"
+
+ echo "$OPTS_SUMMARY"
+ CONFIRM=$(echo -e "Print\nCancel" | fuzzel --dmenu -i -p "Confirm print job")
+
+ if [ "$CONFIRM" = "Print" ]; then
+ # Execute print command
+ if lp -d "$PRINTER" "${LP_OPTS[@]}" "$FILE" 2>"$TEMP_DIR/error.log"; then
+ notify-send "Print.sh" "Print job submitted successfully"
+ else
+ ERROR=$(cat "$TEMP_DIR/error.log")
+ echo "Print failed:\n$ERROR" >&2
+ exit 1
+ fi
+ else
+ echo "Print cancelled"
+ exit 0
+ fi
+}
+
+main "$@"
diff --git a/scripts/dot-local/bin/viml b/scripts/dot-local/bin/viml
new file mode 100755
index 0000000..eef5b0b
--- /dev/null
+++ b/scripts/dot-local/bin/viml
@@ -0,0 +1,2 @@
+#!/bin/sh
+VIM_LIGHT=1 /usr/bin/nvim "$@"