Created
March 20, 2019 03:39
-
-
Save coldnight/5c9964769e9a39bf17bb767c88e8c366 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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