Created
October 12, 2017 14:47
-
-
Save amokan/0901771f58ea16f19e8c22a0feb429f4 to your computer and use it in GitHub Desktop.
web url to markdown command line function
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
#!/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