oh-my-posh/src/segment_session.go

46 lines
744 B
Go
Raw Normal View History

2019-03-13 04:14:30 -07:00
package main
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 {
return "{{ .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
}