fork/fish-shell

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

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

master
6.0 KiB136 linesraw
1# Completions for vagrant, a vm/container management thing.
2# Docs are at https://www.vagrantup.com/docs/cli/.
3#
4# Apparently options can only come after commands, with the exception of "-v" and "-h", which are effectively commands.
5set -l commands box cloud connect destroy \
6    docker-{exec,logs,run} \
7    global-status halt help init list-commands login \
8    package plugin provision push rdp reload resume \
9    rsync rsync-auto share snapshot ssh ssh-config \
10    status suspend up version \
11    port powershell winrm{,-config}
12
13set -l box_commands add help list outdated prune remove repackage update
14set -l cloud_commands auth box search provider publish version
15set -l plugin_commands install license list uninstall update
16set -l snapshot_commands delete list pop push restore save
17
18function __fish_print_vagrant_state
19    # Find a .vagrant file/directory above $PWD
20    set -l root
21    set -l dir (pwd -P)
22    while test $dir != /
23        if test -d $dir.vagrant -o -f $dir.vagrant
24            echo $dir.vagrant
25            return 0
26        end
27        # Go up one directory
28        set dir (string replace -r '[^/]*/?$' '' $dir)
29    end
30    return 1
31end
32
33function __fish_vagrant_machines
34    if set -l state (__fish_print_vagrant_state)
35        test -d "$state"; or return
36        set -l machines $state/machines/*
37        string replace -- $state/machines/ '' $machines
38    end
39end
40
41function __fish_vagrant_boxes
42    set -l vhome $VAGRANT_HOME/boxes
43    set -q vhome[1]; or set vhome ~/.vagrant.d/boxes
44    set -l boxes $vhome/*
45    string replace -- $vhome/ '' $boxes | string replace -- -VAGRANTSLASH- /
46end
47
48function __fish_vagrant_need_command -V commands
49    argparse -s h/help v/version -- (commandline -xpc)[2..-1] 2>/dev/null
50    or return
51    if set -q _flag_help[1]; or set -q _flag_help[1]
52        return 1
53    end
54    if set -q argv[1]
55        echo $argv
56        return 1
57    end
58    return 0
59end
60
61function __fish_vagrant_using_command
62    set -l cmd (__fish_vagrant_need_command)
63    contains -- $cmd[1] $argv
64end
65
66function __fish_vagrant_box_need_command
67    set -l cmd (__fish_vagrant_need_command)
68    test "$cmd[1]" = box 2>/dev/null
69    or return 1
70    set -e cmd[1]
71
72    # Not all of these are valid for all subcommands, but that's not important here.
73    # Yes, none of these have a short version.
74    set -l opts b-box-version= c-cacert= C-capath= 1-cert= 2-clean f-force i-insecure p-provider=
75    set -a opts 3-checksum= 4-checksum-type= n-name=
76    set -a opts g-global d-dry-run a-all B-box
77    argparse -s $opts -- $cmd 2>/dev/null
78    or return 1
79    if set -q argv[1]
80        echo $argv
81        return 1
82    end
83    return 0
84end
85
86function __fish_vagrant_cloud_need_command
87    set -l cmd (__fish_vagrant_need_command)
88    test "$cmd[1]" = cloud 2>/dev/null
89    or return 1
90    set -e cmd[1]
91
92    set -l opts c-check l-logout t-token d-description= s-short-description= p-private b-box-version=
93    set -a opts f-force r-release u-url v-version-description= P-page= S-short= o-order= L-limit= 1-sort-by=
94    argparse -s $opts -- $cmd 2>/dev/null
95    or return 1
96    if set -q argv[1]
97        echo $argv
98        return 1
99    end
100    return 0
101end
102
103complete -c vagrant -n __fish_vagrant_need_command -fa box -d 'Manage boxes: installation, removal, etc.'
104complete -c vagrant -n "__fish_vagrant_using_command box; and __fish_vagrant_box_need_command" -fa "$box_commands"
105complete -c vagrant -n __fish_vagrant_need_command -fa cloud -d 'Manage Vagrant Cloud'
106complete -c vagrant -n "__fish_vagrant_using_command cloud; and __fish_vagrant_cloud_need_command" -fa "$cloud_commands"
107complete -c vagrant -n __fish_vagrant_need_command -fa connect
108complete -c vagrant -n __fish_vagrant_need_command -fa destroy -d 'Stop and delete all traces of the vagrant machine'
109complete -c vagrant -n __fish_vagrant_need_command -fa docker-exec
110complete -c vagrant -n __fish_vagrant_need_command -fa docker-logs
111complete -c vagrant -n __fish_vagrant_need_command -fa docker-run
112complete -c vagrant -n __fish_vagrant_need_command -fa global-status -d 'Show status Vagrant environments for this user'
113complete -c vagrant -n __fish_vagrant_need_command -fa halt -d 'Stop a machine'
114complete -c vagrant -n __fish_vagrant_need_command -fa help -d 'Show help for a subcommand'
115complete -c vagrant -n __fish_vagrant_need_command -fa init -d 'Initialize a new Vagrant env by creating a Vagrantfile'
116complete -c vagrant -n "__fish_vagrant_using_command init" -fa '(__fish_vagrant_boxes)'
117complete -c vagrant -n __fish_vagrant_need_command -fa list-commands
118complete -c vagrant -n __fish_vagrant_need_command -fa login
119complete -c vagrant -n __fish_vagrant_need_command -fa package -d 'Package a running vagrant environment into a box'
120complete -c vagrant -n __fish_vagrant_need_command -fa plugin -d 'Manages plugins: install, uninstall, update, etc.'
121complete -c vagrant -n __fish_vagrant_need_command -fa provision
122complete -c vagrant -n __fish_vagrant_need_command -fa push
123complete -c vagrant -n __fish_vagrant_need_command -fa rdp
124complete -c vagrant -n __fish_vagrant_need_command -fa reload
125complete -c vagrant -n __fish_vagrant_need_command -fa resume
126complete -c vagrant -n __fish_vagrant_need_command -fa rsync
127complete -c vagrant -n __fish_vagrant_need_command -fa rsync-auto
128complete -c vagrant -n __fish_vagrant_need_command -fa share
129complete -c vagrant -n __fish_vagrant_need_command -fa snapshot
130complete -c vagrant -n __fish_vagrant_need_command -fa ssh -d 'Connect to a machine via SSH'
131complete -c vagrant -n __fish_vagrant_need_command -fa ssh-config -d 'Print ssh config to connect to machine'
132complete -c vagrant -n __fish_vagrant_need_command -fa status -d 'Print status of a machine'
133complete -c vagrant -n __fish_vagrant_need_command -fa suspend -d 'Suspend a machine'
134complete -c vagrant -n __fish_vagrant_need_command -fa up -d 'Start and provision the environment'
135complete -c vagrant -n "__fish_vagrant_using_command up" -fa '(__fish_vagrant_machines)'
136complete -c vagrant -n __fish_vagrant_need_command -fa version -d 'Print current and latest version'