Support link desktop entries
parent
ceb8c40dbc
commit
afc162ef65
|
@ -41,7 +41,7 @@ func layout(g *gocui.Gui) error {
|
|||
v.Frame = false
|
||||
v.Wrap = false
|
||||
}
|
||||
if v, err := g.SetView("comment", maxX/2, 1, maxX, 3); err != nil {
|
||||
if v, err := g.SetView("comment", maxX/2, 1, maxX, maxY); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ func layout(g *gocui.Gui) error {
|
|||
comment = v
|
||||
|
||||
v.Frame = false
|
||||
v.Wrap = false
|
||||
v.Wrap = true
|
||||
}
|
||||
}
|
||||
if v, err := g.SetView("list", -1, 0, listWidth, maxY); err != nil {
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"time"
|
||||
|
||||
"git.sr.ht/~tslocum/desktop"
|
||||
"git.sr.ht/~tslocum/gmenu/pkg/config"
|
||||
"github.com/kballard/go-shellquote"
|
||||
"github.com/lithammer/fuzzysearch/fuzzy"
|
||||
"github.com/pkg/errors"
|
||||
|
@ -74,11 +75,10 @@ func updateEntries(buf string) {
|
|||
list.SetCursor(0, 0)
|
||||
defer updateEntryInfo()
|
||||
|
||||
if len(filteredEntries) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
lastEntry := len(filteredEntries) - 1
|
||||
if buf != "" {
|
||||
lastEntry++
|
||||
}
|
||||
for i, entry := range filteredEntries {
|
||||
if i == lastEntry {
|
||||
fmt.Fprint(list, entry.Name)
|
||||
|
@ -86,6 +86,9 @@ func updateEntries(buf string) {
|
|||
fmt.Fprint(list, entry.Name+"\n")
|
||||
}
|
||||
}
|
||||
if buf != "" && len(filteredEntries) > 0 {
|
||||
fmt.Fprint(list, "exec "+buf)
|
||||
}
|
||||
}
|
||||
|
||||
func selectedEntry() *desktop.Entry {
|
||||
|
@ -123,13 +126,16 @@ func updateEntryInfo() {
|
|||
exLine = entry.Exec
|
||||
} else {
|
||||
comLine = "Shell command"
|
||||
exLine = "/bin/bash"
|
||||
exLine = "bash -c "
|
||||
if input != nil {
|
||||
exLine += input.Buffer()
|
||||
}
|
||||
}
|
||||
|
||||
ex.Clear()
|
||||
fmt.Fprint(ex, exLine)
|
||||
comment.Clear()
|
||||
fmt.Fprint(comment, comLine)
|
||||
fmt.Fprint(comment, " "+comLine)
|
||||
}
|
||||
|
||||
func listSelect() error {
|
||||
|
@ -141,12 +147,14 @@ func listSelect() error {
|
|||
waitUntilFinished bool
|
||||
)
|
||||
entry := selectedEntry()
|
||||
if entry != nil {
|
||||
runInTerminal = entry.Terminal
|
||||
execute = entry.ExpandExec(shellquote.Join(flag.Args()...))
|
||||
} else {
|
||||
if entry == nil {
|
||||
waitUntilFinished = true
|
||||
execute = input.Buffer()
|
||||
} else if entry.Type == desktop.Application {
|
||||
runInTerminal = entry.Terminal
|
||||
execute = entry.ExpandExec(shellquote.Join(flag.Args()...))
|
||||
} else { // Type == desktop.Link
|
||||
execute = shellquote.Join(config.BrowserCommand, entry.URL)
|
||||
}
|
||||
execute = strings.TrimSpace(execute)
|
||||
|
||||
|
@ -159,5 +167,10 @@ func listSelect() error {
|
|||
return errors.Wrap(err, "failed to create run script")
|
||||
}
|
||||
|
||||
return run(runScript, waitUntilFinished, runInTerminal)
|
||||
path := ""
|
||||
if entry != nil {
|
||||
path = entry.Path
|
||||
}
|
||||
|
||||
return run(runScript, path, waitUntilFinished, runInTerminal)
|
||||
}
|
||||
|
|
|
@ -60,6 +60,19 @@ func main() {
|
|||
|
||||
for _, entries := range allEntries {
|
||||
for _, entry := range entries {
|
||||
switch entry.Type {
|
||||
case desktop.Application:
|
||||
if entry.Exec == "" {
|
||||
continue
|
||||
}
|
||||
case desktop.Link:
|
||||
if entry.URL == "" {
|
||||
continue
|
||||
}
|
||||
default:
|
||||
continue // Unsupported entry type
|
||||
}
|
||||
|
||||
desktopEntries = append(desktopEntries, entry)
|
||||
desktopNames = append(desktopNames, strings.ToLower(entry.Name))
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func run(runScript string, waitUntilFinished, runInTerminal bool) error {
|
||||
func run(runScript string, path string, waitUntilFinished, runInTerminal bool) error {
|
||||
var cmd *exec.Cmd
|
||||
if runInTerminal {
|
||||
cmd = exec.Command(config.TerminalCommand, "-e", runScript)
|
||||
|
@ -21,6 +21,7 @@ func run(runScript string, waitUntilFinished, runInTerminal bool) error {
|
|||
}
|
||||
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true, Pgid: 0}
|
||||
cmd.Dir = path
|
||||
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stdout = os.Stdout
|
||||
|
|
3
go.mod
3
go.mod
|
@ -3,7 +3,7 @@ module git.sr.ht/~tslocum/gmenu
|
|||
go 1.12
|
||||
|
||||
require (
|
||||
git.sr.ht/~tslocum/desktop v0.1.0
|
||||
git.sr.ht/~tslocum/desktop v0.1.1
|
||||
github.com/jroimartin/gocui v0.4.0
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
|
||||
github.com/lithammer/fuzzysearch v1.0.2
|
||||
|
@ -11,4 +11,5 @@ require (
|
|||
github.com/mattn/go-runewidth v0.0.4 // indirect
|
||||
github.com/nsf/termbox-go v0.0.0-20190624072549-eeb6cd0a1762 // indirect
|
||||
github.com/pkg/errors v0.8.1
|
||||
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 // indirect
|
||||
)
|
||||
|
|
7
go.sum
7
go.sum
|
@ -1,5 +1,7 @@
|
|||
git.sr.ht/~tslocum/desktop v0.1.0 h1:mLmT1m+IhhpTbyfbXejtrJyAyV0S9tJzd8ZyWTkN5Es=
|
||||
git.sr.ht/~tslocum/desktop v0.1.0 h1:cfOcbsBA/XOkemwRjqZ9N5oeYGnGlnC6Vq976aLrrS8=
|
||||
git.sr.ht/~tslocum/desktop v0.1.0/go.mod h1:cUn0Q8ALjkAq40qSei795yN3CfO5pkeYKo2gmzaZ2SI=
|
||||
git.sr.ht/~tslocum/desktop v0.1.1 h1:hS1DgT1Ur0DR42Z4vr+Zsasjjd8M9PVwIEmeAd1xLS4=
|
||||
git.sr.ht/~tslocum/desktop v0.1.1/go.mod h1:cUn0Q8ALjkAq40qSei795yN3CfO5pkeYKo2gmzaZ2SI=
|
||||
github.com/jroimartin/gocui v0.4.0 h1:52jnalstgmc25FmtGcWqa0tcbMEWS6RpFLsOIO+I+E8=
|
||||
github.com/jroimartin/gocui v0.4.0/go.mod h1:7i7bbj99OgFHzo7kB2zPb8pXLqMBSQegY7azfqXMkyY=
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
|
||||
|
@ -14,5 +16,6 @@ github.com/nsf/termbox-go v0.0.0-20190624072549-eeb6cd0a1762 h1:44Lv0bNi88GweB54
|
|||
github.com/nsf/termbox-go v0.0.0-20190624072549-eeb6cd0a1762/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 h1:LepdCS8Gf/MVejFIt8lsiexZATdoGVyp5bcyS+rYoUI=
|
||||
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
|
|
@ -3,4 +3,5 @@ package config
|
|||
var (
|
||||
Version string
|
||||
TerminalCommand = "i3-sensible-terminal"
|
||||
BrowserCommand = "xdg-open"
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue