Skip to content
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

Add option to rewrite sway/window title #1055

Merged
merged 3 commits into from
Apr 21, 2021

Conversation

vrld
Copy link
Contributor

@vrld vrld commented Mar 21, 2021

Rewrites window title according to config option "rewrite".

"rewrite" is an object where keys are regular expressions and values are rewrite rules if the expression matches. Rules may contain references to captures of the expression. Regex and replacement follow ECMA-script rules. If no regex matches, the title is left unchanged.

Useful to add icons depending on the window title, e.g.:

"sway/window": {
  "rewrite": {
    "(.*) - Mozilla Firefox": " $1",
    "(.*) - zsh": " [$1]",
  }
}

Examples:

  • Firefox:
    • before before patch
    • patched after patch
  • Terminal / zsh:
    • before before patch
    • patched after patch

@vrld
Copy link
Contributor Author

vrld commented Mar 21, 2021

Failed test seems to be caused by the runner, not by the changed code:

ERROR: Clock skew detected. File /Users/runner/work/Waybar/Waybar/build/../subprojects/date-3.0.0/meson_options.txt has a time stamp 10.6111s in the future.

@vrld
Copy link
Contributor Author

vrld commented Mar 31, 2021

@Alexays is anything missing?

@Alexays
Copy link
Owner

Alexays commented Apr 15, 2021

LGTM, can you update the man in order to add the change?
Thanks!

@Synthetica9
Copy link
Contributor

Very cool, using this locally and it's working like a charm! +1 for this feature.

Copy link
Contributor

@Synthetica9 Synthetica9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I'd like to request 1 change: if the regex is malformed in some way, it's probably better to keep the window title unchanged rather than crapping out completely and not setting the window title at all as is currently the case.

Rewrites window title according to config option "rewrite".
"rewrite" is an object where keys are regular expressions and values are
rewrite rules if the expression matches. Rules may contain references to
captures of the expression. Regex and replacement follow ECMA-script
rules. If no regex matches, the title is left unchanged.

example:
"sway/window": {
  "rewrite": {
    "(.*) - Mozilla Firefox": " $1",
    "(.*) - zsh": " $1",
  }
}
std::regex and std::regex_replace may throw an std::regex_error if the
expression or replacement contain errors.

Log this error and carry on with the next rule, so that the title is
shown even if the config contains errors.
Add section on rewrite rules and extend example
@vrld vrld force-pushed the feature-rewrite-window-title branch from 6a1a0f5 to 7cdf178 Compare April 21, 2021 10:25
@vrld
Copy link
Contributor Author

vrld commented Apr 21, 2021

@Synthetica9 Good catch. Added try/catch around the regex stuff to fix this issue

@Alexays Added documentation in manpage and rebased on current master.

@Alexays
Copy link
Owner

Alexays commented Apr 21, 2021

Thx! ❤️
Can you also update the Github wiki?

@Alexays Alexays merged commit 66d8035 into Alexays:master Apr 21, 2021
@vrld
Copy link
Contributor Author

vrld commented Apr 21, 2021

@Alexays done :)

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

Successfully merging this pull request may close these issues.

3 participants