irs/src/bin/add-bookmark

35 lines
648 B
Bash
Executable file

#!/bin/sh
bookmarks="${BOOKMARKS:-"$HOME/.config/qutebrowser/bookmarks/urls"}"
usage(){
printf "Usage: %s -c|h\n" "$(basename $0)"
printf "OR\n"
printf "Usage: %s <bookmark-url>\n" "$(basename $0)"
exit 1
}
addUrl(){
url="$1"
if [ "$(grep "$url" "$bookmarks")" ]
then printf "Bookmark of url '%s' already exists\n" "$url" && exit 1
else printf "%s %s\n" \
"$url" \
"$(curl -s "$url" | grep '<title' | sed 's/<title>\(.*\)<\/title>/\1/')" \
>> $bookmarks
fi
printf "added '%s' to '%s'\n" "$url" "$bookmarks"
}
while getopts ch flag; do
case $flag in
c)addUrl $(xclip -o) && exit 0;;
h)usage;;
esac
done
addUrl $1