forked from zsh-users/zsh-completions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_genlop
150 lines (144 loc) · 6.77 KB
/
_genlop
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#compdef genlop
# ------------------------------------------------------------------------------
# Copyright (c) 2011 Github zsh-users - http://github.com/zsh-users
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the zsh-users nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ------------------------------------------------------------------------------
# Description
# -----------
#
# Completion script for GenLop (Gentoo Installation log parser).
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
# * Vadim A. Misbakh-Soloviev <[email protected]>
# * Bapt <[email protected]>
# * kaworu <[email protected]>
# * David Durrleman <[email protected]>
# * oberyno <[email protected]>
# * Mamoru Komachi <[email protected]>
#
# ------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------
#<app-portage/genlop-0.30.8>
_genlop () {
local prev1="$words[CURRENT-1]" prev2="$words[CURRENT-2]" days months arg single state lstate
days=(monday tuesday wednesday thursday friday saturday sunday)
months=(january february march april may june july august september october november december)
arg=( --current -c --time -t --gmt -g --info -i --file -f --rsync -r --unmerge -u --date --search -s --list -l )
single=( --current -c --pretend -p --help -h --version -v )
[[ ${prev2} == (1st|2nd|3rd|4th|5th) ]] &&
compadd in\ $months && return 0
[[ ${prev1} == ([2-9]|[1-9][0-9]*) && ${prev2} != \
(january|february|march|april|may|june|july|august|september|october|november|december) ]] &&
_values '' 'days ago' 'months ago' 'years ago' 'weeks ago' && return 0
[[ ${prev1} == (1) && ${prev2} != \
(january|february|march|april|may|june|july|august|september|october|november|december) ]] &&
_values '' 'day ago' 'month ago' 'year ago' 'week ago' && return 0
case "$prev1" in
last)
_values '' month week
compadd $days && return 0
;;
1st|2nd|3rd|4th|5th)
compadd $days && return 0
;;
january|february|march|april|may|june|july|august|september|october|november|december)
compadd {1..31} && return 0
;;
--date)
_message 'enter number for more options or use mm/dd/yyyy format'
_values '' \
last yesterday 1st 2nd 3rd 4th 5th
_alternative \
'*:*:_genlop_days' '*:*:_genlop_months' && return 0
;;
--file|-f)
_arguments '*:logfile:_files' && return 0
;;
*)
_arguments \
"($single $arg *)"{--current,-c}"[display the current merge in action]" \
"($single)*--date[specify date of event]:date:->date" \
"($single)*-f[specify the logfile to use]:logfile:_files" \
"($single --gmt -g)"{--gmt,-g}"[display time in GMT/UTC format (default is local time)]" \
"($single $arg *)"{--help,-h}"[display help information]" \
"($single --info -i --list -l)"{--info,-i}"[print brief summary about installed ebuild]" \
"($single --search -s --info -i --list -l *)"{--list,-l}"[list merge history]" \
"(--nocolor -n)"{--nocolor,-n}"[disable colored output]" \
"($single $arg *)"{--pretend,-p}"[estimate build time of a piped emerge -p]" \
"($single --search -s --info -i --time -t --unmerge -u --rsync -r *)"{--rsync,-r}"[display rsync history]" \
"($single --rsync -r --search -s --list -l *)"{--search,-s}"[select ebuilds matching the provided regular expression]:pattern:" \
"($single --time -t)"{--time,-t}"[display merge time]" \
"($single --rsync -r --unmerge -u)"{--unmerge,-u}"[display when packages have been unmerged]" \
"($single $arg *)"{--version,-v}"[display version information]" \
"($single)*:package:_gentoo_packages available"
;;
esac
while [[ -n "$state" ]]; do
lstate=$state
state=''
case "$lstate" in
date) _message 'enter number for more options or use mm/dd/yyyy format'
_values '' \
last yesterday 1st 2nd 3rd 4th 5th
_alternative \
':*:_genlop_days' ':*:_genlop_months' && return 0
;;
esac
done
}
_genlop_days() {
local m="monday" t="tuesday" w="wednesday" T="thursday" f="friday" s="saturday" S="sunday"
local day=$(date +%u)
if [[ ${day} == 1 ]] then compadd $m
elif [[ ${day} == 2 ]] then compadd $m $t
elif [[ ${day} == 3 ]] then compadd $m $t $w
elif [[ ${day} == 4 ]] then compadd $m $t $w $T
elif [[ ${day} == 5 ]] then compadd $m $t $w $T $f
elif [[ ${day} == 6 ]] then compadd $m $t $w $T $f $s
elif [[ ${day} == 7 ]] then compadd $m $t $w $T $f $s $S
fi
}
_genlop_months() {
local j="january" f="february" m="march" a="april" M="may" ju="june" J="july" A="august" s="september" o="october" n="november" d="december"
local month=$(date +%m)
if [[ ${month} == 01 ]] then compadd $j
elif [[ ${month} == 02 ]] then compadd $j $f
elif [[ ${month} == 03 ]] then compadd $j $f $m
elif [[ ${month} == 04 ]] then compadd $j $f $m $a
elif [[ ${month} == 05 ]] then compadd $j $f $m $a $M
elif [[ ${month} == 06 ]] then compadd $j $f $m $a $M $ju
elif [[ ${month} == 07 ]] then compadd $j $f $m $a $M $ju $J
elif [[ ${month} == 08 ]] then compadd $j $f $m $a $M $ju $J $A
elif [[ ${month} == 09 ]] then compadd $j $f $m $a $M $ju $J $A $s
elif [[ ${month} == 10 ]] then compadd $j $f $m $a $M $ju $J $A $s $o
elif [[ ${month} == 11 ]] then compadd $j $f $m $a $M $ju $J $A $s $o $n
elif [[ ${month} == 12 ]] then compadd $j $f $m $a $M $ju $J $A $s $o $n $d
fi
}