[Bash-completion-devel] Completion for nvidia-settings

Igor Murzov e-mail at date.by
Fri Nov 2 13:39:50 UTC 2012


> I didn't do terribly much to this, hopefully it is closer to an appropriate 
> style.  

It's still pretty far from what it should look like.
 
> If it's still lacking, I'd appreciate any pointers you could offer.

* --------------------------------------
  have nvidia-settings &&
  _nvidia_settings()
  --------------------------------------
  Since v2.0 calling have() is not needed. The script will not be
  loaded until you try to use it :)


* --------------------------------------
  local cur= prev= i= w= nv_word=
  local -a nv_params=()
  COMPREPLY=()

  _get_comp_words_by_ref -n : cur prev
  --------------------------------------
  Use _init_completion() here.


* --------------------------------------
  if [[ "$prev" == "--config" ]]; then
       ...
  elif [[ "$prev" == @(-e|--describe) ]]; then
       ...
  elif [[ "$prev" == @(-q|--query|-a|--assign) ]]; then
       ...
  fi
  --------------------------------------
  Use case ... esac here to handle $prev.


* --------------------------------------
  nv_params=( $( nvidia-settings --describe list ) )
  --------------------------------------
  When some external program is executed, its errors should be
  suppressed with 2>/dev/null.


* --------------------------------------
  # Possibly better to add all potential completions to COMPREPLY,
  # but that gives loads of duplicates so this seems better
  for w in "${COMPREPLY[@]}"; do
      if [[ "$w" == "$nv_word" ]]; then
          # Clear if already present to avoid duplicates on list
          nv_word=
          break
      fi
  done
  # If not cleared due to duplicate list entry existing, add to list
  [[ -n "$nv_word" ]] && COMPREPLY+=( "$nv_word" )
  --------------------------------------
  compgen should solve your issue with "loads of duplicates".
  Something like
    COMPREPLY+=( $( compgen -W "$nv_word" -- "$cur" ) )
  will probably give the same result as the above snippet.


* --------------------------------------
  "${cur:0:1}" == '-'
  --------------------------------------
  $cur == -*  will do the same thing and it's more straightforward.


* --------------------------------------
  nv_params=( $( nvidia-settings --help |
      command grep -E -- '^  (-[a-zA-Z]( [A-Z]+)?, )?--' |
      command sed -r 's/^  (-[a-zA-Z]( [A-Z]+)?, )?(--[^=]*).*/\3/' ) )
  COMPREPLY=( $( compgen -W "${nv_params[*]}" -- "$cur" ) )
  --------------------------------------
  Check if _parse_help() is sufficient to get the list of available
  options.


-- Igor


> Isaac
> 
> On Sat, Sep 29, 2012 5:40:21 AM Isaac Cammann wrote:
> 
> I wouldn't mind working on the style when I get a chance, though it might not 
> be terribly soon.  I wasn't really thinking of much other than my own use when 
> I wrote it and just submitted it as an afterthought, so I figured it was 
> probably pretty far from standard.  Is there a style guideline somewhere or 
> shall I just go by example from the packaged files?
> 
> Isaac
> 
> 
> On Sat, Sep 22, 2012 at 10:10 AM, Igor Murzov <e-mail at date.by> wrote:
> 
> The style is bad, so it's not likely to be merged in as is. Can you fix
> the style or you want someone else to fix it? Also i don't have any
> nvidia gpu, so i can't test the code and can't fix it.
> 
> 
> -- Igor
> 
> 
> 
> On Sat, 22 Sep 2012 05:55:04 -0500
> Isaac Cammann <icammann at gmail.com> wrote:
> 
> > If anyone is interested, here's a (hopefully) fully functional completion
> > for nvidia-settings.  The style is probably horrible, but it seems to work
> > well.  I don't think it's totally portable, but it's not too far away if
> > someone wants to make that part happen.  Hopefully someone finds it
> > useful.  I release the work to the public domain for anyone to use as they
> > see fit.
> >
> > Isaac Cammann
> 
> 
> 
> 
> 



More information about the Bash-completion-devel mailing list