tldr.plugin.zsh
540 bytes
1tldr-command-line() {
2 # if there is no command typed, use the last command
3 [[ -z "$BUFFER" ]] && zle up-history
4
5 # if typed command begins with tldr, do nothing
6 [[ "$BUFFER" = tldr\ * ]] && return
7
8 # get command and possible subcommand
9 # http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion-Flags
10 local -a args
11 args=(${${(Az)BUFFER}[1]} ${${(Az)BUFFER}[2]})
12
13 BUFFER="tldr ${args[1]}"
14}
15
16zle -N tldr-command-line
17# Defined shortcut keys: [Esc]tldr
18bindkey "\e"tldr tldr-command-line
19