From 210ea9aca3b90cf17b07a4f3a855bc0582df2683 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 10 Apr 2022 18:23:55 +0200 Subject: [PATCH] Replace fstag with xdgtag xdgtag uses user.xdg.tags, supported by dolphin and other applications. --- .config/zsh/completions/{_fstag => _xdgtag} | 4 +- .config/zsh/functions/fstag | 60 +++++---------------- .config/zsh/functions/xdgtag | 56 +++++++++++++++++++ 3 files changed, 70 insertions(+), 50 deletions(-) rename .config/zsh/completions/{_fstag => _xdgtag} (86%) create mode 100644 .config/zsh/functions/xdgtag diff --git a/.config/zsh/completions/_fstag b/.config/zsh/completions/_xdgtag similarity index 86% rename from .config/zsh/completions/_fstag rename to .config/zsh/completions/_xdgtag index aeb6b0d..68ab7a4 100644 --- a/.config/zsh/completions/_fstag +++ b/.config/zsh/completions/_xdgtag @@ -1,4 +1,4 @@ -#compdef fstag +#compdef xdgtag local line state @@ -10,7 +10,7 @@ case ${state} in ;; tags) if [[ ${line[1]} == "del" ]]; then - local tags=$(fstag list ${line[2]}) + local tags=$(xdgtag list ${line[2]}) [[ -n ${tags} ]] && _values 'tags' ${(@s/,/)tags} fi ;; diff --git a/.config/zsh/functions/fstag b/.config/zsh/functions/fstag index 2531a5c..513452d 100755 --- a/.config/zsh/functions/fstag +++ b/.config/zsh/functions/fstag @@ -3,54 +3,18 @@ setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL -zmodload zsh/zutil -local -a o_help=() -zparseopts -D -K -- h=o_help -if [[ ${#o_help} -ne 0 || ! -v 2 ]] || [[ ${1} != "list" && ! -v 3 ]]; then - ret=$(( ${#o_help} ^ 1 )) - print -u $(( 1 + ${ret} )) "usage: ${0} [-h] list|add|del|find [TAG] …" - return ${ret} -fi -local cmd=${1} -shift -local file=${1} -shift -[[ -v 1 ]] && local -a tags=(${@}) +print -u 2 \ +'DEPRECATED, use xdgtag instead. +See +To convert your files from user.fstag.tags to user.xdg.tags, run (in Zsh): zmodload zsh/attr -local namespace="user.fstag" -local _taglist=$(zgetattr ${file} ${namespace}.tags 2> /dev/null) -local -a taglist=(${(@s/,/)_taglist}) -unset _taglist +for file in **/*; do + local tags=$(zgetattr ${file} user.fstag.tags 2> /dev/null) + if [[ -n ${tags} ]]; then + zsetattr ${file} user.xdg.tags ${tags} + zdelattr ${file} user.fstag.tags + fi +done' -case ${cmd} in - list) - [[ -n ${taglist} ]] && print ${(j/,/)taglist} - ;; - add) - taglist+=(${tags}) - taglist=(${(u)taglist}) - zsetattr ${file} ${namespace}.tags ${(j/,/)taglist} - ;; - del) - for tag in ${(@)tags}; do - taglist=(${(@)taglist:#${tag}}) - done - zsetattr ${file} ${namespace}.tags "${(j/,/)taglist}" - ;; - find) - setopt LOCAL_OPTIONS GLOB - for current_file in ${file}/**/*; do - local _taglist=$(${0} list ${current_file}) - local -a current_tags=(${(@s/,/)_taglist}) - unset _taglist - local match=yes - for tag in ${(@)tags}; do - (( ${current_tags[(I)${tag}]} )) || match=no - done - if [[ ${match} == yes ]]; then - print ${current_file}: ${(j/,/)current_tags} - fi - done - ;; -esac +return 1 diff --git a/.config/zsh/functions/xdgtag b/.config/zsh/functions/xdgtag new file mode 100644 index 0000000..0cfa7dd --- /dev/null +++ b/.config/zsh/functions/xdgtag @@ -0,0 +1,56 @@ +#!/usr/bin/env zsh +# tag files using extended attributes + +setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL + +zmodload zsh/zutil +local -a o_help=() +zparseopts -D -K -- h=o_help +if [[ ${#o_help} -ne 0 || ! -v 2 ]] || [[ ${1} != "list" && ! -v 3 ]]; then + ret=$(( ${#o_help} ^ 1 )) + print -u $(( 1 + ${ret} )) "usage: ${0} [-h] list|add|del|find [TAG] …" + return ${ret} +fi +local cmd=${1} +shift +local file=${1} +shift +[[ -v 1 ]] && local -a tags=(${@}) + +zmodload zsh/attr +local attribute="user.xdg.tags" +local _taglist=$(zgetattr ${file} ${attribute} 2> /dev/null) +local -a taglist=(${(@s/,/)_taglist}) +unset _taglist + +case ${cmd} in + list) + [[ -n ${taglist} ]] && print ${(j/,/)taglist} + ;; + add) + taglist+=(${tags}) + taglist=(${(u)taglist}) + zsetattr ${file} ${attribute} ${(j/,/)taglist} + ;; + del) + for tag in ${(@)tags}; do + taglist=(${(@)taglist:#${tag}}) + done + zsetattr ${file} ${attribute} "${(j/,/)taglist}" + ;; + find) + setopt LOCAL_OPTIONS GLOB + for current_file in ${file}/**/*; do + local _taglist=$(${0} list ${current_file}) + local -a current_tags=(${(@s/,/)_taglist}) + unset _taglist + local match=yes + for tag in ${(@)tags}; do + (( ${current_tags[(I)${tag}]} )) || match=no + done + if [[ ${match} == yes ]]; then + print ${current_file}: ${(j/,/)current_tags} + fi + done + ;; +esac