GenerateAliasesAndFunctions.sh #!/bin/zsh # To use: source # I keep this first like in a file called GoLinks_pre.sh which loads first export go_hardlinks=() export go_mylinks=() export go_searchlinks=() # This is kept in Golinks.sh which loads second # LinkedIn Go Links go/ # Note these are provided for example only and will not work outside of the LinkedIn internal network # Now you could setup your own DNS or URL redirect for "go" and redirect it to whatever you wanted. For example bit.ly links. go_hardlinks=(${go_hardlinks[@]} 'helpin' 'questions' 'wiki' # Research ) # go_mylinks=(${go_mylinks[@]} # Web tools 'gmail:https://mail.google.com' # Conversions and Experimentation 'epochconverter:https://www.epochconverter.com' 'jsfiddle:https://jsfiddle.net' 'regex101:https://regex101.com' 'urlencoder:https://meyerweb.com/eric/tools/dencoder' 'keycodes:https://keycode.info' 'keycodechart:http://www.foreui.com/articles/Key_Code_Table.htm' ) # [params] go_searchlinks=($go_searchlinks[@] # Shopping 'amazon:https://www.amazon.com###/s?url=search-alias%3Daps&field-keywords=$$$' # Web Searches 'google:https://www.google.com###/search?q=$$$' 'google_img:https://www.google.com###/search?q=$$$&tbm=isch' # Fun 'httpcat:https://http.cat/###$$$' # Research 'colorhex:https://www.color-hex.com###/color/$$$' 'macapp:http://macappstore.org/###$$$/' 'nasdaq:https://www.nasdaq.com###/symbol/$$$/real-time' 'rfc:https://tools.ietf.org###/html/$$$' 'stackoverflow:https://stackoverflow.com###/search?q=$$$' ) function _golinks_setup() { local go_links app link go_l f go_links=(${go_hardlinks[@]} ${go_mylinks[@]} ${go_searchlinks[@]}) for go_l in ${go_links}; do if [[ "a${go_l}" =~ ":" ]]; then if [[ "a${go_l}" =~ '\$\$\$' ]]; then go_l=${${go_l//\\&/&}//&/\\&} # Escape ambersand, as it expands unintentionally in functions. app=$(echo "${${${go_l}%%:*}}") # Bash subsitution for "cut -f1 -d:" link=$(echo "${${go_l}#*:}") # Bash subsitution for "cut -f2- -d:" # Note the regex requires 4x$ for a match of 3x. Otherwise we keep 1 $. # Define function template and static variables if [[ "a${go_l}" =~ '###' ]]; then f='function ${app}() { if [[ $[#] -eq 0 ]]; then url "${link_s}";else;url "${link}";fi }' # Template function f=$(echo "${f}" | sed 's@${link_s}@'"${link%###*}"'@' | sed 's@${link}@'"${link//\#\#\#/}"'@') else f='function ${app}() { if [[ $[#] -eq 0 ]]; then echo "Error: $0 requires at least 1 argument (search term)";return 1;fi;url "${link}" }' # Template function fi echo $(echo $f | sed 's@${app}@'"${app}"'@' | sed 's@${link}@'"${link//\#\#\#/}"'@' | sed 's/\$\$\$/$(urlencode "${@}")/') >> GenerateAliasesAndFunctions_Generated.sh else app=$(echo "${${${go_l}%%:*}}") link=$(echo "${${go_l}#*:}") echo alias ${app}="'url \"${link}\"'" >> GenerateAliasesAndFunctions_Generated.sh # Define custom alias fi else echo alias go/${go_l}="'url \"http://go/${go_l}\"'" >> GenerateAliasesAndFunctions_Generated.sh # Define simple alias. Only works at Google and LinkedIn fi done } _golinks_setup