summaryrefslogtreecommitdiff
path: root/zsh
diff options
context:
space:
mode:
authorGrégoire Duchêne <gduchene@awhk.org>2020-12-19 15:59:28 +0000
committerGrégoire Duchêne <gduchene@awhk.org>2020-12-19 15:59:28 +0000
commit070094c8819d646dea4fa8e8b8659f54b54a52de (patch)
treeaaddd2dba18639f98af2753bced5d4a718e311c4 /zsh
parent0cc851aeeb4f4f99da91b8778e3218b164c6c140 (diff)
zsh: Add a vault command
Diffstat (limited to 'zsh')
-rw-r--r--zsh/functions/_vault3
-rw-r--r--zsh/functions/vault14
-rw-r--r--zsh/rc2
3 files changed, 18 insertions, 1 deletions
diff --git a/zsh/functions/_vault b/zsh/functions/_vault
new file mode 100644
index 0000000..5cab4e5
--- /dev/null
+++ b/zsh/functions/_vault
@@ -0,0 +1,3 @@
+#compdef vault
+
+_arguments ": :(close open)" ": :_path_files"
diff --git a/zsh/functions/vault b/zsh/functions/vault
new file mode 100644
index 0000000..abe0158
--- /dev/null
+++ b/zsh/functions/vault
@@ -0,0 +1,14 @@
+# -*- mode: sh -*-
+
+case $1 in
+ close)
+ hdiutil unmount -quiet $2
+ ;;
+ open)
+ op get item ${2:t} --fields password --session $(op signin --raw) \
+ | hdiutil attach -quiet -stdinpass $2
+ ;;
+ *)
+ return 1
+ ;;
+esac
diff --git a/zsh/rc b/zsh/rc
index 284e874..00efb2c 100644
--- a/zsh/rc
+++ b/zsh/rc
@@ -10,7 +10,7 @@
done
}
-autoload -Uz compinit op-ssh-add zmv
+autoload -Uz compinit op-ssh-add vault zmv
[[ ! -d ${XDG_CACHE_HOME}/zsh ]] && mkdir -p ${XDG_CACHE_HOME}/zsh
zstyle ':completion:*' cache-path ${XDG_CACHE_HOME}/zsh/cache