adding a setting for when not running X

This commit is contained in:
Vincent Batts 2014-10-09 08:55:20 -04:00
parent 0353abbd93
commit 8dccc692e8
2 changed files with 20 additions and 5 deletions

View file

@ -4,18 +4,25 @@ import (
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"launchpad.net/goyaml"
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
"launchpad.net/goyaml"
) )
type Config struct { type Config struct {
SuspendCmd, LockCmd string SuspendCmd, LockCmd string
NoXSuspendCmd, NoXLockCmd string
} }
func (c *Config) Suspend() (err error) { 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:]...) cmd := exec.Command(args[0], args[1:]...)
stdout, err := cmd.StdoutPipe() stdout, err := cmd.StdoutPipe()
if err != nil { if err != nil {
@ -34,7 +41,12 @@ func (c *Config) Suspend() (err error) {
} }
func (c *Config) Lock() (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:]...) cmd := exec.Command(args[0], args[1:]...)
stdout, err := cmd.StdoutPipe() stdout, err := cmd.StdoutPipe()
if err != nil { if err != nil {

View file

@ -2,8 +2,9 @@ package main
import ( import (
"fmt" "fmt"
"github.com/vbatts/go-lockout/config"
"os" "os"
"github.com/vbatts/go-lockout/config"
) )
func main() { func main() {
@ -40,5 +41,7 @@ Please configure this file to look something like
suspendcmd: sudo /usr/sbin/pm-suspend suspendcmd: sudo /usr/sbin/pm-suspend
lockcmd: xscreensaver-command -lock lockcmd: xscreensaver-command -lock
noxsuspendcmd: sudo /usr/sbin/pm-suspend
noxlockcmd: clear
` `
) )