Remove tagsistant aliases, add tmsu

This commit is contained in:
crater2150 2020-02-24 10:32:03 +01:00
parent 18a233ab66
commit 6292d72015
2 changed files with 41 additions and 74 deletions

View file

@ -95,80 +95,6 @@ cd(){
# filesystem stuff
##############################################################################{{{
t=${TAGSISTANT_ROOT:-$HOME/tagged}/store
tagmount() {
tagsistant ${TAGSISTANT_ROOT:-$HOME/tagged} &>/tmp/tagsistant.$USER
}
tag() {
if [[ -z $2 ]]; then
printf "%s\n" \
"Usage: tag FILE... [-n name] [-v] [-p] TAG..." \
"" \
"Each TAG must end with the @ delimiter component." \
"Each File must have a name different from a single @"
return 1
fi
local name preview
zparseopts -D -E n:=name -name:=name p=preview -preview=preview \
v=verbose -verbose=verbose
local sources=()
local tags=()
for i in "${@}"; do
if [[ ${i:t} == "@" ]]; then
tags+=${i}
else
sources+=${i:A}
fi
done
for source in "${sources[@]}"; do
for tag in "${tags[@]}"; do
target=~t/$tag
if [[ ! -d $target ]]; then mkdir -p $target; fi
if [[ -n $verbose ]]; then echo "Tagging $source with $tag"; fi
${=preview:+echo} ln -s $source $target/${name[2]}
done
done
}
papertag() {
if [[ -z $2 ]]; then
echo "Usage: papertag FILE [-v] [-y YEAR] [AUTHOR...] [:: OTHER TAGS]"
return 1
fi
local year
zparseopts -D -E y:=year -year:=year \
v=verbose -verbose=verbose
local paper=$1; shift
tag $verbose $paper paper/@
if [[ -n "$year" ]]; then
tag $verbose $paper meta:/year/eq/${year[2]}/@/
fi
while [[ -n $1 ]]; do
local author=$1; shift
if [[ "$author" == "::" ]]; then break; fi
tag $verbose $paper meta:/author/eq/$author/@
done
for tag in "$@"; do
tag $verbose $paper $tag
done
}
tcd() {
rpath=$(realpath ~t/$1)
if [[ -d $rpath ]]; then
cd $rpath;
else
cd ${rpath:h}
fi
}
# count files in current or given directory
count() {

41
aliases/tmsu Executable file
View file

@ -0,0 +1,41 @@
#!/bin/zsh
exists tmsu || return
tag() {
separator=${@[(ie):]}
if [[ ${separator} -ge ${#@} ]]; then
echo "Usage: tag FILES... : TAGS..."
return 1
fi
for file in $@[1,$((separator - 1))]; do
tmsu tag --tags="${(j: :)*[$((separator + 1)),${#*}]}" $file
done
}
papertag() {
if [[ -z $2 ]]; then
echo "Usage: papertag FILE [-v] [-y YEAR] [AUTHOR...] [:: OTHER TAGS]"
return 1
fi
local year
zparseopts -D -E y:=year -year:=year \
v=verbose -verbose=verbose
local paper=$1; shift
tag $paper : paper
if [[ -n "$year" ]]; then
tag $verbose $paper meta:/year/eq/${year[2]}/@/
fi
while [[ -n $1 ]]; do
local author=$1; shift
if [[ "$author" == "::" ]]; then break; fi
tag $verbose $paper meta:/author/eq/$author/@
done
for tag in "$@"; do
tag $verbose $paper $tag
done
}