fork/fish-shell

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

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

master
5.6 KiB256 linesraw
1# These are very much incomplete completions for the aws-cli suite.
2# In addition to a complete list of services, the `aws s3` completions are mostly complete
3# (and are the primary reason this file exists). The automatically generated completions
4# for `aws` via `fish_update_completions` are pretty useless due to non-standard formatting.
5
6function __s3_is_maybe_bucket
7    commandline -ct | string match -qr -- '^(|s|s3|s3:?/?/?[^/]*)$'
8end
9
10function __s3_is_bucket
11    commandline -ct | string match -q -r -- '^s3:/?/?[^/]*$'
12end
13
14function __s3_is_remote_path
15    commandline -ct | string match -q -r -- "^s3://.+/.*"
16end
17
18function __s3_ls_buckets
19    aws s3 ls | string replace -rf '.* (\S+)$' 's3://$1/'
20end
21
22function __s3_ls_dir
23    set -l dir (commandline -ct | string replace -rf '(s3://.*/).*' '$1')
24    printf "$dir%s\n" (aws s3 ls $dir 2>/dev/null | string replace -fr '^(:?\S+ +\S+ +\S+ |^.*PRE )(.*)' '$2')
25end
26
27# Determines whether the first non-switch argument to `aws s3` was in $argv
28# This accounts for things like `aws --debug s3 foo ... s3://...`
29function __s3_cmd_in
30    set -l is_s3 0
31    set -l tokens (commandline -cx)
32    for token in $tokens[2..-1]
33        # Ignore switches everywhere
34        if string match -qr -- "^--" $token
35            continue
36        end
37
38        # Check if `aws` command is `s3`
39        if test $is_s3 -eq 0
40            if string match -q -- s3 $token
41                set is_s3 1
42                continue
43            else
44                return 1
45            end
46        end
47
48        # Check if `aws s3` sub-sub-command is in $argv
49        if contains $token $argv
50            return 0
51        else
52            return 1
53        end
54    end
55
56    return 1
57end
58
59# S3 completions
60complete -c aws -n "__fish_prev_arg_in s3" -xa "cp mv rm help sync ls mb mv presign rb website"
61
62# When completing a remote path, complete the bucket name first, then based off
63# the bucket name, we can complete the path itself.
64
65# Commands that take only remote parameters (cannot operate on local files).
66complete -c aws -n "__s3_is_maybe_bucket && __s3_cmd_in ls rb rm" -xa "(__s3_ls_buckets)"
67# Commands that can operate on local or remote files. To prevent the shell
68# locking up unnecessarily, only complete if no argument was specified or if the
69# argument being specified could be an S3 path.
70complete -c aws -n "__s3_is_maybe_bucket && __s3_cmd_in mv cp presign mb sync" -a "(__s3_ls_buckets)"
71
72# Complete the paths themselves
73complete -c aws -n __s3_is_remote_path -xa "(__s3_ls_dir)"
74complete -c aws -n __s3_is_bucket -xa "(__s3_ls_buckets)"
75
76# This list is extracted from the output of `aws help`, which can't be ingested directly,
77# as it emits considerable ANSI output and other terminal control characters.
78set -l aws_services \
79    acm \
80    acm-pca \
81    alexaforbusiness \
82    amplify \
83    apigateway \
84    apigatewaymanagementapi \
85    apigatewayv2 \
86    application-autoscaling \
87    appmesh \
88    appstream \
89    appsync \
90    athena \
91    autoscaling \
92    autoscaling-plans \
93    backup \
94    batch \
95    budgets \
96    ce \
97    chime \
98    cloud9 \
99    clouddirectory \
100    cloudformation \
101    cloudfront \
102    cloudhsm \
103    cloudhsmv2 \
104    cloudsearch \
105    cloudsearchdomain \
106    cloudtrail \
107    cloudwatch \
108    codebuild \
109    codecommit \
110    codepipeline \
111    codestar \
112    cognito-identity \
113    cognito-idp \
114    cognito-sync \
115    comprehend \
116    comprehendmedical \
117    configservice \
118    configure \
119    connect \
120    cur \
121    datapipeline \
122    datasync \
123    dax \
124    deploy \
125    devicefarm \
126    directconnect \
127    discovery \
128    dlm \
129    dms \
130    docdb \
131    ds \
132    dynamodb \
133    dynamodbstreams \
134    ec2 \
135    ecr \
136    ecs \
137    efs \
138    eks \
139    elasticache \
140    elasticbeanstalk \
141    elastictranscoder \
142    elb \
143    elbv2 \
144    emr \
145    es \
146    events \
147    firehose \
148    fms \
149    fsx \
150    gamelift \
151    glacier \
152    globalaccelerator \
153    glue \
154    greengrass \
155    guardduty \
156    health \
157    help \
158    history \
159    iam \
160    importexport \
161    inspector \
162    iot \
163    iot-data \
164    iot-jobs-data \
165    iot1click-devices \
166    iot1click-projects \
167    iotanalytics \
168    kafka \
169    kinesis \
170    kinesis-video-archived-media \
171    kinesis-video-media \
172    kinesisanalytics \
173    kinesisanalyticsv2 \
174    kinesisvideo \
175    kms \
176    lambda \
177    lex-models \
178    lex-runtime \
179    license-manager \
180    lightsail \
181    logs \
182    machinelearning \
183    macie \
184    marketplace-entitlement \
185    marketplacecommerceanalytics \
186    mediaconnect \
187    mediaconvert \
188    medialive \
189    mediapackage \
190    mediastore \
191    mediastore-data \
192    mediatailor \
193    meteringmarketplace \
194    mgh \
195    mobile \
196    mq \
197    mturk \
198    neptune \
199    opsworks \
200    opsworks-cm \
201    organizations \
202    pi \
203    pinpoint \
204    pinpoint-email \
205    pinpoint-sms-voice \
206    polly \
207    pricing \
208    quicksight \
209    ram \
210    rds \
211    rds-data \
212    redshift \
213    rekognition \
214    resource-groups \
215    resourcegroupstaggingapi \
216    robomaker \
217    route53 \
218    route53domains \
219    route53resolver \
220    s3 \
221    s3api \
222    s3control \
223    sagemaker \
224    sagemaker-runtime \
225    sdb \
226    secretsmanager \
227    securityhub \
228    serverlessrepo \
229    servicecatalog \
230    servicediscovery \
231    ses \
232    shield \
233    signer \
234    sms \
235    snowball \
236    sns \
237    sqs \
238    ssm \
239    stepfunctions \
240    storagegateway \
241    sts \
242    support \
243    swf \
244    textract \
245    transcribe \
246    transfer \
247    translate \
248    waf \
249    waf-regional \
250    workdocs \
251    worklink \
252    workmail \
253    workspaces \
254    xray
255
256complete -c aws -n "__fish_is_nth_token 1" -xa "$aws_services"