#!/bin/bash # Author: Alexander Epstein https://github.com/alexanderepstein global currentVersion := '"1.11.1'TODO " declare -a tools = '('currency stocks weather crypt movies taste short geo cheat ytview cloudup qrify) proc askInstall { echo -n "Do you wish to install $1 [Y/n]: " read -r answer if [[ "$answer" == "Y" || "$answer" == "y" ]] { cd $1 || return 1 echo -n "Installing $1: " chmod a+x $1 cp $1 /usr/local/bin > /dev/null !2 > !1 || do { echo "Failure"; echo "Error copying file, try running install script as sudo"; exit 1; } echo "Success" cd .. || return 1 } } proc updateTool { if [[ -f /usr/local/bin/$1 ]]{ cd $1 || return 1 echo -n "Installing $1: " chmod a+x $1 cp $1 /usr/local/bin > /dev/null !2 > !1 || do { echo "Failure"; echo "Error copying file, try running install script as sudo"; exit 1; } echo "Success" cd .. || return 1 } } proc singleInstall { cd $1 || exit 1 echo -n "Installing $1: " chmod a+x $1 cp $1 /usr/local/bin > /dev/null !2 > !1 || do { echo "Failure"; echo "Error copying file, try running install script as sudo"; exit 1; } echo "Success" cd .. || exit 1 } proc copyManpage { cp bash-snippets.1 /usr/local/man/man1 !2 > !1 || do { echo "Failure"; echo "Error copying file, try running install script as sudo"; exit 1; } } if [[ $# == 0 ]] { for tool in [$(tools[@])] { askInstall $tool || exit 1 } copyManpage || exit 1 } elif [[ $1 == "update" ]] { echo "Updating scripts..." for tool in [$(tools[@])] { updateTool $tool || exit 1 } copyManpage || exit 1 } elif [[ $1 == "all" ]]{ for tool in [$(tools[@])] { singleInstall $tool || exit 1 } copyManpage || exit 1 } else { singleInstall $1 || exit 1 copyManpage || exit 1 } echo -n "( •_•)" sleep .75 echo -n -e "\r( •_•)>⌐■-■" sleep .75 echo -n -e "\r " echo -e "\r(⌐■_■)" sleep .5 echo "Bash Snippets version $currentVersion" echo "https://github.com/alexanderepstein/Bash-Snippets" (CommandList children: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:currentVersion) op:Equal rhs:{(DQ (1.11.1))} spids:[6])] spids: [6] ) (Assignment keyword: Assign_Declare flags: ["'-a'"] pairs: [ (assign_pair lhs: (LhsName name:tools) op: Equal rhs: { (ArrayLiteralPart words: [ {(currency)} {(stocks)} {(weather)} {(crypt)} {(movies)} {(taste)} {(short)} {(geo)} {(cheat)} {(ytview)} {(cloudup)} {(qrify)} ] ) } spids: [15] ) ] spids: [11] ) (FuncDef name: askInstall body: (BraceGroup children: [ (C {(echo)} {(-n)} {(DQ ("Do you wish to install ") ($ VSub_Number "$1") (" [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)} {($ VSub_Number "$1")}) (ControlFlow token: arg_word: {(1)} ) ] op_id: Op_DPipe ) (C {(echo)} {(-n)} {(DQ ("Installing ") ($ VSub_Number "$1") (": "))}) (C {(chmod)} {(a) (Lit_Other "+") (x)} {($ VSub_Number "$1")}) (AndOr children: [ (SimpleCommand words: [{(cp)} {($ VSub_Number "$1")} {(/usr/local/bin)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [137] ) (Redir op_id: Redir_GreatAnd fd: 2 arg_word: {(1)} spids: [141] ) ] ) (BraceGroup children: [ (Sentence child: (C {(echo)} {(DQ (Failure))}) terminator: ) (Sentence child: (C {(echo)} {(DQ ("Error copying file, try running install script as sudo"))} ) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [146] ) ] op_id: Op_DPipe ) (C {(echo)} {(DQ (Success))}) (AndOr children: [ (C {(cd)} {(..)}) (ControlFlow token: arg_word: {(1)} ) ] op_id: Op_DPipe ) ] spids: [-1 97] ) ] spids: [-1 188] ) ] spids: [47] ) spids: [43 46] ) (FuncDef name: updateTool body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id: BoolUnary_f child: {(/usr/local/bin/) ($ VSub_Number "$1")} ) ) terminator: ) ] action: [ (AndOr children: [ (C {(cd)} {($ VSub_Number "$1")}) (ControlFlow token: arg_word: {(1)} ) ] op_id: Op_DPipe ) (C {(echo)} {(-n)} {(DQ ("Installing ") ($ VSub_Number "$1") (": "))}) (C {(chmod)} {(a) (Lit_Other "+") (x)} {($ VSub_Number "$1")}) (AndOr children: [ (SimpleCommand words: [{(cp)} {($ VSub_Number "$1")} {(/usr/local/bin)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [251] ) (Redir op_id: Redir_GreatAnd fd: 2 arg_word: {(1)} spids: [255] ) ] ) (BraceGroup children: [ (Sentence child: (C {(echo)} {(DQ (Failure))}) terminator: ) (Sentence child: (C {(echo)} {(DQ ("Error copying file, try running install script as sudo"))} ) terminator: ) (Sentence child: (C {(exit)} {(1)}) terminator: ) ] spids: [260] ) ] op_id: Op_DPipe ) (C {(echo)} {(DQ (Success))}) (AndOr children: [ (C {(cd)} {(..)}) (ControlFlow token: arg_word: {(1)} ) ] op_id: Op_DPipe ) ] spids: [-1 211] ) ] spids: [-1 302] ) ] spids: [197] ) spids: [193 196] ) (FuncDef name: singleInstall body: (BraceGroup children: [ (AndOr children: [(C {(cd)} {($ VSub_Number "$1")}) (C {(exit)} {(1)})] op_id: Op_DPipe ) (C {(echo)} {(-n)} {(DQ ("Installing ") ($ VSub_Number "$1") (": "))}) (C {(chmod)} {(a) (Lit_Other "+") (x)} {($ VSub_Number "$1")}) (AndOr children: [ (SimpleCommand words: [{(cp)} {($ VSub_Number "$1")} {(/usr/local/bin)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [351] ) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[355]) ] ) (BraceGroup children: [ (Sentence child: (C {(echo)} {(DQ (Failure))}) terminator: ) (Sentence child: (C {(echo)} {(DQ ("Error copying file, try running install script as sudo"))}) terminator: ) (Sentence child:(C {(exit)} {(1)}) terminator:) ] spids: [360] ) ] op_id: Op_DPipe ) (C {(echo)} {(DQ (Success))}) (AndOr children:[(C {(cd)} {(..)})(C {(exit)} {(1)})] op_id:Op_DPipe) ] spids: [311] ) spids: [307 310] ) (FuncDef name: copyManpage body: (BraceGroup children: [ (AndOr children: [ (SimpleCommand words: [{(cp)} {(bash-snippets.1)} {(/usr/local/man/man1)}] redirects: [(Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[417])] ) (BraceGroup children: [ (Sentence child: (C {(echo)} {(DQ (Failure))}) terminator: ) (Sentence child: (C {(echo)} {(DQ ("Error copying file, try running install script as sudo"))}) terminator: ) (Sentence child:(C {(exit)} {(1)}) terminator:) ] spids: [422] ) ] op_id: Op_DPipe ) ] spids: [408] ) spids: [404 407] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id:BoolBinary_GlobDEqual left:{($ VSub_Pound "$#")} right:{(0)}) ) terminator: ) ] action: [ (ForEach iter_name: tool iter_words: [ { (DQ (BracedVarSub token: bracket_op: (WholeArray op_id:Lit_At) spids: [471 476] ) ) } ] do_arg_iter: False body: (DoGroup children: [ (AndOr children: [(C {(askInstall)} {($ VSub_Name "$tool")}) (C {(exit)} {(1)})] op_id: Op_DPipe ) ] spids: [480 494] ) spids: [469 -1] ) (AndOr children:[(C {(copyManpage)})(C {(exit)} {(1)})] op_id:Op_DPipe) ] spids: [-1 461] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Number "$1")} right: {(DQ (update))} ) ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Updating scripts..."))}) (ForEach iter_name: tool iter_words: [ { (DQ (BracedVarSub token: bracket_op: (WholeArray op_id:Lit_At) spids: [537 542] ) ) } ] do_arg_iter: False body: (DoGroup children: [ (AndOr children: [(C {(updateTool)} {($ VSub_Name "$tool")}) (C {(exit)} {(1)})] op_id: Op_DPipe ) ] spids: [546 560] ) spids: [535 -1] ) (AndOr children:[(C {(copyManpage)})(C {(exit)} {(1)})] op_id:Op_DPipe) ] spids: [505 520] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Number "$1")} right: {(DQ (all))} ) ) terminator: ) ] action: [ (ForEach iter_name: tool iter_words: [ { (DQ (BracedVarSub token: bracket_op: (WholeArray op_id:Lit_At) spids: [595 600] ) ) } ] do_arg_iter: False body: (DoGroup children: [ (AndOr children: [(C {(singleInstall)} {($ VSub_Name "$tool")}) (C {(exit)} {(1)})] op_id: Op_DPipe ) ] spids: [604 618] ) spids: [593 -1] ) (AndOr children:[(C {(copyManpage)})(C {(exit)} {(1)})] op_id:Op_DPipe) ] spids: [571 585] ) ] else_action: [ (AndOr children: [(C {(singleInstall)} {($ VSub_Number "$1")}) (C {(exit)} {(1)})] op_id: Op_DPipe ) (AndOr children:[(C {(copyManpage)})(C {(exit)} {(1)})] op_id:Op_DPipe) ] spids: [629 651] ) (C {(echo)} {(-n)} {(DQ ("( \u2022_\u2022)"))}) (C {(sleep)} {(.75)}) (C {(echo)} {(-n)} {(-e)} { (DQ (EscapedLiteralPart token:) ("( \u2022_\u2022)>\u2310\u25a0-\u25a0") ) } ) (C {(sleep)} {(.75)}) (C {(echo)} {(-n)} {(-e)} {(DQ (EscapedLiteralPart token:) (" "))} ) (C {(echo)} {(-e)} {(DQ (EscapedLiteralPart token:) ("(\u2310\u25a0_\u25a0)"))} ) (C {(sleep)} {(.5)}) (C {(echo)} {(DQ ("Bash Snippets version ") ($ VSub_Name "$currentVersion"))}) (C {(echo)} {(DQ ("https://github.com/alexanderepstein/Bash-Snippets"))}) ] )