summaryrefslogtreecommitdiff
path: root/plugins/rbw
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2026-01-04 22:47:54 -0800
committerTuowen Zhao <ztuowen@gmail.com>2026-01-04 22:47:54 -0800
commit2aa4cb7a52b28722816ecfd55f3b06293332c55c (patch)
treef02a9f3d59d109c70caf932a24e43368994e0e8c /plugins/rbw
parent7e951c254e779ff0620537cf43ca69dd878387b4 (diff)
parentd23d3ea69fdb839088e6e5589557cce77b34aaf8 (diff)
downloadzsh-2aa4cb7a52b28722816ecfd55f3b06293332c55c.tar.gz
zsh-2aa4cb7a52b28722816ecfd55f3b06293332c55c.tar.bz2
zsh-2aa4cb7a52b28722816ecfd55f3b06293332c55c.zip
Merge remote-tracking branch 'github/master'HEADmaster
Diffstat (limited to 'plugins/rbw')
-rw-r--r--plugins/rbw/rbw.plugin.zsh17
1 files changed, 16 insertions, 1 deletions
diff --git a/plugins/rbw/rbw.plugin.zsh b/plugins/rbw/rbw.plugin.zsh
index b6cecf8b4..0b55e6e5f 100644
--- a/plugins/rbw/rbw.plugin.zsh
+++ b/plugins/rbw/rbw.plugin.zsh
@@ -29,9 +29,24 @@ function rbwpw {
echo "$service not found"
return 1
fi
+
+ # Generate a random identifier for this call to rbwpw
+ # so we can check if the clipboard content has changed
+ local _random="$RANDOM" _cache="$ZSH_CACHE_DIR/.rbwpw"
+ echo -n "$_random" > "$_cache"
+
+ # Use clipcopy to copy the password to the clipboard
echo -n $pw | clipcopy
echo "password for $service copied!"
- {sleep 20 && clipcopy </dev/null 2>/dev/null} &|
+
+ # Clear the clipboard after 20 seconds, but only if the clipboard hasn't
+ # changed (if rbwpw hasn't been called again)
+ {
+ sleep 20 \
+ && [[ "$(<"$_cache")" == "$_random" ]] \
+ && clipcopy </dev/null 2>/dev/null \
+ && command rm -f "$_cache" &>/dev/null
+ } &|
}
function _rbwpw {