fabianmoronzirfas
3/28/2017 - 7:27 AM

a little tool for previewing markdown in the command line for fish shell save it under ~/.config/fish/functions/mdview.fish

a little tool for previewing markdown in the command line for fish shell save it under ~/.config/fish/functions/mdview.fish

function mdview
if set -q argv
  switch $argv
    case -h
      echo "[M↓] Help"
      echo "call the mdview with a Markdown [M↓] file as argument"
      echo "this script needs pandoc and lynx installed"
      echo "on macOS run 'brew install pandoc lynx'"
    case "*"
      # check if pandoc is installed
      if pandoc -v >/dev/null do
      # check if lynx is installed
        if lynx -version >/dev/null do
          # run the magic
          pass the file to pandoc
          it will be converted to HTML and go to stdout
          pipe it into lynx stdin
          pandoc $argv | lynx -stdin
        else
          echo "lynx is not installed"
        end
      else
        echo "pandoc is not installed"
      end
    end
  end
end