Skip to content

Commit

Permalink
Add ability to use the FQDN as hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
dcm committed Feb 26, 2025
1 parent cba7918 commit f4dae20
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ Usage of powerline-go:
Show the older, original icon for SSH connections
-colorize-hostname
Colorize the hostname based on a hash of itself, or use the PLGO_HOSTNAMEFG and PLGO_HOSTNAMEBG env vars (both need to be set).
-fqdn-hostname
Use the longer fully qualified domain name as the hostname
-condensed
Remove spacing between segments
-cwd-max-depth int
Expand Down
3 changes: 2 additions & 1 deletion args.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type arguments struct {
CwdMaxDepth *int
CwdMaxDirSize *int
ColorizeHostname *bool
FqdnHostname *bool
HostnameOnlyIfSSH *bool
SshAlternateIcon *bool
EastAsianWidth *bool
Expand Down Expand Up @@ -69,7 +70,7 @@ var args = arguments{
FqdnHostname: flag.Bool(
"fqdn-hostname",
defaults.FqdnHostname,
comments("Display the fully qualified domain name as ")),
comments("Use the longer fully qualified domain name as the hostname")),
HostnameOnlyIfSSH: flag.Bool(
"hostname-only-if-ssh",
defaults.HostnameOnlyIfSSH,
Expand Down
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Config struct {
CwdMaxDepth int `json:"cwd-max-depth"`
CwdMaxDirSize int `json:"cwd-max-dir-size"`
ColorizeHostname bool `json:"colorize-hostname"`
FqdnHostname bool `json:"fqdn-hostname"`
HostnameOnlyIfSSH bool `json:"hostname-only-if-ssh"`
SshAlternateIcon bool `json:"alternate-ssh-icon"`
EastAsianWidth bool `json:"east-asian-width"`
Expand Down
3 changes: 2 additions & 1 deletion defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var defaults = Config{
CwdMaxDepth: 5,
CwdMaxDirSize: -1,
ColorizeHostname: false,
FqdnHostname: false,
HostnameOnlyIfSSH: false,
SshAlternateIcon: false,
EastAsianWidth: false,
Expand Down Expand Up @@ -147,7 +148,7 @@ var defaults = Config{
EvalPromptRightSuffix: `"`,
},
"bare": {
ColorTemplate: "%s",
ColorTemplate: "%s",
RootIndicator: "$",
EscapedBackslash: `\`,
EscapedBacktick: "`",
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ func main() {
cfg.CwdMaxDirSize = *args.CwdMaxDirSize
case "colorize-hostname":
cfg.ColorizeHostname = *args.ColorizeHostname
case "fqdn-hostname":
cfg.FqdnHostname = *args.FqdnHostname
case "hostname-only-if-ssh":
cfg.HostnameOnlyIfSSH = *args.HostnameOnlyIfSSH
case "alternate-ssh-icon":
Expand Down
9 changes: 6 additions & 3 deletions segment-hostname.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import (
"strings"
)

func getHostName(fullyQualifiedDomainName string) string {
func getHostName(fullyQualifiedDomainName string, keepFqdnHostname bool) string {
if keepFqdnHostname {
return fullyQualifiedDomainName
}
return strings.SplitN(fullyQualifiedDomainName, ".", 2)[0]
}

Expand All @@ -30,7 +33,7 @@ func segmentHost(p *powerline) []pwl.Segment {
}

if p.cfg.ColorizeHostname {
hostName := getHostName(p.hostname)
hostName := getHostName(p.hostname, p.cfg.FqdnHostname)
hostPrompt = hostName

foregroundEnv, foregroundEnvErr := strconv.ParseUint(os.Getenv("PLGO_HOSTNAMEFG"), 0, 8)
Expand All @@ -49,7 +52,7 @@ func segmentHost(p *powerline) []pwl.Segment {
} else if p.cfg.Shell == "zsh" {
hostPrompt = "%m"
} else {
hostPrompt = getHostName(p.hostname)
hostPrompt = getHostName(p.hostname, p.cfg.FqdnHostname)
}

foreground = p.theme.HostnameFg
Expand Down

0 comments on commit f4dae20

Please sign in to comment.