Renamed variables, sanitized (function) comments and clarified global variables
This commit is contained in:
parent
77308bd8b1
commit
84bc7dcb55
219
tldr
219
tldr
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set +vx -o pipefail
|
set +vx -o pipefail
|
||||||
[[ $- = *i* ]] && echo "Don't source this script!" && return 1
|
[[ $- = *i* ]] && echo "Don't source this script!" && return 1
|
||||||
VERSION='0.1a'
|
version='0.1a'
|
||||||
# tldr-bash-client version 0.1a
|
# tldr-bash-client version 0.1a
|
||||||
# Bash client for tldr: community driven man-by-example
|
# Bash client for tldr: community driven man-by-example
|
||||||
# - forked from Ray Lee, http://github.com/raylee/tldr
|
# - forked from Ray Lee, http://github.com/raylee/tldr
|
||||||
|
@ -16,24 +16,23 @@ VERSION='0.1a'
|
||||||
# 'Newline' can be added to the style list to add a newline before the element
|
# 'Newline' can be added to the style list to add a newline before the element
|
||||||
# and 'Space' to add a space at the start of the line (not for Value element)
|
# and 'Space' to add a space at the start of the line (not for Value element)
|
||||||
# (The style items are separated by space, lower or uppercase mixed allowed.)
|
# (The style items are separated by space, lower or uppercase mixed allowed.)
|
||||||
: ${TLDR_TITLE_STYLE:= Newline Space Bold Yellow }
|
: "${TLDR_TITLE_STYLE:= Newline Space Bold Yellow }"
|
||||||
: ${TLDR_DESCRIPTION_STYLE:= Space Yellow }
|
: "${TLDR_DESCRIPTION_STYLE:= Space Yellow }"
|
||||||
: ${TLDR_EXAMPLE_STYLE:= Newline Space Bold Green }
|
: "${TLDR_EXAMPLE_STYLE:= Newline Space Bold Green }"
|
||||||
: ${TLDR_CODE_STYLE:= Space Bold Blue }
|
: "${TLDR_CODE_STYLE:= Space Bold Blue }"
|
||||||
: ${TLDR_VALUE_STYLE:= Space Bold Cyan }
|
: "${TLDR_VALUE_STYLE:= Space Bold Cyan }"
|
||||||
# Color and/or background (Newline and Space also allowed) for error messages
|
# Color and/or background (Newline and Space also allowed) for error messages
|
||||||
: ${TLDR_ERROR_COLOR:= Space Red }
|
: "${TLDR_ERROR_COLOR:= Newline Space Red }"
|
||||||
|
|
||||||
# How long before an attempt will be made to re-download a page
|
# How long before an attempt will be made to re-download a page
|
||||||
: ${TLDR_EXPIRY:= 60 }
|
: "${TLDR_EXPIRY:= 60 }"
|
||||||
|
|
||||||
Usage(){ # $1: optional exit code
|
# $1: [optional] exit code; Uses: version configdir
|
||||||
SELF=$(basename "$0")
|
Usage(){
|
||||||
local exit=${1:-0}
|
|
||||||
Out "$(cat <<-EOF
|
Out "$(cat <<-EOF
|
||||||
$version
|
$version
|
||||||
|
|
||||||
USAGE: $GRE$B$SELF$XB$DEF [$YEL${B}option$XB$DEF] [$BLU${B}platform$XB/$DEF]$CYA$B<command>$XB$DEF
|
USAGE: $GRE$B$(basename "$0")$XB$DEF [$YEL${B}option$XB$DEF] [$BLU${B}platform$XB/$DEF]$CYA$B<command>$XB$DEF
|
||||||
|
|
||||||
$BLU$B platform$XB/$CYA${B}command$XB$DEF: Show page for$CYA$B command$XB$DEF (from$BLU$B platform$XB$DEF)
|
$BLU$B platform$XB/$CYA${B}command$XB$DEF: Show page for$CYA$B command$XB$DEF (from$BLU$B platform$XB$DEF)
|
||||||
|
|
||||||
|
@ -53,27 +52,31 @@ Usage(){ # $1: optional exit code
|
||||||
By default, the cached copies will be re-downloaded after $YEL${TLDR_EXPIRY// /}$DEF days.
|
By default, the cached copies will be re-downloaded after $YEL${TLDR_EXPIRY// /}$DEF days.
|
||||||
EOF
|
EOF
|
||||||
)"
|
)"
|
||||||
exit "$exit"
|
exit "${1:-0}"
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(){ STDERR+=$ERRNL$ERRSP$ERR$B$1$XB$XERR$N;} # $1: keep error messages
|
# $1: keep error messages; Uses/Sets: stderr
|
||||||
|
Err(){ stderr+=$ERRNL$ERRSP$ERR$B$1$XB$XERR$N;}
|
||||||
|
|
||||||
Out(){ STDOUT+=$1$N;} # $1: keep output
|
# $1: keep output; Uses/Sets: stdout
|
||||||
|
Out(){ stdout+=$1$N;}
|
||||||
|
|
||||||
Style(){ # $1: Style specification
|
# $1: Style specification; Uses: color xcolor bg xbg mode xmode
|
||||||
local style
|
Style(){
|
||||||
|
local -l style
|
||||||
STYLES='' XSTYLES='' COLOR='' XCOLOR='' NL='' SP=''
|
STYLES='' XSTYLES='' COLOR='' XCOLOR='' NL='' SP=''
|
||||||
for style in $1
|
for style in $1
|
||||||
do
|
do
|
||||||
[[ ${style,,} = newline ]] && NL=$N
|
[[ $style = newline ]] && NL=$N
|
||||||
[[ ${style,,} = space ]] && SP=' '
|
[[ $style = space ]] && SP=' '
|
||||||
COLOR+=${color[${style,,}]:-}${bg[${style,,}]:-}
|
COLOR+=${color[$style]:-}${bg[$style]:-}
|
||||||
XCOLOR=${xbg[${style,,}]:-}${xcolor[${style,,}]:-}$XCOLOR
|
XCOLOR=${xbg[$style]:-}${xcolor[$style]:-}$XCOLOR
|
||||||
STYLES+=${color[${style,,}]:-}${bg[${style,,}]:-}${mode[${style,,}]:-}
|
STYLES+=${color[$style]:-}${bg[$style]:-}${mode[$style]:-}
|
||||||
XSTYLES=${xmode[${style,,}]:-}${xbg[${style,,}]:-}${xcolor[${style,,}]:-}$XSTYLES
|
XSTYLES=${xmode[$style]:-}${xbg[$style]:-}${xcolor[$style]:-}$XSTYLES
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Sets: color xcolor bg xbg mode xmode
|
||||||
Init_term(){
|
Init_term(){
|
||||||
[[ -t 2 ]] && { # only if interactive session (stderr open)
|
[[ -t 2 ]] && { # only if interactive session (stderr open)
|
||||||
B=$'\e[1m' # $(tput bold || tput md) # Start bold
|
B=$'\e[1m' # $(tput bold || tput md) # Start bold
|
||||||
|
@ -84,7 +87,7 @@ Init_term(){
|
||||||
XI=$'\e[23m' # $(tput ritm || tput ZR) # End italic
|
XI=$'\e[23m' # $(tput ritm || tput ZR) # End italic
|
||||||
R=$'\e[7m' # $(tput smso || tput so) # Start reverse
|
R=$'\e[7m' # $(tput smso || tput so) # Start reverse
|
||||||
XR=$'\e[27m' # $(tput rmso || tput se) # End reverse
|
XR=$'\e[27m' # $(tput rmso || tput se) # End reverse
|
||||||
X=$'\e[0m' # $(tput sgr0 || tput me) # End all
|
#X=$'\e[0m' # $(tput sgr0 || tput me) # End all
|
||||||
|
|
||||||
[[ $TERM != *-m ]] && {
|
[[ $TERM != *-m ]] && {
|
||||||
BLA=$'\e[30m' # $(tput setaf 0 || tput AF 0)
|
BLA=$'\e[30m' # $(tput setaf 0 || tput AF 0)
|
||||||
|
@ -134,30 +137,34 @@ Init_term(){
|
||||||
ERR=$COLOR XERR=$XCOLOR ERRNL=$NL ERRSP=$SP
|
ERR=$COLOR XERR=$XCOLOR ERRNL=$NL ERRSP=$SP
|
||||||
}
|
}
|
||||||
|
|
||||||
Recent(){ find "$1" -mtime -"${TLDR_EXPIRY// /}" &>/dev/null;} # $1: page
|
# $1: page
|
||||||
|
Recent(){ find "$1" -mtime -"${TLDR_EXPIRY// /}" >/dev/null 2>&1;}
|
||||||
|
|
||||||
Update_index(){ # Download index.json
|
# Download index.json; Uses: index index_url base_url zip_url dl
|
||||||
$DL "$index" "$index_url" && Out "${GRE}Index file $I$index$XI re-downloaded$DEF" || {
|
Update_index(){
|
||||||
|
$dl "$index" "$index_url" && Out "${GRE}Index file $I$index$XI re-downloaded$DEF" || {
|
||||||
Err "Could not download index from $I$index_url$XI"
|
Err "Could not download index from $I$index_url$XI"
|
||||||
exit 2
|
exit 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Config(){ # Initialize globals, check the environment
|
# Initialize globals, check the environment; Uses: config configdir version
|
||||||
PLATFORM=common STDOUT='' STDERR='' Q='"' N=$'\n'
|
# Sets: stdout stderr os version dl
|
||||||
|
Config(){
|
||||||
|
os=common stdout='' stderr='' Q='"' N=$'\n'
|
||||||
case "$(uname -s)" in
|
case "$(uname -s)" in
|
||||||
Darwin) PLATFORM='osx' ;;
|
Darwin) os='osx' ;;
|
||||||
Linux) PLATFORM='linux' ;;
|
Linux) os='linux' ;;
|
||||||
SunOS) PLATFORM='sunos' ;;
|
SunOS) os='sunos' ;;
|
||||||
esac
|
esac
|
||||||
Init_term
|
Init_term
|
||||||
trap 'less -RXQFP"Press Q to exit " <<<"$STDOUT$STDERR"' EXIT
|
trap 'less -RXQFP"Press Q to exit " <<<"$stdout$stderr"' EXIT
|
||||||
|
|
||||||
version="$GRE$B tldr-bash-client version $VERSION$XB $YEL http://github.com/pepa65/tldr-bash-client$DEF"
|
version="$GRE$B tldr-bash-client version $version$XB $YEL http://github.com/pepa65/tldr-bash-client$DEF"
|
||||||
|
|
||||||
# Select download method
|
# Select download method
|
||||||
DL="$(type -p curl) -sfo" || {
|
dl="$(type -p curl) -sfo" || {
|
||||||
DL="$(type -p wget) -qNO" || {
|
dl="$(type -p wget) -qNO" || {
|
||||||
Err "tldr requires$I curl$XI or$I wget $XI installed in your path"
|
Err "tldr requires$I curl$XI or$I wget $XI installed in your path"
|
||||||
exit 3
|
exit 3
|
||||||
}
|
}
|
||||||
|
@ -174,119 +181,126 @@ Config(){ # Initialize globals, check the environment
|
||||||
[[ -f $index ]] && Recent "$index" || Update_index
|
[[ -f $index ]] && Recent "$index" || Update_index
|
||||||
}
|
}
|
||||||
|
|
||||||
Unlinted(){ # $1: error message
|
# $1: error message; Uses: md line ln
|
||||||
Err "Page $I$PAGE$XI not properly linted!\nLine $I$L$XI:[$U$REPLY$XU]$N$ERR$B$1"
|
Unlinted(){
|
||||||
|
Err "Page $I$md$XI not properly linted!\nLine $I$ln$XI:[$U$line$XU]$N$ERR$B$1"
|
||||||
exit 4
|
exit 4
|
||||||
}
|
}
|
||||||
|
|
||||||
Get_tldr(){ # $1: page
|
# $1: page; Uses: index index_url configdir base_url platform os dl cached md
|
||||||
|
# Sets: cached md
|
||||||
|
Get_tldr(){
|
||||||
|
local desc err notfound
|
||||||
# convert the local platform name to tldr's version
|
# convert the local platform name to tldr's version
|
||||||
# extract the platform key from index.json, return preferred subpath to page
|
# extract the platform key from index.json, return preferred subpath to page
|
||||||
local desc=$(tr '{' '\n' <$index |grep "\"name\":\"$1\"")
|
desc=$(tr '{' '\n' <$index |grep "\"name\":\"$1\"")
|
||||||
# results in, eg, "name":"netstat","platform":["linux","osx"]},
|
# results in, eg, "name":"netstat","platform":["linux","osx"]},
|
||||||
|
|
||||||
[[ $desc ]] || return # just not found
|
[[ $desc ]] || return # just not found
|
||||||
|
|
||||||
local err=0
|
err=0
|
||||||
if [[ $platform ]]
|
if [[ $platform ]]
|
||||||
then # platform given on commandline
|
then # platform given on commandline
|
||||||
[[ ! $desc =~ \"$platform\" ]] && notfound=$I$platform$XI && err=1 || PAGE=$platform/$1.md
|
[[ ! $desc =~ \"$platform\" ]] && notfound=$I$platform$XI && err=1 || md=$platform/$1.md
|
||||||
else # check common
|
else # check common
|
||||||
[[ $desc =~ \"common\" ]] && PAGE=common/$1.md || { # not in common either
|
[[ $desc =~ \"common\" ]] && md=common/$1.md || { # not in common either
|
||||||
[[ $notfound ]] && notfound+=" or "
|
[[ $notfound ]] && notfound+=" or "
|
||||||
notfound+=${I}common$XI
|
notfound+=${I}common$XI
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
# if no page found yet, try the system platform
|
# if no page found yet, try the system platform
|
||||||
[[ $PAGE ]] || [[ $platform = "$PLATFORM" ]] || {
|
[[ $md ]] || [[ $platform = "$os" ]] || {
|
||||||
[[ $desc =~ \"$PLATFORM\" ]] && PAGE=$PLATFORM/$1.md
|
[[ $desc =~ \"$os\" ]] && md=$os/$1.md
|
||||||
} || {
|
} || {
|
||||||
notfound+=" or $I$PLATFORM$XI"
|
notfound+=" or $I$os$XI"
|
||||||
err=1
|
err=1
|
||||||
}
|
}
|
||||||
# if still no page found, get the first entry in index
|
# if still no page found, get the first entry in index
|
||||||
[[ $PAGE ]] || PAGE=$(cut -d "$Q" -f 8 <<<"$desc")/"$1.md"
|
[[ $md ]] || md=$(cut -d "$Q" -f 8 <<<"$desc")/"$1.md"
|
||||||
((err)) && Err "tldr page $I$1$XI not found in $notfound, page from platform $U${PAGE%/*}$XU instead"
|
((err)) && Err "tldr page $I$1$XI not found in $notfound, page from platform $U${md%/*}$XU instead"
|
||||||
|
|
||||||
# return the local cached copy of the tldrpage, or retrieve and cache from github
|
# return the local cached copy of the tldrpage, or retrieve and cache from github
|
||||||
CACHED=$configdir/$PAGE
|
cached=$configdir/$md
|
||||||
Recent "$CACHED" || {
|
Recent "$cached" || {
|
||||||
mkdir -p "${CACHED%/*}"
|
mkdir -p "${cached%/*}"
|
||||||
$DL "$CACHED" "$base_url/$PAGE" || Err "Could not download page $I$CACHED$XI from index $U$index_url$XU"
|
$dl "$cached" "$base_url/$md" || Err "Could not download page $I$cached$XI from index $U$index_url$XU"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Uses: page stdout stderr; Sets: ln line
|
||||||
Display_tldr(){
|
Display_tldr(){
|
||||||
# read one line at a time, don't strip whitespace ('IFS='), and
|
local newfmt len val
|
||||||
# process last line even if it doesn't have a newline at the end
|
ln=0 line=''
|
||||||
L=0
|
# Read full lines, and process even when no newline at the end
|
||||||
local newfmt len line
|
while read -r line || [[ $line ]]
|
||||||
while read -r || [[ $REPLY ]]
|
|
||||||
do
|
do
|
||||||
((++L))
|
((++ln))
|
||||||
((L==1)) && {
|
((ln==1)) && {
|
||||||
[[ ${REPLY:0:1} = '#' ]] && newfmt=0 || newfmt=1
|
[[ ${line:0:1} = '#' ]] && newfmt=0 || newfmt=1
|
||||||
((newfmt)) && {
|
((newfmt)) && {
|
||||||
[[ $REPLY ]] || Unlinted "No title"
|
[[ $line ]] || Unlinted "No title"
|
||||||
Out "$TNL$TSP$T$REPLY$XT"
|
Out "$TNL$TSP$T$line$XT"
|
||||||
len=${#REPLY}
|
len=${#line}
|
||||||
read -r; ((++L))
|
read -r; ((++ln))
|
||||||
[[ $REPLY =~ [^=] ]] && Unlinted "Title underline must be equal signs"
|
[[ $line =~ [^=] ]] && Unlinted "Title underline must be equal signs"
|
||||||
((len!=${#REPLY})) && Unlinted "Underline length not equal to title's"
|
((len!=${#line})) && Unlinted "Underline length not equal to title's"
|
||||||
read -r; ((++L))
|
read -r; ((++ln))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "${REPLY:0:1}" in # first character
|
case "${line:0:1}" in # first character
|
||||||
'#') ((newfmt)) && Unlinted "Bad first character"
|
'#') ((newfmt)) && Unlinted "Bad first character"
|
||||||
((${#REPLY} <= 2)) && Unlinted "No title"
|
((${#line} <= 2)) && Unlinted "No title"
|
||||||
[[ ! ${REPLY:1:1} = ' ' ]] && Unlinted "2nd character no space"
|
[[ ! ${line:1:1} = ' ' ]] && Unlinted "2nd character no space"
|
||||||
Out "$TNL$TSP$T${REPLY:2}$XT" ;;
|
Out "$TNL$TSP$T${line:2}$XT" ;;
|
||||||
'>') ((${#REPLY} <= 3)) && Unlinted "No valid desciption"
|
'>') ((${#line} <= 3)) && Unlinted "No valid desciption"
|
||||||
[[ ! ${REPLY:1:1} = ' ' ]] && Unlinted "2nd character no space"
|
[[ ! ${line:1:1} = ' ' ]] && Unlinted "2nd character no space"
|
||||||
[[ ! ${REPLY: -1} = '.' ]] && Unlinted "Description doesn't end in full stop"
|
[[ ! ${line: -1} = '.' ]] && Unlinted "Description doesn't end in full stop"
|
||||||
Out "$DNL$DSP$D${REPLY:2}$XD"
|
Out "$DNL$DSP$D${line:2}$XD"
|
||||||
DNL='' ;;
|
DNL='' ;;
|
||||||
'-') ((newfmt)) && Unlinted "Bad first character"
|
'-') ((newfmt)) && Unlinted "Bad first character"
|
||||||
((${#REPLY} <= 2)) && Unlinted "No example content"
|
((${#line} <= 2)) && Unlinted "No example content"
|
||||||
[[ ! ${REPLY:1:1} = ' ' ]] && Unlinted "2nd character no space"
|
[[ ! ${line:1:1} = ' ' ]] && Unlinted "2nd character no space"
|
||||||
Out "$ENL$ESP$E${REPLY:2}$XE" ;;
|
Out "$ENL$ESP$E${line:2}$XE" ;;
|
||||||
' ') ((newfmt)) || Unlinted "Bad first character"
|
' ') ((newfmt)) || Unlinted "Bad first character"
|
||||||
((${#REPLY} <= 4)) && Unlinted "No valid code content"
|
((${#line} <= 4)) && Unlinted "No valid code content"
|
||||||
[[ ${REPLY:0:4} = ' ' ]] || Unlinted "No four spaces before code"
|
[[ ${line:0:4} = ' ' ]] || Unlinted "No four spaces before code"
|
||||||
line=${REPLY:4}
|
val=${line:4}
|
||||||
# Value: convert {{value}}
|
# Value: convert {{value}}
|
||||||
line=${line//\{\{/$CX$V}
|
val=${val//\{\{/$CX$V}
|
||||||
line=${line//\}\}/$XV$C}
|
val=${val//\}\}/$XV$C}
|
||||||
Out "$CNL$CSP$C$line$XC" ;;
|
Out "$CNL$CSP$C$val$XC" ;;
|
||||||
'`') ((newfmt)) && Unlinted "Bad first character"
|
'`') ((newfmt)) && Unlinted "Bad first character"
|
||||||
((${#REPLY} <= 2)) && Unlinted "No valid code content"
|
((${#line} <= 2)) && Unlinted "No valid code content"
|
||||||
[[ ! ${REPLY: -1} = '`' ]] && Unlinted "Code doesn't end in backtick"
|
[[ ! ${line: -1} = '`' ]] && Unlinted "Code doesn't end in backtick"
|
||||||
line=${REPLY:1:-1}
|
val=${line:1:-1}
|
||||||
# Value: convert {{value}}
|
# Value: convert {{value}}
|
||||||
line=${line//\{\{/$CX$V}
|
val=${val//\{\{/$CX$V}
|
||||||
line=${line//\}\}/$XV$C}
|
val=${val//\}\}/$XV$C}
|
||||||
Out "$CNL$CSP$C$line$XC" ;;
|
Out "$CNL$CSP$C$val$XC" ;;
|
||||||
'') continue ;;
|
'') continue ;;
|
||||||
*) ((newfmt)) || Unlinted "Bad first character"
|
*) ((newfmt)) || Unlinted "Bad first character"
|
||||||
[[ -z $REPLY ]] && Unlinted "No example content"
|
[[ -z $line ]] && Unlinted "No example content"
|
||||||
Out "$ENL$EPS$E$REPLY$XE" ;;
|
Out "$ENL$EPS$E$line$XE" ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
trap 'less +Gg -RXQFP"%pB\% tldr $I$page$XI - press Q to exit" <<<"$STDOUT$STDERR"' EXIT
|
trap 'less +Gg -RXQFP"%pB\% tldr $I$page$XI - press Q to exit" <<<"$stdout$stderr"' EXIT
|
||||||
}
|
}
|
||||||
|
|
||||||
List_pages(){ # $1: exit code
|
# $1: exit code; Uses: platform index
|
||||||
local platformtext
|
List_pages(){
|
||||||
|
local platformtext c1 c2 c3
|
||||||
[[ $platform ]] && platformtext=" from platform $I$platform$XI"
|
[[ $platform ]] && platformtext=" from platform $I$platform$XI"
|
||||||
Out "${GRE}Known tldr pages$platformtext:"
|
Out "${GRE}Known tldr pages$platformtext:"
|
||||||
Out "$(while read -r c1 c2 c3; do printf "%-19s %-19s %-19s %-19s$N" "$c1" "$c2" "$c3"; done \
|
Out "$(while read -r c1 c2 c3; do printf "%-19s %-19s %-19s %-19s$N" "$c1" "$c2" "$c3"; done \
|
||||||
<<<$(tr '{' '\n' <"$index" |grep "$platform" |cut -d "$Q" -f4))"
|
<<<$(tr '{' '\n' <$index |grep "$platform" |cut -d "$Q" -f4))"
|
||||||
exit "$1"
|
exit "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
Cache_fill(){ # $1: exit code
|
# $1: exit code; Uses: dl configdir zip_url
|
||||||
local tmp=$(mktemp -d)
|
Cache_fill(){
|
||||||
$DL "$tmp/pages.zip" "$zip_url" || {
|
local tmp unzip
|
||||||
|
tmp=$(mktemp -d)
|
||||||
|
$dl "$tmp/pages.zip" "$zip_url" || {
|
||||||
rm -- "$tmp"
|
rm -- "$tmp"
|
||||||
Err "Could not download pages archive from $U$zip_url$XU"
|
Err "Could not download pages archive from $U$zip_url$XU"
|
||||||
exit 6
|
exit 6
|
||||||
|
@ -305,8 +319,7 @@ Cache_fill(){ # $1: exit code
|
||||||
}
|
}
|
||||||
|
|
||||||
Config
|
Config
|
||||||
markdown=0 err=0
|
markdown=0 err=0 arg=$1
|
||||||
arg=$1
|
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
-l|--list) [[ $2 ]] && {
|
-l|--list) [[ $2 ]] && {
|
||||||
platform=$2
|
platform=$2
|
||||||
|
@ -352,8 +365,8 @@ esac
|
||||||
}
|
}
|
||||||
|
|
||||||
Get_tldr "${page// /-}"
|
Get_tldr "${page// /-}"
|
||||||
[[ ! -s $CACHED ]] && Err "tldr page for command $I$page$XI not found" && exit 23
|
[[ ! -s $cached ]] && Err "tldr page for command $I$page$XI not found" && exit 23
|
||||||
|
|
||||||
((markdown)) && Out "$(cat "$CACHED")" || Display_tldr <"$CACHED"
|
((markdown)) && Out "$(cat "$cached")" || Display_tldr <"$cached"
|
||||||
# The error trap will output the accumulated stdout and stderr
|
# The error trap will output the accumulated stdout and stderr
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in New Issue