diff --git a/Makefile b/Makefile index a1787b6..d068fc7 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ install: @echo "Installing pass-cli plugin (sshkeys.bash)..." @mkdir -p ~/.password-store/.extensions/ - @cp sshkeys.bash ~/.password-store/.extensions/ + @cp extension/sshkeys.bash ~/.password-store/.extensions/ @chmod +x ~/.password-store/.extensions/sshkeys.bash @echo "Installation complete. You can now use 'pass-sshkeys'." \ No newline at end of file diff --git a/README.md b/README.md index 772bbeb..3e2b538 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ alias pass='PASSWORD_STORE_ENABLE_EXTENSIONS=true pass' Import a single host: ```bash -pass ssh import hostname +pass sshkeys import hostname ``` When importing a host, the extension automatically detects and handles ProxyJump configurations: @@ -65,7 +65,7 @@ When importing a host, the extension automatically detects and handles ProxyJump Import all hosts from SSH config: ```bash -pass ssh import-all +pass sshkeys import-all ``` ### Export SSH Keys and Config @@ -73,13 +73,13 @@ pass ssh import-all Export a single host: ```bash -pass ssh export hostname +pass sshkeys export hostname ``` Export all stored hosts: ```bash -pass ssh export-all +pass sshkeys export-all ``` ### Direct Connection @@ -87,7 +87,7 @@ pass ssh export-all Connect to a host using stored keys without importing: ```bash -pass ssh connect hostname +pass sshkeys connect hostname ``` The connect command: diff --git a/completion/pass-sshkeys b/completion/pass-sshkeys new file mode 100644 index 0000000..fead44d --- /dev/null +++ b/completion/pass-sshkeys @@ -0,0 +1,38 @@ +PASSWORD_STORE_EXTENSION_COMMANDS+=(sshkeys) + +__password_store_extension_complete_sshkeys() { + local cur="${COMP_WORDS[COMP_CWORD]}" + local subcommand="${COMP_WORDS[2]}" + + # If we are completing the subcommand itself (at index 2) + if [[ $COMP_CWORD -eq 2 ]]; then + COMPREPLY=($(compgen -W "import import-all export export-all connect -v --verbose -h --help" -- "$cur")) + return + fi + + # If -v or --verbose is at index 2, we might be completing the subcommand at index 3 + if [[ "${COMP_WORDS[2]}" == "-v" || "${COMP_WORDS[2]}" == "--verbose" ]]; then + if [[ $COMP_CWORD -eq 3 ]]; then + COMPREPLY=($(compgen -W "import import-all export export-all connect -h --help" -- "$cur")) + return + fi + # The actual subcommand is at index 3 + subcommand="${COMP_WORDS[3]}" + fi + + # We are completing an argument for a subcommand + case "$subcommand" in + import) + # Suggest hosts from ~/.ssh/config + if [[ -f "$HOME/.ssh/config" ]]; then + local hosts=$(awk '/^[Hh][Oo][Ss][Tt][[:space:]]/{for(i=2;i<=NF;i++){if($i~/#/){break};if($i!="*"){print $i}}}' "$HOME/.ssh/config" | sort -u) + COMPREPLY=($(compgen -W "$hosts" -- "$cur")) + fi + ;; + export|connect) + # Suggest hosts from the password store + local hosts=$(pass ls ssh 2>/dev/null | sed -e 's,^ssh/,,g' -e 's,/.*,,g' | sort -u) + COMPREPLY=($(compgen -W "$hosts" -- "$cur")) + ;; + esac +} diff --git a/sshkey-alt.bash b/deprecated/sshkey-alt.bash similarity index 100% rename from sshkey-alt.bash rename to deprecated/sshkey-alt.bash diff --git a/sshkey-orig.bash b/deprecated/sshkey-orig.bash similarity index 100% rename from sshkey-orig.bash rename to deprecated/sshkey-orig.bash diff --git a/sshkeys.bash b/extension/sshkeys.bash similarity index 97% rename from sshkeys.bash rename to extension/sshkeys.bash index 06eac30..9d7bd6f 100644 --- a/sshkeys.bash +++ b/extension/sshkeys.bash @@ -442,6 +442,20 @@ cmd_connect() { ssh -F "$tmp_config" "$hostname" } +# Show help +cmd_help() { + cat <<-_EOF +Usage: pass ssh [-v|--verbose] import|import-all|export|export-all|connect [hostname] + +Commands: + import - Import a host and its dependencies from ~/.ssh/config. + import-all - Import all hosts from ~/.ssh/config. + export - Export a host and its dependencies to ~/.ssh/config. + export-all - Export all hosts to ~/.ssh/config. + connect - Connect to a host using the stored keys. +_EOF +} + # Main command handler case "$1" in -v | --verbose) @@ -472,5 +486,8 @@ connect) shift cmd_connect "$@" ;; +-h|--help|help) + cmd_help + ;; *) die "Usage: pass ssh [-v|--verbose] import|import-all|export|export-all|connect [hostname]" ;; esac