Use rofi for SSH passphrases

This commit is contained in:
Loic Nageleisen 2024-03-19 14:57:55 +01:00
parent e646389fab
commit bb8b9420d6
Signed by: lloeki
GPG key ID: D05DAEE6889F94C2
3 changed files with 32 additions and 1 deletions

11
bin/ssh-askpass-rofi Executable file
View file

@ -0,0 +1,11 @@
#!/usr/bin/env bash
arg="$*"
key="$(echo "${arg}" | perl -ne "/'(.*)'/"' and print "$1\n"')"
pub="${key}.pub"
fingerprint="$(ssh-keygen -l -v -f "${pub}")"
mesg="${arg}
${fingerprint}
"
rofi -dmenu -disable-history -no-fixed-num-lines -l 1 -i -input /dev/null -password -p 'Passphrase' -mesg "${mesg}"

View file

@ -4,5 +4,6 @@ DOTFILES_ROOT_DIR="$(dirname "$DOTFILES_HOME_DIR")"
DOTFILES_ZSH_DIR="$DOTFILES_ROOT_DIR/zsh"
DOTFILES_BASH_DIR="$DOTFILES_ROOT_DIR/bash"
DOTFILES_SHELL_DIR="$DOTFILES_ROOT_DIR/shell"
DOTFILES_BIN_DIR="$DOTFILES_ROOT_DIR/bin"
# vim: ft=sh

View file

@ -14,7 +14,7 @@ fi
# autoload keys if there's an agent
if [[ -n "${SSH_AUTH_SOCK}" ]]; then
if ! ssh-add -l > /dev/null; then
if ! command ssh-add -l > /dev/null; then
case "${OSTYPE}" in
linux*)
# TODO: unsure yet
@ -33,6 +33,25 @@ if [[ -n "${SSH_AUTH_SOCK}" ]]; then
;;
esac
fi
case "${OSTYPE}" in
linux*)
SSH_ASKPASS="${DOTFILES_BIN_DIR}/ssh-askpass-rofi"
SSH_ASKPASS_REQUIRE='prefer'
export SSH_ASKPASS SSH_ASKPASS_REQUIRE
;;
*)
:
;;
esac
fi
function ssh-add() {
if [[ $# -eq 0 ]]; then
command ssh-add ~/.ssh/id_*[!.pub]
else
command ssh-add "$@"
fi
}
# vim: ft=bash