diff --git a/CHANGELOG.md b/CHANGELOG.md index aebc65a..d2cc4b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,19 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## [Unreleased] +### Added +- `zsh-edit-select` module (zsh): edit the command line like a text editor with + [zsh-edit-select](https://github.com/Michael-Matta1/zsh-edit-select) (Shift + selection, copy, cut, paste, undo, mouse selection). Installed from a pinned + clone (`v0.7.01`); on macOS `apply` builds the clipboard agent from that clone + with `make`, so a failed build degrades the module instead of surfacing on the + first shell start. On Linux the plugin still downloads its agent itself on the + first shell start, from its latest release instead of the pinned tag. + It loads after `autosuggestions` and `syntax-highlighting`. + The terminal needs key bindings for it, which omnishell does not write; the + cheatsheet lists them. A manual install of the plugin blocks the module until + its `source` line is removed. + ## [0.10.0] - 2026-11-28 ### Added diff --git a/README.md b/README.md index 93f6f90..81e261d 100644 --- a/README.md +++ b/README.md @@ -213,6 +213,7 @@ copy is backed up. Only `apply`, `remove`, and `uninstall` change your system (a | `pay-respects` | Suggest a corrected command after a failed one, run via the alias (a Rust `thefuck` alternative) — [iffse/pay-respects](https://github.com/iffse/pay-respects) | `pay-respects` (`brew`); else `git` + `cargo` fallback (needs Rust) | zsh, bash | `alias` (string, default `f`) | | `atuin` | SQLite-backed shell history with fuzzy search, context and stats — [atuinsh/atuin](https://github.com/atuinsh/atuin). **Mutually exclusive with `fzf`** (both bind Ctrl+R) — enabling both is a config error. | `atuin` (`brew`, `pacman`); else `git` + `cargo` fallback (needs Rust) | zsh, bash | `bind_ctrl_r` (bool, default `true`), `bind_up_arrow` (bool, default `true`) | | `ble-sh` | Autosuggestions and syntax highlighting for **bash** (until now zsh-only) via [ble.sh](https://github.com/akinomyoga/ble.sh). **Opt-in, bash only: it replaces parts of Readline** with its own line editor, so it **conflicts with `fzf` and `atuin`** (they rebind Ctrl+R and the completion keys; enabling either alongside is a config error) and may interact with your own `bind` settings. Loads after `completion` and `history`; sourced with `--attach=prompt` in interactive shells only. Built from a pinned clone (`v0.4.0-devel3`), so it needs `make`, `gawk` and `git` (on macOS: `brew install gawk`). A missing build is skipped silently. | pinned `git` clone built with `make` (no package manager ships it) | bash | — | +| `zsh-edit-select` | Edit the command line like a text editor: Shift+arrow selection, copy, cut, paste, undo/redo, type-to-replace and mouse selections — [Michael-Matta1/zsh-edit-select](https://github.com/Michael-Matta1/zsh-edit-select) (MIT). **It needs terminal key bindings** that send its key sequences to the shell (Ghostty, iTerm2, Kitty, WezTerm, VS Code: see the plugin's README; restart the terminal afterwards), and on macOS Accessibility permission for mouse selections (`edit-select setup-ax`). omnishell writes no terminal configuration. Loads after `completion`, `autosuggestions` and `syntax-highlighting`. **A manual install blocks it**: remove the plugin's `source` line from `~/.zshrc`, delete the old clone and stop its agent. `omnishell cheatsheet` lists the keys | pinned `git` clone (`v0.7.01`); on macOS `apply` builds the clipboard agent with `make` (Xcode Command Line Tools). **On Linux the plugin itself downloads its agent on the first shell start, from its latest GitHub release rather than the pinned tag** (checked against that release's `SHA256SUMS.txt`, not against anything omnishell pins); `edit-select build` compiles it from source instead | zsh | — | | `modern-aliases` | Replace ls/cat/find with [eza](https://github.com/eza-community/eza), [bat](https://github.com/sharkdp/bat) and [fd](https://github.com/sharkdp/fd) when selected | `eza`, `bat`, `fd`; `eza` as a release binary where the manager has no package | zsh, bash | `replace` (`list` of `ls`, `cat`, `find`; default `["ls", "cat", "find"]`) | | `colorized-man` | Syntax-highlighted man pages via [bat](https://github.com/sharkdp/bat) when present, with a zero-dependency `less` colour fallback | — (config only) | zsh, bash | — | | `tealdeer` | A fast `tldr` client: short, practical command examples instead of long man pages — [tealdeer-rs/tealdeer](https://github.com/tealdeer-rs/tealdeer). The page cache is not filled by `apply`; `tldr` downloads it on first use | `tealdeer` (all managers); else a verified release binary (Linux x86_64, arm64, armv7) | zsh, bash | — | @@ -232,8 +233,8 @@ copy is backed up. Only `apply`, `remove`, and `uninstall` change your system (a `zsh-completions`, when enabled, loads before `completion` so its directory is on `fpath` when `compinit` runs. `dynamic-completion` (bash) loads after `completion`. `ble-sh` (bash) loads after `completion` and `history`, and cannot be enabled together with `fzf` or `atuin`. -`you-should-use` loads after `modern-aliases`. `autosuggestions` and `syntax-highlighting` are zsh-only and always render last (with `syntax-highlighting` after `autosuggestions`); `fzf-tab`, when enabled, -loads after `completion`/`fzf` and before both of those. `tmux`, when enabled, +`you-should-use` loads after `modern-aliases`. `autosuggestions` and `syntax-highlighting` are zsh-only and render after every other module except `zsh-edit-select` (with `syntax-highlighting` after `autosuggestions`); `fzf-tab`, when enabled, +loads after `completion`/`fzf` and before both of those. `zsh-edit-select` loads after both, the order the plugin is written for. `tmux`, when enabled, loads before the prompt modules (`starship`, `omnishell-prompt`). ### 🔨 Build prerequisites for the `git` fallback @@ -258,6 +259,7 @@ omnishell does not install build tools — install them yourself and re-run | 🦀 | `pay-respects` | `cargo` ≥ 1.85 | | ⚙️ | `welcome` | `cmake` | | ⚙️ | `ble-sh` | `make`, `gawk`, `git` | +| ⚙️ | `zsh-edit-select` | `git`; on macOS `make` and `clang` (Xcode Command Line Tools) | > [!TIP] > Distribution `cargo` packages are often too old. Install a current Rust diff --git a/modules/builtin/zsh-edit-select/cheatsheet.tmpl b/modules/builtin/zsh-edit-select/cheatsheet.tmpl new file mode 100644 index 0000000..0556e7b --- /dev/null +++ b/modules/builtin/zsh-edit-select/cheatsheet.tmpl @@ -0,0 +1,8 @@ +{{ $mod := "Ctrl" }}{{ if eq .Platform "macos" }}{{ $mod = "Cmd" }}{{ end -}} +- `Shift` + arrow keys — select text on the command line; type or paste to replace the selection +- `{{ $mod }}+A` select all, `{{ $mod }}+C` copy, `{{ $mod }}+X` cut, `{{ $mod }}+Z` undo, `{{ $mod }}+Shift+Z` redo +- Paste with your terminal's own paste shortcut; it replaces a selection +- Run `edit-select config` to change the mouse behaviour and the key bindings +- Needs terminal key bindings that send these sequences to the shell (examples for Ghostty, iTerm2, Kitty, WezTerm and VS Code are in the plugin's README); restart the terminal afterwards +{{ if eq .Platform "macos" }}- Mouse selections need Accessibility permission for your terminal: run `edit-select setup-ax` +{{ end }}- A manual install of the plugin blocks this module: remove its `source` line from `~/.zshrc`, delete the old clone and stop its agent, otherwise nothing is loaded from here diff --git a/modules/builtin/zsh-edit-select/manifest.toml b/modules/builtin/zsh-edit-select/manifest.toml new file mode 100644 index 0000000..049196b --- /dev/null +++ b/modules/builtin/zsh-edit-select/manifest.toml @@ -0,0 +1,28 @@ +platforms = ["macos", "linux"] +shells = ["zsh"] +after = ["completion", "autosuggestions", "syntax-highlighting"] + +[module] +id = "zsh-edit-select" +name = "zsh-edit-select" +description = "Edit the command line like a text editor: Shift selection, copy, cut, paste, undo and mouse selection (zsh)" +homepage = "https://github.com/Michael-Matta1/zsh-edit-select" +version = "1.0.0" +schema = 1 + +# No package manager ships the plugin, so it is always a pinned clone (MIT). +# It also needs a native clipboard agent. On macOS the agent is built here, from +# the pinned clone, so a failure shows up in `apply`; the plugin would otherwise +# download an unpinned binary from its latest release on the first shell start. +# The first run entry renders to an empty command on every other platform, which +# skips the build: on Linux the agent depends on the display server (X11 or +# Wayland) and its development libraries, so the plugin provisions it itself. +# Loading after autosuggestions and syntax-highlighting is the order the plugin +# is written for: it registers its hooks on the first prompt, after the widget +# wrappers those plugins install at load time exist. +[[packages.fallback]] +type = "git" +repo = "https://github.com/Michael-Matta1/zsh-edit-select.git" +dest = "{{.VendorDir}}/zsh-edit-select" +ref = "v0.7.01" +run = ["{{ if eq .Platform \"macos\" }}make{{ end }}", "-C", "{{.VendorDir}}/zsh-edit-select/impl-macos/backends/macos"] diff --git a/modules/builtin/zsh-edit-select/zsh.tmpl b/modules/builtin/zsh-edit-select/zsh.tmpl new file mode 100644 index 0000000..b6ac8fc --- /dev/null +++ b/modules/builtin/zsh-edit-select/zsh.tmpl @@ -0,0 +1,3 @@ +if [[ -r {{ pathjoin .VendorDir "zsh-edit-select" "zsh-edit-select.plugin.zsh" | shellquote }} ]]; then + source {{ pathjoin .VendorDir "zsh-edit-select" "zsh-edit-select.plugin.zsh" | shellquote }} +fi diff --git a/modules/testdata/zsh-edit-select/cheatsheet-zsh.golden b/modules/testdata/zsh-edit-select/cheatsheet-zsh.golden new file mode 100644 index 0000000..db297cb --- /dev/null +++ b/modules/testdata/zsh-edit-select/cheatsheet-zsh.golden @@ -0,0 +1,7 @@ +- `Shift` + arrow keys — select text on the command line; type or paste to replace the selection +- `Cmd+A` select all, `Cmd+C` copy, `Cmd+X` cut, `Cmd+Z` undo, `Cmd+Shift+Z` redo +- Paste with your terminal's own paste shortcut; it replaces a selection +- Run `edit-select config` to change the mouse behaviour and the key bindings +- Needs terminal key bindings that send these sequences to the shell (examples for Ghostty, iTerm2, Kitty, WezTerm and VS Code are in the plugin's README); restart the terminal afterwards +- Mouse selections need Accessibility permission for your terminal: run `edit-select setup-ax` +- A manual install of the plugin blocks this module: remove its `source` line from `~/.zshrc`, delete the old clone and stop its agent, otherwise nothing is loaded from here diff --git a/modules/testdata/zsh-edit-select/zsh.golden b/modules/testdata/zsh-edit-select/zsh.golden new file mode 100644 index 0000000..a5dab07 --- /dev/null +++ b/modules/testdata/zsh-edit-select/zsh.golden @@ -0,0 +1,3 @@ +if [[ -r '/home/j/.config/omnishell/vendor/zsh-edit-select/zsh-edit-select.plugin.zsh' ]]; then + source '/home/j/.config/omnishell/vendor/zsh-edit-select/zsh-edit-select.plugin.zsh' +fi diff --git a/modules/zsh_edit_select_test.go b/modules/zsh_edit_select_test.go new file mode 100644 index 0000000..a63d081 --- /dev/null +++ b/modules/zsh_edit_select_test.go @@ -0,0 +1,261 @@ +package modules_test + +import ( + "os" + "os/exec" + "path/filepath" + "strings" + "testing" + "time" + + "github.com/JtheGunner/omnishell/internal/config" + "github.com/JtheGunner/omnishell/internal/engine" + "github.com/JtheGunner/omnishell/internal/graph" + "github.com/JtheGunner/omnishell/internal/lockfile" + "github.com/JtheGunner/omnishell/internal/module" + "github.com/JtheGunner/omnishell/internal/pkgmgr" + "github.com/JtheGunner/omnishell/internal/platform" + "github.com/JtheGunner/omnishell/internal/render" + "github.com/JtheGunner/omnishell/modules" +) + +func zesRegistry(t *testing.T) module.Registry { + t.Helper() + reg, err := module.LoadRegistry(modules.FS(), "") + if err != nil { + t.Fatal(err) + } + return reg +} + +func zesModule(t *testing.T) module.Module { + t.Helper() + m, ok := zesRegistry(t).Get("zsh-edit-select") + if !ok { + t.Fatal("module zsh-edit-select not embedded") + } + return m +} + +func TestZshEditSelectGolden(t *testing.T) { + assertGoldenNamed(t, "zsh-edit-select", "zsh", renderModule(t, "zsh-edit-select", "zsh", nil)) +} + +// The cheatsheet names Cmd on macOS and Ctrl elsewhere, and only macOS needs +// the Accessibility permission. +func TestZshEditSelectCheatsheetPerPlatform(t *testing.T) { + body, has, err := zesModule(t).Cheatsheet() + if err != nil || !has { + t.Fatalf("cheatsheet: has=%v err=%v", has, err) + } + for platform, want := range map[string]struct{ key, ax bool }{ + "macos": {key: true, ax: true}, + "linux": {key: false, ax: false}, + } { + out, err := render.Render(body, render.Context{ + Options: map[string]any{}, Platform: platform, Shell: "zsh", + VendorDir: "/home/j/.config/omnishell/vendor", + ConfigDir: "/home/j/.config/omnishell", + Bin: map[string]string{}, Active: map[string]bool{}, + }) + if err != nil { + t.Fatalf("%s: %v", platform, err) + } + if got := strings.Contains(out, "`Cmd+C`"); got != want.key { + t.Errorf("%s: mentions Cmd+C = %v, want %v\n%s", platform, got, want.key, out) + } + if got := strings.Contains(out, "`Ctrl+C`"); got == want.key { + t.Errorf("%s: mentions Ctrl+C = %v, want %v\n%s", platform, got, !want.key, out) + } + if got := strings.Contains(out, "setup-ax"); got != want.ax { + t.Errorf("%s: mentions setup-ax = %v, want %v", platform, got, want.ax) + } + if !strings.Contains(out, "manual install") { + t.Errorf("%s: the cheatsheet must warn about a manual install:\n%s", platform, out) + } + } +} + +func TestZshEditSelectManifest(t *testing.T) { + m := zesModule(t) + if got := m.Manifest.Shells; len(got) != 1 || got[0] != "zsh" { + t.Errorf("shells = %v, want [zsh]", got) + } + for _, mgr := range []string{"brew", "apt", "dnf", "pacman", "zypper", "apk"} { + if got := m.Manifest.Packages.ForManager(mgr); len(got) != 0 { + t.Errorf("%s packages = %v, want none", mgr, got) + } + } + fbs := m.Manifest.Packages.Fallback + if len(fbs) != 1 { + t.Fatalf("fallbacks = %+v, want exactly one", fbs) + } + fb := fbs[0] + if fb.Type != "git" || fb.Ref != "v0.7.01" || fb.Repo != "https://github.com/Michael-Matta1/zsh-edit-select.git" { + t.Errorf("fallback = %+v, want the pinned git clone", fb) + } + if got := strings.Join(m.Manifest.After, ","); got != "completion,autosuggestions,syntax-highlighting" { + t.Errorf("after = %q", got) + } +} + +func TestZshEditSelectLoadsAfterAutosuggestionsAndHighlighting(t *testing.T) { + reg := zesRegistry(t) + active := map[string]module.Manifest{} + for _, id := range []string{"zsh-edit-select", "completion", "autosuggestions", "syntax-highlighting", "you-should-use", "fzf-tab", "fzf"} { + m, ok := reg.Get(id) + if !ok { + t.Fatalf("module %s missing", id) + } + active[id] = m.Manifest + } + order, err := graph.Order(active) + if err != nil { + t.Fatal(err) + } + pos := map[string]int{} + for i, id := range order { + pos[id] = i + } + for _, dep := range []string{"completion", "autosuggestions", "syntax-highlighting"} { + if pos["zsh-edit-select"] < pos[dep] { + t.Errorf("zsh-edit-select loads before %s: %v", dep, order) + } + } +} + +// The build is the only platform-dependent part: macOS builds the agent from +// the pinned clone, every other platform renders an empty command and so skips +// the build. +func TestZshEditSelectBuildRunsOnMacOSOnly(t *testing.T) { + fb := zesModule(t).Manifest.Packages.Fallback[0] + for platform, wantBuild := range map[string]bool{"macos": true, "linux": false} { + vendor := filepath.Join(t.TempDir(), "vendor") + runner := &pkgmgr.MockRunner{} + ctx := pkgmgr.FallbackContext{VendorDir: vendor, Platform: platform} + dest, err := pkgmgr.InstallGitFallback(fb, ctx, runner) + if err != nil { + t.Fatalf("%s: %v", platform, err) + } + if want := filepath.Join(vendor, "zsh-edit-select"); dest != want { + t.Errorf("%s: dest = %q, want %q", platform, dest, want) + } + build := "make -C " + filepath.Join(vendor, "zsh-edit-select", "impl-macos", "backends", "macos") + var cloned, built bool + for _, c := range runner.Calls { + if strings.Contains(c, " clone ") && strings.Contains(c, "--branch v0.7.01") { + cloned = true + } + if c == build { + built = true + } + if strings.HasPrefix(c, "-C ") { + t.Errorf("%s: a build with an empty command was run: %q", platform, c) + } + } + if !cloned { + t.Errorf("%s: pinned clone not run: %v", platform, runner.Calls) + } + if built != wantBuild { + t.Errorf("%s: built = %v, want %v (calls %v)", platform, built, wantBuild, runner.Calls) + } + } +} + +// A failed macOS build must fail the install, so apply reports the module as +// degraded instead of leaving a plugin without its agent. +func TestZshEditSelectBuildFailureFailsInstall(t *testing.T) { + fb := zesModule(t).Manifest.Packages.Fallback[0] + vendor := filepath.Join(t.TempDir(), "vendor") + build := "make -C " + filepath.Join(vendor, "zsh-edit-select", "impl-macos", "backends", "macos") + runner := &pkgmgr.MockRunner{Responses: map[string]pkgmgr.MockResponse{ + build: {Err: os.ErrNotExist}, + }} + _, err := pkgmgr.InstallGitFallback(fb, pkgmgr.FallbackContext{VendorDir: vendor, Platform: "macos"}, runner) + if err == nil || !strings.Contains(err.Error(), "fallback run") { + t.Fatalf("err = %v, want a fallback run error", err) + } +} + +// With no package manager the module is still planned: it has no package +// entries, only the fallback (see the engine's planPackages). +func TestZshEditSelectPlansFallbackWithoutManager(t *testing.T) { + e := engine.Engine{ + Platform: platform.Info{ + OS: platform.MacOS, HomeDir: t.TempDir(), ConfigDir: t.TempDir(), + Shells: []platform.ShellInfo{{Name: "zsh", RCPath: "/x/.zshrc", Present: true}}, + }, + Registry: zesRegistry(t), + ManagerOK: false, + Runner: &pkgmgr.MockRunner{}, + Now: func() time.Time { return time.Date(2026, 9, 2, 0, 0, 0, 0, time.UTC) }, + } + cfg := config.Config{ + Omnishell: config.OmnishellSection{Version: 1, Shells: []string{"zsh"}}, + Modules: map[string]config.ModuleConfig{"zsh-edit-select": {Enabled: true}}, + } + p, err := engine.ComputePlan(e, cfg, lockfile.Lock{Modules: map[string]lockfile.ModuleState{}}, false) + if err != nil { + t.Fatal(err) + } + mp := p.Modules["zsh-edit-select"] + if mp.DegradedReason != "" || !mp.UsesFallback || len(mp.MissingPackages) != 1 || mp.MissingPackages[0].Manager != "git" { + t.Fatalf("plan = %+v, want the git fallback planned without a manager", mp) + } +} + +func TestZshEditSelectSnippetInRealZsh(t *testing.T) { + zsh, err := exec.LookPath("zsh") + if err != nil { + t.Skip("zsh not installed") + } + vendor := filepath.Join(t.TempDir(), "vendor dir") + pluginDir := filepath.Join(vendor, "zsh-edit-select") + if err := os.MkdirAll(pluginDir, 0o755); err != nil { + t.Fatal(err) + } + stub := "echo stub-sourced\n" + if err := os.WriteFile(filepath.Join(pluginDir, "zsh-edit-select.plugin.zsh"), []byte(stub), 0o644); err != nil { + t.Fatal(err) + } + snippet := func(vendorDir string) string { + body, has, err := zesModule(t).Template("zsh") + if err != nil || !has { + t.Fatalf("zsh template: has=%v err=%v", has, err) + } + out, err := renderSnippet(body, vendorDir) + if err != nil { + t.Fatal(err) + } + return out + } + + out, err := exec.Command(zsh, "-f", "-c", snippet(vendor)).CombinedOutput() + if err != nil { + t.Fatalf("zsh: %v\n%s", err, out) + } + if !strings.Contains(string(out), "stub-sourced") { + t.Errorf("snippet must source the plugin from a path with a space, got %q", out) + } + + missing := snippet(filepath.Join(t.TempDir(), "none")) + out, err = exec.Command(zsh, "-f", "-c", missing).CombinedOutput() + if err != nil { + t.Fatalf("missing plugin: %v\n%s", err, out) + } + if strings.TrimSpace(string(out)) != "" { + t.Errorf("a missing plugin must be silent, got %q", out) + } + + if out, err := exec.Command(zsh, "-n", "-c", snippet(vendor)).CombinedOutput(); err != nil { + t.Errorf("zsh -n: %v\n%s", err, out) + } +} + +func renderSnippet(body, vendorDir string) (string, error) { + return render.Render(body, render.Context{ + Options: map[string]any{}, Platform: "macos", Shell: "zsh", + VendorDir: vendorDir, ConfigDir: filepath.Dir(vendorDir), + Bin: map[string]string{}, Active: map[string]bool{}, + }) +}