Check if tags exist when tagging
This commit is contained in:
parent
473d88b3c9
commit
d7f4a9c299
15
tag.sh
15
tag.sh
|
@ -13,7 +13,6 @@ set -ueo pipefail
|
|||
# - tag $FILENAME $TAG - tag $FILENAME with $TAG, $TAG can be repeated
|
||||
# - listtags $FILENAME - list all tags for $FILENAME
|
||||
|
||||
# TODO: when tagging, check if tags exist
|
||||
# TODO: when tagging, allow more than one tag
|
||||
# FIXME: adding tags doesn't work
|
||||
|
||||
|
@ -165,6 +164,17 @@ add_path_auto() {
|
|||
find "${2}" -type f -regextype posix-extended -iregex "$1" -exec "$0" import "{}" +
|
||||
}
|
||||
|
||||
tag_exists_in_db() {
|
||||
# $TAGLABEL
|
||||
TAG=${1:-}
|
||||
RESULT=$(sqlite_query "SELECT id FROM tags WHERE label = '$TAG'")
|
||||
if [[ -z "$RESULT" ]]; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
|
||||
[ -z "${1:-}" ] && fail "Usage: tag init/add/import/autoimport/list/listtags"
|
||||
|
@ -212,10 +222,11 @@ main() {
|
|||
[ -z "$1" ] && fail "No filename supplied."
|
||||
FILENAME="$1"
|
||||
shift
|
||||
[ -z "$1" ] && fail "No tag supplied."
|
||||
[ -z "${1:-}" ] && fail "No tag supplied."
|
||||
COUNTER=0
|
||||
while true; do
|
||||
LABEL="$1"
|
||||
! tag_exists_in_db "$LABEL" && fail "Tag '$TAG' does not exist in database."
|
||||
shift
|
||||
sqlite3 -table "$DB_FILE" "INSERT INTO tags_ties (id, id) VALUES ((SELECT id FROM files WHERE filename = \"$FILENAME\"),(SELECT id FROM tags WHERE label = \"$LABEL\"))"
|
||||
COUNTER=$((COUNTER++))
|
||||
|
|
Loading…
Reference in New Issue