Add autocomplete option to readme
This commit is contained in:
parent
88d5b7df35
commit
e138c5dd0a
11
README.md
11
README.md
|
@ -30,7 +30,7 @@ coreutils, grep, unzip, curl / wget, less (optional)
|
||||||
|
|
||||||
<img alt="tldr find screenshot" src="tldr-find.jpg" title="tldr find" width="600" />
|
<img alt="tldr find screenshot" src="tldr-find.jpg" title="tldr find" width="600" />
|
||||||
|
|
||||||
## Customisation
|
## Output customisation
|
||||||
<img alt="tldr customize screenshot" src="tldr-customize.jpg" title="tldr customize" width="600" />
|
<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
|
||||||
|
@ -74,6 +74,15 @@ Instead of `less`, use `cat` for output (automatic if less not available)
|
||||||
|
|
||||||
<img alt="tldr list screenshot" src="tldr-list.jpg" title="tldr list" width="600" />
|
<img alt="tldr list screenshot" src="tldr-list.jpg" title="tldr list" width="600" />
|
||||||
|
|
||||||
|
## Autocompletion
|
||||||
|
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
|
||||||
|
complete -W "$(q=($cachedir/*/*); sed 's@\.md @ @g' <<<${q[@]##*/})" tldr
|
||||||
|
```
|
||||||
|
|
||||||
# tldr-lint
|
# tldr-lint
|
||||||
|
|
||||||
* version 0.11
|
* version 0.11
|
||||||
|
|
16
tldr
16
tldr
|
@ -209,11 +209,12 @@ Config(){
|
||||||
pages_url='https://raw.githubusercontent.com/tldr-pages/tldr/master/pages'
|
pages_url='https://raw.githubusercontent.com/tldr-pages/tldr/master/pages'
|
||||||
zip_url='http://tldr.sh/assets/tldr.zip'
|
zip_url='http://tldr.sh/assets/tldr.zip'
|
||||||
|
|
||||||
read cachedir <<<$TLDR_CACHE
|
cachedir=$(echo $TLDR_CACHE)
|
||||||
[[ $cachedir ]] || {
|
if [[ -z $cachedir ]]
|
||||||
[[ $XDG_DATA_HOME ]] && cachedir=$XDG_DATA_HOME/tldr \
|
then
|
||||||
|| cachedir=$HOME/.local/share/tldr
|
[[ $XDG_DATA_HOME ]] && cachedir=$XDG_DATA_HOME/tldr ||
|
||||||
}
|
cachedir=$HOME/.local/share/tldr
|
||||||
|
fi
|
||||||
[[ -d "$cachedir" ]] || mkdir -p "$cachedir" || {
|
[[ -d "$cachedir" ]] || mkdir -p "$cachedir" || {
|
||||||
Err "Can't create the pages cache location $cachedir"
|
Err "Can't create the pages cache location $cachedir"
|
||||||
exit 4
|
exit 4
|
||||||
|
@ -221,6 +222,9 @@ Config(){
|
||||||
index=$cachedir/index.json
|
index=$cachedir/index.json
|
||||||
# update if the file doesn't exists, or if it's older than $TLDR_EXPIRY
|
# update if the file doesn't exists, or if it's older than $TLDR_EXPIRY
|
||||||
[[ -f $index ]] && Recent "$index" || Cache_fill 0
|
[[ -f $index ]] && Recent "$index" || Cache_fill 0
|
||||||
|
|
||||||
|
# initiate autocomplete for current session
|
||||||
|
complete -W "$(q=($cachedir/*/*); sed 's@\.md @ @g' <<<${q[@]##*/})" tldr
|
||||||
}
|
}
|
||||||
|
|
||||||
# $1: error message; Uses: md REPLY ln
|
# $1: error message; Uses: md REPLY ln
|
||||||
|
@ -345,7 +349,7 @@ List_pages(){
|
||||||
exit "$1"
|
exit "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
# $1: regex, $1: exit code; Uses: cachedir
|
# $1: regex, $2: exit code; Uses: cachedir
|
||||||
Find_regex(){
|
Find_regex(){
|
||||||
local list=$(grep "$1" "$cachedir"/*/*.md |cut -d: -f1) regex="$U$1$XU"
|
local list=$(grep "$1" "$cachedir"/*/*.md |cut -d: -f1) regex="$U$1$XU"
|
||||||
local n=$(wc -l <<<"$list")
|
local n=$(wc -l <<<"$list")
|
||||||
|
|
Loading…
Reference in New Issue