Macchina-CLI / macchina

A system information frontend with an emphasis on performance.
https://crates.io/crates/macchina
MIT License
1.24k stars 47 forks source link

Terminal has weird name on NixOS with home-manager #272

Open yavko opened 1 year ago

yavko commented 1 year ago

Describe the bug On NixOS under home-manager the terminal app name starts with a . and ends with -wrapped, I know this is because home-manager creates a kitty script which then calls an executable with the name .kitty-wrapped as seen below ↓ image My proposal is to try parsing the $TERM or $TERMINFO environment variables if possible

To Reproduce Steps to reproduce the behavior:

  1. Run macchina
  2. Look at result

Expected behavior Terminal appears as kitty

Screenshots image

System Information You don't have to provide this information if you're not comfortable doing so, but it'll help us solve the issue a lot faster.

grtcdr commented 1 year ago

The current implementation parses /proc to determine the most likely terminal, but it does so through the /proc/PID/comm file which we have no way of saniziting.

$TERM has proven to be unreliable at detecting the real terminal being used (anyone can for example set the variable to xterm and that would then be reflected in macchina).

$TERMINFO is new to me, I've never had to directly interact with it.

I believe we're better off returning the relevant terminfo description directly.

yavko commented 1 year ago

The current implementation parses /proc to determine the most likely terminal, but it does so through the /proc/PID/comm file which we have no way of saniziting.

Ah makes sense

$TERM has proven to be unreliable at detecting the real terminal being used (anyone can for example set the variable to xterm and that would then be reflected in macchina).

Thats true, I have seen that done a lot

$TERMINFO is new to me, I've never had to directly interact with it.

I believe we're better off returning the relevant terminfo description directly.

Yeah, I agree, idk if this helps but I found a crate that could aid in this https://crates.io/crates/terminfo

grtcdr commented 1 year ago

Yeah, I agree, idk if this helps but I found a crate that could aid in this https://crates.io/crates/terminfo

Yeah it looks like it will, I was never really a fan of our little procfs hack.

yavko commented 1 year ago

Yeah, I agree, idk if this helps but I found a crate that could aid in this crates.io/crates/terminfo

Yeah it looks like it will, I was never really a fan of our little procfs hack.

Oh yeah definitely seems pretty hacky

yavko commented 1 year ago

@grtcdr If you'd like I can write up something with this, just wanna know in case someone has already started on this.

grtcdr commented 1 year ago

Absolutely, go ahead!

I await the improvements your pull request will bring :)

yavko commented 1 year ago

Absolutely, go ahead!

I await the improvements your pull request will bring :)

After implementing terminfo, it seem futile, same issue as with $TERM

with terminfo name: image

with description: image

yavko commented 1 year ago

I found this result on stackoverflow that uses ps -o 'cmd=' -p $(ps -o 'ppid=' -p $$) to get the term name, which results in something like this image could the path then be stripped to only get exec name, as this method seems to use the exact exec name

grtcdr commented 1 year ago

You'll have to manually traverse /proc and compare the values of /proc/<TERMPID>/comm and /proc/<TERMPID>/cmdline.

cmdline should hopefully show you an output like the one returned by the ps command you mentioned.

If it does, and you think the output of cmdline is more consistent, I'd be happy to include the change.

yavko commented 1 year ago

Okay, so it sorta works. I mean it does, but when its in a nix-shell it says rc, which happens to be the exec name of nix shells. I'm quite sad, because I kept getting rc, and was very confused until i just ran ps, and it also said rc image image

I'll make the pr now

yavko commented 1 year ago

I've made a PR now! https://github.com/Macchina-CLI/libmacchina/pull/130

grtcdr commented 1 year ago

Thank you, I'll review it as soon as possible :)