MCPcopy Create free account
hub / github.com/cogentcore/core / HostAndDir

Method HostAndDir

shell/shell.go:194–210  ·  view source on GitHub ↗

HostAndDir returns the name we're running commands on, which is empty if localhost (default), and the current directory on that host.

()

Source from the content-addressed store, hash-verified

192// which is empty if localhost (default),
193// and the current directory on that host.
194func (sh *Shell) HostAndDir() string {
195 host := ""
196 dir := sh.Config.Dir
197 home := errors.Log1(homedir.Dir())
198 cl := sh.ActiveSSH()
199 if cl != nil {
200 host = "@" + sh.SSHActive + ":" + cl.Host + ":"
201 dir = cl.Dir
202 home = cl.HomeDir
203 }
204 rel := errors.Log1(filepath.Rel(home, dir))
205 // if it has to go back, then it is not in home dir, so no ~
206 if strings.Contains(rel, "..") {
207 return host + dir + string(filepath.Separator)
208 }
209 return host + filepath.Join("~", rel) + string(filepath.Separator)
210}
211
212// SSHByHost returns the SSH client for given host name, with err if not found
213func (sh *Shell) SSHByHost(host string) (*sshclient.Client, error) {

Callers 1

PromptMethod · 0.80

Calls 3

ActiveSSHMethod · 0.95
Log1Function · 0.92
ContainsMethod · 0.45

Tested by

no test coverage detected