From c38d587354da2ea8078fa87fb3d8b2d33705df9e Mon Sep 17 00:00:00 2001
From: Ayaz Badouraly <ayaz.badouraly@via.ecp.fr>
Date: Sun, 5 Nov 2017 22:47:42 +0100
Subject: [PATCH] Expanding full hostname as default behavior

---
 README.md                  |  3 +++
 functions/prompt_utils.zsh | 17 ++++++++++++++++-
 via.zsh-theme              |  1 +
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index d72cc74..e631187 100644
--- a/README.md
+++ b/README.md
@@ -54,6 +54,9 @@ ZSH_THEME="oh-my-via/via"
 Time format defaults to `%D{%H:%M}`, but can be overwritten by setting the variable
 `OHMYVIA_TIME_FORMAT` in your `~/.zshrc`.
 
+Hostname may be printed up to the first `.` or hidden with the variable
+`OHMYVIA_CONTEXT_HOSTNAME`.
+
 VCS theme can be set through the variable `OHMYVIA_VCS_THEME`.
 
 
diff --git a/functions/prompt_utils.zsh b/functions/prompt_utils.zsh
index cb97b97..b9177f6 100644
--- a/functions/prompt_utils.zsh
+++ b/functions/prompt_utils.zsh
@@ -10,8 +10,23 @@
 # See https://github.com/bhilburn/powerlevel9k/blob/1ff9da64d974265ce2f22bd1da4a47d0b8f7ca90/powerlevel9k.zsh-theme#L434
 prompt_context () {
 	local username="%(!.$OHMYVIA_CONTEXT_ROOT_COLOR.$OHMYVIA_CONTEXT_USER_COLOR)%n%b%f"
+
+	# Return only username if $OHMYVIA_CONTEXT_HOSTNAME is empty.
+	if [[ $OHMYVIA_CONTEXT_HOSTNAME == "empty" ]]; then
+		echo "${username}"
+		return
+	fi
+
 	local separator="$OHMYVIA_CONTEXT_SEPARATOR_COLOR@%b%f"
-	local hostname="$OHMYVIA_CONTEXT_HOSTNAME_COLOR%m%b%f"
+
+	# Handle hostnames containing `.` (defaults to full machine hostname prompt.)
+	local colorless_hostname="$OHMYVIA_CONTEXT_HOSTNAME"
+	if [[ $OHMYVIA_CONTEXT_HOSTNAME == 'full' ]]; then
+		colorless_hostname="%M"
+	elif [[ $OHMYVIA_CONTEXT_HOSTNAME == 'partial' ]]; then
+		colorless_hostname="%m"
+	fi
+	local hostname="$OHMYVIA_CONTEXT_HOSTNAME_COLOR${colorless_hostname}%b%f"
 
 	echo "${username}${separator}${hostname}"
 }
diff --git a/via.zsh-theme b/via.zsh-theme
index f981a92..564ae84 100644
--- a/via.zsh-theme
+++ b/via.zsh-theme
@@ -24,6 +24,7 @@ source $OHMYVIA_INSTALLATION_PATH/functions/vcs_utils.zsh
 
 ## Properties
 
+set_default OHMYVIA_CONTEXT_HOSTNAME         "full"
 set_default OHMYVIA_CONTEXT_HOSTNAME_COLOR   "%B%F{white}"
 set_default OHMYVIA_CONTEXT_SEPARATOR_COLOR  "%B%F{yellow}"
 set_default OHMYVIA_CONTEXT_ROOT_COLOR       "%B%F{blue}"
-- 
GitLab