Moeologist / scoop-completion

scoop tab completion, work with powershell
MIT License
173 stars 12 forks source link

Autocomplete of aliases fail with name containes dash ('-') #21

Closed Lockszmith-GH closed 4 years ago

Lockszmith-GH commented 4 years ago

I noticed that some aliases are auto-completed while others where not, and the difference was those that were not had dashes in them. I then tested a few other special characters, and it seems that numbers and underscore are ok, the rest are not.

Would it be possible to add support for dashes?


Code I used to test:

# https://github.com/lukesampson/scoop/issues/3528#issuecomment-508120749
try { scoop config alias | Out-Null } catch { scoop config alias @{} }

# define some utility aliases for clarity of code
$(scoop alias rm aliaslist *>&1) | Out-Null
$(scoop alias rm autocomplete-on *>&1) | Out-Null
$(scoop alias rm autocomplete-off *>&1) | Out-Null
scoop alias add aliaslist 'scoop config alias | Out-String -Stream | Where-Object { $_ } | Select-Object @{N="Alias";E={($_ -split ":")[0].Trim()}},@{N="Src";E={($_ -split ":")[1].Trim()}}'
scoop alias add autocomplete-on 'Get-Module -ListAvailable $env:SCOOP\modules\* | Where-Object Name -eq scoop-completion | Import-Module'
scoop alias add autocomplete-off 'Get-Module scoop-completion | Remove-Module'

# remove any previously existing test aliases
# scoop aliaslist | Where-Object Alias -like 'test*' | ForEach-Object { $(scoop alias rm $_.Alias *>&1) | Out-Null }

# Add test aliases
scoop alias add test_one   "echo test_one"
scoop alias add test2me    "echo test2me"
scoop alias add test3      "echo test3"
scoop alias add testFour   "echo testFour"

scoop alias add test-five  "echo test-five"

scoop alias add test=six "echo test=six"
scoop alias add 'test@seven' "echo test@seven"
scoop alias add 'test#eight' "echo test#eight"

# Toggle autocomplete - so that alias cached list will reload
scoop autocomplete-off
scoop autocomplete-on 

# List all test* aliases
scoop aliaslist | Where-Object Alias -like 'test*'

Auto complete worked for the following

scoop test<tab>:

test_one test2me test3
testFour

The following did not auto-complete:

test-five test=six test@seven test#eight

Moeologist commented 4 years ago

Now scoop use shim to create alias,old completion fallback not work, it will be removed. But complete aliases itself still work, using ConvertFrom-Json in completion module can avoid time-consuming (#20, scoop alias is slow). And special character will support.

Lockszmith-GH commented 4 years ago

With the update to v0.2.3 it now works like a charm, thanks!