|
@ -1,6 +1,6 @@
|
||||||
# tldr-bash-client
|
# tldr-bash-client
|
||||||
|
|
||||||
* version 0.36
|
* version 0.37
|
||||||
|
|
||||||
### Bash client for tldr: community driven man-by-example
|
### Bash client for tldr: community driven man-by-example
|
||||||
**A fully-functional [bash](https://tiswww.case.edu/php/chet/bash/bashtop.html)
|
**A fully-functional [bash](https://tiswww.case.edu/php/chet/bash/bashtop.html)
|
||||||
|
@ -23,14 +23,15 @@ sudo chmod +x $loc
|
||||||
If the location is not in $PATH, you need to specify the path to run it.
|
If the location is not in $PATH, you need to specify the path to run it.
|
||||||
|
|
||||||
<img alt="tldr page screenshot" src="tldr-page.jpg" title="tldr page" width="600" />
|
<img alt="tldr page screenshot" src="tldr-page.jpg" title="tldr page" width="600" />
|
||||||
<img alt="tldr list screenshot" src="tldr-list.jpg" title="tldr list" width="600" />
|
<img alt="tldr usage screenshot" src="tldr-usage.jpg" title="tldr usage" width="600" />
|
||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
coreutils, grep, unzip, curl / wget, less (optional)
|
coreutils, grep, unzip, curl / wget, less (optional)
|
||||||
|
|
||||||
<img alt="tldr usage screenshot" src="tldr-usage.jpg" title="tldr usage" width="600" />
|
<img alt="tldr list screenshot" src="tldr-list.jpg" title="tldr list" width="600" />
|
||||||
|
|
||||||
## Customisation
|
## Customisation
|
||||||
|
<img alt="tldr customize screenshot" src="tldr-customize.jpg" title="tldr customize" width="600" />
|
||||||
|
|
||||||
The 5 elements in TLDR markup that can be styled with these colors and
|
The 5 elements in TLDR markup that can be styled with these colors and
|
||||||
backgrounds (last one specified will be used) and modes (more can apply):
|
backgrounds (last one specified will be used) and modes (more can apply):
|
||||||
|
@ -71,7 +72,7 @@ Alternative location of pages cache
|
||||||
Instead of `less`, use `cat` for output (automatic if less not available)
|
Instead of `less`, use `cat` for output (automatic if less not available)
|
||||||
* TLDR_LESS (not set by default; if set to *0* `cat` will be used)
|
* TLDR_LESS (not set by default; if set to *0* `cat` will be used)
|
||||||
|
|
||||||
<img alt="tldr customize screenshot" src="tldr-customize.jpg" title="tldr customize" width="600" />
|
<img alt="tldr find screenshot" src="tldr-find.jpg" title="tldr find" width="600" />
|
||||||
|
|
||||||
# tldr-lint
|
# tldr-lint
|
||||||
|
|
||||||
|
|
86
tldr
|
@ -1,8 +1,8 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env 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.36'
|
version='0.37'
|
||||||
# tldr-bash-client version 0.36
|
# tldr-bash-client version 0.37
|
||||||
# Bash client for tldr: community driven man-by-example
|
# Bash client for tldr: community driven man-by-example
|
||||||
# - forked from Ray Lee, https://github.com/raylee/tldr
|
# - forked from Ray Lee, https://github.com/raylee/tldr
|
||||||
# - modified and expanded by pepa65: https://github.com/pepa65/tldr-bash-client
|
# - modified and expanded by pepa65: https://github.com/pepa65/tldr-bash-client
|
||||||
|
@ -51,13 +51,14 @@ Usage(){
|
||||||
Out "$(cat <<-EOF
|
Out "$(cat <<-EOF
|
||||||
$HHE$version
|
$HHE$version
|
||||||
|
|
||||||
$HDEUSAGE: $HHE$(basename "$0")$XHHE [${HOP}option$XHOP] [${HPL}platform$XHPL/]${HCO}command$XHCO
|
${HDE}USAGE: $HHE$(basename "$0")$XHHE [${HOP}option$XHOP] [${HPL}platform$XHPL/]${HCO}command$XHCO
|
||||||
|
|
||||||
$HDE[${HPL}platform$XHPL/]${HCO}command$XHCO: Show page for ${HCO}command$XHCO (from ${HPL}platform$XHPL)
|
$HDE[${HPL}platform$XHPL/]${HCO}command$XHCO: Show page for ${HCO}command$XHCO (from ${HPL}platform$XHPL)
|
||||||
|
|
||||||
${HPL}platform$XHPL (optional) one of: ${HPL}common$XHPL, ${HPL}linux$XHPL, ${HPL}osx$XHPL, ${HPL}sunos$XHPL, ${HPL}current$XHPL (includes common)
|
${HPL}platform$XHPL (optional) one of: ${HPL}common$XHPL, ${HPL}linux$XHPL, ${HPL}osx$XHPL, ${HPL}sunos$XHPL, ${HPL}current$XHPL (includes common)
|
||||||
|
|
||||||
${HOP}option$XHOP is optionally one of:
|
${HOP}option$XHOP is optionally one of:
|
||||||
|
$HOP-f$XHOP, $HOP--find$XHOP ${HFI}regex$XHFI: Find all ${HFI}regex$XHFI in tldr pages
|
||||||
$HOP-l$XHOP, $HOP--list$XHOP [${HPL}platform$XHPL]: List all pages (from ${HPL}platform$XHPL)
|
$HOP-l$XHOP, $HOP--list$XHOP [${HPL}platform$XHPL]: List all pages (from ${HPL}platform$XHPL)
|
||||||
$HOP-a$XHOP, $HOP--list-all$XHOP: List all pages from current platform + common
|
$HOP-a$XHOP, $HOP--list-all$XHOP: List all pages from current platform + common
|
||||||
$HOP-r$XHOP, $HOP--render$XHOP ${HFI}file$XHFI: Render a local ${HFI}file$XHFI as tldr markdown
|
$HOP-r$XHOP, $HOP--render$XHOP ${HFI}file$XHFI: Render a local ${HFI}file$XHFI as tldr markdown
|
||||||
|
@ -231,7 +232,7 @@ Unlinted(){
|
||||||
# $1: page; Uses: index cachedir pages_url platform os dl cached md
|
# $1: page; Uses: index cachedir pages_url platform os dl cached md
|
||||||
# Sets: cached md
|
# Sets: cached md
|
||||||
Get_tldr(){
|
Get_tldr(){
|
||||||
local desc err notfound
|
local desc err=0 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
|
||||||
desc=$(tr '{' '\n' <"$index" |grep "\"name\":\"$1\"")
|
desc=$(tr '{' '\n' <"$index" |grep "\"name\":\"$1\"")
|
||||||
|
@ -239,10 +240,9 @@ Get_tldr(){
|
||||||
|
|
||||||
[[ $desc ]] || return # nothing found
|
[[ $desc ]] || return # nothing found
|
||||||
|
|
||||||
error=0
|
|
||||||
if [[ $platform ]]
|
if [[ $platform ]]
|
||||||
then # platform given on commandline
|
then # platform given on commandline
|
||||||
[[ ! $desc =~ \"$platform\" ]] && notfound=$I$platform$XI && error=1 || md=$platform/$1.md
|
[[ ! $desc =~ \"$platform\" ]] && notfound=$I$platform$XI && err=1 || md=$platform/$1.md
|
||||||
else # check common
|
else # check common
|
||||||
[[ $desc =~ \"common\" ]] && md=common/$1.md || { # not in common either
|
[[ $desc =~ \"common\" ]] && md=common/$1.md || { # not in common either
|
||||||
[[ $notfound ]] && notfound+=" or "
|
[[ $notfound ]] && notfound+=" or "
|
||||||
|
@ -254,11 +254,11 @@ Get_tldr(){
|
||||||
[[ $desc =~ \"$os\" ]] && md=$os/$1.md
|
[[ $desc =~ \"$os\" ]] && md=$os/$1.md
|
||||||
} || {
|
} || {
|
||||||
notfound+=" or $I$os$XI"
|
notfound+=" or $I$os$XI"
|
||||||
error=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
|
||||||
[[ $md ]] || md=$(cut -d "$Q" -f 8 <<<"$desc")/"$1.md"
|
[[ $md ]] || md=$(cut -d "$Q" -f 8 <<<"$desc")/"$1.md"
|
||||||
((error)) && Err "tldr page $I$1$XI not found in $notfound, from platform $U${md%/*}$XU instead"
|
((err)) && Err "tldr page $I$1$XI not found in $notfound, 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=$cachedir/$md
|
cached=$cachedir/$md
|
||||||
|
@ -268,7 +268,7 @@ Get_tldr(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# $1: text; Uses: page stdout; Sets: ln REPLY
|
# $1: file (optional); Uses: page stdout; Sets: ln REPLY
|
||||||
Display_tldr(){
|
Display_tldr(){
|
||||||
local newfmt len val
|
local newfmt len val
|
||||||
ln=0 REPLY=''
|
ln=0 REPLY=''
|
||||||
|
@ -345,24 +345,42 @@ List_pages(){
|
||||||
exit "$1"
|
exit "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# $1: regex, $1: exit code; Uses: cachedir
|
||||||
|
Find_regex(){
|
||||||
|
local list=$(grep "$1" "$cachedir"/*/*.md |cut -d: -f1) regex="$U$1$XU"
|
||||||
|
local n=$(wc -l <<<"$list")
|
||||||
|
list=$(sort -u <<<"$list")
|
||||||
|
[[ -z $list ]] && Err "Regex $regex not found" && exit 6
|
||||||
|
local t=$(wc -l <<<"$list")
|
||||||
|
if ((t==1))
|
||||||
|
then
|
||||||
|
Display_tldr "$list"
|
||||||
|
else
|
||||||
|
Inf "Regex $regex $I$n$XI times found in these $I$t$XI tldr pages:"
|
||||||
|
Out "$(while read -r c1 c2 c3; do printf "%-19s %-19s %-19s %-19s$N" $c1 $c2 $c3; done \
|
||||||
|
<<<$(sed -e 's@.*/@@' -e 's@...$@@' <<<"$list"))"
|
||||||
|
fi
|
||||||
|
exit "$2"
|
||||||
|
}
|
||||||
|
|
||||||
# $1: exit code; Uses: dl cachedir zip_url
|
# $1: exit code; Uses: dl cachedir zip_url
|
||||||
Cache_fill(){
|
Cache_fill(){
|
||||||
local tmp unzip
|
local tmp unzip
|
||||||
unzip="$(type -p unzip) -q" || {
|
unzip="$(type -p unzip) -q" || {
|
||||||
Err "Unzip is necessary to fill the cache"
|
Err "Unzip is necessary to fill the cache"
|
||||||
exit 6
|
exit 7
|
||||||
}
|
}
|
||||||
tmp=$(mktemp -d)
|
tmp=$(mktemp -d)
|
||||||
$dl "$tmp/pages.zip" "$zip_url" || {
|
$dl "$tmp/pages.zip" "$zip_url" || {
|
||||||
rm -- "$tmp"
|
rm -- "$tmp"
|
||||||
Err "Could not download pages archive from $U$zip_url$XU with $dl"
|
Err "Could not download pages archive from $U$zip_url$XU with $dl"
|
||||||
exit 7
|
exit 8
|
||||||
}
|
}
|
||||||
$unzip "$tmp/pages.zip" -d "$tmp" 'pages/*' || {
|
$unzip "$tmp/pages.zip" -d "$tmp" 'pages/*' || {
|
||||||
rm -- "$tmp"
|
rm -- "$tmp"
|
||||||
Err "Couldn't unzip the cache archive on $tmp/pages.zip"
|
Err "Couldn't unzip the cache archive on $tmp/pages.zip"
|
||||||
exit 8
|
exit 9
|
||||||
}
|
}
|
||||||
rm -rf -- "${cachedir:?}/"*
|
rm -rf -- "${cachedir:?}/"*
|
||||||
mv -- "$tmp/pages/"* "${cachedir:?}/"
|
mv -- "$tmp/pages/"* "${cachedir:?}/"
|
||||||
rm -rf -- "$tmp"
|
rm -rf -- "$tmp"
|
||||||
|
@ -372,56 +390,56 @@ Cache_fill(){
|
||||||
|
|
||||||
# $@: commandline parameters; Uses: version cached; Sets: platform page
|
# $@: commandline parameters; Uses: version cached; Sets: platform page
|
||||||
Main(){
|
Main(){
|
||||||
local markdown err nomore='No more command line arguments allowed'
|
local markdown=0 err=0 nomore='No more command line arguments allowed'
|
||||||
Config
|
Config
|
||||||
markdown=0 err=0
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
-f|--find) [[ -z $2 ]] && Err "Search term (regex) needed" && Usage 10
|
||||||
|
[[ $3 ]] && Err "$nomore" && err=11
|
||||||
|
Find_regex "$2" "$err" ;;
|
||||||
-l|--list) [[ $2 ]] && {
|
-l|--list) [[ $2 ]] && {
|
||||||
platform=$2
|
platform=$2
|
||||||
[[ ,common,linux,osx,sunos,current, = *,$platform,* ]] || {
|
[[ ,common,linux,osx,sunos,current, != *,$platform,* ]] &&
|
||||||
Err "Unknown platform $I$platform$XI"
|
Err "Unknown platform $I$platform$XI" && Usage 12
|
||||||
Usage 9
|
[[ $3 ]] && Err "$nomore" && err=13
|
||||||
}
|
|
||||||
[[ $3 ]] && Err "$nomore" && err=10
|
|
||||||
}
|
}
|
||||||
List_pages "$err" ;;
|
List_pages "$err" ;;
|
||||||
-a|--list-all) [[ $2 ]] && Err "$nomore" && err=11
|
-a|--list-all) [[ $2 ]] && Err "$nomore" && err=14
|
||||||
platform=current
|
platform=current
|
||||||
List_pages $err ;;
|
List_pages $err ;;
|
||||||
-u|--update) [[ $2 ]] && Err "$nomore" && err=12
|
-u|--update) [[ $2 ]] && Err "$nomore" && err=15
|
||||||
Cache_fill "$err" ;;
|
Cache_fill "$err" ;;
|
||||||
-v|--version) [[ $2 ]] && Err "$nomore" && err=13
|
-v|--version) [[ $2 ]] && Err "$nomore" && err=16
|
||||||
Inf "$version"
|
Inf "$version"
|
||||||
exit "$err" ;;
|
exit "$err" ;;
|
||||||
-r|--render) [[ -z $2 ]] && Err "Specify a file to render" && Usage 14
|
-r|--render) [[ -z $2 ]] && Err "Specify a file to render" && Usage 17
|
||||||
[[ $3 ]] && Err "$nomore" && err=15
|
[[ $3 ]] && Err "$nomore" && err=18
|
||||||
[[ -f "$2" ]] && {
|
[[ -f "$2" ]] && {
|
||||||
Display_tldr "$2" && exit "$err"
|
Display_tldr "$2" && exit "$err"
|
||||||
Err "A file error occured"
|
Err "A file error occured"
|
||||||
exit 16
|
exit 19
|
||||||
} || Err "No file: ${I}$2$XI" && exit 17 ;;
|
} || Err "No file: ${I}$2$XI" && exit 20 ;;
|
||||||
-m|--markdown) shift
|
-m|--markdown) shift
|
||||||
page=$*
|
page=$*
|
||||||
[[ -z $page ]] && Err "Specify a page to display" && Usage 18
|
[[ -z $page ]] && Err "Specify a page to display" && Usage 21
|
||||||
[[ -f "$page" && ${page: -3:3} = .md ]] && Out "$(cat "$page")" && exit 0
|
[[ -f "$page" && ${page: -3:3} = .md ]] && Out "$(cat "$page")" && exit 0
|
||||||
markdown=1 ;;
|
markdown=1 ;;
|
||||||
''|-h|-\?|--help) [[ $2 ]] && Err "$nomore" && err=19
|
''|-h|-\?|--help) [[ $2 ]] && Err "$nomore" && err=22
|
||||||
Usage "$err" ;;
|
Usage "$err" ;;
|
||||||
-*) Err "Unrecognized option $I$1$XI"; Usage 20 ;;
|
-*) Err "Unrecognized option $I$1$XI"; Usage 23 ;;
|
||||||
*) page=$* ;;
|
*) page=$* ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
[[ -z $page ]] && Err "No command specified" && Usage 21
|
[[ -z $page ]] && Err "No command specified" && Usage 24
|
||||||
[[ ${page:0:1} = '-' || $page = *' '-* ]] && Err "Only one option allowed" && Usage 22
|
[[ ${page:0:1} = '-' || $page = *' '-* ]] && Err "Only one option allowed" && Usage 25
|
||||||
[[ $page = */* ]] && platform=${page%/*} && page=${page##*/}
|
[[ $page = */* ]] && platform=${page%/*} && page=${page##*/}
|
||||||
[[ $platform && ,common,linux,osx,sunos, != *,$platform,* ]] && {
|
[[ $platform && ,common,linux,osx,sunos, != *,$platform,* ]] && {
|
||||||
Err "Unknown platform $I$platform$XI"
|
Err "Unknown platform $I$platform$XI"
|
||||||
Usage 23
|
Usage 26
|
||||||
}
|
}
|
||||||
|
|
||||||
Get_tldr "${page// /-}"
|
Get_tldr "${page// /-}"
|
||||||
[[ ! -s $cached ]] && Err "tldr page for command $I$page$XI not found" \
|
[[ ! -s $cached ]] && Err "tldr page for command $I$page$XI not found" \
|
||||||
&& Inf "Contribute new pages at:$XB ${URL}https://github.com/tldr-pages/tldr$XURL" && exit 24
|
&& Inf "Contribute new pages at:$XB ${URL}https://github.com/tldr-pages/tldr$XURL" && exit 27
|
||||||
((markdown)) && Out "$(cat "$cached")" || Display_tldr "$cached"
|
((markdown)) && Out "$(cat "$cached")" || Display_tldr "$cached"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 51 KiB |
BIN
tldr-list.jpg
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 8.2 KiB |
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 43 KiB |
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 16 KiB |
BIN
tldr-page.jpg
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 28 KiB |
BIN
tldr-usage.jpg
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 42 KiB |