From 25b9568f2aa6e4533c97e9975447206bda98f6a0 Mon Sep 17 00:00:00 2001 From: mtoohey31 Date: Sun, 22 Aug 2021 11:38:32 -0400 Subject: [PATCH] completion: exif (#8246) Adds completion support for the exif command line tool (upstream: https://github.com/libexif/exif). --- CHANGELOG.rst | 1 + share/completions/exif.fish | 60 +++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 share/completions/exif.fish diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4995e3d9e..e09eadd69 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -87,6 +87,7 @@ Completions - Added completions for: - ``black`` (:issue:`8123`) + - ``exif`` (:issue:`8246`) - ``gping`` (:issue:`8181`) - Angular's ``ng`` (:issue:`8111`) - ``zef`` (:issue:`8114`) diff --git a/share/completions/exif.fish b/share/completions/exif.fish new file mode 100644 index 000000000..342078343 --- /dev/null +++ b/share/completions/exif.fish @@ -0,0 +1,60 @@ +function __fish_exif_target_file_tags + for target in (string match -v -- '-*' (commandline -po)[2..]) + string replace -f '*' '' (exif --list-tags "$target" 2> /dev/null)[2..] | string replace -r '(\s+-){4}' '' | string split -m1 ' ' | string trim + end +end + +function __fish_exif_potential_targets + set -l token (commandline -t) + set -l matching_files (complete -C "__fish_command_without_completions $token") + for file in $matching_files + if eval "test -d \"$file\"" + echo $file + else if eval "exif \"$file\"" &>/dev/null + echo $file + else if not eval "test -e \"$file\"" + # Handle filenames containing $. + if exif $file &>/dev/null + echo $file + end + end + end +end + +function __fish_exif_token_begins_with_arg + not string match -- '-*' (commandline -t) +end + +complete -c exif -f -a "(__fish_exif_potential_targets)" -n __fish_exif_token_begins_with_arg + +for line in (exif --help) + set -l short + set -l long + set -l description + if set -l matches (string match -r '^\s+-([\w?]),\s--([\w=-]+)\s+(.*)$' "$line") + set short $matches[2] + set long $matches[3] + set description $matches[4] + else if set -l matches (string match -r '^\s+--([\w=-]+)\s+(.*)$' "$line") + set long $matches[2] + set description $matches[3] + else + continue + end + + if set -l sub_parts (string split -n --max 1 '=' $long) + set long "$sub_parts[1]" + switch (string lower "$sub_parts[2]") + case tag + complete -c exif -s$short -l $long -d "$description" -x -a "(__fish_exif_target_file_tags)" + case ifd + complete -c exif -s$short -l $long -d "$description" -x -a "0 1 EXIF GPS Interoperability" + case file + complete -c exif -s$short -l $long -d "$description" -F + case "*" + complete -c exif -s$short -l $long -d "$description" -x + end + else + complete -c exif -s$short -l $long -d "$description" + end +end