Skip to content

Commit

Permalink
Use id strategy for apps as well
Browse files Browse the repository at this point in the history
  • Loading branch information
gjhenrique committed Dec 14, 2022
1 parent 5d7a372 commit 6475398
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
11 changes: 3 additions & 8 deletions apps/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package apps
import (
"errors"
"fmt"
"regexp"
"strings"

"code.rocketnine.space/tslocum/desktop"
Expand All @@ -26,10 +25,7 @@ func getDesktopEntries() ([]*desktop.Entry, error) {

for _, dir := range entries {
for _, entry := range dir {
// Getting the regex from rofi
r := regexp.MustCompile(`%[fFuU]`)
entry.Exec = r.ReplaceAllString(entry.Exec, "")

entry.Exec = entry.ExpandExec("")
allEntries = append(allEntries, entry)
}
}
Expand All @@ -52,11 +48,10 @@ func applicationNames(entries []*desktop.Entry) string {
names := make([]string, len(entries))

for i, entry := range entries {
names[i] = applicationName(entry)
names[i] = fmt.Sprintf("%s\\x31%s", entry.Name, applicationName(entry))
}

return strings.Join(names, "\n")

}

func FormattedApplicationNames() (string, error) {
Expand All @@ -78,7 +73,7 @@ func GetEntryFromName(chosenApp string) (*desktop.Entry, error) {
var entry *desktop.Entry

for _, e := range entries {
if strings.TrimSpace(applicationName(e)) == strings.TrimSpace(chosenApp) {
if e.Name == strings.TrimSpace(chosenApp) {
entry = e
}
}
Expand Down
12 changes: 10 additions & 2 deletions mode/mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,20 @@ func (m *Mode) ListEntries() ([]sh.Entry, error) {
entries := make([]sh.Entry, len(entriesFromCmd))

for i, r := range entriesFromCmd {
splittedEntry := strings.Split(r, "\\x31")

text := r
id := text
if len(splittedEntry) > 1 {
id = splittedEntry[0]
text = strings.Join(splittedEntry[1:], " ")
}

if m.Prefix != "" {
text = m.Prefix + r
text = m.Prefix + text
}
entries[i] = sh.Entry{ModeKey: m.Key, Text: text, Id: r}

entries[i] = sh.Entry{ModeKey: m.Key, Text: text, Id: id}
}

if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion sh/sh.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ func SpawnAsyncProcess(command []string, options string) error {
cmd := exec.Command(command[0], args...)

cmd.SysProcAttr = &syscall.SysProcAttr{
Setsid: true,
Setsid: true,
Foreground: false,
}

err := cmd.Start()
Expand Down

0 comments on commit 6475398

Please sign in to comment.