Add tag -i / --interactive

This commit is contained in:
Lukáš Kucharczyk 2022-11-19 00:05:08 +01:00
parent d95aa517df
commit 2dbe0b08c4
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
1 changed files with 24 additions and 0 deletions

24
tag.sh
View File

@ -297,6 +297,12 @@ main() {
if [[ "$1" = "tag" ]]; then
shift
if [[ "${1:-}" = "-i" || "${1:-}" = "--interactive" ]]; then
"$0" --db "$DB_FILE" tagfid \
$(sqlite_query "SELECT id,filename,path FROM files" | fzf | xargs -I{} echo '{}' | awk -F'|' '{print $1}') \
$(sqlite_query "SELECT label FROM tags" | fzf --multi | xargs -I{} echo '{}' | awk -F'|' '{print $1}')
exit 0
fi
[ -z "${1:-}" ] && fail "No filename supplied."
FILENAME="$1"
! file_exists_in_db "$FILENAME" && fail "File '$FILENAME' does not exist in database."
@ -315,6 +321,24 @@ main() {
exit 0
fi
if [[ "$1" = "tagfid" ]]; then
shift
[ -z "${1:-}" ] && fail "No file ID supplied."
local FID="$1"
shift
[ -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
sqlite_query "INSERT INTO tags_ties (fid, tid) VALUES ($FID,(SELECT id FROM tags WHERE label = \"$LABEL\"))"
COUNTER=$((COUNTER++))
[ -z "${1:-}" ] && break
done
exit 0
fi
if [[ "$1" = "listtags" ]]; then
[ -z "${2:-}" ] && { pod2usage "$0"; exit 1 ; }
listtags "$2"