Skip to content

Commit

Permalink
update nushell/xonsh completion scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden committed Apr 26, 2024
1 parent 12bef9b commit a0b60fb
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 26 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ num_cpus = "1.16"
threadpool = "1.8"
base64 = "0.22"
natord = "1.0"
semver = "1.0"
roff = "0.2"

[dev-dependencies]
Expand Down
6 changes: 5 additions & 1 deletion src/completions/argc.xsh
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ def _argc_completer(context):

return result

_add_one_completer('argc', _argc_completer, 'start')
if 'ARGC_XONSH_SCRIPTS' not in __xonsh__.env:
__xonsh__.env['ARGC_XONSH_SCRIPTS'] = []

if 'argc' not in __xonsh__.completers:
_add_one_completer('argc', _argc_completer, 'start')
25 changes: 2 additions & 23 deletions src/completions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::Shell;

use semver::Version;
use std::env;

const BASH_SCRIPT: &str = include_str!("argc.bash");
const ELVISH_SCRIPT: &str = include_str!("argc.elv");
const FISH_SCRIPT: &str = include_str!("argc.fish");
Expand Down Expand Up @@ -30,19 +27,7 @@ pub fn generate_completions(shell: Shell, commands: &[String]) -> String {
FISH_SCRIPT.replace("__COMMANDS__", &commands)
}
Shell::Generic => String::new(),
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::Nushell => NUSHELL_SCRIPT.to_string(),
Shell::Powershell => {
let commands = commands
.iter()
Expand All @@ -52,13 +37,7 @@ pub fn generate_completions(shell: Shell, commands: &[String]) -> String {
POWERSHELL_SCRIPT.replace("__COMMANDS__", &commands)
}
Shell::Xonsh => {
let scripts_env_var = "ARGC_XONSH_SCRIPTS";
if env::var(scripts_env_var).is_ok() {
format!("__xonsh__.env['{scripts_env_var}'].extend({commands:?})")
} else {
let code = format!("__xonsh__.env['{scripts_env_var}'] = {commands:?}");
format!("{XONSH_SCRIPT}\n{code}")
}
format!("{XONSH_SCRIPT}\n__xonsh__.env['ARGC_XONSH_SCRIPTS'].extend({commands:?})")
}
Shell::Zsh => {
let commands = commands.join(" ");
Expand Down

0 comments on commit a0b60fb

Please sign in to comment.