joshmedeski / tmux-nerd-font-window-name

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

Custom Icon Mapping #5

Closed joshmedeski closed 1 year ago

joshmedeski commented 1 year ago

As a user, I want to customize what icons are associated with what window names.

I think a yaml file could work pretty well for this (ex: tmux-nerd-font-window-names.conf)

icons:
  fish: '󰻳'
  python: 'שׂ'

The script would check for any customizations and use defaults as a fallback.

fullstopslash commented 1 year ago

It would also be spiffy if the command search were a bit more flexible, I'm thinking perhaps in a similar manner tmux-resurrect that accomplishes, as there are some many apps who's root command isn't the full and final command. Either way I'm absolutely loving this plugin!

joshmedeski commented 1 year ago

@fullstopslash could you create a pull request sampling how that would work? I agree that I'd love to be more specific with what's running.

b4rlw commented 1 year ago

I have a problem that would be solved by this issue. I am rendering both the icon and its name, as per #2. But if a process does not have an associated icon, the name is rendered twice, ie. with the format: [<tab-number> <icon> <process-name>] I get [1 micromamba micromamba], or [2 python3.10 python 3.10]. It would be ideal if there was an option to assign a fallback generic icon (such as *), or probably more appropriately as you say, some way to let users manually assign an icon to a process.

joshmedeski commented 1 year ago

Ah yes, I didn't think about that edge-case when we added the tmux-nerd-font-window-name-show-name options.

I don't think I'll start on this new feature this week, but I can create a patch for the current bug.

kenos1 commented 1 year ago

Maybe a setting like tmux-nerd-font-window-name-custom-<program-name> and having the program first look at the name of a program, and try to find the name of that setting by replacing <program-name> with the program name, and then set the icon. Something like:

set -g @tmux-nerd-font-window-name-custom-program = "hi world!"
function get_icon
  name=$1
  icon=<insert command for getting the value of a setting from tmux>
  if $? != 0 # check if exit code is true
    echo "$icon"
  else
    echo "$fallback"

This should make the icon for the program program this: hi world

This is obviously pseudocode, but I will try to implement this sometime this week.

kenos1 commented 1 year ago

It has appeared that from my experimentation, trying to get the value of an unset variable from tmux gives an empty string from tmux show -gqv <variable>.

kenos1 commented 1 year ago

Got it to work! Check out the fork at https://github.com/kenos1/tmux-nerd-font-window-name/tree/origin/custom-icons (need to update README soon)

joshmedeski commented 1 year ago

Thanks for experimenting with this approach @kenos1. I don't think I will use tmux variables because it will quickly get out of hand and you could end up with potentially dozens of tmux variables with a lot of redundant names.

I want to create a config file because we could get rid of the switch case entirely and just use a key-value syntax to just map a value to an icon. This should make it easier for contributors to add new flags and even easier for users to overwrite whatever values they want or add custom values that aren't in the tool yet for their own workflow.


The big question is what file format to use. I recommend yaml key/value format as it's one I'm already familiar with and see other tmux plugins use (like gitmux.

icons:
  tmux: ""
  bash: ""
  # etc...
options:
  show_name: false

Then, the user could overwrite what they want with their own ~/.config/tmux/tmux-nerd-font-window-name.conf file (or something like this).

But it will require the yq dependency to keep things simple. I don't think it's a big ask but I know some developers don't like having to add additional dependencies unless absolutely necessary.

What do you think? I'd love feedback before starting development. I'm open to another file format if someone has a suggestion.

p.s. @kenos1 we can refactor your PR, #12, to use this new config file pretty easily once it's implemented.

kenos1 commented 1 year ago

Sounds good to me! I wonder if we can also use something like regex for programs like nix that use a lot of command names (see https://github.com/kenos1/tmux-nerd-font-window-name/blob/78e59fe1ae1a350f733fc33049d7021e0758fa6f/recommended-icons.conf#L42), or for programs with similar names like vi.

kenos1 commented 1 year ago

Working on it: https://github.com/kenos1/tmux-nerd-font-window-name/tree/origin/yaml

joshmedeski commented 1 year ago

@kenos1 thanks! It was a helpful jumping off point.