-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
Add Optional Tags to Change Behavior for Specific Host #24
Comments
Hi, interesting, let me see... |
The problem is that by design this description '#some description#PROD' will be cut to just 'some description'.
Add this array: And add this check:
Then in go_to_target:
Hope this will help. |
Thanks for the suggestion! I tried using your provided code but it results in all hosts connecting using the kitten instead of just those with In the various ways I've tried this I keep running into the problem that if the flag isn't visible in the dialog then I can't act on it, or it doesn't properly attach to the host as the list is built. |
Ah, yes missed {} it should be like this:
|
That did it! I was so close, but I was missing the below portion in my attempts. :
Instead of handling it this way I was trying to save the entire description as another variable or just the #PROD# portion, but I was clearly doing something wrong. Thank you for your help with this! I actually had an idea to define more than one flag so that each is handled differently, mainly different terminal appearance settings depending on what the flag is, but I'm sure there are multiple uses for something like that. I'm not sure what the best approach to that would be, maybe to define the flags at the top of the script with the other configurables and then modify what you provided to look for any of those flags, or pattern match the flag pattern. If I come up with anything that's not too janky I'll share it here. Maybe somebody else will find it useful. Thanks again for your help!! |
I just wanted to leave this here, this is what I ultimately ended up with. I'm using a file to store flags and commands in a comma-separated list. This allows me to look for the flag that's set and run the corresponding command. In my use case the command is just a piece of the whole ssh command, specifically a kitten for the Kitty browser that changes the terminal's theme for the duration of the SSH session. It could easily be expanded to provide the entire command, though.
Then, I made the following changes to the sshto script (changed lines are preceded by 4 underscores):
Line 12, sets the location of the flag-command maps.
Line 22, creates the mapping for the script.
Lines 288-311. This entire section replaces the existing go_to_target function, and looks for the flag in the map table and if found runs the corresponding command. If not found it runs the normal ssh command.
Lines 706-710. This is just where it searches the host line for the flag and associates it with the host.
This is a short snippet of one of my hosts files. The first host is a production server, with a flag of This should be expandable to as many flag/command pairings as desired, without requiring further modifications to the sshto script. Right now it only takes commands in the form of one underscore, four characters, then another underscore. This could be modified easily enough, though, by changing the regular expression used to match in the last code snippet. It does not match correctly if there's a second pound symbol before the first underscore, though, and I haven't figured out why. The Host line has to be entered as I welcome any feedback and suggestions, and I don't know that this is useful on a large enough scale to warrant importing it to the script by default, but maybe this will help somebody else one day. |
I'm looking for a way to add optional tags to a host and have sshto act on those tags.
Specifically, in my environment I have certain hosts that are live and hosts used for testing, as most people probably do. One of the fast ways I differentiate this is by making the background color of the production hosts different from non-production hosts, and I use a kitty browser kitten to do this.
What I'm now trying to do is add a tag to the end of a host description in an sshconfig file, say
Host prod_serv #Production Server#PROD
and then have sshto run a different ssh command when it sees thatPROD
tag. Where I'm running into trouble is I can't quite figure out how to make sshto see the tag or created variable whengo_to_target()
is called. Below is what I have so far, and any suggestions or advice you can provide is greatly appreciated. I couldn't find a way to highlight the specific lines I added, so the edited portions in the second code block are preceded with four underscores (____). Please be forewarned I'm no programmer so it would not surprise me to learn I'm approaching this all wrong.Edit: I suppose I should have included what behavior I'm seeing now. It does not identify the $prod variable in the go_to_target function and so always executes the else statement. In the past I've just put all production servers in the same group and used the $group_name in the if/else statement, but I'd like to get away from having to keep unrelated production servers in the same group.
.
.
.
.
The text was updated successfully, but these errors were encountered: