Skip to content

add tr/// to trigger regex #1510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pascalpoitras opened this issue May 18, 2020 · 7 comments
Closed

add tr/// to trigger regex #1510

pascalpoitras opened this issue May 18, 2020 · 7 comments
Assignees
Labels
feature New feature request
Milestone

Comments

@pascalpoitras
Copy link

pascalpoitras commented May 18, 2020

Feature description

Sometimes someone join #weechat and ask if this is possible to mimic tr in a trigger, tr/// instead of s///. It would be nice if we could use a prefix before the delimiter to specify the desired behavior, for example tr/abc/ABC/ and s/hi/hello/ and when there is no prefix, fallback to s///. But I just created a trigger with a letter as delimiter and the trigger is valid so I guess it's not possible this way since a delimiter can be a letter?

@pascalpoitras pascalpoitras added the feature New feature request label May 18, 2020
@flashcode
Copy link
Member

Hi,
What would do tr compared to s, can you please give examples of both to see the differences?

@pascalpoitras
Copy link
Author

tr/// would replace the first character in pattern by first character in replacement, second character in pattern by second character in replacement and so on. For example: tr/abc/ABC/ will replace a by A, b by B and c by C. On the other hand, s/abc/ABC/ will replace any occurence of abc by ABC

/exec -sh echo 'allo' | tr 'abc' 'ABC' => Allo (occurence of a)
/exec -sh echo 'allo' | sed 's/abc/ABC/' => allo (no occurence of abc)

@sim642
Copy link
Member

sim642 commented May 19, 2020

This starts simple but begs a question how many features this should support. For example, GNU tr also supports regex-like character ranges and character classes. The former might be quite useful for this feature but also significantly complicates the implementation compared to one strchr and string indexing.

@sim642
Copy link
Member

sim642 commented May 19, 2020

Also, I forgot to mention but sed also supports tr-like operations, although under the name y/// not tr///, e.g. sed 'y/abc/ABC/'. So there's also the choice for which name to use for such prefix: the name of a command line tool or the name of an analogous sed expression.

@pascalpoitras
Copy link
Author

y/// could be an "alias" to tr/// so anyone can pick the prefix they're used to
good point for the GNU version of tr, of course this is very useful but even a tr without this would be very useful to reduce the length and complexity of some trigger

@flashcode flashcode self-assigned this Oct 2, 2022
@flashcode flashcode added this to the 3.8 milestone Oct 2, 2022
@flashcode
Copy link
Member

flashcode commented Oct 2, 2022

Hi,

I schedule this for v3.8 and I wrote a specification, your feedback is welcome: https://specs.weechat.org/specs/2022-002-trigger-regex-commands.html

flashcode added a commit that referenced this issue Oct 31, 2022
@flashcode
Copy link
Member

Implemented.

So be careful with old triggers which could have an incompatible regex format, and would then be ignored on upgrade (they must be fixed before upgrading WeeChat).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request
Projects
None yet
Development

No branches or pull requests

3 participants