Skip to content

Commit c15e9de

Browse files
committed
tmp
1 parent 9be601b commit c15e9de

File tree

1 file changed

+33
-0
lines changed
  • pkg/actions/tools/scrcpy

1 file changed

+33
-0
lines changed

pkg/actions/tools/scrcpy/app.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package scrcpy
2+
3+
import (
4+
"regexp"
5+
"strings"
6+
7+
"github.com/carapace-sh/carapace"
8+
"github.com/carapace-sh/carapace/pkg/style"
9+
)
10+
11+
// ActionApps completes apps
12+
//
13+
// com.github.android (GitHub)
14+
// com.github.rsteube.t4 (T4 Launcher)
15+
func ActionApps() carapace.Action {
16+
return carapace.ActionExecCommand("scrcpy", "--list-apps")(func(output []byte) carapace.Action {
17+
lines := strings.Split(string(output), "\n")
18+
r := regexp.MustCompile(`^ (?P<type>[-*]) (?P<name>.+) +(?P<id>.+)$`)
19+
20+
vals := make([]string, 0)
21+
for _, line := range lines {
22+
if matches := r.FindStringSubmatch(line); matches != nil {
23+
switch matches[1] {
24+
case "-":
25+
vals = append(vals, matches[3], matches[2], style.Default)
26+
case "*":
27+
vals = append(vals, matches[3], matches[2], style.Yellow)
28+
}
29+
}
30+
}
31+
return carapace.ActionStyledValuesDescribed(vals...)
32+
}).Tag("apps")
33+
}

0 commit comments

Comments
 (0)