#! /usr/bin/env bash# DISCLAIMER: THE SCRIPT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.# BECAUSE I HAVEN'T USED IT IN AGES.# -------------------------------------------------------------------------------------------------- #function print_help(){cat << EOFUsage: ${0##*/} [prince|pandoc] [http|html] nameURI = scheme:[//authority]path[?query][#fragment]Requirements: pandoc : https://pandoc.org/ prince : https://www.princexml.com/ polar : https://github.com/burtonator/polar-bookshelfErrors: Could not convert svg: rsvg-convert : https://github.com/miyako/console-rsvg-convert pandoc-svg.py : https://gist.github.com/jeromerobert/3996eca3acd12e4c3d40#file-pandoc-svg-pySecurity: The HTML generated by pandoc is not guaranteed to be safe. To be safe, you should run all the generated HTML through an HTML sanitizer.Example as at 2020-05-22:$ html-to-pdf.sh prince https://ucsd-progsys.github.io/liquidhaskell-blog/ Liquid-Haskell-Blog$ html-to-pdf.sh pandoc https://ucsd-progsys.github.io/liquidhaskell-blog/ Liquid-Haskell-BlogEOF}# -------------------------------------------------------------------------------------------------- #if[$# -eq 0];then print_help; exit;fi# -------------------------------------------------------------------------------------------------- #function check_dependency(){if ! (type"$1" > /dev/null 2>&1);thenecho"html-to-pdf: missing dependency: can't find $1"1>&2exit1fi}# -------------------------------------------------------------------------------------------------- #function input(){localENGINES=(prince pandoc)if["$ENGINE"="${ENGINES[0]}"];then prince --input=html --page-size=A4 --output="$PDF""$HTTP"else pandoc --standalone --from=html --to=pdf --output="$PDF""$HTTP"fi}# -------------------------------------------------------------------------------------------------- #function output(){ polar "$PDF";}# -------------------------------------------------------------------------------------------------- #function cleanup(){ rm "$PDF";}# -------------------------------------------------------------------------------------------------- #function main(){ check_dependency pandoc
check_dependency prince
input
output
cleanup
}# -------------------------------------------------------------------------------------------------- #ENGINE="$1"HTTP="$2"PDF="$3.pdf"# -------------------------------------------------------------------------------------------------- #main
exit$?
#! /usr/bin/env bash# DISCLAIMER: THE SCRIPT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.# BECAUSE I HAVEN'T USED IT IN AGES.# -------------------------------------------------------------------------------------------------- #function print_help(){cat << EOFUsage: ${0##*/} [prince|pandoc] [http|md] nameURI = scheme:[//authority]path[?query][#fragment]Requirements: pandoc : https://pandoc.org/ prince : https://www.princexml.com/ polar : https://github.com/burtonator/polar-bookshelfErrors: Could not convert svg: rsvg-convert : https://github.com/miyako/console-rsvg-convert pandoc-svg.py : https://gist.github.com/jeromerobert/3996eca3acd12e4c3d40#file-pandoc-svg-pySecurity: The HTML generated by pandoc is not guaranteed to be safe. To be safe, you should run all the generated HTML through an HTML sanitizer.Example as at 2020-05-22:$ md-to-pdf.sh pandoc README.md local-readme$ md-to-pdf.sh prince https://github.com/jgm/pandoc/blob/master/README.md github-readme$ md-to-pdf.sh pandoc https://bitbucket.org/cloudrepo-examples/maven-library-example/raw/72aa7e3eed2c014e1a2b37b650a940c495abe11b/README.md maven-library-example-readmeEOF}# -------------------------------------------------------------------------------------------------- #if[$# -eq 0];then print_help; exit;fi# -------------------------------------------------------------------------------------------------- #function check_dependency(){if ! (type"$1" > /dev/null 2>&1);thenecho"md-to-pdf: missing dependency: can't find $1"1>&2exit1fi}# -------------------------------------------------------------------------------------------------- #function input(){localENGINES=(prince pandoc)if["$ENGINE"="${ENGINES[0]}"];then prince --input=auto --page-size=A4 --output="$PDF""$MD"else pandoc --standalone --from=markdown --to=pdf --output="$PDF""$MD"fi}# -------------------------------------------------------------------------------------------------- #function output(){ polar "$PDF";}# -------------------------------------------------------------------------------------------------- #function cleanup(){ rm "$PDF";}# -------------------------------------------------------------------------------------------------- #function main(){ check_dependency pandoc
check_dependency prince
input
output
cleanup
}# -------------------------------------------------------------------------------------------------- #ENGINE="$1"MD="$2"PDF="$3.pdf"# -------------------------------------------------------------------------------------------------- #main
exit$?
#! /usr/bin/env bash# THIS SCRIPT DOES NOT WORK WITH POLAR 2.0# THINKING ABOUT FIXING IT FOR LINUX/MAC.# SUGGESTED BY HELP REQUEST: WAIT[P]ID USING SIGNAL.# -------------------------------------------------------------------------------------------------- #function print_help(){cat << EOFUsage: ${0##*/} [pdf|http|name]$ polar filename.pdf$ polar http://.../URI-ends-with.pdf$ polar "http://.../URI-does-not-end-with-pdf" <name>--------^------------------------------------^URI = scheme:[//authority]path[?query][#fragment]requirements: polar : https://github.com/burtonator/polar-bookshelf fd : https://github.com/sharkdp/fd curl : https://curl.haxx.se/Example as at 2020-05-22:$ polar http://ucsd-progsys.github.io/liquidhaskell-tutorial/book.pdfEOF}# -------------------------------------------------------------------------------------------------- #if[$# -eq 0];then print_help; exit;fi# -------------------------------------------------------------------------------------------------- #function check_dependency(){if ! (type"$1" > /dev/null 2>&1);thenecho"polar: missing dependency: can't find $1"1>&2exit1fi}# -------------------------------------------------------------------------------------------------- #function open_polar(){PROCESS_NUM="$(pgrep Polar | wc -l | awk '{print $1}')"if["$PROCESS_NUM" -eq 0];then open -a /Applications/Polar\ Bookshelf.app/
sleep 25s
fi}# -------------------------------------------------------------------------------------------------- #function check_curl(){ifecho"$ARG"| grep -E '^http://|^https://';thenif[["$NARG" -eq 1]];then curl -O "$ARG"ARG="$(fd --show-errors --changed-within 1min --type f --extension pdf --max-depth 1 .)"else curl "$1" --output "$2.pdf"ARG="$2.pdf"fiCURL=truefi}# -------------------------------------------------------------------------------------------------- #function open_pdf(){ open -a /Applications/Polar\ Bookshelf.app/ "$ARG" sleep 5s
}# -------------------------------------------------------------------------------------------------- #function main(){ check_dependency curl
check_dependency fd
open_polar
check_curl "$ARG" open_pdf
}# -------------------------------------------------------------------------------------------------- #NARG="$#"ARG="$1"CURL=false# -------------------------------------------------------------------------------------------------- #main
CODE=$?# -------------------------------------------------------------------------------------------------- #if$CURL;then rm "$ARG";fi# -------------------------------------------------------------------------------------------------- #exit$CODE
Comments (2)
Kirk Duncan
Needs to be extended to coexist with other OS native cli open applications.
CLI_OS="na"
if $(echo "${OSTYPE}" | grep -q msys); then
CLI_OS="windows"
elif $(echo "${OSTYPE}" | grep -q darwin); then
CLI_OS="mac"
else
CLI_OS="linux"
fi
Many ways to do the same task, humans are awesome!
# OS specific support (must be 'true' or 'false').cygwin=falsemsys=falsedarwin=falselinux=falsecase"`uname`"inCYGWIN*)cygwin=true;;Darwin*)darwin=true;;Linux*)linux=true;;MINGW*)msys=true;;esac
Needs to be extended to coexist with other OS native cli
open
applications.Many ways to do the same task, humans are awesome!
mac
linux
Script update required to work with Polar >= 2.0
https://github.com/burtonator/polar-bookshelf/releases