1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 14:47:47 +00:00

[completions-cargo] complete targets from cargo metadata (#194)

* complete targets from cargo metadata

for more precise completions we probably should use cargo metadata to get the available targets

* fix typo
This commit is contained in:
Eschryn 2022-03-29 00:47:22 +02:00 committed by GitHub
parent 7320f99f59
commit f394c2819e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,18 +1,10 @@
## Written by lukexor
def "nu-complete cargo bins" [] {
let $bins = (ls src | where name =~ bin | each { |f| ls -s $f.name } | flatten | where name =~ .rs || type == dir)
if ($bins | length) > 0 {
echo $bins | upsert name { |file| $file.name | str find-replace ".rs" "" } | get name
}
}
def "nu-complete cargo examples" [] {
let $examples = (ls | where name =~ examples | each { |f| ls -s $f.name } | flatten | where name =~ .rs || type == dir)
if ($examples | length) > 0 {
echo $examples | upsert name { |file| $file.name | str find-replace ".rs" "" } | get name
}
def "nu-complete cargo targets" [type: string] {
cargo metadata --format-version=1 --offline --no-deps | from json | get packages.targets | flatten | where ($type in $it.kind) | get name
}
def "nu-complete cargo bins" [] { nu-complete cargo targets bin }
def "nu-complete cargo examples" [] { nu-complete cargo targets example }
def "nu-complete cargo packages" [] {
let metadata = (cargo metadata --format-version=1 --offline --no-deps)