summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlo Sala <carlosalag@protonmail.com>2025-06-25 21:33:17 +0200
committerGitHub <noreply@github.com>2025-06-25 21:33:17 +0200
commit01433503c2a474c049fa56d792ebfd9274e683cc (patch)
treec8a0abdf5662345ed859d7e1f5998bb09b33ba91
parentf8022980a3423f25e3d5e1b6a60d2372a2ba006b (diff)
downloadzsh-01433503c2a474c049fa56d792ebfd9274e683cc.tar.gz
zsh-01433503c2a474c049fa56d792ebfd9274e683cc.tar.bz2
zsh-01433503c2a474c049fa56d792ebfd9274e683cc.zip
fix(rbw): reset clipboard in `rbwpw` only in the last invocation (#13185)
The previous behavior would reset the clipboard after 20 seconds always, even if the `rbwpw` function was called again in between. This commit fixes that behavior. Co-authored-by: Marc Cornellà <marc@mcornella.com>
-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 {