refactor: Change the way that all hooks work
Move hooks to a dedicated module. This allows for greater flexibility and easier editing. TODO: Make hook handling neater (possibly through parsing the hook script to read an "hook-to" marker that allows for automated loading of properly formatted hook functions)
This commit is contained in:
parent
43e3ce2765
commit
9da7b6babf
|
|
@ -108,11 +108,6 @@ program.
|
|||
in that order of preference.
|
||||
`pdf` files are mapped to `zathura` when it's installed.
|
||||
|
||||
#### `./chpwd`
|
||||
This module sets the `chpwd` hook and makes ZSH display any (markdown
|
||||
formatted) readme files
|
||||
found in the current directory using glow.
|
||||
|
||||
#### `./completion`
|
||||
This file configures the powerful completion engine of
|
||||
ZSH.
|
||||
|
|
@ -145,6 +140,10 @@ This makes a few changes:
|
|||
- Ignores duplicates when searching history
|
||||
- Requires you press enter after expanding `!!`
|
||||
|
||||
#### './hooks'
|
||||
This file loads hook functions found in './hooks.d'
|
||||
and makes it easier to assign hooks where necessary.
|
||||
|
||||
#### `./keyboard`
|
||||
This file uses `zkbd`(see `man zshcontrib`) to get information about your
|
||||
keyboard and how your terminal handles it. This can fix issues with keys
|
||||
|
|
|
|||
11
hooks
Normal file
11
hooks
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#This file manages hooks so I can have multiple functions hooked the way I want
|
||||
for file in $(find $ZDOTDIR/hooks.d -type f); do
|
||||
source "$file"
|
||||
done
|
||||
|
||||
add-zsh-hook -Uz chpwd glow
|
||||
add-zsh-hook -Uz chpwd osc7
|
||||
add-zsh-hook -Uz precmd termtitle
|
||||
add-zsh-hook -Uz precmd osc113
|
||||
|
||||
# vim: ft=zsh
|
||||
|
|
@ -1,4 +1,7 @@
|
|||
chpwd() {
|
||||
## Load readme with glow (if available)
|
||||
glow() {
|
||||
has glow || return 0
|
||||
find $PWD -maxdepth 1 -iname 'readme.md' -exec glow {} \;
|
||||
}
|
||||
|
||||
## vim: ft=zsh
|
||||
7
hooks.d/osc113
Normal file
7
hooks.d/osc113
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
## output OSC-113;A to tell foot how to jump between prompts
|
||||
|
||||
osc113() {
|
||||
print -Pn "\e]133;A\e\\"
|
||||
}
|
||||
|
||||
## vim: ft=zsh
|
||||
13
hooks.d/osc7
Normal file
13
hooks.d/osc7
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
## output the current directory in the correct format for foot.
|
||||
|
||||
function osc7 {
|
||||
local LC_ALL=C
|
||||
export LC_ALL
|
||||
|
||||
setopt localoptions extendedglob
|
||||
input=( ${(s::)PWD} )
|
||||
uri=${(j::)input/(#b)([^A-Za-z0-9_.\!~*\'\(\)-\/])/%${(l:2::0:)$(([##16]#match))}}
|
||||
print -n "\e]7;file://${HOSTNAME}${uri}\e\\"
|
||||
}
|
||||
|
||||
# vim: ft=zsh
|
||||
6
hooks.d/termtitle
Normal file
6
hooks.d/termtitle
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
## set terminal title
|
||||
termtitle () {
|
||||
setTermTitle "($(whoami)@$(hostname) $(pwd))"
|
||||
}
|
||||
|
||||
## vim: ft=zsh
|
||||
3
zshrc
3
zshrc
|
|
@ -13,6 +13,7 @@ autoload -U calendar
|
|||
autoload -U run-help
|
||||
autoload -U +X compinit
|
||||
autoload -U edit-command-line
|
||||
autoload -U add-zsh-hook
|
||||
|
||||
## zmodload Modules
|
||||
zmodload zsh/complist
|
||||
|
|
@ -33,7 +34,7 @@ source ${ZDOTDIR}/dir_aliases
|
|||
source ${ZDOTDIR}/prompt
|
||||
source ${ZDOTDIR}/keyboard
|
||||
source ${ZDOTDIR}/history
|
||||
source ${ZDOTDIR}/chpwd
|
||||
source ${ZDOTDIR}/hooks
|
||||
|
||||
|
||||
## Set options
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user