From 91ddee6bf045b1c6144d14233abdb96127186ec3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 10 May 2020 20:32:21 +0200 Subject: nix: Implement basic bash completion --- misc/bash/completion.sh | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 misc/bash/completion.sh (limited to 'misc/bash/completion.sh') diff --git a/misc/bash/completion.sh b/misc/bash/completion.sh new file mode 100644 index 000000000..097353b50 --- /dev/null +++ b/misc/bash/completion.sh @@ -0,0 +1,7 @@ +function _complete_nix { + while IFS= read -r line; do + COMPREPLY+=("$line") + done < <(NIX_GET_COMPLETIONS=$COMP_CWORD "${COMP_WORDS[@]}") +} + +complete -F _complete_nix nix -- cgit v1.2.3 From e0c19ee620c53b52ca7cf69c19d414d782338be1 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 10 May 2020 21:35:07 +0200 Subject: Add completion for paths --- misc/bash/completion.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'misc/bash/completion.sh') diff --git a/misc/bash/completion.sh b/misc/bash/completion.sh index 097353b50..93298c369 100644 --- a/misc/bash/completion.sh +++ b/misc/bash/completion.sh @@ -1,6 +1,14 @@ function _complete_nix { + local have_type while IFS= read -r line; do - COMPREPLY+=("$line") + if [[ -z $have_type ]]; then + have_type=1 + if [[ $line = filenames ]]; then + compopt -o filenames + fi + else + COMPREPLY+=("$line") + fi done < <(NIX_GET_COMPLETIONS=$COMP_CWORD "${COMP_WORDS[@]}") } -- cgit v1.2.3 From da310fac622612b90f8e511b85b8594b56ec8cdf Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 11 May 2020 21:37:53 +0200 Subject: Bash completion: Don't break on ':' --- misc/bash/completion.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'misc/bash/completion.sh') diff --git a/misc/bash/completion.sh b/misc/bash/completion.sh index 93298c369..bc184edd6 100644 --- a/misc/bash/completion.sh +++ b/misc/bash/completion.sh @@ -1,4 +1,7 @@ function _complete_nix { + local -a words + local cword cur + _get_comp_words_by_ref -n ':=&' words cword cur local have_type while IFS= read -r line; do if [[ -z $have_type ]]; then @@ -9,7 +12,8 @@ function _complete_nix { else COMPREPLY+=("$line") fi - done < <(NIX_GET_COMPLETIONS=$COMP_CWORD "${COMP_WORDS[@]}") + done < <(NIX_GET_COMPLETIONS=$cword "${words[@]}") + __ltrim_colon_completions "$cur" } complete -F _complete_nix nix -- cgit v1.2.3 From 04e5d0e7040fdfbbc084634c0694ae7da89765d9 Mon Sep 17 00:00:00 2001 From: regnat Date: Fri, 9 Oct 2020 09:39:51 +0200 Subject: Add a description in the completion outputs Make nix output completions in the form `completion\tdescription`. This can't be used by bash (afaik), but other shells like zsh or fish can display it along the completion choices --- misc/bash/completion.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'misc/bash/completion.sh') diff --git a/misc/bash/completion.sh b/misc/bash/completion.sh index bc184edd6..bea2a40bc 100644 --- a/misc/bash/completion.sh +++ b/misc/bash/completion.sh @@ -4,13 +4,14 @@ function _complete_nix { _get_comp_words_by_ref -n ':=&' words cword cur local have_type while IFS= read -r line; do + local completion=${line%% *} if [[ -z $have_type ]]; then have_type=1 - if [[ $line = filenames ]]; then + if [[ $completion = filenames ]]; then compopt -o filenames fi else - COMPREPLY+=("$line") + COMPREPLY+=("$completion") fi done < <(NIX_GET_COMPLETIONS=$cword "${words[@]}") __ltrim_colon_completions "$cur" -- cgit v1.2.3