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