dvm icon indicating copy to clipboard operation
dvm copied to clipboard

Added bash completion and fzf support

Open jonasfj opened this issue 3 years ago • 7 comments

This adds:

  • Bash completion
    • Renames internal functions to be prefixed _ so they don't show up in dv<tab><tab>
    • dvm use <tab><tab> will show list of installed versions and --default
    • dvm use --default <tab><tab> will show list of installed versions
    • dvm install <tab><tab> will show list of stable versions (this seems like the thing most used will need).
  • Fuzzy matching with fzf
    • dvm install will open fzf with stable versions
    • dvm use will option fzf with installed versions
    • dvm use --default will option fzf with installed versions

To make bash completion and fuzzy matching fast, the list of versions for stable, beta and dev will be saved to:

  • $DVM_ROOT/cache/versions-stable
  • $DVM_ROOT/cache/versions-beta
  • $DVM_ROOT/cache/versions-dev

If older than 5 minutes the list of versions will be refreshed. According to man date this should work on Mac OS too, but I only tested it on Linux.


warning: it's entirely possible that I made a typo in some of this code, I renamed quite a few things -- and I have yet to figure out what dvm alias is good for :see_no_evil:

jonasfj avatar Jun 15 '21 20:06 jonasfj

I think we should consider a dvm default command for setting the default version... possibly even a dvm install [--use] [--default] command, so that updating to the latest version is easy. But that's something we can do later.

For now bash completion and fzf will make most interactions with dvm much smoother.

jonasfj avatar Jun 15 '21 20:06 jonasfj

I think we should consider a dvm default command for setting the default version.

Something like this? :wink:

$ dvm --help |grep use
   use        Select a Dart version to use (--default to set as default)

I'd actually forgotten this feature existed until a couple weeks ago. https://github.com/cbracken/dvm/issues/12. Perhaps the bug was to actually create an alias symlink, rather than writing the file to be sourced which IIRC is what it does now. That's probably actually still a good idea.

cbracken avatar Jun 15 '21 23:06 cbracken

Oh I see, I misread what you'd written; you actually included the above in your completions list. Sounds like you're saying we should add a dvm default command that would allow the user to swing the default version, rather than dvm use --default VERSION?

cbracken avatar Jun 15 '21 23:06 cbracken

Sounds like you're saying we should add a dvm default command that would allow the user to swing the default version, rather than dvm use --default VERSION?

Yeah, or something like that.. I frequently find that what I want to do is:

  • Install a Dart SDK version, and,
  • Set it to be used by default.

There is many ways we could do this. Maybe dvm without any arguments should do: V=$(dvm listall | fzf); dvm install $V; dvm use $V --default;

Just because, listall + install + use + --default is the most common thing to do. But we can consider that later.

jonasfj avatar Jun 16 '21 11:06 jonasfj

@cbracken I assume we both forgot all about this :rofl:

Should we merge... all the stuff about adding additional commands and shortcuts seems like follow up PRs, if we want to do it. With fzf and bash completion using dvm is already a lot easier :D

jonasfj avatar Jun 29 '21 14:06 jonasfj

Just adding a note to apologise for the delay! I haven't forgotten about this, but was out for three weeks starting almost exactly when you last replied and finally got caught up on all the other stuff! Will take a look!

cbracken avatar Aug 11 '21 18:08 cbracken

@cbracken friendly ping :D

jonasfj avatar Sep 24 '21 09:09 jonasfj