mirror of
https://git.sr.ht/~rjarry/aerc
synced 2025-07-03 06:30:22 +02:00

Use go-opt v2 new completion API which returns items descriptions along with their text values. Display the descriptions after the items separated by two spaces. Wrap the descriptions in parentheses to better indicate that they are not part of the completion choices. Limit the description length to 80 characters to avoid display issues. Add a new style object completion_description in stylesets. By default, the object will be rendered with a dimmed terminal attribute. Update all stylesets and documentation accordingly. Implements: https://todo.sr.ht/~rjarry/aerc/271 Link: https://git.sr.ht/~rjarry/go-opt/commit/ebeb82538395a Changelog-added: Command completion now displays descriptions next to completion items. Changelog-added: New `completion_description` style object in style sets used for rendering completion item descriptions. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bojan Gabric <bojan@bojangabric.com> Tested-by: Jason Cox <me@jasoncarloscox.com> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package lib
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
"runtime"
|
|
"strings"
|
|
|
|
"git.sr.ht/~rjarry/go-opt/v2"
|
|
"github.com/danwakefield/fnmatch"
|
|
|
|
"git.sr.ht/~rjarry/aerc/config"
|
|
"git.sr.ht/~rjarry/aerc/lib/log"
|
|
)
|
|
|
|
func XDGOpenMime(
|
|
uri string, mimeType string, args string,
|
|
) error {
|
|
if len(args) == 0 {
|
|
// no explicit command provided, lookup opener from mime type
|
|
for _, o := range config.Openers {
|
|
if fnmatch.Match(o.Mime, mimeType, 0) {
|
|
args = o.Args
|
|
break
|
|
}
|
|
}
|
|
}
|
|
if len(args) == 0 {
|
|
// no opener defined in config, fallback to default
|
|
if runtime.GOOS == "darwin" {
|
|
args = "open"
|
|
} else {
|
|
args = "xdg-open"
|
|
}
|
|
}
|
|
|
|
// Escape URI special characters
|
|
uri = opt.QuoteArg(uri)
|
|
if strings.Contains(args, "{}") {
|
|
// found {} placeholder in args, replace with uri
|
|
args = strings.Replace(args, "{}", uri, 1)
|
|
} else {
|
|
// no {} placeholder in args, add uri at the end
|
|
args = args + " " + uri
|
|
}
|
|
|
|
log.Tracef("running command: %v", args)
|
|
cmd := exec.Command("sh", "-c", args)
|
|
out, err := cmd.CombinedOutput()
|
|
log.Debugf("command: %v exited. err=%v out=%s", args, err, out)
|
|
if err != nil {
|
|
return fmt.Errorf("%v: %w", args, err)
|
|
}
|
|
return nil
|
|
}
|