m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-17 07:43:39 -05:00

add fzf-widget formanpages (zsh only)

lime-desu
2022-11-08 10:33:00 +00:00
parent d5ffb7e836
commit 1a919a1c10

@@ -2061,6 +2061,38 @@ fman() {
# Get the colors in the opened man page itself
export MANPAGER="sh -c 'col -bx | bat -l man -p --paging always'"
```
### fzf-man-pages widget (for zsh)
Same functionality as above but better
- with colored and syntax higlighting
- doesn't exit fzf when pressed enter
- `--tiebreak=begin` for improved search experience (prefers the line with matched substring closer to the beginning)
- additional keybinds for changing preview (optional)
<kbd>Alt-C</kbd> for [cheat sheet](https://github.com/chubin/cheat.sh)
<kbd>Alt-T</kbd> for [tldr](https://github.com/tldr-pages/tldr) (I've used [tealdeer](https://github.com/dbrgn/tealdeer) to customize the colors)
- `Ctrl-H` keybinding to launch the widget (works only on zsh, don't know how to do it on bash and fish (additionaly pressing`ctrl-backspace` will trigger the widget to launch too because both share the same keycode)
![](https://user-images.githubusercontent.com/114978689/200536151-49caf164-7011-44be-943b-b9fd57a3ca78.png)
```sh
fzf-man-widget() {
batman="man {1} | col -bx | bat -l man -p --color always --theme=\"Monokai Extended\""
man -k . | awk -v cyan=$(tput setaf 6) -v blue=$(tput setaf 4) '{$1=cyan $1; $2= blue;} 1' | \
fzf +i +x \
-q "$1" \
--ansi \
--tiebreak=begin \
--prompt=' Man > ' \
--preview-window='up,85%,border-bottom' \
--preview "${batman}" \
--bind "enter:execute(man {1})" \
--bind "alt-c:+change-preview(cht.sh {1})+change-prompt(ﯽ Cheat > )" \
--bind "alt-m:+change-preview(${batman})+change-prompt( Man > )" \
--bind "alt-t:+change-preview(tldr --color=always {1})+change-prompt(ﳁ TLDR > )"
zle reset-prompt
}
bindkey '^h' fzf-man-widget
zle -N fzf-man-widget
```
### Python Behave BDD