Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sync nushell changes to completion scripts #286

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ num_cpus = "1.16"
threadpool = "1.8"
base64 = "0.21"
natord = "1.0"
semver = "1.0.21"

[dev-dependencies]
insta = "1.30"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ New-ItemProperty -LiteralPath 'HKLM:\SOFTWARE\Classes\sh_auto_file\shell\open\co

## License

Copyright (c) 2023-2024 aichat-developers.

argc is made available under the terms of either the MIT License or the Apache License 2.0, at your option.

See the LICENSE-APACHE and LICENSE-MIT files for license details.
2 changes: 1 addition & 1 deletion src/bin/argc/completions/argc.nu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def _argc_completer [args: list<string>] {
argc --argc-compgen nushell "" $args
argc --argc-compgen nushell "" ...$args
| split row "\n" | range 0..-2
| each { |line| $line | split column "\t" value description } | flatten
}
Expand Down
20 changes: 14 additions & 6 deletions src/bin/argc/completions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use argc::Shell;
use semver::Version;
use std::env;

const BASH_SCRIPT: &str = include_str!("argc.bash");
Expand Down Expand Up @@ -31,7 +32,19 @@ pub fn generate(shell: Shell, args: &[String]) -> String {
FISH_SCRIPT.replace("__COMMANDS__", &commands)
}
Shell::Generic => String::new(),
Shell::Nushell => NUSHELL_SCRIPT.to_string(),
Shell::Nushell => {
if env::var("NU_VERSION")
.ok()
.and_then(|v| Version::parse(&v).ok())
.map(|v| v < Version::new(0, 89, 0))
.unwrap_or_default()
{
// https://github.com/nushell/nushell/pull/11289
NUSHELL_SCRIPT.replace("...$args", "$args")
} else {
NUSHELL_SCRIPT.to_string()
}
}
Shell::Powershell => {
let commands = [vec!["argc".to_string()], args.to_vec()].concat();
let commands = commands
Expand Down Expand Up @@ -66,8 +79,3 @@ pub fn generate(shell: Shell, args: &[String]) -> String {
}
}
}

#[test]
fn feature() {
format!("{:?}", vec!["a", "b"]);
}