Skip to content

Instantly share code, notes, and snippets.

@RealMacLucky
Last active January 1, 2022 21:34
Show Gist options
  • Save RealMacLucky/1ed6f54256021ca9bca603d0421a3fc2 to your computer and use it in GitHub Desktop.
Save RealMacLucky/1ed6f54256021ca9bca603d0421a3fc2 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# opentabs.sh
#
# specific use: read a list of URLs from file and open in browser
#
# general use: run a console command many times with parameters read form a text file
#
# $ bash opentabs $filename $start $end
#
# example use: $ bash opentabs hrefs.txt 20 30
filename="$1"
LINE_START=$2
LINE_END=$3
#test parameter filename
if [ -e $filename ]
then
echo "reading file: $filename"
else
echo "invalid arguments";
exit;
fi
#test parameter start line
if [ $LINE_START -gt 0 ] && [ $LINE_END -gt $LINE_START ]
then
echo "reading lines: $LINE_START -> $LINE_END"
else
echo "invalid arguments";
exit;
fi
n=0
(cat $filename; echo) | while read line; do
n=$((n+1))
if [ $n -ge $LINE_START ]
then
echo "$n $line"
if [ $PSVersionTable ] || [ $OSTYPE == 'msys' ]
then
# Windows detencion, either POWERSHELL or GIT BASH
chrome.exe $line
else
exo-open --launch WebBrowser $line
fi
fi
if [ $n -ge $LINE_END ]
then
exit
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment