help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] How to keep only files match the prefix when do command


From: Geir Hauge
Subject: Re: [Help-bash] How to keep only files match the prefix when do command completion?
Date: Wed, 14 Dec 2011 17:13:13 +0100

2011/12/13 Peng Yu <address@hidden>
I have the following defined in bash. I'd like to complete commands for unsion by completing the profile files in ~/.unsion.

~$ complete -p unison
complete -o nospace -F _unison_command unison
~$ type _unison_command
_unison_command is a function
_unison_command ()
{
    COMPREPLY=(`find ~/.unison -name '*.prf' -printf '%f\n'`);
    return 0
}

When I type the following, it shows up every *.prf file in ~/.unison. I checked the usage in /etc/bash_completion, I don't see if I did anything obviously wrong. Yet, /etc/bash_completion can correctly do filtering, for example 'finger'.

unison some_prefix<TAB>

You need to filter out the ones that doesn't start with the current prefix. Try:

_unison_command() {
  local array=(~/.unison/"$2"*.prf)
  if [[ -e ${array[0]} ]]; then
    COMPREPLY=( "address@hidden/#*\/}" )
  fi
}

--
Geir Hauge

reply via email to

[Prev in Thread] Current Thread [Next in Thread]