Skip to content

Instantly share code, notes, and snippets.

@firedynasty
Created October 13, 2021 16:51
Show Gist options
  • Save firedynasty/a293117c866e30326cf37928bcb7f7b2 to your computer and use it in GitHub Desktop.
Save firedynasty/a293117c866e30326cf37928bcb7f7b2 to your computer and use it in GitHub Desktop.
opening links from clipboard (for browsing .txt file)
function browse() {
hello_var=$(echo -n `pbpaste`)
# set the clipboard to a variable
char=":"
# char in case there are multiple links
hello_var_2=$(awk -F"${char}" '{print NF-1}' <<< "${hello_var}")
# checking for mulitple https: links
if [ "$hello_var_2" -gt 1 ]; then
# if there are multiple links then return this statement
echo 'set str1'
echo 'const myArr = str1.split(" ");'
echo 'for (var i = 0; i < myArr.length; i++) {'
echo " window.open(myArr[i], '_blank')"
echo '}'
else
# otherwise open the link in google chrome
open -a 'google chrome' $hello_var
fi
}
# to use this command
# copy a link (with https)
# type browse
# enter and done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment