Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] nushell integration #4122

Open
5 of 10 tasks
MarvinJWendt opened this issue Dec 8, 2024 · 2 comments
Open
5 of 10 tasks

[Feature Request] nushell integration #4122

MarvinJWendt opened this issue Dec 8, 2024 · 2 comments

Comments

@MarvinJWendt
Copy link

MarvinJWendt commented Dec 8, 2024

Checklist

  • I have read through the manual page (man fzf)
  • I have searched through the existing issues
  • For bug reports, I have checked if the bug is reproducible in the latest version of fzf

Output of fzf --version

0.56.3 (v0.56.3)

OS

  • Linux
  • macOS
  • Windows
  • Etc.

Shell

  • bash
  • zsh
  • fish

Feature Request

Hi, I am currently switching to nushell as my main shell. I noticed that fzf does not have a nushell integration.
I would like to propose to add a nushell integration, like it is done for zsh, bash and fish.

I really miss the CTRL+t keybind in nushell, as that was my goto way of selecting files in my terminal.

@igor-ramazanov
Copy link

@@MarvinJWendt

If you save this in the file and do use <filename>.nu *?

# Dependencies: `fd`, `bat, `rg`, `nufmt`, `tree`.


export-env {
  $env.FZF_ALT_C_COMMAND = "fd --type directory --hidden"
  $env.FZF_ALT_C_OPTS = "--preview 'tree -C {} | head -n 200'"
  $env.FZF_CTRL_T_COMMAND = "fd --type file --hidden"
  $env.FZF_CTRL_T_OPTS = "--preview 'bat --color=always --style=full --line-range=:500 {}' "
  $env.FZF_DEFAULT_COMMAND = "fd --type file --hidden"
}

# Directories
const alt_c = {
    name: fzf_dirs
    modifier: alt
    keycode: char_c
    mode: [emacs, vi_normal, vi_insert]
    event: [
      {
        send: executehostcommand
        cmd: "
          let fzf_alt_c_command = \$\"($env.FZF_ALT_C_COMMAND) | fzf ($env.FZF_ALT_C_OPTS)\";
          let result = nu -c $fzf_alt_c_command;
          cd $result;
        "
      }
    ]
}

# History
const ctrl_r = {
  name: history_menu
  modifier: control
  keycode: char_r
  mode: [emacs, vi_insert, vi_normal]
  event: [
    {
      send: executehostcommand
      cmd: "
        let result = history
          | get command
          | str replace --all (char newline) ' '
          | to text
          | fzf --preview 'printf \'{}\' | nufmt --stdin 2>&1 | rg -v ERROR';
        commandline edit --append $result;
        commandline set-cursor --end
      "
    }
  ]
}

# Files
const ctrl_t =  {
    name: fzf_files
    modifier: control
    keycode: char_t
    mode: [emacs, vi_normal, vi_insert]
    event: [
      {
        send: executehostcommand
        cmd: "
          let fzf_ctrl_t_command = \$\"($env.FZF_CTRL_T_COMMAND) | fzf ($env.FZF_CTRL_T_OPTS)\";
          let result = nu -l -i -c $fzf_ctrl_t_command;
          commandline edit --append $result;
          commandline set-cursor --end
        "
      }
    ]
}

# Update the $env.config
export-env {
  if not ($env.__keybindings_loaded? | default false) {
    $env.__keybindings_loaded = true
    $env.config.keybindings = $env.config.keybindings | append [
      $alt_c
      $ctrl_r
      $ctrl_t
    ]
  }
}

@igor-ramazanov
Copy link

I guess, if cleaned up, then it could serve as PR.

Things to consider: remove everything that does not come with the clean nushell installation:

  • fd
  • rg
  • tree
  • bat

And delegating as much as possible to the FZF_* env vars.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants