aboutsummaryrefslogtreecommitdiffhomepage
path: root/share/functions/__fish_complete_suffix.fish
blob: 035911a7692eef349ab9ed16f64e5dcec722b231 (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
46
47
48
49
50
51
52
#
# Find files that complete $argv[1], has the suffix $argv[2], and
# output them as completions with the description $argv[3] Both
# $argv[1] and $argv[3] are optional, if only one is specified, it is
# assumed to be the argument to complete.
#

function __fish_complete_suffix -d "Complete using files"

	# Variable declarations

	set -l comp 
	set -l suff 
	set -l desc 
	set -l files

	switch (count $argv)

		case 1
		set comp (commandline -ct)
		set suff $argv
		set desc (mimedb -d $suff)

		case 2
		set comp $argv[1]
		set suff $argv[2]
		set desc (mimedb -d $suff)

		case 2
		set comp $argv[1]
		set suff $argv[2]
		set desc $argv[2]

	end

	# Perform the completion

	set base (echo $comp |sed -e 's/\.[a-zA-Z0-9]*$//')
	eval "set files $base*$suff"

	if test $files[1]
		printf "%s\t$desc\n" $files
	end

	#
	# Also do directory completion, since there might be files
	# with the correct suffix in a subdirectory
	#

	__fish_complete_directories $comp

end