2021-06-13 06:50:26 +02:00
|
|
|
#compdef nix
|
|
|
|
|
2020-10-09 09:41:55 +02:00
|
|
|
function _nix() {
|
|
|
|
local ifs_bk="$IFS"
|
|
|
|
local input=("${(Q)words[@]}")
|
|
|
|
IFS=$'\n'
|
2022-02-04 22:43:16 +01:00
|
|
|
local res=($(NIX_GET_COMPLETIONS=$((CURRENT - 1)) "$input[@]" 2>/dev/null))
|
2020-10-09 09:41:55 +02:00
|
|
|
IFS="$ifs_bk"
|
|
|
|
local tpe="${${res[1]}%%> *}"
|
|
|
|
local -a suggestions
|
|
|
|
declare -a suggestions
|
|
|
|
for suggestion in ${res:1}; do
|
2022-09-02 06:13:09 +02:00
|
|
|
suggestions+=("${suggestion%% *}")
|
2020-10-09 09:41:55 +02:00
|
|
|
done
|
2022-09-02 06:13:09 +02:00
|
|
|
local -a args
|
2020-10-09 09:41:55 +02:00
|
|
|
if [[ "$tpe" == filenames ]]; then
|
2022-09-02 06:13:09 +02:00
|
|
|
args+=('-f')
|
|
|
|
elif [[ "$tpe" == attrs ]]; then
|
|
|
|
args+=('-S' '')
|
2020-10-09 09:41:55 +02:00
|
|
|
fi
|
2022-09-02 06:13:09 +02:00
|
|
|
compadd -J nix "${args[@]}" -a suggestions
|
2020-10-09 09:41:55 +02:00
|
|
|
}
|
|
|
|
|
2022-09-02 06:13:09 +02:00
|
|
|
# _nix "$@"
|