From c5fc2f5876ca10250079d51a63a54112d1c661c6 Mon Sep 17 00:00:00 2001
From: Case Duckworth
Date: Fri, 29 Jul 2022 15:01:01 -0500
Subject: Add caveat emptor

---
 autoshart.sh | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/autoshart.sh b/autoshart.sh
index 4868846..9e9a1a7 100755
--- a/autoshart.sh
+++ b/autoshart.sh
@@ -5,6 +5,9 @@
 #
 # Commentary:
 #
+# An autostart script.  Called "autoshart" because I literally sharted it out,
+# and have /not/ tested it at all. So, caveat emptor, I guess.
+#
 # Freedesktop autostart specification:
 # https://specifications.freedesktop.org/autostart-spec/latest/
 # Freedesktop desktop entry specification:
@@ -19,12 +22,13 @@ usage() {
 	cat <<EOF
 AUTOSHART: autostart without the shit
 USAGE:	autoshart -h
-	autoshart [-k] [-n]
+	autoshart [-k] [-n] [-q]
 
 FLAGS:
  -h	Show this help and exit.
  -k	Kill all processes started by autoshart and exit.
  -n	Only print what would happen; don't execute anything.
+ -q	Don't print any output.
 EOF
 }
 
@@ -45,6 +49,8 @@ main() {
 	auto_search
 }
 
+## Library functions
+
 auto_kill() {
 	cat "$PID_FILE" | xargs kill
 }
@@ -193,9 +199,13 @@ auto_search() { ## auto_search
 		while read dir; do
 			if test -d "$dir"; then
 				for desktop in "$dir"/*.desktop; do
-					if ! grep "$desktop" "$FOUND_FILE"; then
+					if ! grep -q "$desktop" "$FOUND_FILE"; then
 						auto_start "$desktop" &&
-							print "$desktop" >>"$FOUND_FILE"
+							# `echo' here is
+							# important; it /needs/
+							# to be output to the
+							# $FOUND_FILE
+							echo "$desktop" >>"$FOUND_FILE"
 					else
 						eprint "Already executed: $desktop"
 					fi
@@ -204,7 +214,7 @@ auto_search() { ## auto_search
 		done
 }
 
-####################################
+## Convenience functions
 
 get() { # get KEY FILE
 	grep "^$1" "${2:-}" 2>/dev/null | cut -d= -f2-
@@ -226,6 +236,7 @@ die() {
 	exit $errcode
 }
 
-####################################
+## Entry point
 
+test "$DEBUG" && set -x
 main "$@"
-- 
cgit 1.4.1-21-gabe81