Skip to content

Fix socket discovery splitting and quoting in ssh-find-agent.sh#61

Draft
Copilot wants to merge 2 commits into
masterfrom
copilot/fix-shellcheck-sc2207-warning
Draft

Fix socket discovery splitting and quoting in ssh-find-agent.sh#61
Copilot wants to merge 2 commits into
masterfrom
copilot/fix-shellcheck-sc2207-warning

Conversation

Copilot AI commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

The script was relying on array command substitution for socket discovery, which triggers ShellCheck SC2207 and can mis-handle paths containing spaces. There were also a few tightly related quoting, scoping, and numeric-input issues in agent probing and selection.

  • Socket discovery

    • Replace array command substitution with mapfile -t in sfa_find_all_agent_sockets()
    • Group find predicates so -type s applies to all supported socket name patterns
    • Preserve the existing socket filters while making path handling safe for whitespace
  • Agent probing and selection

    • Fix the no-timeout branch to invoke ssh-add correctly
    • Quote SSH_AUTH_SOCK consistently when probing and exporting sockets
    • Localize temporary variables used during probing/menu rendering
    • Replace the fragile numeric-choice check with a regex-based validation
  • Focused shell test coverage

    • Extend the existing shell test to create an agent socket under a directory with spaces
    • Verify ssh-find-agent -a resolves and exports that socket correctly

Example of the core change:

mapfile -t _ssh_agent_sockets < <(
  find "${sfa_path[@]}" -maxdepth 2 -type s \( \
    -name 'agent.*' \
    -o -name 'S.gpg-agent.ssh' \
    -o -name 'ssh' \
    -o -name 's.*.agent.*' \
    -o -regex '.*/ssh-.*/agent..*$' \
  \) 2>/dev/null |
    grep -E '/ssh-.*/agent.*|/gpg-.*/S.gpg-agent.ssh|/keyring-.*/ssh$|.*/ssh-.*/agent..*$|s\..*\.agent\..*'
)

Copilot AI linked an issue Jun 1, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix shellcheck SC2207 warning in ssh-find-agent Fix socket discovery splitting and quoting in ssh-find-agent.sh Jun 1, 2026
Copilot AI requested a review from wwalker June 1, 2026 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

shellcheck SC2207 (warning)

2 participants