dfb436b54a10c84156a548dded0506d474050a43
- Author
- danielwerg <35052399+danielwerg@users.noreply.github.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
feat(tldr): add tldr plugin (#12429)
Diff
1diff --git a/plugins/tldr/README.md b/plugins/tldr/README.md
2new file mode 100644
3index 0000000000000000000000000000000000000000..fb91d9d1f04a1f57f901674d9cf3727b08e2ae26
4--- /dev/null
5+++ b/plugins/tldr/README.md
6@@ -0,0 +1,15 @@
7+# tldr plugin
8+
9+This plugin adds a shortcut to insert tldr before the previous command.
10+Heavily inspired from [Man plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/man).
11+
12+To use it, add `tldr` to the plugins array in your zshrc file:
13+
14+```zsh
15+plugins=(... tldr)
16+```
17+
18+# Keyboard Shortcuts
19+| Shortcut | Description |
20+|------------------------------------|----------------------------------------------------------------------------|
21+| <kbd>Esc</kbd> + tldr | add tldr before the previous command to see the tldr page for this command |
22diff --git a/plugins/tldr/tldr.plugin.zsh b/plugins/tldr/tldr.plugin.zsh
23new file mode 100644
24index 0000000000000000000000000000000000000000..9f3de5f0ce246bf21d5bf0da66b4a1894a0b5b6c
25--- /dev/null
26+++ b/plugins/tldr/tldr.plugin.zsh
27@@ -0,0 +1,19 @@
28+tldr-command-line() {
29+ # if there is no command typed, use the last command
30+ [[ -z "$BUFFER" ]] && zle up-history
31+
32+ # if typed command begins with tldr, do nothing
33+ [[ "$BUFFER" = tldr\ * ]] && return
34+
35+ # get command and possible subcommand
36+ # http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion-Flags
37+ local -a args
38+ args=(${${(Az)BUFFER}[1]} ${${(Az)BUFFER}[2]})
39+
40+ BUFFER="tldr ${args[1]}"
41+}
42+
43+zle -N tldr-command-line
44+# Defined shortcut keys: [Esc]tldr
45+bindkey "\e"tldr tldr-command-line
46+