Dotfiles/site-modules/core/files/oh-my-zsh/custom/mdman.zsh
Ade Attwood 80239af169 refactor(core): start to make dotfiles public
This is the first commit that brings the privet dotfiles to a public
reop previously this was all one puppet module. Now this has been split
out so I can put all of the private files in a private puppet module
2020-09-20 06:22:17 +01:00

37 lines
660 B
Bash

#
# Displays markdown files in a man format
#
# Arguments:
# 1. The path to the markdown file
# Examples:
# mdman ~/docs/file.md
#
function mdman() {
local file="$1";
local tmp="/tmp/mdman";
local tmp_file="$tmp/$(basename $file).man";
if [[ -f "$tmp_file" ]]; then
man "$tmp_file";
return
fi
mkdir -p "$tmp";
if [[ ! -f "$file" ]]; then
file=`locate "$file.md"`
if [[ ! -f "$file" ]]; then
echo "$file is not found";
return 1;
fi
fi
if [[ ! -f "$tmp_file" ]];then
pandoc -s -t man "$file" -o "$tmp_file";
fi
man "$tmp_file";
}