2019-03-13 04:14:30 -07:00
|
|
|
package main
|
|
|
|
|
2022-01-26 04:53:35 -08:00
|
|
|
import (
|
|
|
|
"oh-my-posh/environment"
|
|
|
|
"oh-my-posh/properties"
|
|
|
|
)
|
2022-01-26 01:23:18 -08:00
|
|
|
|
2022-01-26 05:10:18 -08:00
|
|
|
type Session struct {
|
2022-01-26 04:53:35 -08:00
|
|
|
props properties.Properties
|
2022-01-26 01:23:18 -08:00
|
|
|
env environment.Environment
|
2022-01-22 10:46:56 -08:00
|
|
|
// text string
|
2021-12-03 14:44:58 -08:00
|
|
|
|
2022-01-17 04:16:04 -08:00
|
|
|
SSHSession bool
|
2021-12-03 14:44:58 -08:00
|
|
|
|
2021-12-04 01:22:38 -08:00
|
|
|
// Deprecated
|
2021-02-24 00:04:04 -08:00
|
|
|
DefaultUserName string
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
|
|
|
|
2022-01-26 05:26:56 -08:00
|
|
|
func (s *Session) Enabled() bool {
|
2021-02-24 00:04:04 -08:00
|
|
|
s.SSHSession = s.activeSSHSession()
|
2022-01-22 10:46:56 -08:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-01-26 05:26:56 -08:00
|
|
|
func (s *Session) Template() string {
|
2022-01-23 12:37:51 -08:00
|
|
|
return "{{ .UserName }}@{{ .HostName }}"
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
|
|
|
|
2022-01-26 05:26:56 -08:00
|
|
|
func (s *Session) Init(props properties.Properties, env environment.Environment) {
|
2019-03-13 04:14:30 -07:00
|
|
|
s.props = props
|
|
|
|
s.env = env
|
|
|
|
}
|
|
|
|
|
2022-01-26 05:10:18 -08:00
|
|
|
func (s *Session) activeSSHSession() bool {
|
2020-11-03 11:06:11 -08:00
|
|
|
keys := []string{
|
|
|
|
"SSH_CONNECTION",
|
|
|
|
"SSH_CLIENT",
|
|
|
|
}
|
|
|
|
for _, key := range keys {
|
2022-01-23 12:37:51 -08:00
|
|
|
content := s.env.Getenv(key)
|
2020-11-03 11:06:11 -08:00
|
|
|
if content != "" {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|