nushell / nushell

A new type of shell
https://www.nushell.sh/
MIT License
32.15k stars 1.66k forks source link

Release #3 - Completions #290

Closed sophiajt closed 2 years ago

sophiajt commented 5 years ago

Completions

alecthomas commented 5 years ago

IMO this is the feature that will drive adoption the most. This and probably inline help for commands.

Completions will allow discoverability, where currently there is zero. I type ps | where and I have no idea what fields area available.

omertuc commented 5 years ago

Moreover, if completion information is unknown for a command, maybe it's possible to suggest a list of columns gathered from recent runs of the command. Usually I would do something like this:

1) type ls 2) See the unfiltered output to decide what needs to be filtered 3) type ls | where somecolumn=somevalue according to what I saw in step (2)

Maybe nu could intercept the output in step (2) to cache the different column names / some common values for those columns and suggest those when offering completion in (3).

alecthomas commented 5 years ago

IMO it would be ideal if plugins could (perhaps optionally if not by default) declare an output schema. Completions could then use the schema.

alper commented 5 years ago

Do I get it right that arrow right completes the current suggestion but that this isn't documented yet?

syvanpera commented 5 years ago

Can I suggest you take some inspiration from fish shell on this. It's completions and suggestions work like magic and this is probably the biggest issue at least for me before I'd consider adopting nushell as my shell of choice

Nemikolh commented 5 years ago

Would it be possible to consider having the autocompletion behaviour configurable? In particular, I like a lot if for a directory containing foobar, foobaz, foobar001, ... , foobaz125. I start typing f, press Tab and get fooba instead of one of the possible entries.

I understand some folks like the current behaviour but I personally find it very frustrating when exploring the list of files in a directory. I probably am biased by my daily use of zsh with the zsh-syntax-plugin

JosephTLyons commented 4 years ago

I see there is a desire to support autocomplete of commands, is there any desire for nu to support completion of file names / directory names in real-time as well?

kazysmaster commented 4 years ago

I think it would be nice to have ide like file/directory name completion.

schoetbi commented 4 years ago

I saw that the git branch is displayed in the command prompt but when I enter git checkout branch_name_start and press Tab nothing happens. Is Git branch completion implemented?

sophiajt commented 4 years ago

@schoetbi not yet, but it's something we'd like to add

schoetbi commented 4 years ago

@jonathandturner This is great.

Another question: It seems that the completion for e.g. filenames works with tab. Instead when a command from the history is shown as a suggestion the completion is done with the key "arrow right" Why is there this difference?

sophiajt commented 4 years ago

@schoetbi - these settings come from rustyline, which we use to do the line editing. There may be a way to configure the keybindings. It's something we still need to explore futher.

thegedge commented 4 years ago

Follow https://github.com/nushell/nushell/issues/1958 for updates on any progress on user-configurable key bindings 🙂

thegedge commented 4 years ago

Update for anyone following this issue: I've been working on a custom completion engine for nushell (previously, we used the one built by rustyline). It's built around nushell's parser, which means it can take advantage of command signatures to provide really nice context to the completion engine. This will be available in tomorrow's release, but know that it's a work in progress so it's perhaps a little rough around the edges right now.

Current progress:

Lots of opportunity, but I'm really excited for the simplicity we'll eventually settle on.

We can keep this issue open for the time being, but I think we're nearly there 🙌

Th3Whit3Wolf commented 3 years ago

I'm not sure if this is the appropriate place to ask this but would nushell have any interest in working on something like shellac? It's a protocol for shell-agnostic autocompletion written in rust. From the readme.

Goals

The end result aims toward being a binary that

  • Replies to requests with minimal latency. Ideally, less than 10ms for static completion so it's not even visible for users
  • Is able to support as-you-type completion. That means caching should be used a lot to avoid duplicating work
  • Handle multiple (up to ~20) concurrent clients while keeping latency low for each one of them
  • Support definitions of parameters
  • Support invoking various external commands for dynamic completion
rsteube commented 3 years ago

Can NuCompleter somehow be exposed or is there already a way to add one? Did a little poc and seems to work quite fine: https://github.com/nushell/nushell/compare/main...rsteube:carapace (excuse my rust)

asciicast

gutenye commented 3 years ago

Fig also looks very promising, not sure if it can be used with nushell.

hustcer commented 3 years ago

+1

rsteube commented 3 years ago

Any progress here regarding custom completions? Got multiparts roughly working. asciicast

sophiajt commented 3 years ago

Much of the upcoming completion work has begun. You can see some prototypes of it in https://github.com/nushell/engine-q with the git checkout command we're working on.

The hope is that engine-q will mature to the point we can replace the current nushell engine with engine-q, which will let us then later allow for people to write custom completions as separate files that Nushell can read in.

rsteube commented 3 years ago

Nice, would be great to be able to somehow pass the current words/tokens (up to cursor position) to a command. Kinda like this.

e.g. in elvish this is simply done by:

edit:completion:arg-completer[git] = [@arg]{
    carapace git elvish _ (all $arg) | from-json | all (one) | each [c]{ edit:complex-candidate $c[Value] &display=$c[Display] &code-suffix=$c[CodeSuffix] }
}

tagged a release if anyone wants to try it out - hardcoded and still a bit messy but seems to work quite alright

rsteube commented 3 years ago

Got rid of the hardcoding by using the config (persistent, but seems to be the best approach with current nushell capabilities).

So basically commands can be configured to be called for completion which then return json:

[completion]
git = ["command", "complete"]
> git checkout <TAB>
# command complete git checkout ''
# [{"display":"master (commit msg)","replacement":"master "}]
fdncred commented 2 years ago

ancient

igitur commented 2 years ago

Ancient, but I'm still very much invested in this issue.

fdncred commented 2 years ago

Which parts are you all invested in? We have completions, and the start to external completions.

zeenix commented 2 years ago

Which parts are you all invested in? We have completions, and the start to external completions.

Then perhaps it's miscommunication. The issue was closed with just ancient as the reason instead of being closed by PRs and all the checkboxes in the description are still unchecked.

fdncred commented 2 years ago

ya, that makes sense. I was half asleep when I closed it last night. Sorry. :)

I checked all the boxes in the issue because completions work for commands, plugins, and cd'ing. There's some fancy stuff going on too with menus and such. Like this one.

keybindings: [
    {
      name: complete_in_cd
      modifier: control
      keycode: char_p
      mode: emacs
      event: [
          { edit: { cmd: clear } }
          { edit: { cmd: insertString value: "./" }}
          { send: Menu name: completion_menu }
      ]
    }
  ]

This was posted in discord #cool-oneliners.

Feel-ix-343 commented 2 years ago

This has been very hard to follow. Are there any updates?

Just started trying nushell out, but cant use it without something like zsh completions plugin

fdncred commented 2 years ago

There are some custom completions in our nu_scripts repo.

tobiasBora commented 1 year ago

Carapace-bin also provides more completions https://github.com/rsteube/carapace-bin

DeadRobotDev commented 1 year ago

I checked all the boxes in the issue because completions work for commands, plugins, and cd'ing.

While completions work with cd, it still suggests history that isn't appropriate. For example: I cd into FolderA. I type cd again. It recommends FolderA, even though FolderA does not have a sub-folder/file called FolderA.

rsteube commented 1 year ago

@DeadRobotDev probably best to open a new issue for that