Compare commits

...

9 Commits

Author SHA1 Message Date
gitlab.com/pepa65 e97179376b After Pullreq.#19: Show English tldr if not found in other language 2023-06-04 11:24:34 +07:00
gitlab.com/pepa65 2156390101 Different fix for bash's bug in reading UTF-8 2023-05-31 14:47:16 +07:00
gitlab.com/pepa65 15854a1465 Fix Chinese display in less and debug linting 2023-05-31 06:10:54 +07:00
gitlab.com/pepa65 c65bb3fb1d Debug full stop 2023-05-31 05:39:19 +07:00
gitlab.com/pepa65 ea512b442c New version 0.5.0 2023-05-31 05:15:25 +07:00
gitlab.com/pepa65 ff1fabc6b1 Allow for Chinese full stop when linting
(does the official spec allow for it??)
2023-05-31 05:13:42 +07:00
gitlab.com/pepa65 538acb9b7e master->main 2022-12-28 17:26:49 +07:00
gitlab.com/pepa65 77219cda47 Fix bash completion
Improve readme
2022-11-14 11:22:41 +07:00
gitlab.com/pepa65 6321f7c6df Retire 4e4.win for good4.eu
Go to semver
2022-04-05 11:00:59 +07:00
3 changed files with 41 additions and 27 deletions

View File

@ -1,6 +1,6 @@
# tldr-bash-client
* version 0.48
* version 0.6.2
### Bash client for tldr: community driven man-by-example
**A fully-functional [bash](https://tiswww.case.edu/php/chet/bash/bashtop.html)
@ -15,9 +15,9 @@ This client can render both the old and the new tldr markup format.
Download the tldr bash script to the install location:
```bash
loc=/usr/local/bin/tldr # elevated privileges needed for some locations
sudo wget -qO $loc https://4e4.win/tldr
sudo chmod +x $loc
L=/usr/local/bin/tldr # elevated privileges needed for some locations
sudo wget -qO $L good4.eu/tldr
sudo chmod +x $L
```
If the location is not in $PATH, you need to specify the path to run it.
@ -41,7 +41,7 @@ backgrounds (last one specified will be used) and modes (more can apply):
`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
(style items are separated by space, lower/uppercase mixed allowed)
(style items are separated by space, lower/uppercase mixed allowed):
* TLDR_TITLE_STYLE (defaults to: Newline Space Bold Yellow)
* TLDR_DESCRIPTION_STYLE (defaults to: Space Yellow)
* TLDR_EXAMPLE_STYLE (defaults to: Newline Space Bold Green)
@ -50,7 +50,7 @@ and `Space` to add a space at the start of the line
The Value style (above) is an Inline style: doesn't take Newline or Space
Inline styles for help text: default, URL, option, platform, command, header
Inline styles for help text: default, URL, option, platform, command, header:
* TLDR_DEFAULT_ISTYLE (defaults to: White)
* TLDR_URL_ISTYLE (defaults to: Yellow)
* TLDR_HEADER_ISTYLE (defaults to: Bold)
@ -59,19 +59,19 @@ Inline styles for help text: default, URL, option, platform, command, header
* TLDR_COMMAND_ISTYLE (defaults to: Bold Cyan)
* TLDR_FILE_ISTYLE (defaults to: Bold Magenta)
Color/BG (Newline and Space also allowed) for error and info messages
Color/BG (Newline and Space also allowed) for error and info messages:
* TLDR_ERROR_COLOR (defaults to: Newline Space Red)
* TLDR_INFO_COLOR (defaults to: Newline Space Green)
How many days before freshly downloading a potentially stale page
How many days before freshly downloading a potentially stale page:
* TLDR_EXPIRY (defaults to 7)
Alternative location of pages cache
Alternative location of pages cache:
* TLDR_CACHE (not set by default)
Usage of 'less' or 'cat' for output (set to '0' for cat)
Usage of 'less' or 'cat' for output (set to '0' for cat):
* TLDR_LESS (*1* by default; if set to *0* `cat` will be used)
Force current OS
Force current OS or not:
* TLDR_OS (overrides what is read by `uname -s`)
Force preferred language: ISO639 format (2 lowercase letters)
Force preferred language: ISO639 format (2 lowercase letters):
* TLDR_LANG (not set by default, $LANG is used from environment)
<img alt="tldr list screenshot" src="tldr-list.jpg" title="tldr list" width="600" />
@ -81,7 +81,7 @@ When the following lines are added to `~/.bashrc` or run in the current session,
then *tldr* will autocomplete, which means possible tldr page names will be
suggested when tapping the **Tab** key twice on an incomplete tldr page name:
```
cachedir=~/.local/share/tldr # Or whatever else the location of the tldr cache is
cachedir=~/.local/share/tldr/pages # Or whatever else the location of the tldr cache is
complete -W "$(q=($cachedir/*/*); sed 's@\.md @ @g' <<<${q[@]##*/})" tldr
```
<img alt="tldr new markdown screenshot" src="tldr-markdown-new.jpg" title="tldr new markdown" width="600" />

40
tldr
View File

@ -1,12 +1,12 @@
#!/usr/bin/env bash
set +vx -o pipefail
[[ $- = *i* ]] && echo "Don't source this script!" && return 1
version='0.48'
# tldr-bash-client version 0.48
version=0.6.2
# tldr-bash-client v0.6.2
# Bash client for tldr: community driven man-by-example
# - forked from Ray Lee, https://github.com/raylee/tldr
# - modified and expanded by pepa65: https://gitlab.com/pepa65/tldr-bash-client
# - binary download: https://4e4.win/tldr
# - binary download: https://good4.eu/tldr
# Requiring: coreutils, grep, unzip, curl/wget, less (optional)
# The 5 elements in TLDR markup that can be styled with these colors and
@ -182,7 +182,7 @@ Init_term(){
}
# $1: page
Recent(){ [[ $(find "$1" -mtime -"$TLDR_EXPIRY") ]];}
Recent(){ [[ $(find "$1" -mtime -"$TLDR_EXPIRY" 2>/dev/null) ]];}
# Initialize globals, check the environment; Uses: config cachedir version
# Sets: stdout os version dl pages
@ -210,12 +210,12 @@ Config(){
ver="tldr-bash-client version $version$XB ${URL}https://gitlab.com/pepa65/tldr-bash-client$XURL"
# Select download method
! dl="$(type -P curl) -sLfo" &&
! dl="$(type -P wget) --max-redirect=20 -qNO" &&
! dl="$(type -P curl) --connect-timeout 10 -sLfo" &&
! dl="$(type -P wget) --timeout=10 --max-redirect=20 -qNO" &&
Err "tldr requires ${I}curl$XI or ${I}wget$XI installed in your path" &&
exit 3
repo_url='https://raw.githubusercontent.com/tldr-pages/tldr/master'
repo_url='https://raw.githubusercontent.com/tldr-pages/tldr/main'
zip_url='https://tldr.sh/assets/tldr.zip'
cachedir=$TLDR_CACHE_LOCATION
@ -296,7 +296,7 @@ Get_tldr(){
# $1: file (optional); Uses: page stdout; Sets: ln REPLY
Display_tldr(){
local newfmt len val
local newfmt len val reply
ln=0 REPLY=
[[ $md ]] || md=$1
# Read full lines, and process even when no newline at the end
@ -326,7 +326,8 @@ Display_tldr(){
Out "$TNL$TSP$T${REPLY:2}$XT" ;;
'>') ((${#REPLY} <= 3)) && Unlinted "No valid desciption"
[[ ! ${REPLY:1:1} = ' ' ]] && Unlinted "2nd character no space"
[[ ! ${REPLY: -1} = '.' ]] && Unlinted "Description doesn't end in full stop"
reply=${REPLY//$'\n'}
[[ ! ${reply: -1} = '.' && ! ${reply: -1} = '。' ]] && Unlinted "Description doesn't end in full stop"
Out "$DNL$DSP$D${REPLY:2}$XD"
DNL= ;;
'-') ((newfmt)) && Unlinted "Bad first character"
@ -355,7 +356,7 @@ Display_tldr(){
Out "$ENL$ESP$E$REPLY$XE" ;;
esac
done <"$1"
[[ $TLDR_LESS = 0 ]] &&
[[ $TLDR_LESS = 0 ]] &&
trap 'cat <<<"$stdout"' EXIT ||
trap 'less -Gg -~RXQFP"%pB\% tldr $I$page$XI - browse up/down, press Q to exit" <<<"$stdout"' EXIT
}
@ -491,11 +492,24 @@ Main(){
Usage 27
[[ $platform = all ]] && platform=
Get_tldr "${page// /-}"
[[ ! -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 28
((markdown)) && Out "$(cat "$cached")" || Display_tldr "$cached"
if [[ -s $cached ]]
then # File present
((markdown)) && Out "$(cat "$cached")" || Display_tldr "$cached"
elif [[ ! $lang = en ]]
then # Not English and no file
pages=pages
Get_tldr "${page// /-}"
[[ -s $cached ]] &&
Err "tldr page for command $I$page$XI not found in '$lang' but found in English" &&
((markdown)) && Out "$(cat "$cached")" ||
Display_tldr "$cached"
else # Just not found
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 28
fi
}
export LC_ALL=en_US.UTF-8
Main "$@"
# The exit trap will output the accumulated stdout
exit 0

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
set +vx
[[ $- = *i* ]] && echo "Don't source this script!" && return 1
version='0.13'
version='0.1.4'
# tldr-lint version 0.13
# Linter for new syntax tldr source files
# Old syntax files $f can be changed into new syntax files by: