From 37e7e90bff2e9b8ae6bfe3b4a085d471e21c209b Mon Sep 17 00:00:00 2001 From: NextAlone <12210746+NextAlone@users.noreply.github.com> Date: Thu, 23 Mar 2023 01:24:18 +0800 Subject: [PATCH] completion/ssh-copy-id: add completion (#9675) Add completions for ssh-copy-id. Refactored __ssh_history_completions into its own file for autoloading across completions. (cherry picked from commit 45b6622986f384654ee9769c57541f8281077a60) Conflicts: CHANGELOG.rst --- CHANGELOG.rst | 1 + share/completions/ssh-copy-id.fish | 108 ++++++++++++++++++ share/completions/ssh.fish | 5 - .../functions/__ssh_history_completions.fish | 3 + 4 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 share/completions/ssh-copy-id.fish create mode 100644 share/functions/__ssh_history_completions.fish diff --git a/CHANGELOG.rst b/CHANGELOG.rst index bae40ce65..20758944c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -56,6 +56,7 @@ Completions - ``scrypt`` (:issue:`9583`) - ``stow`` (:issue:`9571`) - ``trash`` and helper utilities ``trash-empty``, ``trash-list``, ``trash-put``, ``trash-restore`` (:issue:`9560`) + - ``ssh-copy-id`` (:issue:`9675`) - Improvements to many completions, including the speed of completing directories in WSL 2 (:issue:`9574`). - Completions using ``__fish_complete_suffix`` are now offered in the correct order, fixing a regression in 3.6.0 (:issue:`8924`). - ``git`` completions for ``git-foo``-style commands was restored, fixing a regression in 3.6.0 (:issue:`9457`). diff --git a/share/completions/ssh-copy-id.fish b/share/completions/ssh-copy-id.fish new file mode 100644 index 000000000..ca8c6984a --- /dev/null +++ b/share/completions/ssh-copy-id.fish @@ -0,0 +1,108 @@ +# Commands +complete -c ssh-copy-id -d Remote -xa "(__fish_complete_user_at_hosts)" +complete -c ssh-copy-id -d Remote -k -fa '(__ssh_history_completions)' + +# Options +complete -c ssh-copy-id -s i -d IdentityFile -r -F +complete -c ssh-copy-id -s p -d Port -r -x +complete -c ssh-copy-id -s F -d 'Alternate ssh config file' -r -F + +# Load completions shared by various ssh tools like ssh, scp and sftp. +complete -c ssh-copy-id -s o -d Options -xa " + AddKeysToAgent + AddressFamily + BatchMode + BindAddress + BindInterface + CanonicalDomains + CanonicalizeFallbackLocal + CanonicalizeHostname + CanonicalizeMaxDots + CanonicalizePermittedCNAMEs + CASignatureAlgorithms + CertificateFile + ChallengeResponseAuthentication + CheckHostIP + Ciphers + ClearAllForwardings + Compression + ConnectionAttempts + ConnectTimeout + ControlMaster + ControlPath + ControlPersist + DynamicForward + EscapeChar + ExitOnForwardFailure + FingerprintHash + ForwardAgent + ForwardX11 + ForwardX11Timeout + ForwardX11Trusted + GatewayPorts + GlobalKnownHostsFile + GSSAPIAuthentication + GSSAPIClientIdentity + GSSAPIDelegateCredentials + GSSAPIKexAlgorithms + GSSAPIKeyExchange + GSSAPIRenewalForcesRekey + GSSAPIServerIdentity + GSSAPITrustDns + HashKnownHosts + Host + HostbasedAuthentication + HostbasedKeyTypes + HostKeyAlgorithms + HostKeyAlias + Hostname + IdentitiesOnly + IdentityAgent + IdentityFile + IPQoS + KbdInteractiveAuthentication + KbdInteractiveDevices + KexAlgorithms + LocalCommand + LocalForward + LogLevel + MACs + Match + NoHostAuthenticationForLocalhost + NumberOfPasswordPrompts + PasswordAuthentication + PermitLocalCommand + PKCS11Provider + Port + PreferredAuthentications + ProxyCommand + ProxyJump + ProxyUseFdpass + PubkeyAcceptedKeyTypes + PubkeyAuthentication + RekeyLimit + RemoteCommand + RemoteForward + RequestTTY + SendEnv + ServerAliveCountMax + ServerAliveInterval + SetEnv + StreamLocalBindMask + StreamLocalBindUnlink + StrictHostKeyChecking + TCPKeepAlive + Tunnel + TunnelDevice + UpdateHostKeys + User + UserKnownHostsFile + VerifyHostKeyDNS + VisualHostKey + XAuthLocation + " + +complete -c ssh-copy-id -s f -d 'Force mode' +complete -c ssh-copy-id -s n -d 'Dry run' +complete -c ssh-copy-id -s s -d 'Use sftp' +complete -c ssh-copy-id -s h -s \? -d 'Show help' diff --git a/share/completions/ssh.fish b/share/completions/ssh.fish index f86317e8b..0e1083610 100644 --- a/share/completions/ssh.fish +++ b/share/completions/ssh.fish @@ -5,11 +5,6 @@ __fish_complete_ssh ssh # ssh specific completions # -# 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 - complete -c ssh -d Remote -xa "(__fish_complete_user_at_hosts)" complete -c ssh -d Remote -k -fa '(__ssh_history_completions)' diff --git a/share/functions/__ssh_history_completions.fish b/share/functions/__ssh_history_completions.fish new file mode 100644 index 000000000..d5b05019c --- /dev/null +++ b/share/functions/__ssh_history_completions.fish @@ -0,0 +1,3 @@ +function __ssh_history_completions -d "Retrieve `user@host` entries from history" + history --prefix ssh --max=100 | string replace -rf '.* ([A-Za-z0-9._:-]+@[A-Za-z0-9._:-]+).*' '$1' +end