1 Commits
Author SHA1 Message Date
keb 833259a36d feat: a link brings back the lazysecrets nvim hid; Azure shows its account
CI / Checks (pull_request) Successful in 40s
PR title / Conventional title (pull_request) Successful in 2s
- In nvim, lazysecrets asks lazysecrets.nvim whether its window is
  shown: a hidden one is brought back for a link, unless nvim is busy
  (typing, a command, a picker, mid-operator), when the link opens
  elsewhere. Without an answer (an older plugin), nothing changes.
- The Azure group is named for its account, Azure · alice, also with
  a single account; its ID, and so stars and cache, stay as they were.
2026-10-28 13:03:21 +01:00
7 changed files with 128 additions and 8 deletions

No files matched your search

+3 -2
View File
@@ -5,8 +5,9 @@ it reuses it.
## Accounts ## Accounts
Every account signed in to az gets its own group in the Sources pane Every account signed in to az gets its own group in the Sources pane,
(`az login` again with another account to add one), and each account's named for it, `Azure · alice` (`az login` again with another account to
add one), and each account's
vaults are read with that account. A subscription several accounts can see vaults are read with that account. A subscription several accounts can see
is listed under each, since their permissions can differ. is listed under each, since their permissions can differ.
+5
View File
@@ -177,6 +177,11 @@ linkHandler:
a hidden dropdown terminal (kitty's quick access terminal) is shown. a hidden dropdown terminal (kitty's quick access terminal) is shown.
With none running, a new window opens. With none running, a new window opens.
- **Hidden in nvim** ([lazysecrets.nvim](https://github.com/karleinarb/lazysecrets.nvim)
hides it when you leave its window): it's brought back, unless nvim is
in the middle of something a window popping up would break (typing, a
command, a picker); then it counts as not running.
The link is then offered as if pasted. `linkHandler.reuse: false` always The link is then offered as if pasted. `linkHandler.reuse: false` always
opens a new window. opens a new window.
+3
View File
@@ -123,6 +123,9 @@ func (s *Server) handle(c net.Conn) {
switch req.Op { switch req.Op {
case "status": case "status":
_, app, reach := place(req.Front) _, app, reach := place(req.Front)
if nvimState(context.Background()) == "busy" {
reach = unreachable // a link would interrupt you: it opens elsewhere
}
s.mu.Lock() s.mu.Lock()
resp.Status = Status{PID: os.Getpid(), LastActive: s.active, Reach: reach, App: app} resp.Status = Status{PID: os.Getpid(), LastActive: s.active, Reach: reach, App: app}
s.mu.Unlock() s.mu.Unlock()
+46
View File
@@ -0,0 +1,46 @@
package instance
import (
"context"
"fmt"
"os"
"os/exec"
"strings"
"time"
)
// In nvim (lazysecrets.nvim), the tmux pane can be in view while
// lazysecrets isn't: the plugin hides its window when you leave it. The
// plugin says (state) and brings it back (reveal), when nvim isn't in the
// middle of something a window popping up would break.
// nvimState is what lazysecrets.nvim says of this lazysecrets: "shown",
// "hidden" (and can be brought back), "busy", or "" outside nvim, or with
// no answer (an older plugin, a plain :terminal): reach as before.
func nvimState(ctx context.Context) string {
switch s := nvim(ctx, "state"); s {
case "shown", "hidden", "busy":
return s
}
return ""
}
// nvimReveal brings this lazysecrets' window back, if the plugin hid it.
func nvimReveal(ctx context.Context) { nvim(ctx, "reveal") }
// nvim calls the plugin's fn with this process' pid, in the nvim that
// started it ($NVIM), and returns what it says.
func nvim(ctx context.Context, fn string) string {
addr := os.Getenv("NVIM")
if addr == "" {
return ""
}
ctx, cancel := context.WithTimeout(ctx, 500*time.Millisecond) // within the link handler's second; a stuck nvim is skipped
defer cancel()
expr := fmt.Sprintf(`luaeval("require('lazysecrets').%s(%d)")`, fn, os.Getpid())
out, err := exec.CommandContext(ctx, "nvim", "--server", addr, "--remote-expr", expr).Output()
if err != nil {
return ""
}
return strings.TrimSpace(string(out))
}
+64
View File
@@ -0,0 +1,64 @@
package instance
import (
"context"
"os"
"os/exec"
"path/filepath"
"strconv"
"testing"
"time"
)
// With a stand-in lazysecrets.nvim in a headless nvim: what it says comes
// back, for this process' pid, and an older plugin's error is "".
func TestNvim(t *testing.T) {
if _, err := exec.LookPath("nvim"); err != nil {
t.Skip("needs nvim")
}
dir := t.TempDir()
lua := filepath.Join(dir, "lua")
os.MkdirAll(lua, 0o755)
pid := strconv.Itoa(os.Getpid())
os.WriteFile(filepath.Join(lua, "lazysecrets.lua"), []byte(`
local M = {}
function M.state(pid) return pid == `+pid+` and vim.g.state or "none" end
function M.reveal(pid) vim.g.revealed = pid; return true end
return M
`), 0o644)
sock := filepath.Join(dir, "nvim.sock")
nv := exec.Command("nvim", "--headless", "--clean", "--listen", sock, "--cmd", "set rtp^="+dir, "--cmd", "let g:state = 'hidden'")
if err := nv.Start(); err != nil {
t.Fatal(err)
}
t.Cleanup(func() { nv.Process.Kill(); nv.Wait() })
for i := 0; i < 50; i++ {
if _, err := os.Stat(sock); err == nil {
break
}
time.Sleep(50 * time.Millisecond)
}
t.Setenv("NVIM", sock)
ctx := context.Background()
if s := nvimState(ctx); s != "hidden" {
t.Errorf("state %q", s)
}
nvimReveal(ctx)
if got := nvim(ctx, "state"); got != "hidden" {
t.Errorf("after reveal: %q", got)
}
out, _ := exec.Command("nvim", "--server", sock, "--remote-expr", "g:revealed").Output()
if string(out) != pid {
t.Errorf("revealed %q, want this pid %s", out, pid)
}
if got := nvim(ctx, "missing"); got != "" { // an older plugin
t.Errorf("a function the plugin lacks: %q", got)
}
t.Setenv("NVIM", "")
if s := nvimState(ctx); s != "" {
t.Errorf("outside nvim: %q", s)
}
}
+2
View File
@@ -2,6 +2,7 @@ package instance
import ( import (
"cmp" "cmp"
"context"
"os" "os"
"os/exec" "os/exec"
"slices" "slices"
@@ -101,6 +102,7 @@ func Raise(front string) {
if reach == unreachable { if reach == unreachable {
return return
} }
nvimReveal(context.Background())
if inTmux() { if inTmux() {
pane := os.Getenv("TMUX_PANE") pane := os.Getenv("TMUX_PANE")
_, _ = tmux("select-window", "-t", pane) _, _ = tmux("select-window", "-t", pane)
+5 -6
View File
@@ -181,10 +181,9 @@ func NewAccounts(s Settings) ([]*Provider, error) {
if i > 0 { if i > 0 {
settings.Vaults = nil settings.Vaults = nil
} }
label := "" // Named for its account, also when it's the only one: which
if len(accounts) > 1 { // account lazysecrets sees Azure through is worth seeing.
label = string(provider.KindAzure) + " · " + labels[i] label := string(provider.KindAzure) + " · " + labels[i]
}
cred := authCredential{ cred := authCredential{
cred: newCLICredential(a.user, a.tenant, func() ([]account, error) { return readAccounts(path) }), cred: newCLICredential(a.user, a.tenant, func() ([]account, error) { return readAccounts(path) }),
login: []string{"az", "login", "--tenant", a.tenant}, login: []string{"az", "login", "--tenant", a.tenant},
@@ -195,9 +194,9 @@ func NewAccounts(s Settings) ([]*Provider, error) {
return nil, err return nil, err
} }
p.account = &accountDetails{account: a, claims: cred.cred.(*cliCredential).claims} p.account = &accountDetails{account: a, claims: cred.cred.(*cliCredential).claims}
if label != "" {
p.id = string(provider.KindAzure) + ":" + a.user + "/" + a.tenant
p.label = label p.label = label
if len(accounts) > 1 { // one keeps the plain ID its stars and cache are under
p.id = string(provider.KindAzure) + ":" + a.user + "/" + a.tenant
} }
out = append(out, p) out = append(out, p)
} }