Skip to content
Snippets Groups Projects
Commit edb869cf authored by Réthelyi Bálint's avatar Réthelyi Bálint :no_mouth:
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
Pipeline #5012 failed
# Created by .ignore support plugin (hsz.mobi)
### Go template
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
.idea
thegreatcommander
\ No newline at end of file
package main
import (
"flag"
"fmt"
"io/ioutil"
"os/exec"
"strings"
)
type Commands struct {
Chosen *bool
Command func() error
}
func execute(c []string) error {
var com *exec.Cmd
if len(c) > 1 {
com = exec.Command(c[0], c[1:]...)
} else {
com = exec.Command(c[0])
}
b,err :=com.CombinedOutput()
fmt.Println(string(b))
if err != nil {
fmt.Println(err)
}
return err
}
func main() {
cmds := []Commands {
{
flag.Bool("l", false, "lock"),
func() error {
status, err := ioutil.ReadFile("/tmp/displaystatus")
if err != nil {
return err
}
str := string(status)
str = strings.ReplaceAll(str, "\n", "")
return execute([]string { "loginctl", "lock-session", str})
},
},
{
flag.Bool("ul", false, "unlock"),
func() error {
status, err := ioutil.ReadFile("/tmp/displaystatus")
if err != nil {
return err
}
str := string(status)
str = strings.ReplaceAll(str, "\n", "")
return execute([]string { "loginctl", "unlock-session", str})
},
},
{
flag.Bool("sus", false, "suspend"),
func() error {
return execute([]string { "systemctl", "suspend"})
},
},
{
flag.Bool("s", false, "shutdown"),
func() error {
return execute([]string { "systemctl", "shutdown"})
},
},
}
flag.Parse()
for _,c := range cmds{
if *c.Chosen {
e := c.Command()
if e != nil {
panic(e)
}
}
}
}
#!/usr/bin/fish
if set -q DISPLAY
echo $XDG_SESSION_ID > /tmp/displaystatus
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment