From 1c064f3e82bd57169f663e58cc89e5ed1ef3d07c Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Mon, 1 Aug 2016 17:24:20 +0200 Subject: [PATCH] dynamically generate hostname color --- .zsh/oh-my-custom/luzifer.zsh-theme | 2 +- bin/color_from_hostname.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100755 bin/color_from_hostname.py diff --git a/.zsh/oh-my-custom/luzifer.zsh-theme b/.zsh/oh-my-custom/luzifer.zsh-theme index bbced78..c03cdcb 100644 --- a/.zsh/oh-my-custom/luzifer.zsh-theme +++ b/.zsh/oh-my-custom/luzifer.zsh-theme @@ -17,7 +17,7 @@ function prompt_char { } function box_color { - [ -f ~/.box_color ] && cat ~/.box_color || echo '$FG[033]' + [ -f ~/.box_color ] && cat ~/.box_color || ~/bin/color_from_hostname.py } function box_name { diff --git a/bin/color_from_hostname.py b/bin/color_from_hostname.py new file mode 100755 index 0000000..c040d94 --- /dev/null +++ b/bin/color_from_hostname.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python + +import socket + +hostname = socket.gethostname() + +s = 0 +for c in hostname: + s = s + ord(c) + +color = str(1 + s % 14).rjust(3, '0') +print '$FG[{}]'.format(color)