Permalink
Browse files

Change all hostname calls for $HOST or $SHORT_HOST

  • Loading branch information...
1 parent 4310a15 commit 95d795e8cad7d1a754dfad520309d7a41b69275f @mcornella mcornella committed Oct 9, 2014
@@ -2,7 +2,7 @@
# This will look for a custom profile for the local machine and each domain or
# subdomain it belongs to. (e.g. com, example.com and foo.example.com)
-parts=(${(s:.:)$(hostname)})
+parts=(${(s:.:)$HOST})
for i in {${#parts}..1}; do
profile=${(j:.:)${parts[$i,${#parts}]}}
file=$ZSH_CUSTOM/profiles/$profile
@@ -13,7 +13,7 @@ patches: <patches|join( → )|pre_applied(%{$fg[yellow]%})|post_applied(%{$reset
}
function box_name {
- [ -f ~/.box-name ] && cat ~/.box-name || hostname -s
+ [ -f ~/.box-name ] && cat ~/.box-name || echo $SHORT_HOST || echo $HOST
@blueyed
blueyed Dec 4, 2014 Contributor

The first echo will be true always.
Same below.

@mcornella
mcornella Jan 15, 2015 Collaborator

Fixed in #3494 by @AlexTalker

}
PROMPT='
@@ -21,7 +21,7 @@ local user="%(!.%{$fg[blue]%}.%{$fg[blue]%})%n%{$reset_color%}"
# Hostname part. compressed and colorcoded per host_repr array
# if not found, regular hostname in default color
-local host="@${host_repr[$(hostname)]:-$(hostname)}%{$reset_color%}"
+local host="@${host_repr[$HOST]:-$HOST}%{$reset_color%}"
@gexarcha
gexarcha Nov 25, 2014

I think SHORT_HOST here would be better.

@AlexTalker
AlexTalker Jan 15, 2015 Contributor

Hey hey hey, folks
In my system $SHORT_HOST doesn't exist at all(Arch Linux)
And echo don't care about it
So, may be you must checkout existing this var before use it?(Else it's just empty)

@mcornella
mcornella Jan 15, 2015 Collaborator

@gexarcha let's see. The idea behind this line I think was to be able to define a particular entry with the hostname and have it translated into a uniquely short, color-coded string (see host_repr definition in line 12).

That said, the logic applied doesn't seem to allow for a custom host_repr variable to be set, since it will be overwritten if the variable is defined before oh-my-zsh is initialized, and it won't be used if it's defined after. So it doesn't matter which one we use because either way nobody is possibly using this feature because it's broken. So we could change it to use $SHORT_HOST.

That said, I believe $HOST is a better alternative here: consider a sysadmin who has the same hostname in two machines, but are on separate networks; maybe said sysadmin works as a consultant in two different enterprises that both have an atlas server. In that case, $SHORT_HOST will be atlas in both, while $HOST will be atlas.evilcorp.net and atlas.notevil.org, allowing the sysadmin to better distinguish those.

I think the logic should be fixed, but the $HOST is good as it is. What do you think?

@gexarcha
gexarcha Jan 15, 2015

Yes, I think you are right.
In general I like the theme but I thought the hostname was too long for no good reason. Fixing the logic though seems like a better option as it would serve more use cases

# Compacted $PWD
local pwd="%{$fg[blue]%}%c%{$reset_color%}"
@@ -21,7 +21,7 @@ function prompt_char {
}
function box_name {
- [ -f ~/.box-name ] && cat ~/.box-name || hostname -s
+ [ -f ~/.box-name ] && cat ~/.box-name || echo $SHORT_HOST || echo $HOST
}
@@ -17,7 +17,7 @@ function prompt_char {
}
function box_name {
- [ -f ~/.box-name ] && cat ~/.box-name || hostname -s
+ [ -f ~/.box-name ] && cat ~/.box-name || echo $SHORT_HOST || echo $HOST
}
local ruby_env=''
@@ -1,7 +1,7 @@
# Simple theme based on my old zsh settings.
function get_host {
- echo '@'`hostname`''
+ echo '@'$HOST
}
PROMPT='> '
@@ -17,7 +17,7 @@ USERNAME_NORMAL_COLOR=$WHITE
USERNAME_ROOT_COLOR=$RED
HOSTNAME_NORMAL_COLOR=$BLUE
# uncomment next line if you want auto-generated hostname color
-#for i in `hostname`; HOSTNAME_NORMAL_COLOR=$COLOR_ARRAY[$[((#i))%7+1]]
+#for i in $HOST; HOSTNAME_NORMAL_COLOR=$COLOR_ARRAY[$[((#i))%7+1]]
HOSTNAME_ROOT_COLOR=$RED
HOSTNAME_COLOR=%(!.$HOSTNAME_ROOT_COLOR.$HOSTNAME_NORMAL_COLOR)
CURRENT_DIR_COLOR=$CYAN
View
@@ -8,7 +8,7 @@
# Machine name.
function box_name {
- [ -f ~/.box-name ] && cat ~/.box-name || hostname
+ [ -f ~/.box-name ] && cat ~/.box-name || echo $HOST
}
# Directory info.

0 comments on commit 95d795e

Please sign in to comment.