Skip to content

Instantly share code, notes, and snippets.

@coldnight coldnight/coin.fish
Created Mar 20, 2019

Embed
What would you like to do?
#!/usr/bin/fish
# 抛硬币脚本
# Author: Lucien-X
# LastModified: 2019-02-22
# LastModified: 2019-03-20 by coldnight: porting to fish shell
# Usage: save this file to ~/.config/fish/functions/coin.fish
function coin
# Define backspace char
set -l BACKSPACE '\b\b'
# Loop animation for about 1s
set -l i "0"
while test "$i" -lt 24
for COIN in '🌝' '🌖' '🌗' '🌘' '🌚' '🌒' '🌓' '🌔'
echo -en "$BACKSPACE$COIN"
sleep 0.0417; # Insure 24 fps (1/24 ≈ 0.0417)
set i (math "$i" + 1)
end
end
# Roll the dice eventually
set -l v (expr (random) % 2)
echo -en $BACKSPACE
if test "$v" -eq 0
echo -en "🌝"
else
echo -en "🌚"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.