1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! Port of `_parameter` from `Completion/Zsh/Context/_parameter`.
//!
//! Full upstream body (8 lines verbatim):
//! ```text
//! sh:1 #compdef -parameter-
//! sh:2
//! sh:3 if compset -P '*:'; then
//! sh:4 _history_modifiers p
//! sh:5 return
//! sh:6 fi
//! sh:7
//! sh:8 _parameters -e
//! ```
//!
//! `compset -P '*:'` shifts past a leading `prefix:` match. When
//! present, dispatch `_history_modifiers p`; else `_parameters -e`.
use crate::ported::exec_hooks::dispatch_function_call;
use crate::ported::zle::complete::bin_compset;
use crate::ported::zsh_h::{options, MAX_OPS};
fn make_ops() -> options {
options {
ind: [0u8; MAX_OPS],
args: Vec::new(),
argscount: 0,
argsalloc: 0,
}
}
/// `_parameter` — `${...}` parameter-expansion context completion.
pub fn _parameter() -> i32 {
// sh:3 if compset -P '*:'
if bin_compset(
"compset",
&["-P".to_string(), "*:".to_string()],
&make_ops(),
0,
) == 0
{
// sh:4-5
return dispatch_function_call("_history_modifiers", &["p".to_string()]).unwrap_or(1);
}
// sh:8
dispatch_function_call("_parameters", &["-e".to_string()]).unwrap_or(1)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn returns_one_without_executor() {
let _g = crate::test_util::global_state_lock();
assert_eq!(_parameter(), 1);
}
}