about summary refs log tree commit diff
path: root/Functions/MIME/zsh-mime-contexts
blob: 08f125158a48168b4bd51e6ba5dd221234d93a72 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Helper for zsh-mime-handler.
#
# Pass in a zstyle option, a suffix, which might include multiple parts
# (e.g. pdf.gz), plus remaining zstyle arguments plus arguments to zstyle.
# Try to match the style starting with the longest possible suffix.

local context suffix option

option=$1
shift
suffix=$1
shift

while true; do
  context=":mime:.${suffix}:"
  zstyle $option $context "$@" && return 0
  if [[ $suffix = *.* ]]; then
    suffix=${suffix#*.}
  else
    break
  fi
done

return 1