clean up comments

This commit is contained in:
Rowan 2025-03-07 12:30:13 -06:00
parent abb286ba2a
commit c3a3b1ab98

View file

@ -1,5 +1,6 @@
#!/usr/bin/env sh #!/usr/bin/env sh
# configure default XDG paths
XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}" XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}" XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}"
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}" XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
@ -22,14 +23,11 @@ subpath() {
parent_path="$1" parent_path="$1"
sub_path="$2" sub_path="$2"
# Normalize paths (remove trailing slashes, handle relative paths, etc.)
parent_path=$(cd "$parent_path" && pwd) parent_path=$(cd "$parent_path" && pwd)
sub_path=$(cd "$sub_path" && pwd) sub_path=$(cd "$sub_path" && pwd)
# Add trailing slash to parent_path if it doesn't have one
[[ "$parent_path" != */ ]] && parent_path+="/" [[ "$parent_path" != */ ]] && parent_path+="/"
# Check if sub_path starts with parent_path
if [[ "$sub_path" == "$parent_path"* ]]; then if [[ "$sub_path" == "$parent_path"* ]]; then
return 0 # is a subpath return 0 # is a subpath
else else
@ -60,6 +58,7 @@ CHANGESET="$CHANGESET_DIR/$SELECTED"
UPPER_DIR="$XDG_STATE_HOME/config/$SELECTED" UPPER_DIR="$XDG_STATE_HOME/config/$SELECTED"
WORKDIR="$XDG_STATE_HOME/config/.work_$SELECTED" WORKDIR="$XDG_STATE_HOME/config/.work_$SELECTED"
# no changeset has been given, display help and exit
if [ -z "$SELECTED" ]; then if [ -z "$SELECTED" ]; then
usage usage
exit exit
@ -80,7 +79,7 @@ if [ "$2" == "unmount" ]; then
exit 0 exit 0
fi fi
# Unmount if already mounted. # unmount if already mounted
if mountpoint -q "$MOUNT_POINT"; then if mountpoint -q "$MOUNT_POINT"; then
fusermount -u "$MOUNT_POINT" fusermount -u "$MOUNT_POINT"
fi fi
@ -108,6 +107,7 @@ diff "$TMP" "$SVC_FILE" > /dev/null 2>&1
HAS_DIFF=$? HAS_DIFF=$?
PROMPT=0 PROMPT=0
IS_HIDDEN=0 IS_HIDDEN=0
# is the generated service file different?
if [ "$HAS_DIFF" -gt 0 ]; then if [ "$HAS_DIFF" -gt 0 ]; then
if subpath "$MOUNT_POINT" "$SVC_PATH"; then if subpath "$MOUNT_POINT" "$SVC_PATH"; then
IS_HIDDEN=1 IS_HIDDEN=1
@ -119,9 +119,8 @@ if [ "$HAS_DIFF" -gt 0 ]; then
echo echo
fi fi
if [ "$HAS_DIFF" -eq 2 ]; then # either the file doesn't exist or -f is being used
mv "$TMP" "$SVC_FILE" if [ "$HAS_DIFF" -eq 2 ] && [ "$HAS_DIFF" -eq 1 ] && [ "$FORCE" -eq 1 ]; then
elif [ "$HAS_DIFF" -eq 1 ] && [ "$FORCE" -eq 1 ]; then
mv "$TMP" "$SVC_FILE" mv "$TMP" "$SVC_FILE"
elif [ "$HAS_DIFF" -eq 1 ] && [ "$FORCE" -eq 0 ]; then elif [ "$HAS_DIFF" -eq 1 ] && [ "$FORCE" -eq 0 ]; then
echo "INFO: Changes detected in existing service file but refusing to ovewrite." echo "INFO: Changes detected in existing service file but refusing to ovewrite."
@ -129,6 +128,7 @@ if [ "$HAS_DIFF" -gt 0 ]; then
echo echo
fi fi
# either enable the service file now, or prompt the user to do it later
if [ "$AUTOMOUNT" -eq 1 ]; then if [ "$AUTOMOUNT" -eq 1 ]; then
systemctl --user enable --now "$SVC_FILE" systemctl --user enable --now "$SVC_FILE"
else else