Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(rexctl): show the full path when rexctl isn't on PATH (#3592)

Hampus9c7fe302c26d
diff --git a/fluxer_docs/src/installer/install.sh b/fluxer_docs/src/installer/install.sh
index cecd94557..da53abff0 100644
--- a/fluxer_docs/src/installer/install.sh
+++ b/fluxer_docs/src/installer/install.sh
@@ -239,8 +239,20 @@ printf '%s Installed rexctl %s\n' "$glyph_ok" "$version" >&2
case ":$PATH:" in
*":$bin_dir:"*) ;;
*)
- printf '%s rexctl is in %s, which isn'"'"'t on your PATH.\n' "$glyph_warn" "$bin_dir" >&2
- printf ' Add it to your PATH to run rexctl from anywhere.\n' >&2
+ case $bin_dir in
+ "$HOME"/*)
+ shown="~${bin_dir#"$HOME"}"
+ path_dir="\$HOME${bin_dir#"$HOME"}"
+ ;;
+ *)
+ shown=$bin_dir
+ path_dir=$bin_dir
+ ;;
+ esac
+ printf '%s rexctl is in %s, which isn'"'"'t on your PATH yet.\n' "$glyph_warn" "$shown" >&2
+ printf ' Run it as %s/rexctl for now. To run rexctl by name in this terminal, run:\n' "$shown" >&2
+ printf ' export PATH="%s:%s"\n' "$path_dir" "\$PATH" >&2
+ printf ' On most Linux distributions, rexctl works by name in a new terminal.\n' >&2
;;
esac
diff --git a/fluxer_rexctl/cmd/app.go b/fluxer_rexctl/cmd/app.go
index d82072a7e..217fea8e4 100644
--- a/fluxer_rexctl/cmd/app.go
+++ b/fluxer_rexctl/cmd/app.go
@@ -8,8 +8,10 @@ import (
"fmt"
"net/url"
"os"
+ "os/exec"
"os/user"
"reflect"
+ "runtime"
"strconv"
"strings"
@@ -53,12 +55,40 @@ func (a *App) init(c *cobra.Command) {
Stdout: c.OutOrStdout(),
Stderr: c.ErrOrStderr(),
})
+ var commands []string
+ for _, sub := range c.Root().Commands() {
+ commands = append(commands, sub.Name())
+ }
+ a.UI.CallSelf(selfCommand(), commands)
host.SetTerminalHold(a.UI.Hold)
if a.Flags.Verbose {
engine.SetDetail(detailWriter{a.UI})
}
}
+func selfCommand() string {
+ if runtime.GOOS == "windows" {
+ return ""
+ }
+ exe, err := os.Executable()
+ if err != nil {
+ return ""
+ }
+ if found, err := exec.LookPath("rexctl"); err == nil {
+ onPath, perr := os.Stat(found)
+ running, rerr := os.Stat(exe)
+ if perr == nil && rerr == nil && os.SameFile(onPath, running) {
+ return ""
+ }
+ }
+ if home, err := os.UserHomeDir(); err == nil {
+ if rel, ok := strings.CutPrefix(exe, home+"/"); ok {
+ return "~/" + rel
+ }
+ }
+ return exe
+}
+
type detailWriter struct{ u *ui.UI }
func (w detailWriter) Write(p []byte) (int, error) {
diff --git a/fluxer_rexctl/internal/ui/ui.go b/fluxer_rexctl/internal/ui/ui.go
index ea1bf69da..17c1c14cd 100644
--- a/fluxer_rexctl/internal/ui/ui.go
+++ b/fluxer_rexctl/internal/ui/ui.go
@@ -9,6 +9,7 @@ import (
"fmt"
"io"
"os"
+ "regexp"
"strings"
"sync"
"unicode"
@@ -55,6 +56,8 @@ type UI struct {
themeOnce sync.Once
mu sync.Mutex
spin *spinner
+ self *regexp.Regexp
+ selfName string
}
func New(opts Options) *UI {
@@ -143,12 +146,23 @@ func (u *UI) themed() Theme {
return u.theme
}
+func (u *UI) CallSelf(name string, commands []string) {
+ if name == "" || len(commands) == 0 {
+ return
+ }
+ u.self = regexp.MustCompile(`(^|[\s(])rexctl (` + strings.Join(commands, "|") + `)\b`)
+ u.selfName = strings.ReplaceAll(name, "$", "$$")
+}
+
func (u *UI) emit(s string) {
u.mu.Lock()
defer u.mu.Unlock()
if u.spin != nil {
u.spin.clear()
}
+ if u.self != nil {
+ s = u.self.ReplaceAllString(s, "${1}"+u.selfName+" ${2}")
+ }
fmt.Fprint(u.errw, s)
}