all repos — dotfiles-extra @ e7b4874516df8a3f5886c29fff1d1ae88e86607a

extra configs that may be extraneous and/or may be platform specific

bin/open-tabs.sh

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
#!/bin/sh

# misc. niceties
red="\033[91m"
green="\033[92m"
yellow="\033[93m"
rst="\033[0m"
die() {
    printf "${red}error: $1${rst}\nAborting...\n" >&2 ; exit 1
}
warn() {
    printf "${yellow}warn: $1${rst}\n" >&2
}


url_file="$1"

if [ "$#" -ne 1 ]; then
    echo "usage: $0 [path-to-URLs-file.url]" ; exit 1
fi

if [ "$BROWSER" = "" ]; then
    die "BROWSER variable unset"
fi

# TODO check if file empty
dry_run="" # TODO handle '--dry-run'

browser_args=""; line=""
while IFS='' read -r line || [ -n "${line}" ]; do
    # TODO: fix tabs not being counted here
    if (echo "$line" | grep -Eq '^[ \t]*#') || [ -z "${line}" ]; then
        :  # comment or empty, pass
    # TODO handle '://' after both http and https
    elif (echo "$line" | grep -Eq '^[ \t]*http'); then
        line_stripped="$(echo -e "${line}" | tr -d ' \t')"
        browser_args="${browser_args} --new-tab $line_stripped"
    else
        warn "'$line' not valid URL or comment"
    fi
done < "$url_file"

if [ "$dry_run" != "" ]; then
    echo "dry run"
    echo "$BROWSER $browser_args"
else
    $BROWSER $browser_args
fi