installShellCompletion using command

Hello, I’m working on adding spring-boot-cli to nixpkgs here. Everything works except shell completion. In the completion file the spring command is used. How can I use the spring command in a bash-completion file?

  1 # bash completion for spring                                                    
  2 # Installation: source this file locally in a terminal or from                  
  3 # ~/.bashrc or put it in /etc/bash_completions.d (debian)                       
  4                                                                                 
  5 _spring()                                                                       
  6 {                                                                               
  7     local cur prev help helps words cword command commands i                    
  8                                                                                 
  9     _get_comp_words_by_ref cur prev words cword                                 
 10                                                                                 
 11     COMPREPLY=()                                                                
 12                                                                                 
 13     while read -r line; do                                                      
 14         reply=`echo "$line" | awk '{print $1;}'`                                
 15         COMPREPLY+=("$reply")                                                   
 16     done < <(spring hint ${cword} ${words[*]})                                  
 17                                                                                 
 18     if [ $cword -ne 1 ]; then                                                   
 19         _filedir                                                                
 20     fi                                                                          
 21                                                                                 
 22 } && complete -F _spring spring

Line 16 uses the spring command that is installed by the package.

Surely spring is in the PATH by the time the _spring completion function is executed.

Looking at your linked packages, you’re renaming the zsh file from _spring to _springboot. I’m not all that familiar with zsh, but doesn’t it have to be named _spring if it’s a completion for the command spring? I’m not sure if there’s any such restrictions on the bash filenames, though matching the command should be conventional there too.

Thanks! I think renaming was the problem. I removed the names for both and it works.