summaryrefslogtreecommitdiff
path: root/etc/completions/_hashl
blob: 49565ac17abf51e8bc0b1433f26da1f4871a59ce (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#compdef hashl

typeset -a arguments
typeset -A argument_pairs argument_postfix
typeset arg expl
typeset -i NORMARG

function _hashl_directory {
	_files -/
}

function _hashl_db_file {
	typeset index=${words[(I)(-d|--database)]}
	typeset dbfile=${words[$((index+1))]}
	typeset IFS=$'\n'
	if [[ ${index} != 0 && -r ${dbfile} ]] {
		_wanted file expl 'file' \
		compadd $(hashl -d ${dbfile} list-files)
	} else {
		_wanted file expl 'file' \
		compadd $(hashl list-files)
	}
}

function _hashl_action {
	_wanted action expl 'action' \
	compadd copy find-known find-new ignore info list list-ignored update
}

function _hashl_action_args {
	case ${words[$NORMARG]} in
		copy|find-known|find-new|ignore)
			_hashl_directory
		;;
		info)
			_hashl_db_file
		;;
		*)
			_message 'no more arguments'
		;;
	esac
}

argument_pairs=(
	database      d
	no-progress   n
	read-size     s+
)

argument_postfix=(
	database      '[hashl db]:file:_files'
	no-progress   '[Do not show progress]'
	read-size     '[Change hashed file part]:bytes'
)

for arg in ${(k)argument_pairs}; {
	arguments+='(--'${arg}')-'${argument_pairs[$arg]}${argument_postfix[$arg]}
	arguments+='(-'${argument_pairs[$arg]}[1]')--'${arg}${argument_postfix[$arg]}
}

arguments+=(
	\*{-e,--extra-db}'[additional hashl db]:file:_files'
	':action:_hashl_action'
	'*:arguments:_hashl_action_args'
)

_arguments -n ${arguments}