adding a setting for when not running X
This commit is contained in:
parent
0353abbd93
commit
8dccc692e8
2 changed files with 20 additions and 5 deletions
|
@ -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
|
||||
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 {
|
||||
|
|
|
@ -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
|
||||
`
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue