commit c88b931a43f428f62c9bdce38f0bde57dacf92a0
parent 401a3b74c30076d2dd6cd2ac0575f95333eb95a7
Author: Anton Konyahin <me@konyahin.xyz>
Date: Sun, 4 Jun 2023 20:57:34 +0300
Fix erros, add path command
Diffstat:
M | tagger | | | 29 | +++++++++++++++++++++++------ |
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/tagger b/tagger
@@ -52,9 +52,14 @@ ptagged () {
err "$2 should be added before: $1"
}
+ptag () {
+ [ ! -d "$base/../$1" ] &&
+ err "$2 should exist: $1"
+}
+
pbase () {
[ ! -d "$base" ] &&
- err "$2 should be tagger folder: $1"
+ err "$2 should be initialized by tagger: $1"
}
# Script logic
@@ -72,7 +77,9 @@ Usage:
tagger untag folder file tag
remove tag from file in tagger folder
tagger ls folder
- list all files under tagger folder"
+ list all files under tagger folder
+ tagger path folder file
+ get path for tagged file"
}
## tagger init name
@@ -97,7 +104,7 @@ add_file () {
## add tag to file from tagger folder
tag_file () {
check "$1" "tagger folder" pdir pbase
- check "$2" "file" pfile ptagged
+ check "$2" "file" ptagged
check "$3" "tag"
tag_folder="$1/$3"
@@ -109,8 +116,8 @@ tag_file () {
## remove tag from file in tagger folder
untag_file () {
check "$1" "tagger folder" pdir pbase
- check "$2" "file" pfile ptagged
- check "$3" "tag"
+ check "$2" "file" ptagged
+ check "$3" "tag" ptag
tag_folder="$1/$3"
rm -f "$tag_folder/$2"
@@ -123,6 +130,15 @@ list () {
ls -1 "$base"
}
+## tagger path folder file
+## get path for tagged file
+path () {
+ check "$1" "tagger folder" pdir pbase
+ check "$2" "file" ptagged
+
+ echo "$base/$2"
+}
+
# Process arguments
[ "$#" -lt 1 ] && print_help
@@ -137,6 +153,7 @@ case "$command" in
add) add_file "$@" ;;
tag) tag_file "$@" ;;
untag) untag_file "$@" ;;
- ls) list "$@" ;;
+ ls) list "$@" ;;
+ path) path "$@" ;;
*) err "Unknown command $command" ;;
esac