crypto (1099B)
1 #! /bin/sh 2 3 # Written in a FORTH-like manner. Experimentally. 4 5 usage() { 6 echo "crypto -- calculates value of your crypto portfolio with rate.sx" 7 echo 8 echo "USAGE" 9 echo "\t\$XDG_CONFIG_HOME/cryptorc should be an executable file that is" 10 echo "\tsetting the following enviromental variables:" 11 echo 12 echo "\t* currency: the currency you want to show the result in." 13 echo "\t* amount: the crypto values, separated by \"+\", as it is" 14 echo "\t the format rate.sx accepts." 15 echo 16 echo "EXAMPLE CRYPTORC" 17 echo "\t#!/bin/sh" 18 echo "\tcurrency=\"eur\"" 19 echo "\tamount=\"0.55btc+11eth\"" 20 exit 1 21 } 22 23 [ "$1" = "-h" ] && usage 24 25 _configfile="$XDG_CONFIG_HOME/cryptorc" 26 27 alias config_not_exists\?="[ ! -x $_configfile ]" 28 alias source_config=". $_configfile" 29 alias exit_with_error="echo 'Error: config file nonexistent or not executable' && exit" 30 31 config_not_exists? && exit_with_error || source_config 32 33 alias get="curl -s 'http://$currency.rate.sx/$amount'" 34 alias floor="cut -d. -f1" 35 alias xprint="xargs printf '%s kr\n'" 36 37 get | floor | xprint 38