nu_scripts icon indicating copy to clipboard operation
nu_scripts copied to clipboard

fuzzy-history menu is blatantly incorrect

Open alecStewart1 opened this issue 6 months ago • 1 comments

The following is used for a fuzzy completion menu:

  {
    name: fuzzy_history
    modifier: control
    keycode: char_h
    mode: [emacs, vi_normal, vi_insert]
    event: {
      send: executehostcommand
      cmd: "commandline (
        history
        | par-each { |it| $it.command }
        | uniq
        |  reverse
        | input list --fuzzy
          $'Please choose a (ansi magenta)command for history(ansi reset):'
      )"
    }
  }

However you cannot give commandline a positional argument:

~> Error: nu::parser::extra_positional                                                                                                                                                                                                                       06/09/2025 07:42:57 PM

  × Extra positional argument.
   ╭─[entry #27:1:13]
 1 │ ╭─▶ commandline (
 2 │ │           history
 3 │ │           | par-each { |it| $it.command }
 4 │ │           | uniq
 5 │ │           |  reverse
 6 │ │           | input list --fuzzy
 7 │ │             $'Please choose a (ansi magenta)command for history(ansi reset):'
 8 │ ├─▶       )
   · ╰──── extra positional argument
   ╰────
  help: Usage: commandline

alecStewart1 avatar Jun 10 '25 00:06 alecStewart1

This is because the example is outdated since commandline has changed since that was written. I use this one on macos.

  {
    name: fuzzy_history_fzf
    modifier: control
    keycode: char_r
    mode: [emacs , vi_normal, vi_insert]
    event: {
      send: executehostcommand
      cmd: "commandline edit --replace (
        history
          | where exit_status == 0
          | get command
          | reverse
          | uniq
          | str join (char -i 0)
          | fzf --scheme=history --read0 --tiebreak=chunk --layout=reverse --preview='echo {..}' --preview-window='bottom:3:wrap' --bind alt-up:preview-up,alt-down:preview-down --height=70% -q (commandline) --preview='echo -n {} | nu --stdin -c \'nu-highlight\''
          | decode utf-8
          | str trim
      )"
    }
  }

fdncred avatar Jun 10 '25 11:06 fdncred