nvm-sh / nvm

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions
MIT License
80k stars 8.01k forks source link

we need fish_completion ! #3430

Closed halohsu closed 1 month ago

halohsu commented 1 month ago

We need:

cp .nvm/fish_completion $HOME/.config/fish/conf.d/nvm.fish
halohsu commented 1 month ago

Create by GPT4-Turbo:

function __fish_nvm_using_command
    set cmd (commandline -opc)
    if [ (count $cmd) -gt (count $argv) ]
        for i in (seq (count $argv))
            if [ $cmd[$i] != $argv[$i] ]
                return 1
            end
        end
        return 0
    end
    return 1
end

function __fish_nvm_needs_command
    set cmd (commandline -opc)
    if [ (count $cmd) -eq 1 -a $cmd[1] = 'nvm' ]
        return 0
    end
    return 1
end

complete -c nvm -n '__fish_nvm_needs_command' -a 'help install uninstall use run exec alias unalias reinstall-packages current list ls list-remote ls-remote install-latest-npm cache deactivate unload version version-remote which' -d 'Commands'

complete -c nvm -n '__fish_nvm_using_command nvm use' -a '(nvm ls)' -d 'Node versions installed'
complete -c nvm -n '__fish_nvm_using_command nvm run' -a '(nvm ls)' -d 'Run script using node version'
complete -c nvm -n '__fish_nvm_using_command nvm exec' -a '(nvm ls)' -d 'Execute command with node version'
complete -c nvm -n '__fish_nvm_using_command nvm alias' -a '(nvm alias)' -d 'Show aliases'
complete -c nvm -n '__fish_nvm_using_command nvm unalias' -a '(nvm alias)' -d 'Remove alias'
halohsu commented 1 month ago

The following effects are achieved:

⋊> ~ nvm uninstall                                                                                                                                                                     14:09:16
alias       (Commands)  Documents/           install-latest-npm  (Commands)  ls-remote  (Commands)  Public/                         unload          (Commands)
cache       (Commands)  Downloads/           Library/                        Movies/                reinstall-packages  (Commands)  use             (Commands)
current     (Commands)  exec     (Commands)  list                (Commands)  Music/                 run                 (Commands)  version         (Commands)
deactivate  (Commands)  help     (Commands)  list-remote         (Commands)  OneDrive/              unalias             (Commands)  version-remote  (Commands)
Desktop/                install  (Commands)  ls                  (Commands)  Pictures/              uninstall           (Commands)  which           (Commands)

I hope nvm will officially release a fish completion support.

ljharb commented 1 month ago

fish isn’t a posix-compliant shell, and nvm doesn’t support it at all.