1

I my bashrc. I have a bash completion for the command scp implemented as follows

function _scp_complete
{
  COMPREPLY=""
  COMPREPLY+=( $(cat ~/.ssh_complete ) )
  COMPREPLY+=( $( find . ! -name . -prune -type f ) )
}
complete -F _scp_complete scp

The idea is that when pressing scp [tab] I see all files in the current directory and the words listed in the text file ~/.ssh_complete. Let's assume this file contain the following entries:

[email protected]
[email protected]

The desired behavior is as follows: I type scp alex@ [tab] and tab completion'completes' the command to scp [email protected]. automatically, because there are only two possible arguments starting with alex@ (assuming there is no file named similar to that in the currect working directory.).

The behavior I get with the current implementation is as follows: I type scp alex@ [tab] and the tab completion does not complete anything, but lists every possible argument below the command.

How can I get the desired behavior?

1 Answer 1

1

This works for me:

_foo() 
{
  local cur
  COMPREPLY=()
  cur=${COMP_WORDS[COMP_CWORD]}
  opts=""
  while read line           
  do           
    opts+=" $line"
  done < ~/.ssh_complete
  opts+=" "
  opts+=$(find . ! -name . -prune -type f)
  case "$cur" in
    *)
    COMPREPLY=( $( compgen -W '$opts' -- $cur ) );;
  esac

  return 0
}

complete -F _foo scp
1
  • @Alex: If this answer solved your problem, please mark it as accepted by clicking the check mark. Feb 7, 2013 at 0:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .