Eshel Yaron <[email protected]> writes: > Hi Michael,
Hi Eshel, >> I see. What about extending tramp-connection-properties to use also a >> function as property value? Something like >> >> (add-to-list 'tramp-connection-properties >> (list "^/kubedv2:kube-hostname:" "login-program" >> #'my-kubectl-function)) >> >> The regexp is always applied to the hop name, that is it is applied in >> both "/ssh:[email protected]|kubedv2:kubed-hostname:/some/file" and >> "/kubedv2:kube-hostname:/some/file" cases. my-kubectl-function could >> return a proper string based on some calculations over default-directory >> or whatever, don't know. > > Yeah, I think something like that could work. The important thing is > that my-kubectl-function needs access to the "previous" hop, the one on > which we will be executing the login-program. Also, since we're > choosing login-program based on the previous hop, not based on which > kube-hostname we connect to, we'll probably use this without specifying > any kube-hostname, so something like this: > > (add-to-list 'tramp-connection-properties > (list "^/kubedv2:" "login-program" #'my-kubectl-function)) OK. Appended is a patch which ought to implement this functionality. The function is called with the current connection vec, i.e. in your example (my-kubectl-function '(tramp-file-name "kubedv2" nil nil "kubed-hostname" nil "/some/file" "ssh:[email protected]|")) Everything untested. Does it make sense to you? > Best, > > Eshel Best regards, Michael.
diff --git a/lisp/tramp-cache.el b/lisp/tramp-cache.el index 1fc3fb3a..5b98ccf1 100644 --- a/lisp/tramp-cache.el +++ b/lisp/tramp-cache.el @@ -105,6 +105,9 @@ matches remote file names. It can be nil. PROPERTY is a string, and VALUE the corresponding value. They are used, if there is no matching entry for PROPERTY in `tramp-cache-data'. +If VALUE is a function, this function is called with the current vector +as argument. This vector includes all hops from a multi-hop file name. + PROPERTY can also be a string representing a parameter in `tramp-methods'. For more details see the Info node `(tramp) Predefined connection information'." @@ -153,7 +156,10 @@ If KEY is `tramp-cache-undefined', don't create anything, and return nil." (tramp-make-tramp-file-name key 'noloc)) ;; Mark it as taken from `tramp-connection-properties'. (tramp-set-connection-property - key (propertize (nth 1 elt) 'tramp-default t) (nth 2 elt))))) + key (propertize (nth 1 elt) 'tramp-default t) + (if (functionp (nth 2 elt)) + (funcall (nth 2 elt) (car tramp-current-connection)) + (nth 2 elt)))))) hash))))) ;; We cannot use the `declare' form for `tramp-suppress-trace' in
