zsh: Add _page_readme_chpwd_handler()

Open READMEs in a pager when going into a directory that contains one.
This commit is contained in:
2022-02-07 04:22:32 +01:00
parent 17433d0528
commit a14478f758
3 changed files with 21 additions and 0 deletions

View File

@@ -2,6 +2,8 @@ autoload -U select-word-style && select-word-style bash
autoload edit-command-line; zle -N edit-command-line
autoload -U add-zsh-hook
(( ! $+aliases[run-help] )) || unalias run-help
autoload -Uz run-help run-help-git zmv

View File

@@ -490,3 +490,18 @@ create_venv() {
direnv allow
fi
}
# Open READMEs in a pager when going into a directory that contains one.
# See 45-hooks.zsh
_page_readme_chpwd_handler() {
local readme
local -a readmes=(README.md README.txt README Readme.md Readme.txt Readme
readme.md readme.txt readme)
for readme in "$readmes[@]"; do
[[ -e "$readme" ]] || continue
${PAGER:-less} "$readme"
break
done
}

View File

@@ -0,0 +1,4 @@
# vim: ft=zsh
(( ! $+function[_page_readme_chpwd_handler] )) \
|| add-zsh-hook chpwd _page_readme_chpwd_handler