mirror of
				https://github.com/ItsDrike/dotfiles.git
				synced 2025-11-04 09:16:36 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			24 lines
		
	
	
	
		
			751 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
	
		
			751 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
#!/usr/bin/env bash
 | 
						|
 | 
						|
# Command not found hook that uses `pkgfile` package
 | 
						|
# to search through the package database in order to
 | 
						|
# find a package which includes given command, which
 | 
						|
# was resolved as not found, if there are no such packages
 | 
						|
# only print command not found message
 | 
						|
command_not_found_handler() {
 | 
						|
	local pkgs cmd="$1" files=()
 | 
						|
	printf 'zsh: command not found: %s' "$cmd" # print command not found asap, then search for packages
 | 
						|
	files=(${(f)"$(pkgfile ${cmd})"})
 | 
						|
	if (( ${#files[@]} )); then
 | 
						|
		printf '\r%s may be found in the following packages:\n' "$cmd"
 | 
						|
		local res=() repo package version file
 | 
						|
		for file in "$files[@]"; do
 | 
						|
			res=("${(0)file}")
 | 
						|
			repo="$res[1]"
 | 
						|
			printf '  %s\n' "$repo"
 | 
						|
		done
 | 
						|
	else
 | 
						|
		printf '\n'
 | 
						|
	fi
 | 
						|
	return 127
 | 
						|
}
 |