diff --git a/README.md b/README.md index d72cc74965ed7a74d05fd50c1424d8b11cba60a7..e63118753d8ef44f1f16159734462552055734c5 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 cb97b975eb5dfb426eded1cf7844471a6d6b98ae..b9177f612e6dfdf0f2de09094e1336c601878738 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 f981a92c48c53350b9b8549503ffb6474ec93ede..564ae84f21cb95520b8606992f6908239f7dd7d7 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}"