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