summaryrefslogtreecommitdiffstats
path: root/bash-completion
blob: 2a53c1a2408d3f225432d9d508bf92a16738fcfd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# mkinitcpio bash completion by Seblu <seblu@seblu.net>

_lsinitcpio ()
{
	local action cur
	action="-a -h -v -x"
	_get_comp_words_by_ref cur
	case "$cur" in
		-*)	COMPREPLY=($(compgen -W "${action}" -- "$cur"));;
		*) _filedir;;
	esac
}

_find_kernel_versions() {
	local -a matches
	local regex

	regex="Linux kernel.*version"
	while IFS=':' read -r file metadata; do
		[[ $metadata =~ $regex ]] || continue
		matches+=("$file")
	done < <(file -e ascii /boot/*)

	COMPREPLY=($(cd /lib/modules && compgen -d -- $cur)
		$(compgen -W "${matches[*]}" -- $cur))
}

_mkinitcpio ()
{
	local action cur prev
	action="-c -k -s -b -g -p -S -v -M -L -H -h"
	_get_comp_words_by_ref cur prev
	case "$prev" in
		-c|-g) _filedir;;
		-k) _find_kernel_versions;;
		-b) COMPREPLY=($(compgen -d "$cur" -- $cur));;
		-p) COMPREPLY=($(cd /etc/mkinitcpio.d/ && compgen -X '!*.preset' -f  -- $cur|sed 's/\.preset//'));;
		-H|-S) COMPREPLY=($(cd /lib/initcpio/install/ && compgen -f -- $cur));;
		*)	COMPREPLY=($(compgen -W "${action}" -- "$cur"));;
	esac
}
complete -F _mkinitcpio mkinitcpio
complete -F _lsinitcpio lsinitcpio

# vim: set ts=2 sw=2 ft=sh noet: