fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Johannes AltmanningerMerge branch 'completions-to-use-expanded-tokens'a9618477e

master
9.1 KiB253 linesraw
1function __schtasks_print_tasks -d 'Helper function to print tasks'
2    schtasks /query /fo csv /nh | awk -F ',' '{ print $1 }'
3end
4
5function __schtasks_change_complete_args -a previous_token
6    if test "$previous_token" = /tn
7        __schtasks_print_tasks
8        return
9    end
10
11    if string match -r -q -- "$previous_token" '^/r?u$'
12        __fish_print_windows_users
13        return
14    end
15
16    if __fish_seen_argument -w s
17        echo -e '/u\tRun this command with the permissions of the specified user account'
18    end
19
20    if __fish_seen_argument -w u
21        echo -e '/p\tSpecify the password of the user account specified in the /u parameter'
22    end
23
24    if not __fish_seen_argument -w et -w du
25        echo -e '/et\tSpecify the end time for the task
26/du\tA value that specifies the duration'
27    end
28
29    if not __fish_seen_argument -w ENABLE -w DISABLE
30        echo -e '/ENABLE\tSpecify to enable the scheduled task
31/DISABLE\tSpecify to disable the scheduled task'
32    end
33
34    echo -e '/tn\tIdentify the task to be changed
35/s\tSpecify the name or IP address of a remote computer
36/ru\tChange the user name under which the scheduled task has to run
37/rp\tSpecify a new password for the existing user account, or the user account specified by /ru
38/tr\tChange the program that the task runs
39/st\tSpecify the start time for the task
40/ri\tSpecify the repetition interval for the scheduled task
41/k\tStop the program that the task runs at the time specified by /et or /du
42/sd\tSpecify the first date on which the task should be run
43/ed\tSpecify the last date on which the task should be run
44/it\tSpecify to run the scheduled task only when the run as user is logged on to the computer
45/z\tSpecify to delete the task upon the completion of its schedule
46/?\tShow help'
47end
48
49function __schtasks_create_complete_args -a previous_token
50    if test "$previous_token" = /sc
51        echo -e 'MINUTE\tSpecify the number of minutes before the task should run
52HOURLY\tSpecify the number of hours before the task should run
53DAILY\tSpecify the number of days before the task should run
54WEEKLY\tSpecify the number of weeks before the task should run
55MONTHLY\tSpecify the number of months before the task should run
56ONCE\tSpecify that that task runs once at a specified date and time
57ONSTART\tSpecify that the task runs every time the system starts
58ONLOGON\tSpecify that the task runs whenever a user logs on
59ONIDLE\tSpecify that the task runs whenever the system is idle for a specified period of time'
60        return
61    end
62
63    if string match -r -q -- "$previous_token" '^/r?u$'
64        __fish_print_windows_users
65        return
66    end
67
68    if test "$previous_token" = /mo
69        echo -e 'MINUTE\tSpecify that the task runs every n minutes
70HOURLY\tSpecify that the task runs every n hours
71DAILY\tSpecify that the task runs every n days
72WEEKLY\tSpecify that the task runs every n weeks
73MONTHLY\tSpecify that the task runs every n months
74ONCE\tSpecify that the task runs once
75ONSTART\tSpecify that the task runs at startup
76ONLOGON\tSpecify that the task runs when the user specified by the /u parameter logs on
77ONIDLE\tSpecify that the task runs after the system is idle for the number of minutes specified by /i'
78        return
79    end
80
81    if __fish_seen_argument -w s
82        echo -e '/u\tRun this command with the permissions of the specified user account'
83    end
84
85    if __fish_seen_argument -w u
86        echo -e '/p\tSpecify the password of the user account specified in the /u parameter'
87    end
88
89    if not __fish_seen_argument -w et -w du
90        echo -e '/et\tSpecify the time of day that a minute or hourly task schedule ends
91/du\tSpecify a maximum length of time for a minute or hourly schedule'
92    end
93
94    echo -e '/sc\tSpecify the schedule type
95/tn\tSpecify a name for the task
96/tr\tSpecify the program or command that the task runs
97/s\tSpecify the name or IP address of a remote computer
98/ru\tRun the task with permissions of the specified user account
99/rp\tSpecify a the password for the existing user account, or the user account specified by /ru
100/mo\tSpecify how often the task runs within its schedule type
101/d\tSpecify how often the task runs within its schedule type
102/m\tSpecify a month or months of the year during which the scheduled task should run
103/i\tSpecify how many minutes the computer is idle before the task starts
104/st\tSpecify the start time for the task
105/ri\tSpecify the repetition interval for the scheduled task
106/k\tStop the program that the task runs at the time specified by /et or /du
107/sd\tSpecify the date on which the task schedule starts
108/ed\tSpecify the date on which the schedule ends
109/it\tSpecify to run the scheduled task only when the run as user is logged on to the computer
110/z\tSpecify to delete the task upon the completion of its schedule
111/f\tSpecify to create the task and suppress warnings if the specified task already exists
112/?\tShow help'
113end
114
115function __schtasks_delete_complete_args -a previous_token
116    if test "$previous_token" = /tn
117        __schtasks_print_tasks
118        return
119    end
120
121    if test "$previous_token" = /u
122        __fish_print_windows_users
123        return
124    end
125
126    if __fish_seen_argument -w s
127        echo -e '/u\tRun this command with the permissions of the specified user account'
128    end
129
130    if __fish_seen_argument -w u
131        echo -e '/p\tSpecify the password of the user account specified in the /u parameter'
132    end
133
134    echo -e '/tn\tIdentify the task to be deleted
135/f\tSuppress the confirmation message
136/s\tSpecify the name or IP address of a remote computer
137/?\tShow help'
138end
139
140function __schtasks_end_complete_args -a previous_token
141    if test "$previous_token" = /tn
142        __schtasks_print_tasks
143        return
144    end
145
146    if test "$previous_token" = /u
147        __fish_print_windows_users
148        return
149    end
150
151    if __fish_seen_argument -w s
152        echo -e '/u\tRun this command with the permissions of the specified user account'
153    end
154
155    if __fish_seen_argument -w u
156        echo -e '/p\tSpecify the password of the user account specified in the /u parameter'
157    end
158
159    echo -e '/tn\tIdentify the task that started the program
160/s\tSpecify the name or IP address of a remote computer
161/?\tShow help'
162end
163
164function __schtasks_query_complete_args -a previous_token
165    if test "$previous_token" = /fo
166        echo -e 'TABLE
167LIST
168CSV'
169        return
170    end
171
172    if test "$previous_token" = /u
173        __fish_print_windows_users
174        return
175    end
176
177    if __fish_seen_argument -w s
178        echo -e '/u\tRun this command with the permissions of the specified user account'
179    end
180
181    if __fish_seen_argument -w u
182        echo -e '/p\tSpecify the password of the user account specified in the /u parameter'
183    end
184
185    echo -e '/fo\tSpecify the output format
186/nh\tRemove column headings
187/v\tAdd the advanced properties of the task
188/s\tSpecify the name or IP address of a remote computer
189/?\tShow help'
190end
191
192function __schtasks_run_complete_args -a previous_token
193    if test "$previous_token" = /tn
194        __schtasks_print_tasks
195        return
196    end
197
198    if test "$previous_token" = /u
199        __fish_print_windows_users
200        return
201    end
202
203    if __fish_seen_argument -w s
204        echo -e '/u\tRun this command with the permissions of the specified user account'
205    end
206
207    if __fish_seen_argument -w u
208        echo -e '/p\tSpecify the password of the user account specified in the /u parameter'
209    end
210
211    echo -e '/tn\tIdentify the task to start
212/s\tSpecify the name or IP address of a remote computer
213/?\tShow help'
214end
215
216function __schtasks_complete_args -d 'Function to generate args'
217    set --local previous_token (commandline -xc)[-1]
218
219    if __fish_seen_argument -w change
220        __schtasks_change_complete_args "$previous_token"
221    else if __fish_seen_argument -w create
222        __schtasks_create_complete_args "$previous_token"
223    else if __fish_seen_argument -w delete
224        __schtasks_delete_complete_args "$previous_token"
225    else if __fish_seen_argument -w end
226        __schtasks_end_complete_args "$previous_token"
227    else if __fish_seen_argument -w query
228        __schtasks_query_complete_args "$previous_token"
229    else if __fish_seen_argument -w run
230        __schtasks_run_complete_args "$previous_token"
231    end
232end
233
234complete -c schtasks -f -a '(__schtasks_complete_args)'
235
236complete -c schtasks -f -n 'not __fish_seen_argument -w change -w create -w delete -w end \
237    -w query -w run' -a /change \
238    -d 'Change one or more properties of a task'
239complete -c schtasks -f -n 'not __fish_seen_argument -w change -w create -w delete -w end \
240    -w query -w run' -a /create \
241    -d 'Schedule a new task'
242complete -c schtasks -f -n 'not __fish_seen_argument -w change -w create -w delete -w end \
243    -w query -w run' -a /delete \
244    -d 'Delete a scheduled task'
245complete -c schtasks -f -n 'not __fish_seen_argument -w change -w create -w delete -w end \
246    -w query -w run' -a /end \
247    -d 'Stop a program started by a task'
248complete -c schtasks -f -n 'not __fish_seen_argument -w change -w create -w delete -w end \
249    -w query -w run' -a /query \
250    -d 'Display tasks scheduled to run on the computer'
251complete -c schtasks -f -n 'not __fish_seen_argument -w change -w create -w delete -w end \
252    -w query -w run' -a /run \
253    -d 'Start a scheduled task immediately'