Skip to content

shell: nushell integration scripts#4630

Open
sim590 wants to merge 87 commits intojunegunn:masterfrom
sim590:nushell-integration
Open

shell: nushell integration scripts#4630
sim590 wants to merge 87 commits intojunegunn:masterfrom
sim590:nushell-integration

Conversation

@sim590
Copy link
Copy Markdown

@sim590 sim590 commented Dec 9, 2025

  • Keybindings alt_c, ctrl_r and ctrl_t
  • Completion functions:
    • base implementation for ** completion
    • extra completion functionalities for programs such as:
      • pass
      • ssh, scp, sftp, telnet
      • kill
      • cd, pushd, rmdir

Closes: #4122

imsys and others added 30 commits May 4, 2025 04:58
Fixes some path issues. There are still some other things to fix
Pass~[1] is a command line password storage utility. Possible queries
are deduced from the file GPG hierarchy under ~/.password-store.

[1]: https://www.passwordstore.org/
Not sure why it doesn't work in this context, but if those are not
removed, the completion process doesn't substitute the selected value
to '**'.
fix typo  shell/key-bindinds.nu → shell/key-bindings.nu
@github-actions github-actions Bot added docs Documentation go Go code shell Shell scripts test Tests install Install/uninstall scripts labels Apr 19, 2026
@sim590
Copy link
Copy Markdown
Author

sim590 commented Apr 19, 2026

Hi @junegunn,

I've done a significant overhaul of the nushell integration to address all the points you raised. Here's a summary of the changes:

Alignment with bash/zsh/fish

Key bindings (key-bindings.nu):

  • CTRL-T, CTRL-R, ALT-C now use the same fzf options as bash/zsh (e.g. --scheme=history, --bind=ctrl-r:toggle-sort, --wrap-sign, --highlight-line, +m for CTRL-R)
  • Added __fzf_defaults to properly merge FZF_DEFAULT_OPTS and FZF_DEFAULT_OPTS_FILE
  • Added __fzfcmd for FZF_TMUX / fzf-tmux support
  • Use fzf's built-in walker instead of fd for CTRL-T and ALT-C (matching bash/zsh default behavior)
  • Key bindings can be individually disabled by setting FZF_CTRL_T_COMMAND, FZF_CTRL_R_COMMAND, or FZF_ALT_C_COMMAND to an empty string
  • CTRL-R replaces the command line content instead of inserting (matching bash/zsh behavior)

Completion (completion.nu):

  • FZF_COMPLETION_DIR_COMMANDS defaults to ['cd', 'pushd', 'rmdir'] (matching bash/zsh)
  • Dedicated handlers for: kill, ssh/scp/sftp/telnet, pacman, pass
  • Removed dead code for export/unset/unalias — these commands don't exist in nushell (their equivalents are $env.VAR = ..., hide-env, and nushell has no unalias), so fzf completion handlers for them are unreachable
  • Extensibility is documented for users who want to add custom completions

Installation approach

Unlike bash/zsh where the install script appends a source line to the shell rc file, nushell's source is a parser keyword — not a command — meaning the path must be a string literal or a const, and it cannot be used dynamically. The install script instead generates a fzf.nu file in the nushell autoload/ directory ($XDG_CONFIG_HOME/nushell/autoload/), which nushell loads automatically at startup. This is similar to how fish integration works with its conf.d/ directory.

Infrastructure

  • Added --nushell flag to fzf to emit shell integration scripts (like --bash, --zsh, --fish)
  • Updated install and uninstall scripts with nushell support
  • Added nushell to README.md

Tests

  • Added TestNushell test class with 7 passing tests: test_ctrl_t, test_ctrl_t_unicode, test_alt_c, test_alt_c_command, test_ctrl_r, test_ctrl_r_abort, and test_ctrl_r_multiline (omitted — nushell doesn't support multiline command recall the same way)
  • All 18 bash tests still pass, unaffected by the changes

Notable nushell-specific decisions

  • CTRL-T and ALT-C pipe custom commands through sh -c rather than nu -c, because a nushell subprocess intercepts TTY input and prevents fzf keybindings from working
  • History deduplication in CTRL-R uses reverse | uniq on plaintext history
  • The pacman and pass completions are nushell-specific additions that don't exist in bash/zsh — happy to remove them if you'd prefer strict parity

Question: git completion?

While reviewing coverage, I noticed that none of the shell implementations (bash, zsh, fish) include dedicated fzf completion for git (branches, tags, remotes, etc.). This could be a useful addition for nushell (and potentially other shells), but I don't want to exceed the expected scope of this PR. Would this be something you'd welcome as a follow-up, or is it better left to third-party tools?

@junegunn
Copy link
Copy Markdown
Owner

Hi, please rebase work onto the latest master. In the meanwhile, fish got its fuzzy completion.

sim590 and others added 2 commits April 19, 2026 20:03
Skip sudo prefix to determine the actual command for completion
dispatch. Add paru as an alias for pacman completion. Show package
info preview with pacman -Si in the fzf selector.

Co-authored-by: René Jochum <rene@jochum.dev>
@sim590
Copy link
Copy Markdown
Author

sim590 commented Apr 20, 2026

Done!

Comment thread todo.txt Outdated
Comment thread README.md Outdated
sim590 added 2 commits April 19, 2026 22:10
Move the Nushell fuzzy completion documentation into its own section
after the fish completion section, matching the project structure.
Remove debug_nu_2.rb that was accidentally included.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class Nushell integration to fzf, aligning with existing bash/zsh/fish integrations by shipping keybindings + completion scripts, wiring them into fzf --nushell, and updating install/uninstall/docs/tests accordingly.

Changes:

  • Add --nushell CLI flag to print Nushell integration scripts (embedded in the binary).
  • Add Nushell keybindings (alt-c, ctrl-r, ctrl-t) and **<TAB> completion via Nushell external completer.
  • Update install/uninstall scripts, README, and test harness to support Nushell.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
install Adds nushell to supported shells and generates autoload/fzf.nu via fzf --nushell.
uninstall Removes generated Nushell autoload script.
main.go Embeds .nu scripts and prints them when --nushell is requested.
src/options.go Adds --nushell option parsing and Options.Nushell.
shell/key-bindings.nu Implements Nushell keybindings and fzf-tmux selection logic.
shell/completion.nu Implements Nushell external completer (**) and command-specific completions.
test/lib/common.rb Adds Nushell tmux shell bootstrap and tweaks prepare for Nushell.
test/test_shell_integration.rb Adds Nushell keybinding tests.
README.md Documents Nushell setup and Nushell-specific completion behavior/variables.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/test_shell_integration.rb
Comment thread shell/completion.nu Outdated
Comment thread install
Comment thread shell/completion.nu Outdated
Comment thread shell/completion.nu Outdated
Comment thread shell/completion.nu Outdated
Comment thread shell/key-bindings.nu Outdated
Comment thread test/lib/common.rb
sim590 added 6 commits April 21, 2026 03:24
- Remove FZF_COMPLETION_VAR_COMMANDS (export/unset/printenv completions
  were already removed, the variable was left behind)
- Fix typos: 'an Nushell' -> 'a Nushell', 'does't' -> 'doesn't',
  'exept' -> 'except'
- Guard ALT-C cd with is-not-empty check to prevent errors when fzf
  is cancelled
Add a basic **<TAB> file completion test that exercises the external
completer pipeline. Uses single selection since nushell's completion
system replaces the current token rather than appending.
- Restore 'src=${prefix_expand}.${shell}' that was lost during merge
  conflict resolution, which caused the install script to write to an
  undefined path for bash/zsh
- Fix non-idiomatic 'let $fzf_all_opts' to 'let fzf_all_opts' in
  completion.nu
pacman -Slq is a valid flag, not a typo for Sql.
Add the Gemfury apt repository for nushell so that
integration tests can run against nu in CI.
Use single quotes where there is no interpolation, replace
assert+include? with assert_includes, and use safe navigation
operator in teardown to prevent NoMethodError.
@github-actions github-actions Bot added the ci CI/GitHub Actions label Apr 21, 2026
@sim590
Copy link
Copy Markdown
Author

sim590 commented Apr 21, 2026

I added nushell installation to the CI workflow (.github/workflows/linux.yml) using the official Gemfury apt repository (as documented on nushell.sh), so that the nushell integration tests can run in the pipeline.

I also fixed the typos spell checker false positive on pacman -Slq and a couple of rubocop warnings in the test file.

Comment thread README.md
install script, you can manually set it up:
```nu
# Generate the integration script
# (run this in your regular shell, not in Nushell)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Care to explain what this means? What are the regular shells, anything but Nushell? Can they interpret this command?

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class Nushell integration to fzf, including keybindings, **<TAB> fuzzy completion via Nushell’s external completer mechanism, installation/uninstallation support, and CI/test coverage to prevent regressions.

Changes:

  • Add fzf --nushell flag that prints Nushell integration scripts (keybindings + completion)
  • Add Nushell install/uninstall handling (autoload fzf.nu) and update docs
  • Add Nushell integration tests + Linux CI dependency install for nushell

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
main.go Embeds and prints Nushell integration scripts when --nushell is used
src/options.go Adds --nushell option parsing and Options.Nushell flag
shell/key-bindings.nu Implements CTRL-T / CTRL-R / ALT-C bindings for Nushell
shell/completion.nu Implements ** completion via Nushell external completer + command-specific completers
install Adds Nushell to supported shells and generates autoload fzf.nu
uninstall Removes Nushell autoload file during uninstall
README.md Documents Nushell integration setup and limitations
test/lib/common.rb Adds Nushell shell harness + tmux prep behavior
test/test_shell_integration.rb Adds Nushell-specific integration tests (bindings + completion smoke test)
.github/workflows/linux.yml Installs nushell in CI to run Nushell tests
typos.toml Adds Slq to allowed words (for pacman -Slq)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread shell/completion.nu
Comment on lines +374 to +375
# Assuming standard ps output where PID is the second column
$selected_line | lines | each { $in | from ssv --noheaders | get 0.column1 } | to text
Comment thread README.md
install script, you can manually set it up:
```nu
# Generate the integration script
# (run this in your regular shell, not in Nushell)
Comment thread README.md

> [!NOTE]
> `--bash`, `--zsh`, and `--fish` options are only available in fzf 0.48.0 or
> `--bash`, `--zsh`, `--fish`, and `--nushell` options are only available in fzf 0.48.0 or
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci CI/GitHub Actions docs Documentation go Go code install Install/uninstall scripts shell Shell scripts test Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] nushell integration

6 participants