zsh: Add _page_readme_chpwd_handler()
Open READMEs in a pager when going into a directory that contains one.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
4
.config/zsh/zshrc.d/45-hooks.zsh
Normal file
4
.config/zsh/zshrc.d/45-hooks.zsh
Normal file
@@ -0,0 +1,4 @@
|
||||
# vim: ft=zsh
|
||||
|
||||
(( ! $+function[_page_readme_chpwd_handler] )) \
|
||||
|| add-zsh-hook chpwd _page_readme_chpwd_handler
|
||||
Reference in New Issue
Block a user