summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/gui/nsend28
-rwxr-xr-xscripts/gui/sclip21
-rwxr-xr-xscripts/gui/sslock49
-rwxr-xr-xscripts/gui/swall3
-rwxr-xr-xscripts/slib49
5 files changed, 111 insertions, 39 deletions
diff --git a/scripts/gui/nsend b/scripts/gui/nsend
index 80e1764..1bfc1f4 100755
--- a/scripts/gui/nsend
+++ b/scripts/gui/nsend
@@ -14,19 +14,21 @@ EOF
exit 0
}
-check_program "notify-send" "libnotify must be installed"
-
-case "${1}" in
-"-s")
- [ "${#}" -gt 3 ] && invalid_use
-
- shift
- eval $(printf 'notify-send "%s" "%s"' "${1}" "${2}")
-
- exit 0
+case "${#}" in
+1)
+ [ "${1}" = "-h" ] && help
+ invalid_use
+;;
+2)
+ [ "${1}" = "-s" ] || invalid_use
+ notification_string="${2}"
+;;
+3)
+ [ "${1}" = "-s" ] || invalid_use
+ notification_string="${2}: ${3}"
;;
-"-h") help ;;
-
*) invalid_use ;;
-
esac
+
+
+send_notification "${notification_string}"
diff --git a/scripts/gui/sclip b/scripts/gui/sclip
index 3666448..3d2caa5 100755
--- a/scripts/gui/sclip
+++ b/scripts/gui/sclip
@@ -18,12 +18,15 @@ exit 0
check_program "xclip"
i_flg=0
-while getopts "f:c:ih" option; do
+silent=0
+while getopts "f:c:sih" option; do
case "${option}" in
f) filepath="${OPTARG}" ;;
c) input="${OPTARG}" ;;
+ s) silent=1 ;;
+
i) i_flg=1 ;;
h) help ;;
@@ -38,6 +41,11 @@ shift $((OPTIND - 1))
if [ -n "${filepath}" ]; then
mime_type=$(file --mime-type -b "${filepath}")
+
+ if [ "${silent}" -eq 1 ]; then
+ run "xclip -selection clipboard -t ${mime_type} -i ${filepath}"
+ fi
+
run --success-notify "${filepath} copied" \
--failure-notify "${filepath} failed to copy" \
"xclip -selection clipboard -t ${mime_type} -i ${filepath}"
@@ -46,8 +54,17 @@ fi
[ "${i_flg}" -eq 1 ] && input=$(cat)
if [ -n "${input}" ]; then
+ # Don't use `run` since pipes are used
printf '%s' "${input}" | xclip -selection clipboard
- exit 0
+
+ if [ $? -eq 0 ]; then
+ [ "${silent}" -eq 0 ] && send_notification "${argv0}:" "'${input}' copied"
+ exit 0
+ fi
+
+ [ "${silent}" -eq 0 ] && send_notification "${argv0}:" "'${input}' failed to copy"
+
+ exit 1
fi
run "xclip -o -selection clipboard"
diff --git a/scripts/gui/sslock b/scripts/gui/sslock
index 0751de7..26ba2cf 100755
--- a/scripts/gui/sslock
+++ b/scripts/gui/sslock
@@ -4,7 +4,12 @@
help() {
cat << EOF
-${0}: Wrapper script to set lock the screen
+${0}: Wrapper script to take screenshots
+options:
+ -n Black screen
+ -b Blur
+ -c Take the current state of the desktop
+ -h Print this message and exit
EOF
exit 0
@@ -12,9 +17,43 @@ exit 0
check_program "slock"
-[ "${#}" -eq 1 ] && [ "${1}" = "-h" ] && help
+blur=0
+set_current_state=0
+current_wallpaper="${XDG_CACHE_HOME:-$HOME/.cache}/wallpaper/current"
+while getopts "bcnh" option; do
+ case "${option}" in
+ b)
+ check_program "mogrify" "imagemagick must be installed"
+ blur=1 ;;
-[ "${#}" != 0 ] && invalid_use
+ c)
+ check_program "scrot"
+ set_current_state=1
+ ;;
+ n)
+ slock
+ exit 0;;
-BACKGROUND="${XDG_CACHE_HOME:-$HOME/.cache}/wallpaper/current"
-slock -f "${BACKGROUND}"
+ h) help ;;
+
+ *) invalid_use -h ;;
+
+ esac
+done
+
+shift $((OPTIND - 1))
+
+[ "${#}" -eq 0 ] || invalid_use
+
+background="/tmp/$(date '+%b%d::%H%M%S').png"
+
+if [ "$set_current_state" -eq 0 ]; then
+ # Avoid distorting the wallpaper when calling `mogrify`
+ cp "${current_wallpaper}" "${background}"
+else
+ scrot -z "${background}"
+fi
+
+[ "${blur}" -eq 1 ] && mogrify -blur 0x8 "${background}"
+
+slock -f "${background}"
diff --git a/scripts/gui/swall b/scripts/gui/swall
index 9cb9e39..a225481 100755
--- a/scripts/gui/swall
+++ b/scripts/gui/swall
@@ -18,7 +18,6 @@ EOF
exit 0
}
-
check_program "xwallpaper"
SYMLINK="${XDG_CACHE_HOME:-$HOME/.cache}/wallpaper/current"
@@ -59,7 +58,7 @@ if [ -n "${input}" ]; then
fi
if [ -n "${waldir}" ]; then
- image=$(find "${waldir}" -iregex '.*.\(jpg\|jpeg\|png\|gif\)' 2>/dev/null \
+ image=$(find "${waldir}" -iregex '.*.\(jpg\|jpeg\|png\)' 2>/dev/null \
| shuf -n 1 )
fi
diff --git a/scripts/slib b/scripts/slib
index 0e0de36..4e21eb6 100755
--- a/scripts/slib
+++ b/scripts/slib
@@ -1,7 +1,6 @@
#!/bin/sh
-# Avoid using full paths instead only use the program names.
-argv0="${0}"
+argv0=$(basename "${0}")
# @FUNCTION: err
# @USAGE: [-x] <message> ...
@@ -14,7 +13,6 @@ argv0="${0}"
# This function is intended for fatal errors; it always exits the script.
# @EXAMPLE:
# err "Invalid usage" "Try '${argv0} -h' for help."
-
err() {
if [ "${1}" != "-x" ]; then
printf "%s: " "${argv0}"
@@ -61,21 +59,38 @@ check_program() {
err "${1} must be installed"
}
+# @FUNCTION: send_notification
+# @USAGE: send_notification <message> ...
+# @DESCRIPTION:
+# Write a notification message to a temporary file and trigger a dwm notification signal.
+# The message is written to /tmp/noti.txt. If writing fails, a warning is printed to stderr.
+# After writing, a dwm signal is sent using `xsetroot -name "fsignal:1"`.
+#
+# @EXAMPLE:
+# Send a desktop notification with the message "Backup complete".
+#
+# send_notification "Backup complete"
+
+send_notification() {
+ echo "$@" > /tmp/noti.txt || echo "Warning: failed to write to notification file" >&2
+ xsetroot -name "fsignal:1"
+}
+
# @FUNCTION: run
-# @USAGE: [--reload-status] [--reload-compositor] [--on-success <cmd>] [--on-failure <cmd>] <command> [success-msg] [failure-msg]
+# @USAGE: [--reload-status] [--reload-compositor] [--success-notify <msg>] [--failure-notify <msg>] <command> [success-msg] [failure-msg]
# @DESCRIPTION:
# Safely execute a simple shell command, print optional success/failure messages,
-# and optionally reload status bars or restart the compositor.
+# and optionally reload the status bar or restart the compositor.
#
# Success messages are printed to stdout; failure messages are printed to stderr.
-# To specify a failure message, a success message must also be provided.
+# Optional desktop notifications can be sent using --success-notify and --failure-notify.
# Command output is not suppressed.
#
# Options:
# --reload-status Reload the status bar (via `slreload`).
# --reload-compositor Restart the compositor (kills and restarts `picom`).
-# --on-success <cmd> Run another command if the main command succeeds.
-# --on-failure <cmd> Run another command if the main command fails.
+# --success-notify <msg> Send a desktop notification on success.
+# --failure-notify <msg> Send a desktop notification on failure.
#
# Restrictions:
# - Does NOT use `eval`; only simple commands and arguments are supported.
@@ -83,7 +98,7 @@ check_program() {
# - This design prevents unintended execution and makes the function safe in scripts.
#
# Return value:
-# 0 if the command succeeds, 1 otherwise.
+# Exits with 0 if the command succeeds, 1 otherwise.
#
# @EXAMPLES:
# # Run xwallpaper and print the image path on success
@@ -92,10 +107,10 @@ check_program() {
# # Restart compositor and show a success message
# run --reload-compositor "xwallpaper --zoom ${image}" "Wallpaper updated" "Wallpaper failed"
#
-# # With success and failure hooks
-# run --on-success "notify-send 'OK'" \
-# --on-failure "notify-send 'Failed'" \
-# "cp config config.bak" "Backup complete" "Backup failed"
+# # With notification hooks
+# run --success-notify "Wallpaper set" \
+# --failure-notify "Wallpaper failed" \
+# "xwallpaper --zoom ${image}" "Wallpaper updated" "Wallpaper failed"
run() {
relstat=0
@@ -105,8 +120,8 @@ run() {
case "$1" in
--reload-status) relstat=1 ;;
--reload-compositor) compstat=1 ;;
- --on-success) success_command="${2}"; shift ;;
- --on-failure) failure_command="${2}"; shift ;;
+ --success-notify) success_msg="${2}"; shift ;;
+ --failure-notify) failure_msg="${2}"; shift ;;
*) break;
esac
shift
@@ -118,10 +133,10 @@ run() {
if ${1}; then
[ -n "${2}" ] && echo "${2}"
- [ -n "${success_command}" ] && sh -c "${success_command}"
+ [ -n "${success_msg}" ] && send_notification "${argv0}:" "${success_msg}"
else
[ -n "${3}" ] && err "${3}"
- [ -n "${failure_command}" ] && sh -c "${failure_command}"
+ [ -n "${failure_msg}" ] && send_notification "${argv0}:" "${failure_msg}"
exit 1
fi