Skip to content

Instantly share code, notes, and snippets.

@mslinn
Last active April 21, 2019 08:31
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 mslinn/3c6cb4445e8b3efcac147961d2dd9602 to your computer and use it in GitHub Desktop.
Save mslinn/3c6cb4445e8b3efcac147961d2dd9602 to your computer and use it in GitHub Desktop.
View GitHub Markdown files in a console
#!/bin/bash
function help {
echo "View GitHub markdown files in a console using less.
1. Install pandoc and lynx.
a. For Ubuntu (and WSL): sudo apt install pandoc lynx
b. For MacOS: brew install pandoc lynx
2. Name the this script as less and save it somewhere on the PATH, for example /usr/local/bin.
3. Make the script executable, for example: chmod a+x /usr/local/bin/less.
4. Type 'hash -r' or /usr/bin/less will run instead of this script
5. Type 'less myfile.md' to view a file as usual; this script will handle files with filetype md as GitHub markdown and render colorized output to the console
"
exit 1
}
if [ "$1" == -h ]; then help; fi
if [ "${1##*.}" == md ]; then
pandoc "$1" | lynx -stdin
else
/usr/bin/less "$1"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment