HostAndDir returns the name we're running commands on, which is empty if localhost (default), and the current directory on that host.
()
| 192 | // which is empty if localhost (default), |
| 193 | // and the current directory on that host. |
| 194 | func (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 |
| 213 | func (sh *Shell) SSHByHost(host string) (*sshclient.Client, error) { |