Add gpg key loading through peco
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
4e91ed6c22
commit
3968f6203d
1 changed files with 24 additions and 6 deletions
22
.zsh/peco.sh
22
.zsh/peco.sh
|
@ -1,5 +1,5 @@
|
||||||
# Helpers
|
# Helpers
|
||||||
function exists { which $1 &> /dev/null }
|
function exists() { which $1 &>/dev/null; }
|
||||||
|
|
||||||
# kill process
|
# kill process
|
||||||
function peco-kill-process() {
|
function peco-kill-process() {
|
||||||
|
@ -11,6 +11,22 @@ function peco-kill-process() {
|
||||||
}
|
}
|
||||||
alias killp='peco-kill-process'
|
alias killp='peco-kill-process'
|
||||||
|
|
||||||
|
# load gpg-key
|
||||||
|
function peco-load-gpg-key() {
|
||||||
|
local keys
|
||||||
|
keys=$({
|
||||||
|
for keyid in $(vault list secret/gpg-key | tail -n+3); do
|
||||||
|
local uid=$({gpg --with-colons -k "${keyid}" 2>/dev/null || echo ""} | awk -F: '$1=="uid" {print $10; exit}')
|
||||||
|
[[ -n $uid ]] || continue # Key is not present on machine
|
||||||
|
echo "${uid} (${keyid})"
|
||||||
|
done
|
||||||
|
} | peco --query "$LBUFFER")
|
||||||
|
[[ -n $keys ]] || return
|
||||||
|
|
||||||
|
sed -E 's/.*\((.*)\)/\1/' <<<"${keys}" | xargs vault-gpg
|
||||||
|
}
|
||||||
|
alias pgpgkey='peco-load-gpg-key'
|
||||||
|
|
||||||
# load ssh-key
|
# load ssh-key
|
||||||
function peco-load-ssh-key() {
|
function peco-load-ssh-key() {
|
||||||
local keys
|
local keys
|
||||||
|
@ -24,10 +40,12 @@ alias psshkey='peco-load-ssh-key'
|
||||||
# select history
|
# select history
|
||||||
function peco-select-history() {
|
function peco-select-history() {
|
||||||
local tac
|
local tac
|
||||||
exists gtac && tac="gtac" || { exists tac && tac="tac" || { tac="tail -r" } }
|
exists gtac && tac="gtac" || { exists tac && tac="tac" || { tac="tail -r"; }; }
|
||||||
BUFFER=$(fc -l -n 1 | eval $tac | peco --query "$LBUFFER")
|
BUFFER=$(fc -l -n 1 | eval $tac | peco --query "$LBUFFER")
|
||||||
CURSOR=$#BUFFER # move cursor
|
CURSOR=$#BUFFER # move cursor
|
||||||
zle -R -c # refresh
|
zle -R -c # refresh
|
||||||
}
|
}
|
||||||
zle -N peco-select-history
|
zle -N peco-select-history
|
||||||
bindkey '^R' peco-select-history
|
bindkey '^R' peco-select-history
|
||||||
|
|
||||||
|
# vim: set ft=zsh :
|
||||||
|
|
Loading…
Reference in a new issue