]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/rbw/rbw.plugin.zsh
initial
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / rbw / rbw.plugin.zsh
1 if (( ! $+commands[rbw] )); then
2   return
3 fi
4
5 # If the completion file doesn't exist yet, we need to autoload it and
6 # bind it to `rbw`. Otherwise, compinit will have already done that.
7 if [[ ! -f "$ZSH_CACHE_DIR/completions/_rbw" ]]; then
8   typeset -g -A _comps
9   autoload -Uz _rbw
10   _comps[rbw]=_rbw
11 fi
12
13 rbw gen-completions zsh >| "$ZSH_CACHE_DIR/completions/_rbw" &|
14
15 # rbwpw function copies the password of a service to the clipboard
16 # and clears it after 20 seconds
17 function rbwpw {
18   if [[ $# -ne 1 ]]; then
19     echo "usage: rbwpw <service>"
20     return 1
21   fi
22   local service=$1
23   if ! rbw unlock; then
24     echo "rbw is locked"
25     return 1
26   fi
27   local pw=$(rbw get $service 2>/dev/null)
28   if [[ -z $pw ]]; then
29     echo "$service not found"
30     return 1
31   fi
32   echo -n $pw | clipcopy
33   echo "password for $service copied!"
34   {sleep 20 && clipcopy </dev/null 2>/dev/null} &|
35 }
36
37 function _rbwpw {
38   local -a services
39   services=("${(@f)$(rbw ls 2>/dev/null)}")
40   [[ -n "$services" ]] && compadd -a -- services
41 }
42
43 compdef _rbwpw rbwpw