Menu for managing SSH ZSH sessions

So, let me see if I’ve got this right:

You open a new terminal and it gives you those errors?

No,

I run your code and get that error.

As far as I am concerned, with Z4H you exec zsh, you do not source ~/.zshrc.

I just tried adding exec zsh at the beginning of my menu script, but it didn’t help.

At what point does the error occur? After you enter a number and press enter?

So what’s on lines 9 and 64, it would help if you’d post your .zshrc in full.

I’d never even heard of z4h before this thread. I asked you to do that first as part of pulling in z4h, but it was mostly the .zshenv I thought might help.

Then we added a function to .zshrc, so you either needed to source it or open a new terminal to be able to use the function.

So we know that ssh is a z4h function, is username-pc1 also a z4h thing or is it from .ssh/config?

9: z4h source ~/.env.zsh
64: z4h install ohmyzsh/ohmyzsh || return

It is strange though, because other lines start in Z4H, but only these are reported as errors. The errors are thrown after calling the script, before showing the menu.

Yes, the thread already contains excerpts with the ssh and z4h funcitons. username-pc1 is an alias from .ssh/config.

I am very close to giving up on this one, though.

My code shouldn’t trigger those lines. Seems like you’re sourcing it still.

Indeed.

It sounds like you’re still sourcing the file, in your script.

I said forget about the script. I asked you to call the function.

Let’s see if this is easier:

  1. Open a new terminal
  2. Copy this:
myssh() {

PS3="Enter session nr.: "

select sshs in username@pc1 root@pc1 username@pc2 root@pc2 "Quit Menu"
do
    case $sshs in
        "username@pc1")
           echo ssh username-pc1 && break;;
        "root@pc1")
           echo ssh root-pc1 && break;;
        "username@pc2")
           echo ssh username-pc2 && break;;
        "root@pc2")
           echo ssh root-pc2 && break;;
        "Quit Menu")
           break;;
        *)
           echo "Invalid input";;
    esac
done
}
  1. Paste it into the terminal and press enter.
  2. Type myssh and press enter.
  3. Hopefully see a prompt.
  4. Either way copy the command and the output, and paste it here.

You’re not the only one. :grin:

Dang it! It worked as a function! :partying_face: Nice!

I still don’t understand why it wouldn’t work as a script though… but nice! It is not the solution I wanted, but it is indeed a solution!

1 Like

The function is only temporary unless you put it in ~/.zshrc, and you should be able to source the script, instead of running it.

So the best options I can think of atm:

  1. If you haven’t already, put the function in ~/.zshrc (like in posts 36 and 56, which have been improved).
    or
  2. Put alias myssh="source /path/to/your/script" in ~/.zshrc. Don’t source any zsh files.

I think I’d prefer the function, the code relies on your zsh config so I think it should be part of said config.

Of course feel free to change the name of the alias/function, if you haven’t already done so. Probably best not to call it ssh, there’s enough of them already.

1 Like

This topic was automatically closed 3 hours after the last reply. New replies are no longer allowed.