2018-02-10 11:26:35 +00:00
|
|
|
# Helpers
|
2023-06-14 10:36:10 +00:00
|
|
|
function exists() { which $1 &>/dev/null; }
|
2018-02-10 11:26:35 +00:00
|
|
|
|
|
|
|
# kill process
|
|
|
|
function peco-kill-process() {
|
2018-02-10 11:31:51 +00:00
|
|
|
local procs
|
|
|
|
procs=$(ps ax -o pid,user,time,command | peco --query "$LBUFFER" | awk '{print $1}')
|
|
|
|
if [ -n "${procs}" ]; then
|
|
|
|
echo "${procs}" | xargs kill
|
|
|
|
fi
|
2018-02-10 11:14:23 +00:00
|
|
|
}
|
2018-02-10 11:26:35 +00:00
|
|
|
alias killp='peco-kill-process'
|
2018-02-10 11:14:23 +00:00
|
|
|
|
2023-06-14 10:36:10 +00:00
|
|
|
# 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'
|
|
|
|
|
2018-02-11 12:02:38 +00:00
|
|
|
# load ssh-key
|
|
|
|
function peco-load-ssh-key() {
|
|
|
|
local keys
|
|
|
|
keys=$(vault list secret/ssh-key | tail -n+3 | peco --query "$LBUFFER")
|
|
|
|
if [ -n "${keys}" ]; then
|
|
|
|
echo "${keys}" | xargs vault-sshadd
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
alias psshkey='peco-load-ssh-key'
|
|
|
|
|
2018-02-10 11:26:35 +00:00
|
|
|
# select history
|
|
|
|
function peco-select-history() {
|
2023-06-14 10:36:10 +00:00
|
|
|
local tac
|
|
|
|
exists gtac && tac="gtac" || { exists tac && tac="tac" || { tac="tail -r"; }; }
|
|
|
|
BUFFER=$(fc -l -n 1 | eval $tac | peco --query "$LBUFFER")
|
|
|
|
CURSOR=$#BUFFER # move cursor
|
|
|
|
zle -R -c # refresh
|
2018-02-10 11:26:35 +00:00
|
|
|
}
|
2018-02-10 11:14:23 +00:00
|
|
|
zle -N peco-select-history
|
|
|
|
bindkey '^R' peco-select-history
|
2023-06-14 10:36:10 +00:00
|
|
|
|
|
|
|
# vim: set ft=zsh :
|