Replace fstag with xdgtag
xdgtag uses user.xdg.tags, supported by dolphin and other applications. <https://xdg.freedesktop.narkive.com/f7GQ2EpR/commonextendedattributes-xattr-tags>
This commit is contained in:
parent
25dbe712e1
commit
210ea9aca3
|
@ -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
|
||||
;;
|
|
@ -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 <FILE|DIR> [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 <https://xdg.freedesktop.narkive.com/f7GQ2EpR/commonextendedattributes-xattr-tags>
|
||||
|
||||
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
|
||||
|
|
56
.config/zsh/functions/xdgtag
Normal file
56
.config/zsh/functions/xdgtag
Normal file
|
@ -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 <FILE|DIR> [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
|
Loading…
Reference in New Issue
Block a user