Crates.io | tagctl |
lib.rs | tagctl |
version | 1.2.1 |
source | src |
created_at | 2024-12-11 03:41:59.386954 |
updated_at | 2024-12-11 03:51:18.953154 |
description | Adds or removes tags to given paths inside square brackets or to extended attributes |
homepage | |
repository | https://gitlab.com/KodyVB/tagctl |
max_upload_size | |
id | 1479534 |
size | 89,461 |
[[TOC]]
Tagctl is a command line program written in Rust which can add or remove tags to files.
The tags can either be in the name or under user.xdg.tags
in the extended attributes.
Tagctl can take multiple files as input from both the left hand side (LHS) and right hand side (RHS).
It breaks the inputs up by new lines, using each line as a new file.
Before altering the file, it checks to make sure the file does exist, and if it doesn't exist tagctl will move on to the next file.
For instructions, you can run tagctl -h
, and for more verbose instructions you can run tagctl --help
.
Tagctl can either be built from scratch via Rust or the pre-compiled binary can be used.
cargo install tagctl
--target x86_64-unknown-linux-musl
flag for general Linux usechmod +x path/to/tagctl
Once installed, tagctl can generate the completion files via the -g
flag for Bash, Elvish, Fish, and Zsh.
To utilize the script, do the step relevant to your shell:
tagctl.bash
file to your bash_completion.d
or bash-completion/completions
directory, or source
it otherwise
tagctl -g bash > $XDG_DATA_HOME/bash-completion/completions/tagctl.bash
tagctl.elv
file to a module search directory, such as $XDG_CONFIG_HOME/elvish/lib
, and add use tagctl
to your rc.elv
file
tagctl -g elvish > $XDG_CONFIG_HOME/elvish/lib/tagctl.elv
tagctl.fish
file to $XDG_CONFIG_HOME/fish/completions
tagctl -g fish > $XDG_CONFIG_HOME/fish/completions/tagctl.fish
_tagctl
file to somewhere in your $fpath
, preferably creating a custom $fpath
directory by doing something like mkdir -pv $XDG_CONFIG_HOME/zsh/completions && tagctl -g zsh > $XDG_CONFIG_HOME/zsh/completions/_tagctl
, then adding the following to your zshrc
:fpath=(${XDG_CONFIG_HOME}/zsh/completions "${fpath[@]}")
autoload -Uz compinit
compinit -u
Tags can be specified as a normal string or one of the following escaped sequences:
%p
- the file's parent directory's name%y
- the year the file was modified%m
- the month the file was modified%d
- the day the file was modified%w
- the weekday the file was modifiedIn order to specify the tags, use the -t
or --tag
flag.
For example, in order to add the tag "this example" to the file "a.txt", the following would e used:
$ ls
a.txt
$ tagctl -t "this example" a.txt
$ ls
'a[this example].txt'
In order to remove a tag, add the -r
or --remove
flag to the command.
For example, to remove the tag "this example" from the file "a.txt", the following would be used:
$ ls
'a[this example].txt'
$ tagctl -rt "this example" a\[this\ example\].txt
$ ls
a.txt
You could also remove all of the tags from a file using the -R
or --remove_all
flag.
For example, to remove all of the tags from "a.txt", the following could be used:
$ ls
'a[this example,another example].txt'
$ tagctl -R a\[this\ example,another\ example\].txt
$ ls
a.txt
If you don't want to use the default delimiter of "," to separate multiple tags, use the -d
or --delimiter
flag.
It is left to the user to stay consistent with delimiters - if the user adds the tags "first", "second", and "third" to a file with the default delimiter of "," and then uses the delimiter flag to change the delimiter to something else, tagctl will see "first,second,third" as a single tag.
An example of the delimiter flag being used is shown here:
$ ls
a.txt
$ tagctl -t "first" -d "-" a.txt
$ ls
'a[first].txt'
$ tagctl -t "second" -d "-" a\[first\].txt
$ ls
'a[first-second].txt'
Tagctl has the option to change the tags in extended attributes, which can be accessed via the command line with programs such as getfattr
and setfattr
.
It uses the standard that KDE's file indexer, Baloo, uses, being user.xdg.tags
.
In order to use the extended attributes, add the -x
or --xattr
flag to the command.
For example, to add the tag "picture" to the file "a.jpg", the following would be used:
$ ls
a.jpg
$ tagctl -xt "picture" a.jpg
$ ls
a.jpg
$ getfattr -n user.xdg.tags a.jpg
# file: a.jpg
user.xdg.tags="picture"
$ baloosearch tag:picture
...
/path/to/a.jpg
...
Tagctl optionally takes in file names from the left hand side via pipes via the -i
and --input
flags.
Some examples are shown here:
$ find . -type f | tagctl -it "tagName"
$ ls | tagctl -xivt "anotherTagName"
$ ls > file_list.txt
$ cat file_list.txt | tagctl -xivrt "anotherTagName"