fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
e0916e793
master
1# Completions for the FreeBSD `kldload` kernel module load utility 2function __fish_list_kldload_options 3set -l klds( __fish_complete_suffix --complete=/boot/kernel/( commandline -ct) ".ko" | string replace -r'.*/(.+)\\.ko' '$1' ) 4# Completing available klds is fast, but completing it with a call to __fish_whatis 5# is decidedly not. With 846 modules (FreeBSD 11.1), fish --profile 'complete -C"kldload "' returns the following: 6# 10671 11892698 > complete -C"kldload " 7# A 12 second completion delay is obviously out of the question, so don't provide a description unless there are 8# fewer than 50 results. (Update: now 200 after the switch to __kld_whatis.) 9# Additionally, we can halve the time by not shelling out to `whatis` if we know the man file for the kernel module 10# in question does not exist, since the paths are hardcoded. 11set -l kld_count( count $klds ) 12if test $kld_count -le 200 -a $kld_count -gt 0 13# print name and description 14for kldin $klds 15printf '%s\t%s\n' $kld ( test -f /usr/share/man/man4/$kld .4.gz; 16and __kld_whatis $kld ;or echo "kernel module" )[ 1 ] 17end 18else if test $kld_count -gt 0 19# print name only 20printf '%s\n' $klds 21else 22# print name only (description won't exist since the kernel module isn't installed) 23__fish_complete_suffix .ko 24end 25end 26 27# This is up to 10-50x faster than using __fish_whatis but it could someday break. 28# (zcat is part of the standard FreeBSD distribution.) 29# Without this, we can't reasonably show descriptions for most completions within our time budget. 30function __kld_whatis 31set -l kld$argv [ 1 ] 32set -l path /usr/share/man/man4/$kld .4.gz 33zcat $path | string replace -rf'\.Nd "?([^"]+).*' '$1' 34end 35 36# Only attempt to match a local file if there isn't a match in /boot/kernel, 37# as odds are that is the desired source. 38complete -c kldload -xa'(__fish_list_kldload_options)'