Compare commits

...

2 Commits

Author SHA1 Message Date
Lukáš Kucharczyk abe44c3f92
Add hash TODO 2022-11-11 13:20:24 +01:00
Lukáš Kucharczyk face6e04a6
Improve listing tags 2022-11-11 13:20:11 +01:00
1 changed files with 18 additions and 2 deletions

20
tag.sh
View File

@ -15,15 +15,29 @@ fail() {
}
listtags() {
# $FILENAME $LIMIT
[ -z "$1" ] && fail "No filename supplied."
FILENAME="$1"
sqlite3 -table "$DB_FILE" "SELECT filename, label from files INNER JOIN tags_ties ON tags_ties.fid = files.fid INNER JOIN tags ON tags.tid = tags_ties.tid WHERE filename = \"$FILENAME\""
shift
LIMIT="${1:-0}"
ADDITIONAL_QUERY=""
[ $LIMIT -gt 0 ] && ADDITIONAL_QUERY="LIMIT $LIMIT"
sqlite3 -table "$DB_FILE" \
"SELECT filename, label from files \
INNER JOIN tags_ties ON tags_ties.fid = files.fid \
INNER JOIN tags ON tags.tid = tags_ties.tid \
WHERE filename = \"$FILENAME\"\
$ADDITIONAL_QUERY"
}
if [[ "$1" = "add" ]]; then
shift
[ "$1" = "tag" ] && TABLE="tags" && COLUMN="label"
[ "$1" = "file" ] && TABLE="files" && COLUMN="filename"
# TODO: refactor the add function to allow adding hashes
# [ "$1" = "hash" ] && TABLE="hashes" && COLUMN="md5,filename"
shift
[ -z "$1" ] && fail "No value supplied."
COUNTER=0
@ -58,13 +72,15 @@ if [[ "$1" = "tag" ]]; then
FILENAME="$1"
shift
[ -z "$1" ] && fail "No tag supplied."
COUNTER=0
while true; do
LABEL="$1"
shift
sqlite3 -table "$DB_FILE" "INSERT INTO tags_ties (fid, tid) VALUES ((SELECT fid FROM files WHERE filename = \"$FILENAME\"),(SELECT tid FROM tags WHERE label = \"$LABEL\"))"
COUNTER=$((COUNTER++))
[ -z "${1:-}" ] && break
done
listtags "$FILENAME"
listtags "$FILENAME" "$COUNTER"
exit 0
fi