-
-
Save jpouellet/854b1bf993abd4375f5673c3a200d16b to your computer and use it in GitHub Desktop.
Table flip all the strings!
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/env zsh | |
function flipstr() { | |
local chars='_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890()[]{}<>' | |
local flipped='¯ɐqɔpǝɟɓɥıɾʞlɯuodbɹsʇnʌʍxʎz∀𐐒ƆᗡƎℲ⅁HIſ⋊⅂WNOԀΌᴚS⊥∩ΛMX⅄Z⇂ᄅƐㄣގ9ㄥ860)([]}{><' | |
local string="$*" | |
local newstring='' | |
for ((i = ${#string}; i > 0; i--)); do | |
#newstring+=${flipped[${chars[(i)${string[$i]}*]}]} | |
char=${string[$i]} | |
flipchar=${flipped[${chars[(i)${char}*]}]} | |
newstring+=${flipchar:-${char}} | |
done | |
printf %s "$newstring" | |
} | |
flip() { | |
echo "(╯°□°)╯︵ $(flipstr "${@:-┻━┻}")" | |
} | |
unflip() { | |
echo "${*:-┬──┬} ノ( ゜-゜ノ)" | |
} | |
# so sourcing only grabs fns, but execing flips tables | |
if [[ $# -ne 0 ]]; then | |
flip "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment