mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-30 02:44:42 +01:00
refactor(rbw): add comments and delete temporary cache on success
This commit is contained in:
parent
f3c1180f65
commit
0ab83bb0d5
1 changed files with 16 additions and 3 deletions
|
|
@ -29,11 +29,24 @@ function rbwpw {
|
||||||
echo "$service not found"
|
echo "$service not found"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
local _random="$RANDOM"
|
|
||||||
echo -n $_random > $ZSH_CACHE_DIR/rbwpw_cache
|
# 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 -n $pw | clipcopy
|
||||||
echo "password for $service copied!"
|
echo "password for $service copied!"
|
||||||
{sleep 20 && [[ $(<$ZSH_CACHE_DIR/rbwpw_cache) == $_random ]] && 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 {
|
function _rbwpw {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue