Compare commits
2 Commits
c1564178fa
...
abe44c3f92
Author | SHA1 | Date |
---|---|---|
Lukáš Kucharczyk | abe44c3f92 | |
Lukáš Kucharczyk | face6e04a6 |
20
tag.sh
20
tag.sh
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue