#!/usr/bin/env zsh typeset -a files untagged=0 setopt null_glob while [[ ${1} == --* ]]; do case $1 in --untagged) untagged=1 ;; --) shift; break ;; esac shift done function notag { [[ -z $(echo .tags/*/${REPLY}(N)) ]] } if [[ -n ${commands[symlinks]} ]] { # Remove tags for deleted files symlinks -rd .tags > /dev/null } if ((untagged)) { files=( *(.+notag) ) if [[ $#files == 0 ]] { exit 0 } } elif [[ ${*[-1]} == -* ]] { files=(.) } mkdir .captions for tfile (.tags/*/*) { tag=${tfile:h:t} file=.captions/${tfile:t:t}.txt if [[ -e ${file} ]] { echo -n ', ' >> ${file} } echo -n ${tag} >> ${file} } feh --cycle-once --scale-down ${*} ${files} --caption-path .captions for cfile (.captions/*); { file=${cfile:r:t} for tag in ${(s:, :)$(<${cfile})}; { mkdir -p .tags/${tag} if [[ ! -e .tags/${tag}/${file} ]] { ln -s -f ../../${file} .tags/${tag}/${file} } } rm ${cfile} } rmdir .captions