oh-my-posh/src/segments/session.go

46 lines
786 B
Go
Raw Normal View History

2022-01-26 06:54:36 -08:00
package segments
2019-03-13 04:14:30 -07:00
import (
"oh-my-posh/environment"
"oh-my-posh/properties"
)
2022-01-26 05:10:18 -08:00
type Session struct {
props properties.Properties
env environment.Environment
2022-01-22 10:46:56 -08:00
// text string
2021-12-03 14:44:58 -08:00
SSHSession bool
2021-12-03 14:44:58 -08:00
2021-12-04 01:22:38 -08:00
// Deprecated
DefaultUserName string
2019-03-13 04:14:30 -07:00
}
func (s *Session) Enabled() bool {
s.SSHSession = s.activeSSHSession()
2022-01-22 10:46:56 -08:00
return true
}
func (s *Session) Template() string {
2022-02-01 05:07:58 -08:00
return " {{ if .SSHSession }}\uf817 {{ end }}{{ .UserName }}@{{ .HostName }} "
2019-03-13 04:14:30 -07: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 {
keys := []string{
"SSH_CONNECTION",
"SSH_CLIENT",
}
for _, key := range keys {
content := s.env.Getenv(key)
if content != "" {
return true
}
}
return false
}