Remove hardcoded db filename
Also prevent db files from getting tracked by git
This commit is contained in:
parent
9f1eccdf1a
commit
c1564178fa
|
@ -0,0 +1 @@
|
|||
*.db
|
13
tag.sh
13
tag.sh
|
@ -7,6 +7,7 @@ set -ueo pipefail
|
|||
# - tag $FILENAME $TAG - tag $FILENAME with $TAG, $TAG can be repeated
|
||||
# - listtags $FILENAME - list all tags for $FILENAME
|
||||
|
||||
DB_FILE="tags.db"
|
||||
|
||||
fail() {
|
||||
echo "$1" >&2;
|
||||
|
@ -16,7 +17,7 @@ fail() {
|
|||
listtags() {
|
||||
[ -z "$1" ] && fail "No filename supplied."
|
||||
FILENAME="$1"
|
||||
sqlite3 -table tags.db "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\""
|
||||
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\""
|
||||
}
|
||||
|
||||
if [[ "$1" = "add" ]]; then
|
||||
|
@ -29,25 +30,25 @@ if [[ "$1" = "add" ]]; then
|
|||
while true; do
|
||||
NEW_TAG="$1"
|
||||
shift
|
||||
sqlite3 -table tags.db "INSERT INTO $TABLE ($COLUMN) VALUES (\"${NEW_TAG}\")"
|
||||
sqlite3 -table "$DB_FILE" "INSERT INTO $TABLE ($COLUMN) VALUES (\"${NEW_TAG}\")"
|
||||
COUNTER=$((COUNTER++))
|
||||
[ -z "${1:-}" ] && break
|
||||
done
|
||||
sqlite3 -table tags.db "SELECT * FROM \"$TABLE\" LIMIT $COUNTER"
|
||||
sqlite3 -table "$DB_FILE" "SELECT * FROM \"$TABLE\" LIMIT $COUNTER"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "$1" = "list" ]]; then
|
||||
[ -z "$2" ] && fail "No table supplied."
|
||||
TABLE_NAME="$2"
|
||||
sqlite3 -table tags.db "SELECT * FROM \"${TABLE_NAME}\""
|
||||
sqlite3 -table "$DB_FILE" "SELECT * FROM \"${TABLE_NAME}\""
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "$1" = "bytag" ]]; then
|
||||
[ -z "$2" ] && fail "No tag supplied."
|
||||
TAG_NAME="$2"
|
||||
sqlite3 -table tags.db "SELECT filename FROM files WHERE fid = (SELECT fid FROM tags_ties WHERE tid = (SELECT tid FROM tags WHERE label = \"${TAG_NAME}\"))"
|
||||
sqlite3 -table "$DB_FILE" "SELECT filename FROM files WHERE fid = (SELECT fid FROM tags_ties WHERE tid = (SELECT tid FROM tags WHERE label = \"${TAG_NAME}\"))"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
@ -60,7 +61,7 @@ if [[ "$1" = "tag" ]]; then
|
|||
while true; do
|
||||
LABEL="$1"
|
||||
shift
|
||||
sqlite3 -table tags.db "INSERT INTO tags_ties (fid, tid) VALUES ((SELECT fid FROM files WHERE filename = \"$FILENAME\"),(SELECT tid FROM tags WHERE label = \"$LABEL\"))"
|
||||
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\"))"
|
||||
[ -z "${1:-}" ] && break
|
||||
done
|
||||
listtags "$FILENAME"
|
||||
|
|
Loading…
Reference in New Issue