fork/fish-shell

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

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

master
2.0 KiB60 linesraw
1function __fish_exif_target_file_tags
2    for target in (string match -v -- '-*' (commandline -px)[2..])
3        string replace -f '*' '' (exif --list-tags "$target" 2> /dev/null)[2..] | string replace -r '(\s+-){4}' '' | string split -m1 ' ' | string trim
4    end
5end
6
7function __fish_exif_potential_targets
8    set -l token (commandline -t)
9    set -l matching_files (complete -C "__fish_command_without_completions $token")
10    for file in $matching_files
11        if test -d "$file"
12            echo $file
13        else if exif "$file" &>/dev/null
14            echo $file
15        else if not test -e "$file"
16            # Handle filenames containing $.
17            if exif $file &>/dev/null
18                echo $file
19            end
20        end
21    end
22end
23
24function __fish_exif_token_begins_with_arg
25    not string match -- '-*' (commandline -t)
26end
27
28complete -c exif -f -a "(__fish_exif_potential_targets)" -n __fish_exif_token_begins_with_arg
29
30for line in (exif --help)
31    set -l short
32    set -l long
33    set -l description
34    if set -l matches (string match -r '^\s+-([\w?]),\s--([\w=-]+)\s+(.*)$' "$line")
35        set short $matches[2]
36        set long $matches[3]
37        set description $matches[4]
38    else if set -l matches (string match -r '^\s+--([\w=-]+)\s+(.*)$' "$line")
39        set long $matches[2]
40        set description $matches[3]
41    else
42        continue
43    end
44
45    if set -l sub_parts (string split -n --max 1 '=' $long)
46        set long "$sub_parts[1]"
47        switch (string lower "$sub_parts[2]")
48            case tag
49                complete -c exif -s$short -l $long -d "$description" -x -a "(__fish_exif_target_file_tags)"
50            case ifd
51                complete -c exif -s$short -l $long -d "$description" -x -a "0 1 EXIF GPS Interoperability"
52            case file
53                complete -c exif -s$short -l $long -d "$description" -F
54            case "*"
55                complete -c exif -s$short -l $long -d "$description" -x
56        end
57    else
58        complete -c exif -s$short -l $long -d "$description"
59    end
60end