位置引数は一度だけ完了してください。

位置引数は一度だけ完了してください。

gsSSHホスト名を最初の引数として使用し、任意の文字列を2番目の引数として使用するコマンド()の完成を作成しようとしています。

私は基本的なSSH完成からこれを盗んだ。

# Load completions shared by various ssh tools like ssh, scp and sftp.
__fish_complete_ssh ssh
# Also retrieve `user@host` entries from history
function __ssh_history_completions
    history --prefix ssh --max=100 | string replace -rf '.* ([A-Za-z0-9._:-]+@[A-Za-z0-9._:-]+).*' '$1'
end

私はこれを使って私のコマンドのパラメータを完成させますgs

complete -c gs -d Remote -xa "(__fish_complete_user_at_hosts)"
complete -c gs -d Remote -ka '(__ssh_history_completions)'

これはうまくいきますが、SSHホスト名を完成させます。2つの引数:

  • と入力すると、gs <tab>fishはSSHホスト名を正しく入力します。
  • と入力すると、gs somehost <tab>fishはSSHホスト名を再度誤って完了します(このパラメータは完成しないでください。任意の文字列です)。

この完了に影響を与えるにはどうすればよいですか?最初私のコマンドの位置パラメータ?

ベストアンサー1

--conditionヘルパー機能と一緒にまたは-nオプションを使用してください。complete__fish_is_first_arg

complete -c gs -d Remote -xa "(__fish_complete_user_at_hosts)" -n '__fish_is_first_arg'

おすすめ記事