Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
executable file
·
53 lines (43 loc) · 1.67 KB

File metadata and controls

executable file
·
53 lines (43 loc) · 1.67 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env bash
# md: Pager wrapper for md2ansi
# Forwards all arguments to md2ansi and pipes the rendered ANSI output
# through `less` so colour escapes survive and short docs auto-exit.
set -euo pipefail
declare -r VERSION=1.0.0
#shellcheck disable=SC2155
declare -r SCRIPT_PATH=$(realpath -- "$0")
declare -r SCRIPT_DIR=${SCRIPT_PATH%/*} SCRIPT_NAME=${SCRIPT_PATH##*/}
# Help / version - intercepted before delegating to md2ansi so the wrapper
# can identify itself; any other args (including md2ansi's own -h/-V) are
# passed through.
if (($#)); then
if [[ $1 == '-h' || $1 == '--help' ]]; then
cat <<HELP
$SCRIPT_NAME $VERSION - Wrapper for md2ansi that pipes output through less
Provides paginated viewing of markdown files via md2ansi.
Usage: $SCRIPT_NAME [OPTIONS] file.md
cat file.md | $SCRIPT_NAME [OPTIONS]
$SCRIPT_NAME --help
$SCRIPT_NAME --version
OPTIONS are md2ansi options: see md2ansi --help
Examples:
$SCRIPT_NAME README.md
cat README.md | $SCRIPT_NAME --no-syntax-highlight --width 76
HELP
exit 0
fi
if [[ $1 == '-V' || $1 == '--version' ]]; then
printf '%s %s\n' "$SCRIPT_NAME" "$VERSION"
exit 0
fi
fi
# less flags for ANSI markdown viewing:
# -F quit if entire output fits on one screen
# -X do not send terminal init/deinit (preserves output after exit)
# -R pass raw ANSI colour escapes through to the terminal
# -S chop long lines instead of wrapping (preserves table layout)
export LESS='-FXRS'
# Delegate to the sibling md2ansi binary so dev-mode (running from the
# checkout) and installed-mode (both files in /usr/local/bin) both work.
"$SCRIPT_DIR/md2ansi" "$@" | less
#fin
Morty Proxy This is a proxified and sanitized view of the page, visit original site.