Last active
November 5, 2020 10:52
-
-
Save h8rt3rmin8r/1d63902c9db09113802f25a594fd843d to your computer and use it in GitHub Desktop.
Extract URLs from an input CSS document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
#>------------------------------------------------------------------------------ | |
#> | |
#> [ csslinks ] | |
#> | |
#> Extract URLs from an input CSS document | |
#> | |
#> USAGE: | |
#> | |
#> ./csslinks <INPUT> | |
#> ./csslinks <OPTION> | |
#> | |
#> where "INPUT" is some CSS data or CSS file reference; and where "OPTION" | |
#> is one of the following: | |
#> | |
#> | | |
#> -h, --help | Print this help text to the terminal | |
#> | | |
#> | |
#> ATTRIBUTION: | |
#> | |
#> Created on 20201105 by h8rt3rmin8r ([email protected]) | |
#> Source (pastebin.com): https://bit.ly/2HZYUoa | |
#> Source (github.com): https://bit.ly/2TWIxec | |
#> | |
#>------------------------------------------------------------------------------ | |
function _help() { | |
cat "${0}" \ | |
| grep -E '^#[>]' \ | |
| sed 's/^..//' | |
return $? | |
} | |
function _main() { | |
dos2unix \ | |
| tr -s '\t' ' ' \ | |
| tr -s '\n' ' ' \ | |
| tr -d ' ' \ | |
| sed 's/url[(]./ /g' \ | |
| tr ' ' '\n' \ | |
| tail -n +2 \ | |
| sed 's/.[)].*//' \ | |
| grep --color=never -E '.' | |
return $? | |
} | |
if [[ "${1}" =~ ^[-][hH]$ || "${1}" =~ ^[-]+help$ ]]; then | |
_help | |
exit $? | |
fi | |
if [ -t 0 ]; then | |
if [[ "x${1}" == "x" ]]; then | |
exit 1 | |
elif [[ -f "${1}" ]]; then | |
_main <"${1}" | |
else | |
_main <<<"$@" | |
fi | |
else | |
_main | |
fi | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment