#!/bin/bash # Author: Alexander Epstein https://github.com/alexanderepstein global base := ''"" global exchangeTo := ''"" global currentVersion := '"1.11.1'" global configuredClient := ''"" ## This function determines which http get tool the system has installed and returns an error if there isnt one proc getConfiguredClient { if command -v curl &>/dev/null ; { global configuredClient := '"curl'" } elif command -v wget &>/dev/null ; { global configuredClient := '"wget'" } elif command -v fetch &>/dev/null ; { global configuredClient := '"fetch'" } else { echo "Error: This tool reqires either curl, wget, or fetch to be installed." return 1 } } ## Allows to call the users configured client without if statements everywhere proc httpGet { matchstr $configuredClient { curl { curl -A curl -s @Argv} wget { wget -qO- @Argv} fetch { fetch -o "..."} } } proc checkValidCurrency { if [[ $1 != "AUD" && $1 != "BGN" && $1 != "BRL" \ && $1 != "CAD" && $1 != "CHF" && $1 != "CNY" && $1 != "CZK" && $1 != "DKK" \ && $1 != "EUR" && $1 != "GBP" && $1 != "HKD" && $1 != "HRK" && $1 != "HUF" \ && $1 != "IDR" && $1 != "ILS" && $1 != "INR" && $1 != "JPY" && $1 != "KRW" \ && $1 != "MXN" && $1 != "MYR" && $1 != "NOK" && $1 != "NZD" && $1 != "PHP" \ && $1 != "PLN" && $1 != "RON" && $1 != "RUB" && $1 != "SEK" && $1 != "SGD" \ && $1 != "THB" && $1 != "TRY" && $1 != "USD" && $1 != "ZAR" ]]{ echo "1" } else { echo "0" } } ## Grabs the base currency from the user and validates it with all the possible currency ## types available on the API and guides user through input (doesnt take in arguments) proc getBase { echo -n "What is the base currency: " read -r base global base := $[echo $base | tr /a-z/ /A-Z/] if [[ $(checkValidCurrency $base) == "1" ]]{ unset base echo "Invalid base currency" getBase } } ## Checks base currency from the user and validates it with all the possible currency ## types available on the API (requires argument) proc checkBase { global base := $1 global base := $[echo $base | tr /a-z/ /A-Z/] if [[ $(checkValidCurrency $base) == "1" ]]{ unset base echo "Invalid base currency" exit 1 } } ## Grabs the exchange to currency from the user and validates it with all the possible currency ## types available on the API and guides user through input (doesnt take in arguments) proc getExchangeTo { echo -n "What currency to exchange to: " read -r exchangeTo global exchangeTo := $[echo $exchangeTo | tr /a-z/ /A-Z/] if [[ $(checkValidCurrency $exchangeTo) == "1" ]]{ echo "Invalid exchange currency" unset exchangeTo getExchangeTo } } ## Grabs the exchange to currency from the user and validates it with all the possible currency ## types available on the API (requires arguments) proc checkExchangeTo { global exchangeTo := $1 global exchangeTo := $[echo $exchangeTo | tr /a-z/ /A-Z/] if [[ $(checkValidCurrency $exchangeTo) == "1" ]]{ echo "Invalid exchange currency" unset exchangeTo exit 1 } } ## Get the amount that will be exchanged and validate that the user has entered a number (decimals are allowed) ## doesnt take in argument, it guides user through input proc getAmount { echo -n "What is the amount being exchanged: " read -r amount if [[ ! "$amount" =~ ^[0-9]+(\.[0-9]+)?$ ]] { echo "The amount has to be a number" unset amount getAmount } } ## Get the amount that will be exchanged ## validate that the user has entered a number (decimals are allowed and requires argument) proc checkAmount { global amount := $1 if [[ ! "$amount" =~ ^[0-9]+(\.[0-9]+)?$ ]] { echo "The amount has to be a number" unset amount exit 1 } } proc checkInternet { echo -e "GET http://google.com HTTP/1.0\n\n" | nc google.com 80 > /dev/null !2 > !1 if test $Status -eq 0 { return 0 } else { echo "Error: no active internet connection" > !2 return 1 } } ## Grabs the exchange rate and does the math for converting the currency proc convertCurrency { global exchangeRate := $[httpGet "http://api.fixer.io/latest?base=$base&symbols=$exchangeTo" | grep -Eo "[0-9]*[.][0-9]*] > /dev/null global exchangeAmount := $[echo "$exchangeRate * $amount" | bc] echo echo "=========================" echo "| $base to $exchangeTo" echo "| Rate: $exchangeRate" echo "| $base: $amount" echo "| $exchangeTo: $exchangeAmount" echo "=========================" } proc update { # Author: Alexander Epstein https://github.com/alexanderepstein # Update utility version 1.2.0 # To test the tool enter in the defualt values that are in the examples for each variable global repositoryName := '"Bash-Snippets'" #Name of repostiory to be updated ex. Sandman-Lite global githubUserName := '"alexanderepstein'" #username that hosts the repostiory ex. alexanderepstein global nameOfInstallFile := '"install.sh'" # change this if the installer file has a different name be sure to include file extension if there is one global latestVersion := $[httpGet https://api.github.com/repos/$githubUserName/$repositoryName/tags | grep -Eo '"name":.*?[^\\]",'| head -1 | grep -Eo "[0-9.]+] #always grabs the tag without the v option if [[ $currentVersion == "" || $repositoryName == "" || $githubUserName == "" || $nameOfInstallFile == "" ]]{ echo "Error: update utility has not been configured correctly." > !2 exit 1 } elif [[ $latestVersion == "" ]]{ echo "Error: no active internet connection" > !2 exit 1 } else { if [[ "$latestVersion" != "$currentVersion" ]] { echo "Version $latestVersion available" echo -n "Do you wish to update $repositoryName [Y/n]: " read -r answer if [[ "$answer" == "Y" || "$answer" == "y" ]] { cd ~ || do { echo 'Update Failed' ; exit 1 ; } if [[ -d ~/$repositoryName ]] { rm -r -f $repositoryName || do { echo "Permissions Error: try running the update as sudo"; exit 1; } ; } git clone "https://github.com/$githubUserName/$repositoryName" || do { echo "Couldn't download latest version" ; exit 1; } cd $repositoryName || do { echo 'Update Failed' ; exit 1 ;} git checkout "v$latestVersion" !2 > /dev/null || git checkout $latestVersion !2 > /dev/null || echo "Couldn't git checkout to stable release, updating to latest commit." chmod a+x install.sh #this might be necessary in your case but wasnt in mine. ./$nameOfInstallFile "update" || exit 1 cd .. rm -r -f $repositoryName || do { echo "Permissions Error: update succesfull but cannot delete temp files located at ~/$repositoryName delete this directory with sudo"; exit 1; } } else { exit 1 } } else { echo "$repositoryName is already the latest version" } } } proc usage { echo "Currency" echo "Description: A realtime currency converter." echo " With no flags it will guide you through the currency exchange" echo "Usage: currency or currency [flag] or currency [base] [exchangeTo] [amount]" echo " -u Update Bash-Snippet Tools" echo " -h Show the help" echo " -v Get the tool version" echo "Supported Currencies:" echo " _______________________" echo "| AUD | BGN | BRL | CAD |" echo "| CHF | CNY | CZK | DKK |" echo "| EUR | GBP | HKD | HRK |" echo "| HUF | IDR | ILS | INR |" echo "| JPY | KRW | MXN | MYR |" echo "| NOK | NZD | PHP | PLN |" echo "| RON | RUB | SEK | SGD |" echo "| THB | TRY | USD | ZAR |" echo " _______________________" echo "Examples:" echo " currency EUR USD 12.35" echo " currency" } getConfiguredClient || exit 1 checkInternet || exit 1 # check if we have a valid internet connection if this isnt true the rest of the script will not work so stop here while getopts "uvh" opt { matchstr $opt { \? { echo "Invalid option: -$OPTARG" > !2 exit 1 } h { usage exit 0 } v { echo "Version $currentVersion" exit 0 } u { update exit 0 } : { echo "Option -$OPTARG requires an argument." > !2 exit 1 } } } if [[ $# == 0 ]] { getBase # get base currency getExchangeTo # get exchange to currency getAmount # get the amount to be converted convertCurrency # grab the exhange rate and perform the conversion exit 0 } elif [[ $# == "1" ]] { if [[ $1 == "update" ]]{ update } elif [[ $1 == "help" ]] { usage } else { echo "Not a valid argument" usage exit 1 } } elif [[ $# == "2" ]] { echo "Not a valid argument" usage exit 1 } elif [[ $# == "3" ]]{ checkBase $1 checkExchangeTo $2 checkAmount $3 convertCurrency exit 0 } (CommandList children: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:base) op:Equal rhs:{(DQ )} spids:[7])] spids: [7] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:exchangeTo) op:Equal rhs:{(DQ )} spids:[11])] spids: [11] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:currentVersion) op:Equal rhs:{(DQ (1.11.1))} spids:[15])] spids: [15] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:configuredClient) op:Equal rhs:{(DQ )} spids:[20])] spids: [20] ) (FuncDef name: getConfiguredClient body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(command)} {(-v)} {(curl)}) terminator: ) (Sentence child: (SimpleCommand redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [44] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredClient) op: Equal rhs: {(DQ (curl))} spids: [52] ) ] spids: [52] ) ] spids: [-1 49] ) (if_arm cond: [ (Sentence child: (C {(command)} {(-v)} {(wget)}) terminator: ) (Sentence child: (SimpleCommand redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [67] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredClient) op: Equal rhs: {(DQ (wget))} spids: [75] ) ] spids: [75] ) ] spids: [58 72] ) (if_arm cond: [ (Sentence child: (C {(command)} {(-v)} {(fetch)}) terminator: ) (Sentence child: (SimpleCommand redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [90] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredClient) op: Equal rhs: {(DQ (fetch))} spids: [98] ) ] spids: [98] ) ] spids: [81 95] ) ] else_action: [ (C {(echo)} {(DQ ("Error: This tool reqires either curl, wget, or fetch to be installed."))} ) (ControlFlow token: arg_word:{(1)}) ] spids: [104 119] ) ] spids: [32] ) spids: [28 31] ) (FuncDef name: httpGet body: (BraceGroup children: [ (Case to_match: {(DQ ($ VSub_Name "$configuredClient"))} arms: [ (case_arm pat_list: [{(curl)}] action: [(C {(curl)} {(-A)} {(curl)} {(-s)} {(DQ ($ VSub_At "$@"))})] spids: [144 145 158 -1] ) (case_arm pat_list: [{(wget)}] action: [(C {(wget)} {(-qO-)} {(DQ ($ VSub_At "$@"))})] spids: [161 162 171 -1] ) (case_arm pat_list: [{(fetch)}] action: [(C {(fetch)} {(-o)} {(DQ (...))})] spids: [174 175 184 -1] ) ] spids: [135 141 187] ) ] spids: [132] ) spids: [128 131] ) (FuncDef name: checkValidCurrency body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Number "$1")} right: {(DQ (AUD))} ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Number "$1")} right: {(DQ (BGN))} ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Number "$1")} right: {(DQ (BRL))} ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Number "$1")} right: {(DQ (CAD))} ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Number "$1")} right: {(DQ (CHF))} ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Number "$1")} right: {(DQ (CNY))} ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Number "$1")} right: {(DQ (CZK))} ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Number "$1")} right: {(DQ (DKK))} ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Number "$1")} right: {(DQ (EUR))} ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Number "$1")} right: {(DQ (GBP))} ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Number "$1")} right: {(DQ (HKD))} ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: { ($ VSub_Number "$1") } right: {(DQ (HRK))} ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: { ($ VSub_Number "$1" ) } right: {(DQ (HUF))} ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: { ($ VSub_Number "$1" ) } right: {(DQ (IDR))} ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: { ($ VSub_Number "$1" ) } right: { (DQ ( ILS ) ) } ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: { ($ VSub_Number "$1" ) } right: { (DQ ( INR ) ) } ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: { ($ VSub_Number "$1" ) } right: { (DQ ( JPY ) ) } ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: { ($ VSub_Number "$1" ) } right: { (DQ ( KRW ) ) } ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: { ($ VSub_Number "$1" ) } right: { (DQ ( MXN ) ) } ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: { ($ VSub_Number "$1" ) } right: { (DQ ( MYR ) ) } ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: { ($ VSub_Number "$1" ) } right: { (DQ ( NOK ) ) } ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: { ($ VSub_Number "$1" ) } right: { (DQ ( NZD ) ) } ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: { ($ VSub_Number "$1" ) } right: { (DQ ( PHP ) ) } ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: { ($ VSub_Number "$1" ) } right: { (DQ ( PLN ) ) } ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: { ($ VSub_Number "$1" ) } right: { (DQ ( RON ) ) } ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: { ($ VSub_Number "$1" ) } right: { (DQ ( RUB ) ) } ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: { ($ VSub_Number "$1" ) } right: { (DQ ( SEK ) ) } ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: { ($ VSub_Number "$1" ) } right: { (DQ ( SGD ) ) } ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: { ($ VSub_Number "$1" ) } right: { (DQ ( THB ) ) } ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: { ($ VSub_Number "$1" ) } right: { (DQ ( TRY ) ) } ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobNEqual left: { ($ VSub_Number "$1" ) } right: { (DQ ( USD ) ) } ) right: (BoolBinary op_id: BoolBinary_GlobNEqual left: { ($ VSub_Number "$1" ) } right: { (DQ ( ZAR ) ) } ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) terminator: ) ] action: [(C {(echo)} {(DQ (1))})] spids: [-1 535] ) ] else_action: [(C {(echo)} {(DQ (0))})] spids: [545 555] ) ] spids: [196] ) spids: [192 195] ) (FuncDef name: getBase body: (BraceGroup children: [ (C {(echo)} {(-n)} {(DQ ("What is the base currency: "))}) (C {(read)} {(-r)} {(base)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:base) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$base")}) (C {(tr)} {(/a-z/)} {(/A-Z/)}) ] negated: False ) ] ) left_token: spids: [590 602] ) } spids: [589] ) ] spids: [589] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: { (CommandSubPart command_list: (CommandList children: [(C {(checkValidCurrency)} {($ VSub_Name "$base")})] ) left_token: spids: [609 613] ) } right: {(DQ (1))} ) ) terminator: ) ] action: [ (C {(unset)} {(base)}) (C {(echo)} {(DQ ("Invalid base currency"))}) (C {(getBase)}) ] spids: [-1 623] ) ] spids: [-1 641] ) ] spids: [570] ) spids: [566 569] ) (FuncDef name: checkBase body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:base) op: Equal rhs: {($ VSub_Number "$1")} spids: [658] ) ] spids: [658] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:base) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$base")}) (C {(tr)} {(/a-z/)} {(/A-Z/)}) ] negated: False ) ] ) left_token: spids: [663 675] ) } spids: [662] ) ] spids: [662] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: { (CommandSubPart command_list: (CommandList children: [(C {(checkValidCurrency)} {($ VSub_Name "$base")})] ) left_token: spids: [682 686] ) } right: {(DQ (1))} ) ) terminator: ) ] action: [ (C {(unset)} {(base)}) (C {(echo)} {(DQ ("Invalid base currency"))}) (C {(exit)} {(1)}) ] spids: [-1 696] ) ] spids: [-1 716] ) ] spids: [655] ) spids: [651 654] ) (FuncDef name: getExchangeTo body: (BraceGroup children: [ (C {(echo)} {(-n)} {(DQ ("What currency to exchange to: "))}) (C {(read)} {(-r)} {(exchangeTo)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:exchangeTo) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$exchangeTo")}) (C {(tr)} {(/a-z/)} {(/A-Z/)}) ] negated: False ) ] ) left_token: spids: [751 763] ) } spids: [750] ) ] spids: [750] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: { (CommandSubPart command_list: (CommandList children: [ (C {(checkValidCurrency)} {($ VSub_Name "$exchangeTo")}) ] ) left_token: spids: [770 774] ) } right: {(DQ (1))} ) ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Invalid exchange currency"))}) (C {(unset)} {(exchangeTo)}) (C {(getExchangeTo)}) ] spids: [-1 784] ) ] spids: [-1 802] ) ] spids: [731] ) spids: [727 730] ) (FuncDef name: checkExchangeTo body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:exchangeTo) op: Equal rhs: {($ VSub_Number "$1")} spids: [820] ) ] spids: [820] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:exchangeTo) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$exchangeTo")}) (C {(tr)} {(/a-z/)} {(/A-Z/)}) ] negated: False ) ] ) left_token: spids: [825 837] ) } spids: [824] ) ] spids: [824] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: { (CommandSubPart command_list: (CommandList children: [ (C {(checkValidCurrency)} {($ VSub_Name "$exchangeTo")}) ] ) left_token: spids: [844 848] ) } right: {(DQ (1))} ) ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Invalid exchange currency"))}) (C {(unset)} {(exchangeTo)}) (C {(exit)} {(1)}) ] spids: [-1 858] ) ] spids: [-1 878] ) ] spids: [817] ) spids: [813 816] ) (FuncDef name: getAmount body: (BraceGroup children: [ (C {(echo)} {(-n)} {(DQ ("What is the amount being exchanged: "))}) (C {(read)} {(-r)} {(amount)}) (If arms: [ (if_arm cond: [ (DBracket expr: (LogicalNot child: (BoolBinary op_id: BoolBinary_EqualTilde left: {(DQ ($ VSub_Name "$amount"))} right: {(Lit_Other "^") (Lit_Other "[") (0-9) (Lit_Other "]") (Lit_Other "+") ("(") (EscapedLiteralPart token:) (Lit_Other "[") (0-9) (Lit_Other "]") (Lit_Other "+") (")") (Lit_Other "?") (Lit_Other "$") } ) ) ) ] action: [ (C {(echo)} {(DQ ("The amount has to be a number"))}) (C {(unset)} {(amount)}) (C {(getAmount)}) ] spids: [-1 942] ) ] spids: [-1 960] ) ] spids: [893] ) spids: [889 892] ) (FuncDef name: checkAmount body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:amount) op: Equal rhs: {($ VSub_Number "$1")} spids: [978] ) ] spids: [978] ) (If arms: [ (if_arm cond: [ (DBracket expr: (LogicalNot child: (BoolBinary op_id: BoolBinary_EqualTilde left: {(DQ ($ VSub_Name "$amount"))} right: {(Lit_Other "^") (Lit_Other "[") (0-9) (Lit_Other "]") (Lit_Other "+") ("(") (EscapedLiteralPart token:) (Lit_Other "[") (0-9) (Lit_Other "]") (Lit_Other "+") (")") (Lit_Other "?") (Lit_Other "$") } ) ) ) ] action: [ (C {(echo)} {(DQ ("The amount has to be a number"))}) (C {(unset)} {(amount)}) (C {(exit)} {(1)}) ] spids: [-1 1012] ) ] spids: [-1 1032] ) ] spids: [975] ) spids: [971 974] ) (FuncDef name: checkInternet body: (BraceGroup children: [ (Pipeline children: [ (C {(echo)} {(-e)} { (DQ ("GET http://google.com HTTP/1.0") (EscapedLiteralPart token:) (EscapedLiteralPart token:) ) } ) (SimpleCommand words: [{(nc)} {(google.com)} {(80)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [1062] ) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[1066]) ] ) ] negated: False ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_QMark "$?")} {(-eq)} {(0)} {(Lit_Other "]")}) terminator: ) ] action: [(ControlFlow token: arg_word:{(0)})] spids: [-1 1083] ) ] else_action: [ (SimpleCommand words: [{(echo)} {(DQ ("Error: no active internet connection"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[1100])] ) (ControlFlow token: arg_word:{(1)}) ] spids: [1091 1109] ) ] spids: [1041] ) spids: [1037 1040] ) (FuncDef name: convertCurrency body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:exchangeRate) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(httpGet)} { (DQ ("http://api.fixer.io/latest?base=") ($ VSub_Name "$base") ("&symbols=") ($ VSub_Name "$exchangeTo") ) } ) (C {(grep)} {(-Eo)} {(DQ ("[0-9]*[.][0-9]*"))}) ] negated: False ) ] ) left_token: spids: [1125 1144] ) } spids: [1124] ) ] spids: [1124] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:exchangeAmount) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} { (DQ ($ VSub_Name "$exchangeRate") (" * ") ($ VSub_Name "$amount")) } ) (C {(bc)}) ] negated: False ) ] ) left_token: spids: [1152 1165] ) } spids: [1151] ) ] spids: [1151] ) (C {(echo)}) (C {(echo)} {(DQ ("========================="))}) (C {(echo)} {(DQ ("| ") ($ VSub_Name "$base") (" to ") ($ VSub_Name "$exchangeTo"))}) (C {(echo)} {(DQ ("| Rate: ") ($ VSub_Name "$exchangeRate"))}) (C {(echo)} {(DQ ("| ") ($ VSub_Name "$base") (": ") ($ VSub_Name "$amount"))}) (C {(echo)} {(DQ ("| ") ($ VSub_Name "$exchangeTo") (": ") ($ VSub_Name "$exchangeAmount"))}) (C {(echo)} {(DQ ("========================="))}) ] spids: [1121] ) spids: [1117 1120] ) (FuncDef name: update body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:repositoryName) op: Equal rhs: {(DQ (Bash-Snippets))} spids: [1244] ) ] spids: [1244] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:githubUserName) op: Equal rhs: {(DQ (alexanderepstein))} spids: [1253] ) ] spids: [1253] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:nameOfInstallFile) op: Equal rhs: {(DQ (install.sh))} spids: [1262] ) ] spids: [1262] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:latestVersion) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(httpGet)} {(https) (Lit_Other ":") (//api.github.com/repos/) ($ VSub_Name "$githubUserName") (/) ($ VSub_Name "$repositoryName") (/tags) } ) (C {(grep)} {(-Eo)} {(SQ <"\"name\":.*?[^\\\\]\",">)}) (C {(head)} {(-1)}) (C {(grep)} {(-Eo)} {(DQ ("[0-9.]+"))}) ] negated: False ) ] ) left_token: spids: [1272 1308] ) } spids: [1271] ) ] spids: [1271] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalOr left: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$currentVersion")} right: {(DQ )} ) right: (LogicalOr left: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$repositoryName")} right: {(DQ )} ) right: (LogicalOr left: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$githubUserName")} right: {(DQ )} ) right: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$nameOfInstallFile")} right: {(DQ )} ) ) ) ) ) terminator: ) ] action: [ (SimpleCommand words: [ {(echo)} {(DQ ("Error: update utility has not been configured correctly."))} ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[1364])] ) (C {(exit)} {(1)}) ] spids: [-1 1355] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$latestVersion")} right: {(DQ )} ) ) terminator: ) ] action: [ (SimpleCommand words: [{(echo)} {(DQ ("Error: no active internet connection"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[1395])] ) (C {(exit)} {(1)}) ] spids: [1373 1386] ) ] else_action: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {(DQ ($ VSub_Name "$latestVersion"))} right: {(DQ ($ VSub_Name "$currentVersion"))} ) ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Version ") ($ VSub_Name "$latestVersion") (" available"))}) (C {(echo)} {(-n)} { (DQ ("Do you wish to update ") ($ VSub_Name "$repositoryName") (" [Y/n]: ")) } ) (C {(read)} {(-r)} {(answer)}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalOr left: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$answer"))} right: {(DQ (Y))} ) right: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$answer"))} right: {(DQ (y))} ) ) ) terminator: ) ] action: [ (AndOr children: [ (C {(cd)} {(TildeSubPart prefix:"")}) (BraceGroup children: [ (Sentence child: (C {(echo)} {(SQ <"Update Failed">)}) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [1492] ) ] op_id: Op_DPipe ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id: BoolUnary_d child: {(Lit_Tilde "~") (/) ($ VSub_Name "$repositoryName") } ) ) terminator: ) ] action: [ (Sentence child: (AndOr children: [ (C {(rm)} {(-r)} {(-f)} {($ VSub_Name "$repositoryName")}) (BraceGroup children: [ (Sentence child: (C {(echo)} { (DQ ( "Permissions Error: try running the update as sudo" ) ) } ) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [1536] ) ] op_id: Op_DPipe ) terminator: ) ] spids: [-1 1524] ) ] spids: [-1 1554] ) (AndOr children: [ (C {(git)} {(clone)} { (DQ ("https://github.com/") ($ VSub_Name "$githubUserName") (/) ($ VSub_Name "$repositoryName") ) } ) (BraceGroup children: [ (Sentence child: (C {(echo)} {(DQ ("Couldn't download latest version"))}) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [1570] ) ] op_id: Op_DPipe ) (AndOr children: [ (C {(cd)} {($ VSub_Name "$repositoryName")}) (BraceGroup children: [ (Sentence child: (C {(echo)} {(SQ <"Update Failed">)}) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [1594] ) ] op_id: Op_DPipe ) (AndOr children: [ (SimpleCommand words: [ {(git)} {(checkout)} {(DQ (v) ($ VSub_Name "$latestVersion"))} ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [1621] ) ] ) (AndOr children: [ (SimpleCommand words: [ {(git)} {(checkout)} {(DQ ($ VSub_Name "$latestVersion"))} ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [1635] ) ] ) (C {(echo)} { (DQ ( "Couldn't git checkout to stable release, updating to latest commit." ) ) } ) ] op_id: Op_DPipe ) ] op_id: Op_DPipe ) (C {(chmod)} {(a) (Lit_Other "+") (x)} {(install.sh)}) (AndOr children: [ (C {(./) ($ VSub_Name "$nameOfInstallFile")} {(DQ (update))}) (C {(exit)} {(1)}) ] op_id: Op_DPipe ) (C {(cd)} {(..)}) (AndOr children: [ (C {(rm)} {(-r)} {(-f)} {($ VSub_Name "$repositoryName")}) (BraceGroup children: [ (Sentence child: (C {(echo)} { (DQ ( "Permissions Error: update succesfull but cannot delete temp files located at ~/" ) ($ VSub_Name "$repositoryName") (" delete this directory with sudo") ) } ) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [1689] ) ] op_id: Op_DPipe ) ] spids: [-1 1483] ) ] else_action: [(C {(exit)} {(1)})] spids: [1708 1716] ) ] spids: [-1 1424] ) ] else_action: [ (C {(echo)} {(DQ ($ VSub_Name "$repositoryName") (" is already the latest version"))} ) ] spids: [1719 1730] ) ] spids: [1404 1733] ) ] spids: [1229] ) spids: [1225 1228] ) (FuncDef name: usage body: (BraceGroup children: [ (C {(echo)} {(DQ (Currency))}) (C {(echo)} {(DQ ("Description: A realtime currency converter."))}) (C {(echo)} {(DQ (" With no flags it will guide you through the currency exchange"))}) (C {(echo)} {(DQ ("Usage: currency or currency [flag] or currency [base] [exchangeTo] [amount]"))} ) (C {(echo)} {(DQ (" -u Update Bash-Snippet Tools"))}) (C {(echo)} {(DQ (" -h Show the help"))}) (C {(echo)} {(DQ (" -v Get the tool version"))}) (C {(echo)} {(DQ ("Supported Currencies:"))}) (C {(echo)} {(DQ (" _______________________"))}) (C {(echo)} {(DQ ("| AUD | BGN | BRL | CAD |"))}) (C {(echo)} {(DQ ("| CHF | CNY | CZK | DKK |"))}) (C {(echo)} {(DQ ("| EUR | GBP | HKD | HRK |"))}) (C {(echo)} {(DQ ("| HUF | IDR | ILS | INR |"))}) (C {(echo)} {(DQ ("| JPY | KRW | MXN | MYR |"))}) (C {(echo)} {(DQ ("| NOK | NZD | PHP | PLN |"))}) (C {(echo)} {(DQ ("| RON | RUB | SEK | SGD |"))}) (C {(echo)} {(DQ ("| THB | TRY | USD | ZAR |"))}) (C {(echo)} {(DQ (" _______________________"))}) (C {(echo)} {(DQ ("Examples:"))}) (C {(echo)} {(DQ (" currency EUR USD 12.35"))}) (C {(echo)} {(DQ (" currency"))}) ] spids: [1744] ) spids: [1740 1743] ) (AndOr children:[(C {(getConfiguredClient)})(C {(exit)} {(1)})] op_id:Op_DPipe) (AndOr children:[(C {(checkInternet)})(C {(exit)} {(1)})] op_id:Op_DPipe) (While cond: [(Sentence child:(C {(getopts)} {(DQ (uvh))} {(opt)}) terminator:)] body: (DoGroup children: [ (Case to_match: {($ VSub_Name "$opt")} arms: [ (case_arm pat_list: [{(EscapedLiteralPart token:)}] action: [ (SimpleCommand words: [{(echo)} {(DQ ("Invalid option: -") ($ VSub_Name "$OPTARG"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[1948])] ) (C {(exit)} {(1)}) ] spids: [1937 1938 1957 -1] ) (case_arm pat_list: [{(h)}] action: [(C {(usage)}) (C {(exit)} {(0)})] spids: [1960 1961 1972 -1] ) (case_arm pat_list: [{(v)}] action: [ (C {(echo)} {(DQ ("Version ") ($ VSub_Name "$currentVersion"))}) (C {(exit)} {(0)}) ] spids: [1975 1976 1992 -1] ) (case_arm pat_list: [{(u)}] action: [(C {(update)}) (C {(exit)} {(0)})] spids: [1995 1996 2007 -1] ) (case_arm pat_list: [{(Lit_Other ":")}] action: [ (SimpleCommand words: [ {(echo)} {(DQ ("Option -") ($ VSub_Name "$OPTARG") (" requires an argument."))} ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[2022])] ) (C {(exit)} {(1)}) ] spids: [2010 2011 2031 -1] ) ] spids: [1930 1934 2034] ) ] spids: [1927 2036] ) ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id:BoolBinary_GlobDEqual left:{($ VSub_Pound "$#")} right:{(0)}) ) terminator: ) ] action: [ (C {(getBase)}) (C {(getExchangeTo)}) (C {(getAmount)}) (C {(convertCurrency)}) (C {(exit)} {(0)}) ] spids: [-1 2052] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Pound "$#")} right: {(DQ (1))} ) ) terminator: ) ] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Number "$1")} right: {(DQ (update))} ) ) terminator: ) ] action: [(C {(update)})] spids: [-1 2115] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Number "$1")} right: {(DQ (help))} ) ) terminator: ) ] action: [(C {(usage)})] spids: [2121 2136] ) ] else_action: [(C {(echo)} {(DQ ("Not a valid argument"))}) (C {(usage)}) (C {(exit)} {(1)})] spids: [2142 2160] ) ] spids: [2083 2098] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Pound "$#")} right: {(DQ (2))} ) ) terminator: ) ] action: [(C {(echo)} {(DQ ("Not a valid argument"))}) (C {(usage)}) (C {(exit)} {(1)})] spids: [2162 2177] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Pound "$#")} right: {(DQ (3))} ) ) terminator: ) ] action: [ (C {(checkBase)} {($ VSub_Number "$1")}) (C {(checkExchangeTo)} {($ VSub_Number "$2")}) (C {(checkAmount)} {($ VSub_Number "$3")}) (C {(convertCurrency)}) (C {(exit)} {(0)}) ] spids: [2194 2208] ) ] spids: [-1 2233] ) ] )