From 8dccc692e8668abca569515908f20be88686bf07 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Thu, 9 Oct 2014 08:55:20 -0400 Subject: [PATCH] adding a setting for when not running X --- config/config.go | 20 ++++++++++++++++---- lockout/main.go | 5 ++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/config/config.go b/config/config.go index 7cf4239..733c48b 100644 --- a/config/config.go +++ b/config/config.go @@ -4,18 +4,25 @@ import ( "fmt" "io" "io/ioutil" - "launchpad.net/goyaml" "os" "os/exec" "strings" + + "launchpad.net/goyaml" ) type Config struct { - SuspendCmd, LockCmd string + SuspendCmd, LockCmd string + NoXSuspendCmd, NoXLockCmd string } func (c *Config) Suspend() (err error) { - args := strings.Split(c.SuspendCmd, " ") + var args []string + if len(os.Getenv("DISPLAY")) > 0 { + args = strings.Split(c.SuspendCmd, " ") + } else { + args = strings.Split(c.NoXSuspendCmd, " ") + } cmd := exec.Command(args[0], args[1:]...) stdout, err := cmd.StdoutPipe() if err != nil { @@ -34,7 +41,12 @@ func (c *Config) Suspend() (err error) { } func (c *Config) Lock() (err error) { - args := strings.Split(c.LockCmd, " ") + var args []string + if len(os.Getenv("DISPLAY")) > 0 { + args = strings.Split(c.LockCmd, " ") + } else { + args = strings.Split(c.NoXLockCmd, " ") + } cmd := exec.Command(args[0], args[1:]...) stdout, err := cmd.StdoutPipe() if err != nil { diff --git a/lockout/main.go b/lockout/main.go index ce7cdb0..b1f5d7f 100644 --- a/lockout/main.go +++ b/lockout/main.go @@ -2,8 +2,9 @@ package main import ( "fmt" - "github.com/vbatts/go-lockout/config" "os" + + "github.com/vbatts/go-lockout/config" ) func main() { @@ -40,5 +41,7 @@ Please configure this file to look something like suspendcmd: sudo /usr/sbin/pm-suspend lockcmd: xscreensaver-command -lock + noxsuspendcmd: sudo /usr/sbin/pm-suspend + noxlockcmd: clear ` )