Closed valentinocossar closed 3 years ago
Ok, I understand the request. Maybe we can follow the logic applied to my version of SSH. The file host to read match the pattern config. For example:
.ssh
- config.hssh.d
- host01
- host02
- config.agency.d
- host_a
- host_b
- config
- config.2
The system matches each file contained in a folder with name contains config and the same for the files. In this case the file to read will be:
- config.hssh.d/host01
- config.hssh.d/host02
- config.agency.d/host_a
- config.agency.d/host_b
- config
- config.2
Or maybe we can read a config file and take all files included.
# config
Include config.hssh.d/*
Include config.agency.d/*
Include config.2
This alternative maybe is more declarative and less prone to errors.
@CasvalDOT yes, I prefer the first option, we can find valid hosts inside the .ssh
folder with these 2 criteria:
config
as pattern in the nameconfig
as pattern in the nameBut the CLI will only include config.hssh.d
folder inside .ssh/config
file automatically, other includes have to be added manually to the file.
What do you think?
I really like the first solution, but in my opinion the second is more robust as it would not generate errors due to the lack of the host
@valentinocossar, I've created the first possible implementation about this improvement. Now the list command (find and connect use the same logic) use this procedure:
I've also tried to optimize the read / parsing process adding goroutines. A nice to have will be discriminated unique host configurations.
When you have a moment try it to develop branch.
NOTE:
This is a first approach. An analysis must be performed to understand which patterns are allowed in the Include syntax. Currently, the system know a folder if the string have the * or / as final character, but what's happen if the included have this pattern?
# Using wildcard in the middle of the string
Include config*meta/*
It is allowed and must be managed? If so, the reading of files and folders should be managed differently.
@CasvalDOT Super! As far as I know, the most used includes patterns are:
Include folder/*
Include folder/file
Include /absolute/path/folder/*
Include /absolute/pathfolder/file
Include ~/folder/*
Include ~/folder/file
So at this time, we can only support these integrations.
But I discovered that in the Include
declaration you can use the wildcard in each step of the path. More info in the Include description below:
Include
Include the specified configuration file(s). Mul‐
tiple pathnames may be specified and each pathname
may contain glob(3) wildcards and, for user config‐
urations, shell-like “~” references to user home
directories. Files without absolute paths are
assumed to be in ~/.ssh if included in a user con‐
figuration file or /etc/ssh if included from the
system configuration file. Include directive may
appear inside a Match or Host block to perform con‐
ditional inclusion.
The support for the wildcard in each pathname can be a further improvement to consider in the next releases.
At this point, I'll test the integration as soon as possible to give you feedback about any improvement or bug.
Ok! I miss handling the ~ character.
@valentinocossar, I've push another version. I reduced the logic and using filepath.Glob(...)
I can now resolve every wildcard.
I've also add the ~ handler
👍🏻 I'll test it along with all other features!
Add
~/.ssh/config
custom hosts to connect and find commands. Allow using custom hosts not added by the sync command but added manually to the~/.ssh/config
file.