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

ZSH support #18

Closed
EItanya opened this issue Apr 4, 2020 · 13 comments · Fixed by #19
Closed

ZSH support #18

EItanya opened this issue Apr 4, 2020 · 13 comments · Fixed by #19

Comments

@EItanya
Copy link
Contributor

EItanya commented Apr 4, 2020

Support spawning ZSH sub shells.

As mentioned in the recent blog post, zsh support is planned for the future.

@EItanya
Copy link
Contributor Author

EItanya commented Apr 4, 2020

Wanted to create an issue to track this feature as this would be an absolutely game changing feature for me personally. From the FISH issue it sounds like this is already being worked on, but if not I would be more than happy to give it a try. I am not rust expert by any means, but I have done some in the past for work.

@sbstp
Copy link
Owner

sbstp commented Apr 4, 2020

I'm working on it right now. There's three major components to zsh support.

  1. reliably detect which shell is in use
  2. be able to start zsh with a custom rc file
  3. be able to add a preexec hook before commands run

I've investigated these and they seem possible to do with zsh. I'm currently working on detecting which shell is in use.

@EItanya
Copy link
Contributor Author

EItanya commented Apr 4, 2020

Sounds good to me, as I said, let me know if there is anything I can do. Maybe to start have a configuration option for the type of shell. And then add in auto discovery right after?

I am a pretty heavy zsh user, 2. should be fairly easy, no idea about 3

@sbstp sbstp mentioned this issue Apr 4, 2020
@sbstp
Copy link
Owner

sbstp commented Apr 5, 2020

Hey I think ZSH support is in a good shape now. It works well on my Linux machine. Can you try it out and let me know if you have any issues? You can compile the support-zsh branch to test it.

@EItanya
Copy link
Contributor Author

EItanya commented Apr 5, 2020

Of course!
Here is the result without setting to zsh in the settings file.

~/src/rust/kubie/target/debug on  support-zsh
✗ ./kubie ctx
Error: Could not detect shell in use

However, when I set shell: zsh in ~/kube/kubie.yaml it works!

Can debug the detection in a little bit, need to finish up some work on my end first. Might either be OSX details, or a peculiarity with my machine.

Thanks so much for adding ZSH support so quickly though. This tool is really a game changer, and editing one line of yaml is not a big deal at all!

@sbstp
Copy link
Owner

sbstp commented Apr 5, 2020

I asked my buddy to test it on his Mac, and he also got this error. It seems like the ps command doesn't behave the same on Mac. I could probably read the SHELL variable, but it is not set by the shell, it's set at the user level. Would still be better than nothing!

I'm trying to setup a Mac virtual machine to test kubie on it.

@sbstp
Copy link
Owner

sbstp commented Apr 5, 2020

Ok so I ran ps on the Mac virtual machine... The zsh binary is called -zsh on Mac for some reason! WTF moment, but easy to fix.

@sbstp
Copy link
Owner

sbstp commented Apr 5, 2020

@EItanya can you try again? I searched on the net and this is because zsh is a login shell, so ps adds a dash before. I added a commit to trim it.

@EItanya
Copy link
Contributor Author

EItanya commented Apr 5, 2020

Just tried again, that's working for me!
A couple of things to note however:

My shell is now displaying 2 separate prompts, this may have to do with my particular setup, because I am running [starship]https://github.com/starship/starship.
Screen Shot 2020-04-05 at 16 26 45
Also, as you can see from the picture above, my starship prompt does not transition to the new kube context until after I run a command. It seems like the ENV var changes you are applying don't take proper affect until after a single command is run. As far as the double display I cannot say.
Is kubie adding this:

[gke_solo-corp_us-central1-a_standard-cluster-1|default]

Overall though working great, just those 2 small things

@EItanya
Copy link
Contributor Author

EItanya commented Apr 5, 2020

Okay, just read through the code, based on my limited knowledge of the zsh impl of spawn_shell it seems like it is in fact creating a prompt, which I just verified locally, going to dig a bit into what might be causing the lag in in my prompt. Maybe a setting to disable the prompt from kubie? I would be more than happy to add that in.

@sbstp
Copy link
Owner

sbstp commented Apr 5, 2020

Yeah kubie adds the [gke_solo-corp_us-central1-a_standard-cluster-1|default] prompt. I could add a setting to disable it altogether.

@EItanya
Copy link
Contributor Author

EItanya commented Apr 5, 2020

Yea that would be awesome! Not sure how common this will be, but I know for instance that most people in my office also have their own prompts, so 🤷‍♂

@sbstp
Copy link
Owner

sbstp commented Apr 5, 2020

Kubie is meant to prepend its prompt to whatever prompt is configured, so it shouldn't break your prompt.

I'm not sure why the interaction with starship is weird like this, it might just be because the kubie prompt and the starship prompt combine to something too long.

@sbstp sbstp closed this as completed in #19 Apr 5, 2020
fsommar added a commit to fsommar/kubie that referenced this issue Oct 25, 2020
I've reused the prompt for bash/zsh for simplicity's sake. This could
definitely be improved in the future by having a more generic structure
for constructing the prompt based on the output of the `kubie info`
commands and a set of colors.

This change was verified with my fish prompt based on starship.rs, and
while it works, it's not prepending it on the same line. This is because
of the starship prompt is outputting a clearing ANSI escape code. (It
would be possible to check for the existence of that code and inject the
prompt after it, effectively ending up where one would expect the prompt
to be, though I'm not convinced that type of logic belongs in Kubie.)
The outcome is exactly the same as in
[this
comment](sbstp#18 (comment)).

The right-side prompt works as expected, though. I reused the zsh RPS1
setting for determining whether right-side prompt is enabled. It would
feel redundant to have one right-prompt setting per shell, but OTOH the
current name is hard-tied to zsh.
fsommar added a commit to fsommar/kubie that referenced this issue Oct 27, 2020
I've reused the prompt for bash/zsh for simplicity's sake. This could
definitely be improved in the future by having a more generic structure
for constructing the prompt based on the output of the `kubie info`
commands and a set of colors.

This change was verified with my fish prompt based on starship.rs, and
while it works, it's not prepending it on the same line. This is because
of the starship prompt is outputting a clearing ANSI escape code. (It
would be possible to check for the existence of that code and inject the
prompt after it, effectively ending up where one would expect the prompt
to be, though I'm not convinced that type of logic belongs in Kubie.)
The outcome is exactly the same as in
[this
comment](sbstp#18 (comment)).

The right-side prompt works as expected, though. I reused the zsh RPS1
setting for determining whether right-side prompt is enabled. It would
feel redundant to have one right-prompt setting per shell, but OTOH the
current name is hard-tied to zsh.
fsommar added a commit to fsommar/kubie that referenced this issue Oct 27, 2020
I've reused the prompt for bash/zsh for simplicity's sake. This could
definitely be improved in the future by having a more generic structure
for constructing the prompt based on the output of the `kubie info`
commands and a set of colors.

This change was verified with my fish prompt based on starship.rs, and
while it works, it's not prepending it on the same line. This is because
of the starship prompt is outputting a clearing ANSI escape code. (It
would be possible to check for the existence of that code and inject the
prompt after it, effectively ending up where one would expect the prompt
to be, though I'm not convinced that type of logic belongs in Kubie.)
The outcome is exactly the same as in
[this
comment](sbstp#18 (comment)).

The right-side prompt works as expected, though. I reused the zsh RPS1
setting for determining whether right-side prompt is enabled. It would
feel redundant to have one right-prompt setting per shell, but OTOH the
current name is hard-tied to zsh.
sbstp pushed a commit that referenced this issue Oct 27, 2020
I've reused the prompt for bash/zsh for simplicity's sake. This could
definitely be improved in the future by having a more generic structure
for constructing the prompt based on the output of the `kubie info`
commands and a set of colors.

This change was verified with my fish prompt based on starship.rs, and
while it works, it's not prepending it on the same line. This is because
of the starship prompt is outputting a clearing ANSI escape code. (It
would be possible to check for the existence of that code and inject the
prompt after it, effectively ending up where one would expect the prompt
to be, though I'm not convinced that type of logic belongs in Kubie.)
The outcome is exactly the same as in
[this
comment](#18 (comment)).

The right-side prompt works as expected, though. I reused the zsh RPS1
setting for determining whether right-side prompt is enabled. It would
feel redundant to have one right-prompt setting per shell, but OTOH the
current name is hard-tied to zsh.
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 a pull request may close this issue.

2 participants