diff --git a/Readme.md b/Readme.md index c82d2bb..a2bf452 100644 --- a/Readme.md +++ b/Readme.md @@ -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 diff --git a/hooks b/hooks new file mode 100644 index 0000000..3d703de --- /dev/null +++ b/hooks @@ -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 diff --git a/chpwd b/hooks.d/glow similarity index 56% rename from chpwd rename to hooks.d/glow index bf7edbf..f0d55fd 100644 --- a/chpwd +++ b/hooks.d/glow @@ -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 diff --git a/hooks.d/osc113 b/hooks.d/osc113 new file mode 100644 index 0000000..f1ac4d4 --- /dev/null +++ b/hooks.d/osc113 @@ -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 diff --git a/hooks.d/osc7 b/hooks.d/osc7 new file mode 100644 index 0000000..eb80e24 --- /dev/null +++ b/hooks.d/osc7 @@ -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 diff --git a/hooks.d/termtitle b/hooks.d/termtitle new file mode 100644 index 0000000..abf8e54 --- /dev/null +++ b/hooks.d/termtitle @@ -0,0 +1,6 @@ +## set terminal title +termtitle () { + setTermTitle "($(whoami)@$(hostname) $(pwd))" +} + +## vim: ft=zsh diff --git a/zshrc b/zshrc index 26c8340..323d4b0 100644 --- a/zshrc +++ b/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