Topic: Fuzzy tagging using FZF [Linux]

Posted under e621 Tools and Applications

ft is a command-line tool which provides interactive fuzzy tagging via fzf . It downloads the list of tags from e621 and colorizes them according to type (eg. species tags are red). The selected tags are automatically copied to the clipboard so they can be pasted into e621's 'edit tags' field.

This is more or less a proof of concept. I expect it will be most useful for quickly selecting taggings in preparation for upload.

Once installed, invoking ft on the commandline begins the interactive selection of tags; for those unfamiliar with fzf, this means that typing filters the list of tags to show only those that match, and you may continue typing to refine the search, or use TAB to select some of them. This selects ONLY from existing e621 tags, ie. you cannot enter new tags or metatags.

Git is currently required in order to install ft (but no actual skill with git is necessary). Run git clone https://github.com/lautik/e6-fzftag.git; cd e6-fzftag to get a copy of the source. Other dependencies are fzf, curl, xsel, and jq. More details on how to install them are in the README, which also provides a brief guide to using fzf in case you are not familiar with it.

It may be possible to use ft on platforms other than Linux, however no testing has been done on other platforms.

I'd prefer to have a screencast here. For the moment I have this somewhat silly screenshot showing the query, the colorization of tag types, and the preview of the final list of tags. It should be noted that the dark BG and subdued colors in this shot is down to my terminal color configuration, not ft -- if your terminal looks light, then ft should look light.

Updated

I tried installing all the requirements and fiddling with the code a little to get it to work (replacing function example() { with just example() { for example), and the closest I was able to get was this: http://20sofp.tk/devops/ft/ft-bug-01.gif

Even trying the same command from the Linux box itself fails to work.

Updated by anonymous

Thanks for testing.

Looks like the tag database didn't build properly (the '0' at the bottom indicates fzf read 0 items).

When you ran ft-updatedb, what was the output?

It should have eventually (after some activity fetching documents from e621) printed a line like ..............! (~12000 tags fetched) and lastly said
Database written to ~/.cache/e621-fzftags

I'm assuming that you have in fact run ft-updatedb, as, in my tests, the 'Exit if DB is not present' code in ft seems to work correctly. Perhaps ft should also check whether the DB looks sane (>0 entries)? (EDIT: done)

The database is a text file with one item per line; each item may have ANSI color escapes applied. You should be able to inspect it with less -r ~/.cache/e621-fzftags, if necessary.

Is function foo () { rather than foo () { a BASHism? I definitely want to remove it if so -- I want to be sh or ideally even dash compatible -- , but I haven't been able to find out for sure yet.
(EDIT: Seems it is a BASHism . By the time you read this, uses of function should be removed from ft)

EDIT3: OK, the most likely cause for this bug is bashisms $'\t' / $'\e', which are now replaced with sh/dash-compatible equivalents. You should be able to pull these changes, run ./install.sh again, run ft-updatedb -f to force an update of the db, and ft should then hopefully work normally.

Updated by anonymous

A few animations... trying to get termcasting working properly.
Right now it only works for shorter casts.

A little blurb about setting FZF_DEFAULT_OPTS -- I might explicitly pass --tiebreak=begin to fzf in future versions, since it seems to be best for tagging. For now, including it in FZF_DEFAULT_OPTS is just strongly recommended. A few suggested keybinds are also covered.

(EDIT: I've now obsoleted most of the above by detecting whether FZF_DEFAULT_OPTS defines --tiebreak or relevant bindings, and setting --tiebreak / bindings only if detected. Also added alt-e binding to bring up the wiki of the currently selected tag.)

A quick tagging demo -- just replicating the tags of post #1485754 in as few keystrokes as possible.
Demonstrates a few things, but not explicitly:

  • query abc in a fuzzy system is equivalent to a wildcard search *a*b*c* (so pnok matches photonoko). This implies that spaces are generally optional (two search terms is not the same as one search term, but 'matches *a*b* and matches *c*' often gives the same results as plain 'matches *a*b*c*')
  • if the input list is sorted by number of taggings, popular tags can be input very quickly, eg 'a' -> anthro, 'f' -> female, 's' -> solo, 'b' -> breasts, 'd' -> 'duo', 'di' -> digital_media_(artwork) , 'ab' -> absurd_res )

Updated by anonymous

  • 1