Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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

function _scp_complete
  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:


The desired behavior is as follows: I type scp alex@ [tab] and tab completion'completes' the command to scp alex@192.0.0. 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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

This works for me:

  local cur
  while read line           
    opts+=" $line"
  done < ~/.ssh_complete
  opts+=" "
  opts+=$(find . ! -name . -prune -type f)
  case "$cur" in
    COMPREPLY=( $( compgen -W '$opts' -- $cur ) );;

  return 0

complete -F _foo scp
share|improve this answer
yse, finally! Thanks a lot. – Alex Feb 6 '13 at 9:01
@Alex: If this answer solved your problem, please mark it as accepted by clicking the check mark. – Mechanical snail Feb 7 '13 at 0:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.