-
-
Save cdzombak/e4ebbfdbb425f7e7c1de83ecec5e62b0 to your computer and use it in GitHub Desktop.
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
set -eo pipefail | |
# ref: http://hints.macworld.com/article.php?story=20040111200114634 | |
url="$(pbpaste)" | |
fname=$(curl -sL "$url" | "/opt/homebrew/bin/pup" 'head title:first-of-type text{}' | tr -cd 'A-Za-z0-9_- ' | awk '{$1=$1};1') | |
# if we couldn't use page title as filename, fallback to a stripped-down version of the URL: | |
if [ "$fname" == "" ]; then | |
fname=$(echo "$url" | tr -cd 'A-Za-z0-9_- ' | awk '{$1=$1};1') | |
fi | |
# check if the file exists already: | |
fname="./""$fname"".url" | |
if [ -e "$fname" ] && [ "$force" != true ] ; then | |
echo "error: file '$fname' exists" | |
exit 2 | |
fi | |
fname="$1/$fname" | |
cat << EOF > "$fname" | |
[InternetShortcut] | |
URL=$url | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment