Skip to content

Commit

Permalink
Refs #118, added suspend/zzz command with different variants how to p…
Browse files Browse the repository at this point in the history
…rocess the command.
  • Loading branch information
tvrzna committed Aug 8, 2024
1 parent 2abb75b commit b2a7f3e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type config struct {
SelectLastUser enSelectLastUser `config:"SELECT_LAST_USER" parser:"ParseSelectLastUser" default:"false"`
CmdPoweroff string `config:"CMD_POWEROFF" parser:"SanitizeValue" default:"poweroff"`
CmdReboot string `config:"CMD_REBOOT" parser:"SanitizeValue" default:"reboot"`
CmdSuspend string `config:"CMD_SUSPEND" parser:"SanitizeValue" default:""`
}

// LoadConfig handles loading of application configuration.
Expand Down
24 changes: 24 additions & 0 deletions src/emptty.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ Available commands:
:help, :? print this help
:poweroff, :shutdown process poweroff command
:reboot process reboot command
:suspend, :zzz process suspend command
`)
waitForReturnToExit(0)
case "poweroff", "shutdown":
Expand All @@ -204,6 +205,29 @@ Available commands:
} else {
waitForReturnToExit(0)
}
case "suspend", "zzz":
var variants []string
if c.CmdSuspend != "" {
variants = append(variants, c.CmdSuspend)
}
variants = append(variants, "zzz")
variants = append(variants, "systemctl suspend")
variants = append(variants, "loginctl suspend")

var err error
for _, v := range variants {
if err = processCommandAsCmd(v); err != nil {
continue
} else {
break
}
}

if err != nil {
handleErr(err)
} else {
waitForReturnToExit(0)
}
default:
handleStrErr(fmt.Sprintf("Unknown command '%s'", command))
}
Expand Down

0 comments on commit b2a7f3e

Please # to comment.