Compare commits

...

6 Commits

Author SHA1 Message Date
9da7b6babf
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)
2023-04-11 22:45:38 +01:00
43e3ce2765
refactor(prompt): Add hook in the conventional way
Change how I add the `vcs_info` function call to the `precmd` hook.
Using add-zsh-hook allows me to have multiple hook functions on `precmd`
and makes it clear what is done for each hook when listing them
2023-04-11 22:42:43 +01:00
c2f60ba7fd
feat(zshrc): Enable more options and Document
- Extended Globbing
- Chase Dots
- Mark Dirs
- rm Star Wait
- Interactive comments

These options have been enabled as I belive that I will find them
useful. For more information on functionality please see appropriate
documentation.
2023-04-11 00:00:02 +01:00
ef86f64945
fix(zshrc): Allow loading local site-functions
Some programs install completion to `~/.local/zsh/site-functions`
adding this path to `fpath` allows them to be loaded by `compinit`
2023-04-01 22:03:34 +01:00
7ad661267e
fix(zshrc): check for homebrew first
make zsh check if the homebrew directory is present before attempting to
load it.
2023-04-01 21:57:33 +01:00
a79e9e988f
fix(history): Change set to setopt
Kinda borked the history settings by using set instead of setopt
mia culpa
Fixed now
2023-04-01 21:54:05 +01:00
9 changed files with 90 additions and 25 deletions

View File

@ -63,6 +63,12 @@ and how it works.
- Automatic use of the directory stack `popd` to go back whence you came
- Smart history
- Plug-ins chosen for greatness
- Extended Globbing enabled.
- 10 second thinking time enforced for big deletes
- Expanded directories automatically have `/` appended
- Allow comments in interactive mode (this may be useful to mark history
items)
- Neaten paths like `../foo/..` to `..` (ChaseDots)
## Breakdown
The following sections break down what is in the repository and what
@ -102,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.
@ -139,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

21
history
View File

@ -1,19 +1,25 @@
## History Configuration
[ ! -d $XDG_STATE_HOME/zsh ] && mkdir -p $XDG_STATE_HOME/zsh
## Options relating to saving history
export HISTSIZE=10000
export SAVEHIST=6000
export HISTFILE=$XDG_STATE_HOME/zsh/history
set hist_ignore_dups ## Don't log the same thing twice
set hist_ignore_space ## Don't log things that start with space
set hist_reduce_blanks ## Compact unnecessary white-space
set hist_expire_dups_first ## Remove duplicates first (if any exist) when compacting history
set hist_save_no_dups ## Remove duplicates from history when writing
setopt extended_history ## Save timestamp in history
setopt inc_append_history_time ## incrementally append to history
## This option means that the history is updated by all shell sessions
## However it doesn't load them in like share_history does
setopt hist_ignore_dups ## Don't log the same thing twice
setopt hist_ignore_space ## Don't log things that start with space
setopt hist_reduce_blanks ## Compact unnecessary white-space
setopt hist_expire_dups_first ## Remove duplicates first (if any exist) when compacting history
setopt hist_save_no_dups ## Remove duplicates from history when writing
## Options relating to history use
set hist_find_no_dups ## Don't show duplicates when searching history
set hist_verify ## Dont' immediately execute expanded history `eg: sudo !!`
setopt hist_find_no_dups ## Don't show duplicates when searching history
setopt hist_verify ## Dont' immediately execute expanded history `eg: sudo !!`
## This stops certain commands saving into the history file
export HISTORY_IGNORE='(cd(| *)|ls(| *)|pushd(| *)|popd(| *))'
@ -24,3 +30,4 @@ zshaddhistory() {
emulate -L zsh
[[ ${1%%$'\n'} != ${~HISTORY_IGNORE} ]]
}
# vim: ft=zsh

11
hooks Normal file
View 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

View File

@ -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
View 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
View 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
View File

@ -0,0 +1,6 @@
## set terminal title
termtitle () {
setTermTitle "($(whoami)@$(hostname) $(pwd))"
}
## vim: ft=zsh

8
prompt
View File

@ -22,12 +22,12 @@ zstyle ':vcs_info:git*' check-for-changes true
zstyle ':vcs_info:git*' formats "-(%{%F{203}%} %{%f%}%s:%{%F{2}%}שׂ %{%f%}%b %u%c)"
zstyle ':vcs_info:git*' actionformats "-(%{%F{203}%} %{%f%}%s:%{%F{2}%}שׂ %{%f%}%b %u%c)(%a)"
## set precmd to get vcs_info
## precmd runs before every prompt
precmd() {
## do precmd stuff
_vcsinfo() {
vcs_info
setTermTitle "($(whoami)@$(hostname) $(pwd))"
}
add-zsh-hook precmd _vcsinfo
PROMPT="╭╼(%{%F{81}%}%n%{%F{245}%}@%{%F{206}%}%m %{%F{245}%}%2~%{%F{259}%})─(%(?.😎.😞 %?))"$'\n'"╰┤"
export RPROMPT='${vcs_info_msg_0_}'

25
zshrc
View File

@ -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
@ -24,21 +25,31 @@ autoload setTermTitle
autoload tempPersist
autoload has
## check for and load .local/share/zsh/site-functions
[ -d "$HOME/.local/share/zsh/site-functions" ] && fpath=("$HOME/.local/share/zsh/site-functions" $fpath)
## Source Other files
source ${ZDOTDIR}/aliases
source ${ZDOTDIR}/dir_aliases
source ${ZDOTDIR}/prompt
source ${ZDOTDIR}/keyboard
source ${ZDOTDIR}/history
source ${ZDOTDIR}/chpwd
source ${ZDOTDIR}/hooks
## Set option
#setopt emacs ## Emacs style keybinds
setopt vi
setopt autocd ## Change to directory if given as command
setopt autopushd ## Automatically use pushd and stack
## Set options
## NOTE: zsh ignores case and underscores
setopt vi ## Use vi style keybinds
setopt autoCd ## Change to directory if given as command
setopt autoPushd ## Automatically use pushd and stack
setopt chaseDots ## Remove contradictory .. from cd path (e.g cd foo/bar/.. -> cd foo)
setopt correct ## Pick up on Spelling errors
setopt extendedGlob ## Allow extended globbing (see man zshexpn)
setopt markDirs ## Add a trailing '/' to directories when globbing
setopt interactiveComments ## allow comments in interactive shells
setopt rmStarWait ## wait 10 seconds when confirming large deletes
source ${ZDOTDIR}/completion
@ -57,7 +68,9 @@ fi
## Load external stuff
##Configure for homebrew
if [[ -d "/home/linuxbrew" ]]; then
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi
## Configure Plugins
export ZSH_AUTOSUGGEST_STRATEGY=(completion history) # suggest from completion then history