deno icon indicating copy to clipboard operation
deno copied to clipboard

Shell completions for tasks in `deno task`?

Open dsherret opened this issue 3 years ago • 17 comments

Would it be possible to do shell completions for tasks in deno task? I'm unfamiliar with how shell completions work.

From #14036

dsherret avatar Mar 19 '22 21:03 dsherret

it should be possible, i havent looked into this aspect of clap (and completions) yet

crowlKats avatar Mar 19 '22 21:03 crowlKats

@mcornella, do you know if zsh (and friends), have the capability of "dynamic" completions?

crowlKats avatar Mar 19 '22 21:03 crowlKats

@mcornella, do you know if zsh (and friends), have the capability of "dynamic" completions?

I use zsh and git seems to be having dynamic completions based on the current working directory: git branch [tab] autocompletes with all the available branches.

jespertheend avatar Mar 19 '22 21:03 jespertheend

I do wonder how that works though. Is the completion system given a specific command to run to get a list? as it cant just magically know, there must be some logic.

crowlKats avatar Mar 19 '22 21:03 crowlKats

Shell completions scripts are just written as a bash script function, you can dynamically execute anything in that context to determine what the tab completion should be. The problem is clap doesn't have a feature which allows us to inject custom logic there (https://github.com/clap-rs/clap/issues/1232). It has https://docs.rs/clap/3.1.6/clap/enum.ValueHint.html for basic things like "complete with a file path here" but deno task <entry-in-deno.jsonc> would need something custom.

nayeemrmn avatar Mar 19 '22 22:03 nayeemrmn

@nayeemrmn perfect, thats what i wanted to know. tbh, i'd be against doing something custom, we should rather wait for clap.

crowlKats avatar Mar 19 '22 22:03 crowlKats

The main issue I mentioned in #14036 was paths not autocompleting after deno task. Completing from the list of tasks in the config would certainly be nice, but maybe it would be possible to add file path completions in the mean time?

jespertheend avatar Mar 19 '22 22:03 jespertheend

i'd be against doing something custom, we should rather wait for clap.

To clarify by "custom" I didn't mean bypassing clap (no idea where we'd even start) I meant the clap feature to inject custom logic beyond the ValueHint presets.

nayeemrmn avatar Mar 19 '22 22:03 nayeemrmn

Yea, I am aware, it doesnt seem ideal to go down that route

crowlKats avatar Mar 19 '22 22:03 crowlKats

Yea, I am aware, it doesnt seem ideal to go down that route

The route of https://github.com/clap-rs/clap/issues/1232? Still not sure we're clear, that part is fundamental to implementing this (i.e. clap won't have an inbuilt feature to scan upwards for a deno.jsonc and look at the "tasks" field or something).

nayeemrmn avatar Mar 19 '22 22:03 nayeemrmn

hm, yea i misunderstood something at one point, my bad (and yea, obviously clap itself wouldnt be able to do that scan for the tasks field)

crowlKats avatar Mar 19 '22 22:03 crowlKats

npm has this functionality, so I'm pretty sure we'd be able to implement it too.

Refs:

  • https://docs.npmjs.com/cli/v8/commands/npm-completion
  • https://github.com/npm/cli/blob/latest/lib/utils/completion.sh
  • https://github.com/npm/cli/blob/latest/lib/commands/completion.js

bartlomieju avatar Mar 19 '22 22:03 bartlomieju

Yea, it is definitively doable

crowlKats avatar Mar 19 '22 23:03 crowlKats

npm has this functionality, so I'm pretty sure we'd be able to implement it too.

They maintain their own completion script generation, we would have to drop clap and do the same or wait a long time.

nayeemrmn avatar Mar 19 '22 23:03 nayeemrmn

Adding this would definitely make my mission (which is "converting as many in-house teams as possible from node to deno") much easier. Folks working with npm are used to having this functionality, and consider not having it an adoption blocker.

opus131 avatar Sep 27 '22 15:09 opus131

Since there is clap_complete::engine::ArgValueCompleter, we can implement this feature!

4513ECHO avatar Sep 06 '24 11:09 4513ECHO

Any update on this issue? This would greatly improve my day-to-day experience with Deno

JLCarveth avatar Oct 23 '24 18:10 JLCarveth

+1

MerryOscar avatar Nov 15 '24 10:11 MerryOscar

+1

avrosorin avatar Nov 26 '24 20:11 avrosorin

+1

JLCarveth avatar Aug 21 '25 19:08 JLCarveth