feat: if not found cmd in other language, tried to locate in English & add timeout limit for downloading.
This commit is contained in:
parent
2156390101
commit
46e07b0216
22
tldr
22
tldr
|
@ -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,8 +210,8 @@ 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
|
||||
|
||||
|
@ -492,9 +492,19 @@ 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
|
||||
((markdown)) && Out "$(cat "$cached")" || Display_tldr "$cached"
|
||||
|
||||
elif [[ $lang != en ]] ; then
|
||||
pages=pages
|
||||
Get_tldr "${page// /-}"
|
||||
if [[ -s $cached ]] ; then
|
||||
Err "tldr page for command $I$page$XI not found in preferred language $lang, but found in language en." && ((markdown)) && Out "$(cat "$cached")" || Display_tldr "$cached"
|
||||
fi
|
||||
else
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue