Activate zsh rehash with pacman hook
This commit is contained in:
parent
0250876649
commit
da9abb7282
4 changed files with 49 additions and 7 deletions
|
@ -21,6 +21,34 @@ _fzf_compgen_path() {
|
|||
_skim_compgen_path
|
||||
}
|
||||
|
||||
# Command not found handler
|
||||
# source https://wiki.archlinux.org/title/Zsh#pacman_-F_%22command_not_found%22_handler
|
||||
function command_not_found_handler {
|
||||
local purple='\e[1;35m' bright='\e[0;1m' green='\e[1;32m' reset='\e[0m'
|
||||
printf 'zsh: command not found: %s\n' "$1"
|
||||
local entries=(
|
||||
${(f)"$(/usr/bin/pacman -F --machinereadable -- "/usr/bin/$1")"}
|
||||
)
|
||||
if (( ${#entries[@]} ))
|
||||
then
|
||||
printf "${bright}$1${reset} may be found in the following packages:\n"
|
||||
local pkg
|
||||
for entry in "${entries[@]}"
|
||||
do
|
||||
# (repo package version file)
|
||||
local fields=(
|
||||
${(0)entry}
|
||||
)
|
||||
if [[ "$pkg" != "${fields[2]}" ]]
|
||||
then
|
||||
printf "${purple}%s/${bright}%s ${green}%s${reset}\n" "${fields[1]}" "${fields[2]}" "${fields[3]}"
|
||||
fi
|
||||
printf ' /%s\n' "${fields[4]}"
|
||||
pkg="${fields[2]}"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# search and install packages with skim
|
||||
pi() {
|
||||
SELECTED_PKGS="$(paru -Slq | sk --header='Install packages' -m --preview 'paru -Si {1}')"
|
||||
|
|
|
@ -1,6 +1,17 @@
|
|||
# from https://wiki.archlinux.org/index.php/Zsh#On-demand_rehash
|
||||
catch_signal_usr1() {
|
||||
trap catch_signal_usr1 USR1
|
||||
rehash
|
||||
|
||||
zshcache_time="$(date +%s%N)"
|
||||
|
||||
autoload -Uz add-zsh-hook
|
||||
|
||||
rehash_precmd() {
|
||||
if [[ -a /var/cache/zsh/pacman ]]; then
|
||||
local paccache_time="$(date -r /var/cache/zsh/pacman +%s%N)"
|
||||
if (( zshcache_time < paccache_time )); then
|
||||
rehash
|
||||
zshcache_time="$paccache_time"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
trap catch_signal_usr1 USR1
|
||||
|
||||
add-zsh-hook -Uz precmd rehash_precmd
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue