tagspaces icon indicating copy to clipboard operation
tagspaces copied to clipboard

Tags in filename without spaces: Good practice

Open tifDev opened this issue 5 years ago • 20 comments

As you may know, spaces in filenames are bad practice for Linux specially and should be avoided. Spaces are generally replaced by "-" or "_" (good practice), example:

filename[tag1 tag2].jpg

Would become:

filename[tag1-tag2].jpg or
filename[tag1_tag2].jpg -> I believe that this would be the best option in this case because this would allow to use tags with "-" like tag-a_tag-b.

I believe this is not a complicated thing to do as you might only need to change the character used between the tags and then make this new character be detected by tagspaces as the new tag sparator replacing the spaces between brackets.

This change is very important especially for Linux users, so please whenever it's possible, implement this. :)

Congratulations for you all for this amazing project.

Regards

tifDev avatar Sep 30 '20 20:09 tifDev

Maybe the tag delimiter needs to be in settings? @uggrock what you think

sytolk avatar Oct 01 '20 07:10 sytolk

And what about when there are tags like: "Twilight_Sparkle", "Derpy_Hooves", and "anti-White" are present?

They would become: filename[Twilight_Sparkle_Derpy_Hooves_anti-White].jpg or filename[Twilight_Sparkle-Derpy_Hooves-anti-White].jpg

gitdocke avatar Oct 01 '20 07:10 gitdocke

Tag separator can be one default and array of characters [-_ ] for backward compatibility -> all configurable in settings. If you need to use some the separators in tag name it's need to be escaped like: anti-White -> anti-White (I have write Hyphen with entity here: & # 45;)

sytolk avatar Oct 01 '20 07:10 sytolk

Maybe the tag delimiter needs to be in settings? @uggrock what you think

Yes, maybe the it's the best approach to have an option in settings to allow users to input the character that they want as tag delimiter if they choose the option to store the tags in filenames.

tifDev avatar Oct 01 '20 08:10 tifDev

Tag separator can be one default and array of characters [-_ ] for backward compatibility -> all configurable in settings. If you need to use some the separators in tag name it's need to be escaped like: anti-White -> anti-White (Hyphen: & # 45;)

That would solve @gitdocke 's question.

tifDev avatar Oct 01 '20 08:10 tifDev

Other idea: use the "[" as separator. The first "[" encountered in filename would mean "Tags start", then all the others after this would be read as "tag separator" until we reach the final "]" that means "Tags end". Examples:

filename[tag1[tag2[tag3].jpg

I think this is a good idea because if you allow users an input field for them to choose any character they might input invalid character like "]", "?", "/", "&", just name a few (or put a note with a list of the invalid characters behind the input field).

tifDev avatar Oct 01 '20 08:10 tifDev

The true question is who can provide PR ? ;)

sytolk avatar Oct 01 '20 08:10 sytolk

The true question is who can provide PR ? ;)

Well, I don't know what's under the hood but if you or anyone could point me to the location of the code where this changes should be done , I can try :) I can also put here the programming logic so it's easier for someone that's more experienced with this project to implement.

tifDev avatar Oct 01 '20 08:10 tifDev

This is the SettingsGeneral I think this is the right place for this setting: https://github.com/tagspaces/tagspaces/blob/develop/app/components/dialogs/settings/SettingsGeneral.tsx http://snpy.in/Ww2a0S

It's have method that set tag delimiter in global redux state here: https://github.com/tagspaces/tagspaces/blob/develop/app/components/dialogs/settings/SettingsGeneral.tsx#L95 I see that this functionality was implemented in tha past but it is commented now: https://github.com/tagspaces/tagspaces/blob/develop/app/components/dialogs/settings/SettingsGeneral.tsx#L265

sytolk avatar Oct 01 '20 08:10 sytolk

This feature was available in version 2.0 of TagSpaces, but was not really migrated, due to lack of interest. But now it appears to have interest in it, so feel free to implement it. The current tagDelimiter is hardcoded here: https://github.com/tagspaces/tagspaces/blob/develop/app/config.ts#L38 . We need to sign our CLA in order to accept changes.

uggrock avatar Oct 01 '20 09:10 uggrock

Hum... I know JS but I don't know react. But for what I see, it's easy as this was already implemented before.

We just need to uncomment this and this will show the input field for the tag delimiter in settings menu.

Then we need to place here the value of that input field in property tagDelimiter.

Correct me if I'm wrong.

tifDev avatar Oct 02 '20 21:10 tifDev

@tifDev its ok to uncomment tag delimiter input here. but this will set the tag delimiter settings in Redux global state -> settings.tagDelimiter (settings.ts is Reducer) Next it's need to remove hadcoded tagDelimiter from here and replace it in all places from reducer only.

sytolk avatar Oct 05 '20 06:10 sytolk

replace it in all places from reducer only.

Please give me 1 or two examples of code where this replacement needs to happen

And here we would need to place something like tagDelimiter: this.props.getTagDelimiter right?

tifDev avatar Oct 06 '20 21:10 tifDev

export const AppConfig = {
  tagDelimiter: ' ', // delete this row

and replace AppConfig.tagDelimiter usage with this.props.tagDelimiter -> don't forget to inject in component tagDelimiter props from redux store like:

function mapStateToProps(state) {
  return {
    tagDelimiter: state.settings.tagDelimiter
  };
}
export default connect(mapStateToProps)(componentName);

in utils-io.ts and paths.ts in functions tagDelimiter can be set like required parameter like: export function enhanceEntry(entry: any, tagDelimiter: string) -> next its need to set addittional parameter to enhanceEntry usage too

sytolk avatar Oct 07 '20 06:10 sytolk

inject in component tagDelimiter props from redux

Could you point to the location of this pls?

tifDev avatar Oct 19 '20 20:10 tifDev

Here and here must be props.loadDirectoryContent(props.directoryPath, props.tagDelimiter); and Here its need to inject tagDelimiter props like:

function mapStateToProps(state) {
  return {
    tagDelimiter: state.settings.tagDelimiter
  };
}
export default connect(mapStateToProps, mapDispatchToProps)(DirectoryMenu);

Next its need to add the new tagDelimiter parameter here in loadDirectoryContent(directoryPath, tagDelimiter) -> prepareDirectoryContent(..., tagDelimiter) -> enhanceDirectoryContent(..., tagDelimiter) -> enhanceEntry(..., tagDelimiter) and finnaly to replace this AppConfig.tagDelimiter must be replaced with tagDelimiter function parameter from enhanceEntry(entry: any, tagDelimiter: string)

sytolk avatar Oct 20 '20 08:10 sytolk

Hello all,

Sorry for not being able to work on this so far, I've been with a lot of work. @sytolk I see that you assigned this. At this time it's easier for me to donate and someone that is already in the project development to do this.

I did a small search but I didn't found a donation link...

Thank you

tifDev avatar Nov 18 '20 23:11 tifDev

For some reason I assumed separators are customizable, but guess not. That's a pretty big bummer.

I agree that this should be an option, but I'd go a step farther: It's not just spaces that can be problematic, but also special characters like "]" and "[" which are currently used as delimiters. I think both the separators and delimiters should be customizable, so, for example, a pattern like this should be possible:

20220317-nice-filename--tag1-tag2.txt

where 20220317 is the date, nice-filename is the filename, and tag1 and tag2 are the tags. In this case, the separator is -, the beginning delimiter is --, and the end delimiter is either . or .<extension>.

github-account1111 avatar Mar 17 '22 19:03 github-account1111

An icing on the cake would be an ability to choose tag location, so

20220317-tag1-tag2--nice-filename.txt

would possible, where the beginning delimiter is a regular expression \d{8}\-, and the end delimiter is a string --. This way, all the tags are aligned and thus can be viewed at a glance even in File Explorer.

github-account1111 avatar Mar 17 '22 19:03 github-account1111

Great suggestion!

tifDev avatar Mar 19 '22 13:03 tifDev