#!/bin/bash # Author: Alexander Epstein https://github.com/alexanderepstein global currentVersion := '"1.11.1'" global configuredClient := ''"" global directionsFlag := '"0'" global directionsMapFlag := '"0'" global staticMapFlag := '"0'" source ~/.bash_profile ## allows grabbing enviornment variable global MAPQUEST_API_KEY := $MAPQUEST_API_KEY if test -d ~/temp{ rm -rf ~/temp;} ## 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 checkInternet { echo -e "GET http://google.com HTTP/1.0\n\n" | nc google.com 80 > /dev/null !2 > !1 # query google with a get request if test $Status -eq 0 { #check if the output is 0, if so no errors have occured and we have connected to google successfully return 0 } else { echo "Error: no active internet connection" > !2 #sent to stderr return 1 } } 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 getDirections { global response := $[httpGet "https://www.mapquestapi.com/directions/v2/route?key=$MAPQUEST_API_KEY&from=$1&to=$2&outFormat=json&ambiguities=ignore&routeType=fastest&doReverseGeocode=false&enhancedNarrative=false&avoidTimedConditions=false] global firstDirection := $[echo $response | grep -Eo "origNarrative\":\"[a-Z -./0-9]*" | grep -Eo "[^origNarrative\":][a-Z -./0-9]*] global tempDirections := '('$(echo $response | grep -Eo "\"narrative\":\"[a-Z -./0-9]*")) global distances := '('$(echo $response | grep -Eo "distance\":[0-9]*[.][0-9]*" | grep -Eo "[^distance\":][0-9]*[.][0-9]*" )) global totalDist := $(distances[0]) global count := '"0'" global count := '"-1'" global temp := $(tempDirections[0]) for direct in [$(tempDirections[@])] { if [[ $(echo $direct | grep -Eo "narrative" ) == "narrative" ]]{ global count := $[echo $count + 1 | bc] directions[$count]=$temp global temp := $[echo $direct | grep -Eo "[^\"narrative:\"][a-Z 0-9./]*] } else { global temp := ""$temp $direct"" } } #for distance in $tempDistances directions[0]=$firstDirection } proc getDirectionsMap { echo "Generating route map from $unformattedFromLocation to $unformattedToLocation" mkdir ~/temp || return 1 httpGet "https://www.mapquestapi.com/staticmap/v5/map?start=$1&end=$2&size=600,400@2x&key=$MAPQUEST_API_KEY" >> ~/temp/routeImage.png || return 1 if [[ "$OSTYPE" == "linux"* ]]{ display ~/temp/routeImage.png > /dev/null || return 1 } elif [[ "$OSTYPE" == "darwin"* ]] { open ~/temp/routeImage.png > /dev/null } rm -rf ~/temp > /dev/null } proc printDirections { echo echo "From $unformattedFromLocation to $unformattedToLocation ($totalDist mi)" echo "===================================================" global count := '0' for direct in [$(directions[@])] { if test $count -ne 0{ echo -n "$[echo $count | bc]). ";} if [[ $direct != "" ]]{ # sometimes original Narrative is blank global direct := ""$direct ($(distances[$(echo $count + 1 | bc)]) mi)"" if test $count -ne 0{ echo $direct;} global count := $[echo $count + 1 | bc] } } echo "Welcome to $unformattedToLocation" echo "===================================================" echo } proc getLocations { echo -n "Enter your starting location: " read fromLocation echo -n "Enter your destination: " read toLocation global unformattedFromLocation := $fromLocation global unformattedToLocation := $toLocation global fromLocation := $[echo $fromLocation | sed s/','/"+"/g | sed s/' '/"+"/g] global toLocation := $[echo $toLocation | sed s/','/"+"/g | sed s/' '/"+"/g] } proc checkImagemagick { if [[ "$OSTYPE" == "linux"* ]]{ if ! command -v display &>/dev/null ;{ echo "Error: you need to install imagemagick to use map features." &>2 return 1 } else { return 0 } } else { return 0 } } proc getMapLocation { echo -n "Enter the city or address you want to generate a map for: " read mapLocation echo "Generating static map for $mapLocation" global mapLocation := "=$[echo $mapLocation | sed s/','/"+"/g | sed s/' '/"+"/g]" } proc getStaticMap { mkdir ~/temp || return 1 httpGet "https://www.mapquestapi.com/staticmap/v5/map?key=$MAPQUEST_API_KEY¢er=$1&zoom=15&type=hyb&size=600,400@2x" >> ~/temp/mapImage.png || return 1 if [[ "$OSTYPE" == "linux"* ]]{ display ~/temp/mapImage.png > /dev/null || return 1 } elif [[ "$OSTYPE" == "darwin"* ]] { open ~/temp/mapImage.png > /dev/null || return 1 } rm -rf ~/temp > /dev/null || return 1 } getConfiguredClient || exit 1 checkInternet || exit 1 ## getDirections Denver Boulder || exit 1 ## printDirections Denver Boulder || exit 1 ## getDirectionsMap Denver Boulder || exit 1 ## getStaticMap Paramus || exit 1 while getopts "drmuvh" opt { matchstr $opt { \? { echo "Invalid option: -$OPTARG" > !2 exit 1 } h { usage exit 0 } d { global directionsFlag := '"1'" } m { global staticMapFlag := '"1'" } r { global directionsMapFlag := '"1'" } v { echo "Version $currentVersion" exit 0 } u { update exit 0 } : { echo "Option -$OPTARG requires an argument." > !2 exit 1 } } } if [[ $# == 0 ]] { usage exit 0 } elif [[ $# == "1" ]] { if [[ $1 == "update" ]]{ update exit 0 } elif [[ $1 == "help" ]] { usage exit 0 } } if [[ $directionsFlag == "0" && $staticMapFlag == "1" ]]{ checkImagemagick || exit 1 getMapLocation || exit 1 getStaticMap $mapLocation || exit 1 } elif [[ $directionsFlag == "1" ]]{ getLocations || exit 1 getDirections $fromLocation $toLocation || exit 1 printDirections $fromLocation $toLocation || exit 1 checkImagemagick || exit 1 if [[ $directionsMapFlag == "1" ]]{ getDirectionsMap $fromLocation $toLocation || exit 1;} if [[ $staticMapFlag = "1" ]]{ echo "Generating static map for $unformattedFromLocation" && getStaticMap $fromLocation || exit 1 echo "Generating static map for $unformattedToLocation" && getStaticMap $toLocation || exit 1 } } (CommandList children: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:currentVersion) op:Equal rhs:{(DQ (1.11.1))} spids:[7])] spids: [7] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:configuredClient) op:Equal rhs:{(DQ )} spids:[12])] spids: [12] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:directionsFlag) op:Equal rhs:{(DQ (0))} spids:[16])] spids: [16] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:directionsMapFlag) op:Equal rhs:{(DQ (0))} spids:[21])] spids: [21] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:staticMapFlag) op:Equal rhs:{(DQ (0))} spids:[26])] spids: [26] ) (C {(source)} {(TildeSubPart prefix:"") (/.bash_profile)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:MAPQUEST_API_KEY) op: Equal rhs: {($ VSub_Name "$MAPQUEST_API_KEY")} spids: [39] ) ] spids: [39] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-d)} {(TildeSubPart prefix:"") (/temp)} {(Lit_Other "]")}) terminator: ) ] action: [ (Sentence child: (C {(rm)} {(-rf)} {(TildeSubPart prefix:"") (/temp)}) terminator: ) ] spids: [-1 53] ) ] spids: [-1 62] ) (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: [83] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredClient) op: Equal rhs: {(DQ (curl))} spids: [91] ) ] spids: [91] ) ] spids: [-1 88] ) (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: [106] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredClient) op: Equal rhs: {(DQ (wget))} spids: [114] ) ] spids: [114] ) ] spids: [97 111] ) (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: [129] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:configuredClient) op: Equal rhs: {(DQ (fetch))} spids: [137] ) ] spids: [137] ) ] spids: [120 134] ) ] else_action: [ (C {(echo)} {(DQ ("Error: This tool reqires either curl, wget, or fetch to be installed."))} ) (ControlFlow token: arg_word:{(1)}) ] spids: [143 158] ) ] spids: [71] ) spids: [67 70] ) (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: [183 184 197 -1] ) (case_arm pat_list: [{(wget)}] action: [(C {(wget)} {(-qO-)} {(DQ ($ VSub_At "$@"))})] spids: [200 201 210 -1] ) (case_arm pat_list: [{(fetch)}] action: [(C {(fetch)} {(-o)} {(DQ (...))})] spids: [213 214 223 -1] ) ] spids: [174 180 226] ) ] spids: [171] ) spids: [167 170] ) (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: [257] ) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[261]) ] ) ] 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 281] ) ] else_action: [ (SimpleCommand words: [{(echo)} {(DQ ("Error: no active internet connection"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[301])] ) (ControlFlow token: arg_word:{(1)}) ] spids: [292 313] ) ] spids: [236] ) spids: [232 235] ) (FuncDef name: update body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:repositoryName) op: Equal rhs: {(DQ (Bash-Snippets))} spids: [337] ) ] spids: [337] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:githubUserName) op: Equal rhs: {(DQ (alexanderepstein))} spids: [346] ) ] spids: [346] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:nameOfInstallFile) op: Equal rhs: {(DQ (install.sh))} spids: [355] ) ] spids: [355] ) (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: [365 401] ) } spids: [364] ) ] spids: [364] ) (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:[457])] ) (C {(exit)} {(1)}) ] spids: [-1 448] ) (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:[488])] ) (C {(exit)} {(1)}) ] spids: [466 479] ) ] 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: [585] ) ] 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: [629] ) ] op_id: Op_DPipe ) terminator: ) ] spids: [-1 617] ) ] spids: [-1 647] ) (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: [663] ) ] 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: [687] ) ] 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: [714] ) ] ) (AndOr children: [ (SimpleCommand words: [ {(git)} {(checkout)} {(DQ ($ VSub_Name "$latestVersion"))} ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [728] ) ] ) (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: [782] ) ] op_id: Op_DPipe ) ] spids: [-1 576] ) ] else_action: [(C {(exit)} {(1)})] spids: [801 809] ) ] spids: [-1 517] ) ] else_action: [ (C {(echo)} {(DQ ($ VSub_Name "$repositoryName") (" is already the latest version"))} ) ] spids: [812 823] ) ] spids: [497 826] ) ] spids: [322] ) spids: [318 321] ) (FuncDef name: getDirections body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:response) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(httpGet)} { (DQ ("https://www.mapquestapi.com/directions/v2/route?key=") ($ VSub_Name "$MAPQUEST_API_KEY") ("&from=") ($ VSub_Number "$1") ("&to=") ($ VSub_Number "$2") ( "&outFormat=json&ambiguities=ignore&routeType=fastest&doReverseGeocode=false&enhancedNarrative=false&avoidTimedConditions=false" ) ) } ) ] ) left_token: spids: [839 851] ) } spids: [838] ) ] spids: [838] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:firstDirection) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$response")}) (C {(grep)} {(-Eo)} { (DQ (origNarrative) (EscapedLiteralPart token: ) (":") (EscapedLiteralPart token:) ("[a-Z -./0-9]*") ) } ) (C {(grep)} {(-Eo)} { (DQ ("[^origNarrative") (EscapedLiteralPart token: ) (":][a-Z -./0-9]*") ) } ) ] negated: False ) ] ) left_token: spids: [854 885] ) } spids: [853] ) ] spids: [853] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:tempDirections) op: Equal rhs: { (ArrayLiteralPart words: [ { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$response")}) (C {(grep)} {(-Eo)} { (DQ (EscapedLiteralPart token:) (narrative) (EscapedLiteralPart token:) (":") (EscapedLiteralPart token: ) ("[a-Z -./0-9]*") ) } ) ] negated: False ) ] ) left_token: spids: [889 908] ) } ] ) } spids: [887] ) ] spids: [887] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:distances) op: Equal rhs: { (ArrayLiteralPart words: [ { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$response")}) (C {(grep)} {(-Eo)} { (DQ (distance) (EscapedLiteralPart token: ) (":[0-9]*[.][0-9]*") ) } ) (C {(grep)} {(-Eo)} { (DQ ("[^distance") (EscapedLiteralPart token: ) (":][0-9]*[.][0-9]*") ) } ) ] negated: False ) ] ) left_token: spids: [913 942] ) } ] ) } spids: [911] ) ] spids: [911] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:totalDist) op: Equal rhs: { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{(Lit_Digits 0)})) spids: [946 951] ) } spids: [945] ) ] spids: [945] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:count) op:Equal rhs:{(DQ (0))} spids:[953])] spids: [953] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:count) op:Equal rhs:{(DQ (-1))} spids:[958])] spids: [958] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:temp) op: Equal rhs: { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{(Lit_Digits 0)})) spids: [964 969] ) } spids: [963] ) ] spids: [963] ) (ForEach iter_name: direct iter_words: [ { (DQ (BracedVarSub token: bracket_op: (WholeArray op_id:Lit_At) spids: [978 983] ) ) } ] do_arg_iter: False body: (DoGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$direct")}) (C {(grep)} {(-Eo)} {(DQ (narrative))}) ] negated: False ) ] ) left_token: spids: [993 1008] ) } right: {(DQ (narrative))} ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:count) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$count")} {(Lit_Other "+")} {(1)} ) (C {(bc)}) ] negated: False ) ] ) left_token: spids: [1022 1035] ) } spids: [1021] ) ] spids: [1021] ) (C {(directions) (Lit_Other "[") ($ VSub_Name "$count") (Lit_Other "]") (Lit_Other "=") ($ VSub_Name "$temp") } ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:temp) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$direct")}) (C {(grep)} {(-Eo)} { (DQ ("[^") (EscapedLiteralPart token: ) ("narrative:") (EscapedLiteralPart token:) ("][a-Z 0-9./]*") ) } ) ] negated: False ) ] ) left_token: spids: [1047 1065] ) } spids: [1046] ) ] spids: [1046] ) ] spids: [-1 1018] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:temp) op: Equal rhs: {(DQ ($ VSub_Name "$temp") (" ") ($ VSub_Name "$direct"))} spids: [1071] ) ] spids: [1071] ) ] spids: [1068 1079] ) ] spids: [986 1082] ) spids: [976 -1] ) (C {(directions) (Lit_Other "[") (0) (Lit_Other "]") (Lit_Other "=") ($ VSub_Name "$firstDirection") } ) ] spids: [836] ) spids: [832 835] ) (FuncDef name: getDirectionsMap body: (BraceGroup children: [ (C {(echo)} { (DQ ("Generating route map from ") ($ VSub_Name "$unformattedFromLocation") (" to ") ($ VSub_Name "$unformattedToLocation") ) } ) (AndOr children: [ (C {(mkdir)} {(TildeSubPart prefix:"") (/temp)}) (ControlFlow token: arg_word:{(1)}) ] op_id: Op_DPipe ) (AndOr children: [ (SimpleCommand words: [ {(httpGet)} { (DQ ("https://www.mapquestapi.com/staticmap/v5/map?start=") ($ VSub_Number "$1") ("&end=") ($ VSub_Number "$2") ("&size=600,400@2x&key=") ($ VSub_Name "$MAPQUEST_API_KEY") ) } ] redirects: [ (Redir op_id: Redir_DGreat fd: -1 arg_word: {(TildeSubPart prefix:"") (/temp/routeImage.png)} spids: [1139] ) ] ) (ControlFlow token: arg_word:{(1)}) ] op_id: Op_DPipe ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$OSTYPE"))} right: {(DQ (linux)) (Lit_Other "*")} ) ) terminator: ) ] action: [ (AndOr children: [ (SimpleCommand words: [{(display)} {(TildeSubPart prefix:"") (/temp/routeImage.png)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [1176] ) ] ) (ControlFlow token: arg_word: {(1)} ) ] op_id: Op_DPipe ) ] spids: [-1 1168] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$OSTYPE"))} right: {(DQ (darwin)) (Lit_Other "*")} ) ) terminator: ) ] action: [ (SimpleCommand words: [{(open)} {(TildeSubPart prefix:"") (/temp/routeImage.png)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[1213])] ) ] spids: [1187 1205] ) ] spids: [-1 1218] ) (SimpleCommand words: [{(rm)} {(-rf)} {(TildeSubPart prefix:"") (/temp)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[1228])] ) ] spids: [1103] ) spids: [1099 1102] ) (FuncDef name: printDirections body: (BraceGroup children: [ (C {(echo)}) (C {(echo)} { (DQ ("From ") ($ VSub_Name "$unformattedFromLocation") (" to ") ($ VSub_Name "$unformattedToLocation") (" (") ($ VSub_Name "$totalDist") (" mi)") ) } ) (C {(echo)} {(DQ ("==================================================="))}) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:count) op:Equal rhs:{(0)} spids:[1265])] spids: [1265] ) (ForEach iter_name: direct iter_words: [ { (DQ (BracedVarSub token: bracket_op: (WholeArray op_id:Lit_At) spids: [1276 1281] ) ) } ] do_arg_iter: False body: (DoGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_Name "$count")} {(-ne)} {(0)} {(Lit_Other "]")} ) terminator: ) ] action: [ (Sentence child: (C {(echo)} {(-n)} { (DQ (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$count")}) (C {(bc)}) ] negated: False ) ] ) left_token: spids: [1307 1315] ) ("). ") ) } ) terminator: ) ] spids: [-1 1300] ) ] spids: [-1 1319] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Name "$direct")} right: {(DQ )} ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:direct) op: Equal rhs: { (DQ ($ VSub_Name "$direct") (" (") (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$count")} {(Lit_Other "+")} {(1)} ) (C {(bc)}) ] negated: False ) ] ) left_token: spids: [1348 1360] ) } ) ) spids: [1345 1362] ) (" mi)") ) } spids: [1341] ) ] spids: [1341] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_Name "$count")} {(-ne)} {(0)} {(Lit_Other "]")} ) terminator: ) ] action: [ (Sentence child: (C {(echo)} {($ VSub_Name "$direct")}) terminator: ) ] spids: [-1 1379] ) ] spids: [-1 1385] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:count) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$count")} {(Lit_Other "+")} {(1)} ) (C {(bc)}) ] negated: False ) ] ) left_token: spids: [1389 1402] ) } spids: [1388] ) ] spids: [1388] ) ] spids: [-1 1335] ) ] spids: [-1 1405] ) ] spids: [1285 1408] ) spids: [1274 -1] ) (C {(echo)} {(DQ ("Welcome to ") ($ VSub_Name "$unformattedToLocation"))}) (C {(echo)} {(DQ ("==================================================="))}) (C {(echo)}) ] spids: [1239] ) spids: [1235 1238] ) (FuncDef name: getLocations body: (BraceGroup children: [ (C {(echo)} {(-n)} {(DQ ("Enter your starting location: "))}) (C {(read)} {(fromLocation)}) (C {(echo)} {(-n)} {(DQ ("Enter your destination: "))}) (C {(read)} {(toLocation)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:unformattedFromLocation) op: Equal rhs: {($ VSub_Name "$fromLocation")} spids: [1466] ) ] spids: [1466] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:unformattedToLocation) op: Equal rhs: {($ VSub_Name "$toLocation")} spids: [1470] ) ] spids: [1470] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:fromLocation) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$fromLocation")}) (C {(sed)} {(s/) (SQ <",">) (/) (DQ ("+")) (/g)}) (C {(sed)} {(s/) (SQ <" ">) (/) (DQ ("+")) (/g)}) ] negated: False ) ] ) left_token: spids: [1475 1508] ) } spids: [1474] ) ] spids: [1474] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:toLocation) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$toLocation")}) (C {(sed)} {(s/) (SQ <",">) (/) (DQ ("+")) (/g)}) (C {(sed)} {(s/) (SQ <" ">) (/) (DQ ("+")) (/g)}) ] negated: False ) ] ) left_token: spids: [1512 1545] ) } spids: [1511] ) ] spids: [1511] ) ] spids: [1435] ) spids: [1431 1434] ) (FuncDef name: checkImagemagick body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$OSTYPE"))} right: {(DQ (linux)) (Lit_Other "*")} ) ) terminator: ) ] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (Pipeline children: [(C {(command)} {(-v)} {(display)})] negated: True ) terminator: ) (Sentence child: (SimpleCommand redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [1588] ) ] ) terminator: ) ] action: [ (Sentence child: (C {(echo)} { (DQ ( "Error: you need to install imagemagick to use map features." ) ) } ) terminator: ) (SimpleCommand redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(2)} spids:[1602])] ) (ControlFlow token: arg_word: {(1)} ) ] spids: [-1 1592] ) ] else_action: [(ControlFlow token: arg_word:{(0)})] spids: [1611 1619] ) ] spids: [-1 1574] ) ] else_action: [(ControlFlow token: arg_word:{(0)})] spids: [1622 1630] ) ] spids: [1554] ) spids: [1550 1553] ) (FuncDef name: getMapLocation body: (BraceGroup children: [ (C {(echo)} {(-n)} {(DQ ("Enter the city or address you want to generate a map for: "))}) (C {(read)} {(mapLocation)}) (C {(echo)} {(DQ ("Generating static map for ") ($ VSub_Name "$mapLocation"))}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:mapLocation) op: Equal rhs: {(Lit_Other "=") (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$mapLocation")}) (C {(sed)} {(s/) (SQ <",">) (/) (DQ ("+")) (/g)}) (C {(sed)} {(s/) (SQ <" ">) (/) (DQ ("+")) (/g)}) ] negated: False ) ] ) left_token: spids: [1667 1700] ) } spids: [1665] ) ] spids: [1665] ) ] spids: [1640] ) spids: [1636 1639] ) (FuncDef name: getStaticMap body: (BraceGroup children: [ (AndOr children: [ (C {(mkdir)} {(TildeSubPart prefix:"") (/temp)}) (ControlFlow token: arg_word:{(1)}) ] op_id: Op_DPipe ) (AndOr children: [ (SimpleCommand words: [ {(httpGet)} { (DQ ("https://www.mapquestapi.com/staticmap/v5/map?key=") ($ VSub_Name "$MAPQUEST_API_KEY") ("¢er=") ($ VSub_Number "$1") ("&zoom=15&type=hyb&size=600,400@2x") ) } ] redirects: [ (Redir op_id: Redir_DGreat fd: -1 arg_word: {(TildeSubPart prefix:"") (/temp/mapImage.png)} spids: [1734] ) ] ) (ControlFlow token: arg_word:{(1)}) ] op_id: Op_DPipe ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$OSTYPE"))} right: {(DQ (linux)) (Lit_Other "*")} ) ) terminator: ) ] action: [ (AndOr children: [ (SimpleCommand words: [{(display)} {(TildeSubPart prefix:"") (/temp/mapImage.png)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [1771] ) ] ) (ControlFlow token: arg_word: {(1)} ) ] op_id: Op_DPipe ) ] spids: [-1 1763] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$OSTYPE"))} right: {(DQ (darwin)) (Lit_Other "*")} ) ) terminator: ) ] action: [ (AndOr children: [ (SimpleCommand words: [{(open)} {(TildeSubPart prefix:"") (/temp/mapImage.png)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [1808] ) ] ) (ControlFlow token: arg_word: {(1)} ) ] op_id: Op_DPipe ) ] spids: [1782 1800] ) ] spids: [-1 1819] ) (AndOr children: [ (SimpleCommand words: [{(rm)} {(-rf)} {(TildeSubPart prefix:"") (/temp)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[1829])] ) (ControlFlow token: arg_word:{(1)}) ] op_id: Op_DPipe ) ] spids: [1709] ) spids: [1705 1708] ) (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 (drmuvh))} {(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:[1904])] ) (C {(exit)} {(1)}) ] spids: [1893 1894 1913 -1] ) (case_arm pat_list: [{(h)}] action: [(C {(usage)}) (C {(exit)} {(0)})] spids: [1916 1917 1928 -1] ) (case_arm pat_list: [{(d)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:directionsFlag) op: Equal rhs: {(DQ (1))} spids: [1935] ) ] spids: [1935] ) ] spids: [1931 1932 1941 -1] ) (case_arm pat_list: [{(m)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:staticMapFlag) op: Equal rhs: {(DQ (1))} spids: [1948] ) ] spids: [1948] ) ] spids: [1944 1945 1954 -1] ) (case_arm pat_list: [{(r)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:directionsMapFlag) op: Equal rhs: {(DQ (1))} spids: [1961] ) ] spids: [1961] ) ] spids: [1957 1958 1967 -1] ) (case_arm pat_list: [{(v)}] action: [ (C {(echo)} {(DQ ("Version ") ($ VSub_Name "$currentVersion"))}) (C {(exit)} {(0)}) ] spids: [1970 1971 1987 -1] ) (case_arm pat_list: [{(u)}] action: [(C {(update)}) (C {(exit)} {(0)})] spids: [1990 1991 2002 -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:[2017])] ) (C {(exit)} {(1)}) ] spids: [2005 2006 2026 -1] ) ] spids: [1886 1890 2029] ) ] spids: [1883 2031] ) ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id:BoolBinary_GlobDEqual left:{($ VSub_Pound "$#")} right:{(0)}) ) terminator: ) ] action: [(C {(usage)}) (C {(exit)} {(0)})] spids: [-1 2047] ) (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)}) (C {(exit)} {(0)})] spids: [-1 2089] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Number "$1")} right: {(DQ (help))} ) ) terminator: ) ] action: [(C {(usage)}) (C {(exit)} {(0)})] spids: [2100 2115] ) ] spids: [-1 2126] ) ] spids: [2057 2072] ) ] spids: [-1 2128] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalAnd left: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$directionsFlag")} right: {(DQ (0))} ) right: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$staticMapFlag")} right: {(DQ (1))} ) ) ) terminator: ) ] action: [ (AndOr children:[(C {(checkImagemagick)})(C {(exit)} {(1)})] op_id:Op_DPipe) (AndOr children:[(C {(getMapLocation)})(C {(exit)} {(1)})] op_id:Op_DPipe) (AndOr children: [(C {(getStaticMap)} {($ VSub_Name "$mapLocation")}) (C {(exit)} {(1)})] op_id: Op_DPipe ) ] spids: [-1 2155] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$directionsFlag")} right: {(DQ (1))} ) ) terminator: ) ] action: [ (AndOr children:[(C {(getLocations)})(C {(exit)} {(1)})] op_id:Op_DPipe) (AndOr children: [ (C {(getDirections)} {($ VSub_Name "$fromLocation")} {($ VSub_Name "$toLocation")}) (C {(exit)} {(1)}) ] op_id: Op_DPipe ) (AndOr children: [ (C {(printDirections)} {($ VSub_Name "$fromLocation")} {($ VSub_Name "$toLocation")}) (C {(exit)} {(1)}) ] op_id: Op_DPipe ) (AndOr children:[(C {(checkImagemagick)})(C {(exit)} {(1)})] op_id:Op_DPipe) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$directionsMapFlag")} right: {(DQ (1))} ) ) terminator: ) ] action: [ (Sentence child: (AndOr children: [ (C {(getDirectionsMap)} {($ VSub_Name "$fromLocation")} {($ VSub_Name "$toLocation")} ) (C {(exit)} {(1)}) ] op_id: Op_DPipe ) terminator: ) ] spids: [-1 2261] ) ] spids: [-1 2275] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobEqual left: {($ VSub_Name "$staticMapFlag")} right: {(DQ (1))} ) ) terminator: ) ] action: [ (AndOr children: [ (C {(echo)} { (DQ ("Generating static map for ") ($ VSub_Name "$unformattedFromLocation") ) } ) (AndOr children: [ (C {(getStaticMap)} {($ VSub_Name "$fromLocation")}) (C {(exit)} {(1)}) ] op_id: Op_DPipe ) ] op_id: Op_DAmp ) (AndOr children: [ (C {(echo)} { (DQ ("Generating static map for ") ($ VSub_Name "$unformattedToLocation")) } ) (AndOr children: [ (C {(getStaticMap)} {($ VSub_Name "$toLocation")}) (C {(exit)} {(1)}) ] op_id: Op_DPipe ) ] op_id: Op_DAmp ) ] spids: [-1 2292] ) ] spids: [-1 2335] ) ] spids: [2186 2200] ) ] spids: [-1 2337] ) ] )