Skip to content

Commit 01d6562

Browse files
committed
Throttle fish greeting to show tips once every 6 hours
1 parent a1a2da7 commit 01d6562

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

dot_config/fish/functions/fish_greeting.fish

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,28 @@ function fish_greeting
129129
"tv fuzzy finder TUI (television)" \
130130
"tv --preview fuzzy find with preview"
131131

132+
# Only show tips once every 6 hours
133+
set -l stamp_file ~/.cache/fish_greeting_stamp
134+
set -l interval 21600 # 6 hours in seconds
135+
set -l now (date +%s)
136+
set -l show false
137+
138+
if not test -f $stamp_file
139+
set show true
140+
else
141+
set -l last (cat $stamp_file)
142+
if test (math $now - $last) -ge $interval
143+
set show true
144+
end
145+
end
146+
147+
if test $show = false
148+
return
149+
end
150+
151+
mkdir -p ~/.cache
152+
echo $now > $stamp_file
153+
132154
set -l count (count $tips)
133155
set -l idx1 (random 1 $count)
134156
set -l idx2 (random 1 $count)

0 commit comments

Comments
 (0)