Skip to content

Instantly share code, notes, and snippets.

@amokan
Created October 12, 2017 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amokan/0901771f58ea16f19e8c22a0feb429f4 to your computer and use it in GitHub Desktop.
Save amokan/0901771f58ea16f19e8c22a0feb429f4 to your computer and use it in GitHub Desktop.
web url to markdown command line function
#!/bin/zsh -e
function clipcopy() {
emulate -L zsh
local file=$1
if [[ $OSTYPE == darwin* ]]; then
if [[ -z $file ]]; then
pbcopy
else
cat $file | pbcopy
fi
elif [[ $OSTYPE == cygwin* ]]; then
if [[ -z $file ]]; then
cat > /dev/clipboard
else
cat $file > /dev/clipboard
fi
else
if (( $+commands[xclip] )); then
if [[ -z $file ]]; then
xclip -in -selection clipboard
else
xclip -in -selection clipboard $file
fi
elif (( $+commands[xsel] )); then
if [[ -z $file ]]; then
xsel --clipboard --input
else
cat "$file" | xsel --clipboard --input
fi
else
print "clipcopy: Platform $OSTYPE not supported or xclip/xsel not installed" >&2
return 1
fi
fi
}
if [ -t 0 ]; then
if [ -n "$1" ]; then
pandoc -s -r html $1 -t markdown_github | clipcopy
echo " Markdown saved to clipboard"
else
echo " a url is required like './html_to_md https://foo.bar'"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment