Skip to content

Commit

Permalink
🎨 add some logging to the cli improvements clemenstyp added
Browse files Browse the repository at this point in the history
  • Loading branch information
actuallymentor committed Mar 12, 2023
1 parent b3e268e commit 010eeda
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion battery.sh
Original file line number Diff line number Diff line change
Expand Up @@ -487,19 +487,29 @@ if [[ "$action" == "create_daemon" ]]; then
"

mkdir -p "${daemon_path%/*}"

# check if daemon already exists
if test -f "$daemon_path"; then

log "Daemon already exists, checking for differences"
daemon_definition_difference=$(diff --brief --ignore-space-change --strip-trailing-cr --ignore-blank-lines <( cat "$daemon_path" 2> /dev/null ) <(echo "$daemon_definition"))

# remove leading and trailing whitespaces
daemon_definition_difference=$(echo "$daemon_definition_difference" | xargs)
if [[ "$daemon_definition_difference" != "" ]]; then
# daemon_definition changed: replace with new definitions

log "daemon_definition changed: replace with new definitions"
echo "$daemon_definition" > "$daemon_path"

fi
else

# daemon not available, create new launch deamon
log "Daemon does not yet exist, creating daemon file at $daemon_path"
echo "$daemon_definition" > "$daemon_path"

fi

# enable daemon
launchctl enable "gui/$(id -u $USER)/com.battery.app"
exit 0
Expand All @@ -509,6 +519,7 @@ fi
# Disable daemon
if [[ "$action" == "disable_daemon" ]]; then

log "Disabling daemon at gui/$(id -u $USER)/com.battery.app"
launchctl disable "gui/$(id -u $USER)/com.battery.app"
exit 0

Expand Down

0 comments on commit 010eeda

Please sign in to comment.