Last active
August 7, 2024 19:13
-
-
Save sebastiancarlos/2294c4b15854d63c9791ae4576860061 to your computer and use it in GitHub Desktop.
groff-preview
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
#! /usr/bin/env bash | |
# All my gist code is licensed under the MIT license. | |
# Add this somewhere in your .bashrc | |
# groff-preview-terminal | |
# - previews roff file in the terminal | |
# - uses grog to figure out needed preprocessor and macros | |
# - sends to terminal output by passing -Tutf8 and then to a pager | |
function groff-preview-terminal () { | |
# print usage on --help/-h or no arguments | |
if [[ $# -eq 0 || "$1" == "--help" || "$1" == "-h" ]]; then | |
echo "usage: groff-preview-terminal <file>" | |
echo " - previews roff <file> in the terminal" | |
echo " - uses grog to figure out needed preprocessor and macros" | |
echo " - sends to terminal output by passing -Tutf8 and then to a pager" | |
return 1 | |
fi | |
grog --run -Tutf8 "$@" | less -R | |
} | |
# groff-preview-pdf | |
# - previews roff file as a PDF | |
# - uses grog to figure out needed preprocessor and macros | |
# - generates a pdf in a temporary folder, and open it | |
function groff-preview-pdf () { | |
# print usage on --help/-h or no arguments | |
if [[ $# -eq 0 || "$1" == "--help" || "$1" == "-h" ]]; then | |
echo "usage: groff-preview-pdf <file>" | |
echo " - previews roff <file> as a PDF" | |
echo " - uses grog to figure out needed preprocessor and macros" | |
echo " - generates a pdf in a temporary folder, and open it" | |
return 1 | |
fi | |
local file="$1" | |
local name="${file##*/}" | |
name="${name%.*}" | |
local outputFolder="/tmp/groff-preview-pdf" | |
mkdir -p "$outputFolder" | |
local pdf="$outputFolder/$name.pdf" | |
grog --run -Tpdf "$file" >| "$pdf" | |
xdg-open "$pdf" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment