Created
August 17, 2019 06:26
-
-
Save gavinwy/47d3af89813608d1218d0cfbaeda2d17 to your computer and use it in GitHub Desktop.
WIP hostname coloring based on OS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
# Copyright 2019 Gavin Weifert-Yeh | |
# | |
# Copying and distribution of this file, with or without modification, | |
# are permitted in any medium without royalty provided the copyright | |
# notice and this notice are preserved. This file is offered as-is, | |
# without any warranty. | |
gwy_prompt_host_color() { | |
local os_for_prompt | |
local kernel_name | |
kernel_name=$(uname -s) | |
case "$kernel_name" in | |
('Linux') | |
# Gets from os-release file if present. File is present on all systemd OSes. | |
if [[ -f /etc/os-release ]]; then os_for_prompt=$(cat /etc/os-release \ | |
| grep '^ID=' \ | |
| cut -c 4- | most) | |
else os_for_prompt='Linux' | |
fi | |
;; | |
('Darwin') | |
os_for_prompt='Darwin' | |
;; | |
('*BSD') | |
if [[ "$kernel_name" == 'FreeBSD' ]]; then | |
os_for_prompt='FreeBSD' | |
elif [[ "$kernel_name" == 'NetBSD' ]]; then | |
os_for_prompt='NetBSD' | |
elif [[ "$kernel_name" == 'OpenBSD' ]]; then | |
os_for_prompt='OpenBSD' | |
else | |
os_for_prompt='unknown_BSD' | |
fi | |
;; | |
('DragonFly') | |
os_for_prompt='DragonFly' | |
;; | |
('CYGWIN') | |
os_for_prompt='CYGWIN' | |
;; | |
(*) | |
os_for_prompt='unknown' | |
;; | |
esac | |
case "$os_for_prompt" in | |
('arch') | |
echo $'%{\e[38;2;23;147;209m%}' | |
;; | |
('centos') | |
echo $'%{\e[38;2;164;70;143m%}' | |
;; | |
('CYGWIN') | |
echo $'%{\e[38;2;222;0;0m%}' | |
;; | |
('Darwin') | |
echo $'%{\e[38;2;99;99;99m%}' | |
;; | |
('DragonFly') | |
echo $'%{\e[38;2;179;211;69m%}' | |
;; | |
('debian') | |
echo $'%{\e[38;2;199;0;54m%}' | |
;; | |
('fedora') | |
echo $'%{\e[38;2;41;65;114m%}' | |
;; | |
('FreeBSD') | |
echo $'%{\e[38;2;239;0;0m%}' | |
;; | |
('gentoo') | |
echo $'%{\e[38;2;203;199;255m%}' | |
;; | |
('Linux') | |
echo $'%{\e[38;2;252;198;36m%}' | |
;; | |
('linuxmint') | |
echo $'%{\e[38;2;191;255;128m%}' | |
;; | |
('NetBSD') | |
echo $'%{\e[38;2;242;103;17m%}' | |
;; | |
('other_BSD') | |
echo $'%{\e[38;2;190;0;0m%}' | |
;; | |
('puppy') | |
echo $'%{\e[38;2;205;205;205m%}' | |
;; | |
('rhel') | |
echo $'%{\e[38;2;238;0;0m%}' | |
;; | |
('slackware') | |
echo $'%{\e[38;2;115;0;0m%}' | |
;; | |
('SunOS') # Includes Solaris. | |
echo $'%{\e[38;2;85;131;163m%}' | |
;; | |
('ubuntu') | |
echo $'%{\e[38;2;233;84;32m%}' | |
;; | |
('WSL') # Windows Subsystem for Linux | |
echo $'%{\e[38;2;0;103;184m%}' | |
;; | |
esac | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment