joshmedeski / tmux-nerd-font-window-name

Nerd Font icons for your tmux windows
145 stars 29 forks source link

Tmux window name not updating unless focused upon #9

Closed hqkhan closed 1 year ago

hqkhan commented 1 year ago

Hello. I have noticed that the tmux window name won't update to the correct icon or name unless I focus on it. For instance, I'm running bash and the icon is there. I'll then run some arbitrary command CMD the window name changes to the command since there's no icon for it. Then even though the command has finished running, the window name will stay as CMD until I focus on it and press a button.

Is there a way to have it update automatically?

joshmedeski commented 1 year ago

I've noticed his as well. No sure the underlying cause yet. If you learn anything please let me know.

I'll spend some more time looking into it.

hqkhan commented 1 year ago

Got it. I'll do the same.

On Wed, Apr 5, 2023, 12:03 PM Josh Medeski @.***> wrote:

I've noticed his as well. No sure the underlying cause yet. If you learn anything please let me know.

I'll spend some more time looking into it.

— Reply to this email directly, view it on GitHub https://github.com/joshmedeski/tmux-nerd-font-window-name/issues/9#issuecomment-1497750839, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFM7VFPDFGGWKUGPNZKURH3W7WJV7ANCNFSM6AAAAAAWUIRLK4 . You are receiving this because you authored the thread.Message ID: @.***>

hqkhan commented 1 year ago

I was trying to look into this.

From tmux's man page:

In addition, the last line of a shell command's output may be inserted using ‘#()’. For example, ‘#(uptime)’ will insert the system's uptime. When constructing formats, tmux does not wait for ‘#()’ commands to finish; instead, the previous result from running the same command is used, or a placeholder if the command has not been run before. If the command hasn't exited, the most recent line of output will be used, but the status line will not be updated more than once a second. Commands are executed using /bin/sh and with the tmux global environment set (see the GLOBAL AND SESSION ENVIRONMENT section).

By default, the settings are probably something like:

set-option -g automatic-rename on
set-option -g automatic-rename-format '#{pane_current_command}'

But with a bash script being called, it's too slow to meet the requirements of #()? I'm mainly just jotting down any thoughts/findings. I haven't been able to get it to work. But tmux out of the box will update window names properly

joshmedeski commented 1 year ago

Thanks, I've also been reading through tmux's man page and came to the same conclusion.

but the status line will not be updated more than once a second

I don't think we can expect this to change unless someone contributed to tmux directly to find a better solution for dealing with running scripts on the automatic-rename-format option (which I don't have the bandwidth to attempt right now).

So far, it doesn't bother me. I wrote this plugin to make the windows (mostly) disappear. But I recognize in this instant terminal-base workflow it's an annoyance to some.

Let me know if you learn anything new.

hqkhan commented 1 year ago

That's fair! Yeah, agreed. I'll try to keep looking around whenever I find some time. If I do find anything worth sharing, I'll post updates here.

joshmedeski commented 1 year ago

Since no solution has been found, I'm closing this issue. If new information is found we I can reopen it.

hqkhan commented 1 year ago

Hi @joshmedeski. I started messing around with dotfiles after getting them to a stable version and just working. There were a few things I wanted to play with and got going again which includes this particular issue. I really needed the automatic rename to work on its own as opposed to me having to "wake it up" for it to trigger the renaming script. On top of that, I love this particular plugin as it's the exact minimalist setup I've come to love after watching your setup videos.

I do think we were correct about the timing issue of #(). I started reading a bit into the formats section of man tmux. I messed around with the conditionals and got a prototype to test:

set-option -g automatic-rename-format "#{?#{==:#{pane_current_command},nvim},,\#{?#{==:#{pane_current_command},bash}\,\,#{pane_current_command}}}"

It's very ugly and crude but it does work. This definitely lacks the flexibility that a bash script provides.

This is what I've been able to find thus far. I was thinking of potentially opening either an issue or a discussion over on tmux's github and see if folks there have a better solution in mind. Otherwise, I might just have a a really long nested if statement like this :)

Edit:

Further enhancement:

set-option -g automatic-rename-format "#{?#{m/ri:^(n)?vi(m)?$,#{pane_current_command}},,\#{?#{==:#{pane_current_command},bash}\,\,#{pane_current_command}}}"

Instead of if statement, use regex to match against pane_current_command. We can have a regex per case.

joshmedeski commented 1 year ago

Thanks @hqkhan, I think stating a conversation with the tmux contributors would be a great next step.

I opened #13 and will be working on a graceful way of deprecating the currently methodology in favor of a yaml file that defines all of the icons and removes the conditional logic.

Maybe combined with your insight we can find a way to improve the plugin.

hqkhan commented 1 year ago

I think stating a conversation with the tmux contributors would be a great next step.

Sounds good. I'll be doing that soon. A config file like yaml should be parseable into a format that tmux wants.

hqkhan commented 1 year ago

Hi @joshmedeski. I made an issue over on tmux's github and I learned that #() will definitely not work for our case. By default, it does not trigger an update which is why it's always waiting for some change to occur (in our case, it's us "waking" the pane up by keypress).

The proper tmux format will be evaluated fully which is what we want. I imagine, we'll want to have a parser for yaml -> tmux syntax. I'll probably work on this once I get an idea of what the yaml file looks like. In particular, I'm curious about how the or are handled in a yaml file. For example, "vi", "vim" or "nvim", I updated my original prototype to use simple regex for capturing this. We could even simplify it further by doing something naive like "vi|vim|nvim" as our regex. I bet that'll suffice...

Just some food for thought. I'll update here once I make some headway on a parser.

joshmedeski commented 1 year ago

Right now, the decision I made was to have vi, vim and nvim be separate key values in the yaml file. Seems much easier to implement and maintain than some regex pattern in the yaml.