Fix patag function to rewrite tags instead of adding

- Changed patag function to drop existing tags before adding new ones
- Fixed tag parsing to properly split on '#' separator using tr command
- Tags are now stored as individual entries instead of single string
- Function now properly rewrites tags instead of adding to existing ones

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Yan Lin 2025-07-29 23:36:28 +02:00
parent 2b47bfba47
commit a061ecbdf2
2 changed files with 9 additions and 12 deletions

View file

@ -103,7 +103,7 @@
fi
}
# Papis tag function - add multiple tags using hash-separated format
# Papis tag function - rewrite tags using hash-separated format
patag() {
if [ $# -ne 2 ]; then
echo "Usage: patag \"tag1#tag2#tag3\" <query>"
@ -115,21 +115,17 @@
local tags_string="$1"
local query="$2"
# Build --add arguments by processing each tag
local add_args=""
local oldIFS="$IFS"
IFS='#'
for tag in $tags_string; do
# First, drop all existing tags
papis tag --drop "$query"
# Add each tag individually by splitting on #
echo "$tags_string" | tr '#' '\n' | while read tag; do
# Trim whitespace
tag=$(echo "$tag" | xargs)
if [ -n "$tag" ]; then
add_args="$add_args --add \"$tag\""
papis tag --add "$tag" "$query"
fi
done
IFS="$oldIFS"
# Execute the papis tag command
eval "papis tag $add_args \"$query\""
}
'';
}