Skip to content

Commit

Permalink
.bashrc, .zshrc: ホスト毎に色を変えるを256色に
Browse files Browse the repository at this point in the history
  • Loading branch information
tmsanrinsha committed Mar 24, 2012
1 parent c68bc73 commit df8b61f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 71 deletions.
70 changes: 35 additions & 35 deletions .bashrc
Expand Up @@ -17,46 +17,46 @@ complete -c man

# set prompt

# Solarized
# https://github.com/seebi/dircolors-solarized
# 現在のホストによってプロンプトの色を変える。
# http://absolute-area.com/post/6664864690/zshを参考にした
if [ `uname` = FreeBSD ];then
colnum=$((0x`hostname | md5 | cut -c1` % 8))
else
colnum=$((0x`hostname | md5sum | cut -c1` % 8))
fi
# `hostname | md5 | cut -c1`
# hostnameをmd5でハッシュに変更して、最初の一文字を取る
# $((0x`...` % 8))
# これを16進法の数値にして8の余りを求める。
# 8の余りを求めたのはsolarizedの8色だけ使いたいので
case $colnum in
0) col=136;; # yellow
1) col=166;; # brred
2) col=160;; # red
3) col=125;; # magenta
4) col=61;; # brmagenta
5) col=33;; # blue
6) col=37;; # cyan
7) col=64;; # green
esac

# 現在のホストによってプロンプトの色を変える。
# http://absolute-area.com/post/6664864690/zshを参考にした
## Solarized
## https://github.com/seebi/dircolors-solarized
## 現在のホストによってプロンプトの色を変える。
## http://absolute-area.com/post/6664864690/zshを参考にした
#if [ `uname` = FreeBSD ];then
# col=$((0x`hostname | md5 | cut -c1-8` % 214 + 17))
# colnum=$((0x`hostname | md5 | cut -c1` % 8))
#else
# col=$((0x`hostname | md5sum | cut -c1-8` % 214 + 17))
# colnum=$((0x`hostname | md5sum | cut -c1` % 8))
#fi
# hostnameをmd5でハッシュに変更する
# 長いとエラーが出るので最初の8文字を使う
# 0-15はdefault terminal color、
# 最後の24色はグレースケールなのでこれを取り除いた226色を使う
## `hostname | md5 | cut -c1`
## hostnameをmd5でハッシュに変更して、最初の一文字を取る
## $((0x`...` % 8))
## これを16進法の数値にして8の余りを求める。
## 8の余りを求めたのはsolarizedの8色だけ使いたいので
#case $colnum in
# 0) col=136;; # yellow
# 1) col=166;; # brred
# 2) col=160;; # red
# 3) col=125;; # magenta
# 4) col=61;; # brmagenta
# 5) col=33;; # blue
# 6) col=37;; # cyan
# 7) col=64;; # green
#esac

# 現在のホストによってプロンプトの色を変える。
# http://absolute-area.com/post/6664864690/zshを参考にした
# 256色の内、カラーで背景黒の時見やすい色はこの217色かな
colArr=({1..6} {9..14} {22..186} {190..229})
# xtermの色についてはこちら
# http://frexx.de/xterm-256-notes/
PS1="\[\e[38;5;${col}m\][\h:\w]\\$ \[\e[0m\]"
#PS1="\[\e[0;${col}m\][\h:\w]\\$ \[\e[0m\]"

# hostnameをmd5でハッシュに変更する
# 長いとエラーが出るので最初の8文字を使う
if [ `uname` = FreeBSD ];then
num=$((0x`hostname | md5 | cut -c1-8` % 217)) # zshの配列のインデックスは0から
else
num=$((0x`hostname | md5sum | cut -c1-8` % 217))
fi
PS1="\[\e[38;5;${colArr[$num]}m\][\h:\w]\\$ \[\e[0m\]"
#PS1="\[\e[0;${col}m\][\u@\h \w]\\$ \[\e[0m\]"


Expand Down
71 changes: 35 additions & 36 deletions .zshrc
Expand Up @@ -129,49 +129,48 @@ unsetopt promptcr
#C-zでサスペンドしたとき(18)以外のエラー終了時に%#を赤く表示
local pct="%0(?||%18(?||%{"$'\e'"[31m%}))%#%{"$'\e'"[m%}"

# Solarized
# https://github.com/seebi/dircolors-solarized
# 現在のホストによってプロンプトの色を変える。
# http://absolute-area.com/post/6664864690/zshを参考にした
if [ `uname` = FreeBSD ];then
colnum=$((0x`hostname | md5 | cut -c1` % 8))
else
colnum=$((0x`hostname | md5sum | cut -c1` % 8))
fi
# `hostname | md5 | cut -c1`
# hostnameをmd5でハッシュに変更して、最初の一文字を取る
# $((0x`...` % 8))
# これを16進法の数値にして8の余りを求める。
# 8の余りを求めたのはsolarizedの8色だけ使いたいので
case $colnum in
0) col=136;; # yellow
1) col=166;; # brred
2) col=160;; # red
3) col=125;; # magenta
4) col=61;; # brmagenta
5) col=33;; # blue
6) col=37;; # cyan
7) col=64;; # green
esac

# 現在のホストによってプロンプトの色を変える。
# http://absolute-area.com/post/6664864690/zshを参考にした
## Solarized
## https://github.com/seebi/dircolors-solarized
## 現在のホストによってプロンプトの色を変える。
## http://absolute-area.com/post/6664864690/zshを参考にした
#if [ `uname` = FreeBSD ];then
# col=$((0x`hostname | md5 | cut -c1-8` % 214 + 17))
# colnum=$((0x`hostname | md5 | cut -c1` % 8))
#else
# col=$((0x`hostname | md5sum | cut -c1-8` % 214 + 17))
# colnum=$((0x`hostname | md5sum | cut -c1` % 8))
#fi
# hostnameをmd5でハッシュに変更する
# 長いとエラーが出るので最初の8文字を使う
# 0-15はdefault terminal color、
# 最後の24色はグレースケールなのでこれを取り除いた226色だが
# 最初と最後の方は見にくので17-230までを使う
## `hostname | md5 | cut -c1`
## hostnameをmd5でハッシュに変更して、最初の一文字を取る
## $((0x`...` % 8))
## これを16進法の数値にして8の余りを求める。
## 8の余りを求めたのはsolarizedの8色だけ使いたいので
#case $colnum in
# 0) col=136;; # yellow
# 1) col=166;; # brred
# 2) col=160;; # red
# 3) col=125;; # magenta
# 4) col=61;; # brmagenta
# 5) col=33;; # blue
# 6) col=37;; # cyan
# 7) col=64;; # green
#esac

# 現在のホストによってプロンプトの色を変える。
# http://absolute-area.com/post/6664864690/zshを参考にした
# 256色の内、カラーで背景黒の時見やすい色はこの217色かな
colArr=({1..6} {9..14} {22..186} {190..229})
# xtermの色についてはこちら
# http://frexx.de/xterm-256-notes/

# hostnameをmd5でハッシュに変更する
# 長いとエラーが出るので最初の8文字を使う
if [ `uname` = FreeBSD ];then
num=$((0x`hostname | md5 | cut -c1-8` % 217 + 1)) # zshの配列のインデックスは1から
else
num=$((0x`hostname | md5sum | cut -c1-8` % 217 + 1))
fi
#PROMPT="%{"$'\e'"[${col}m%}[%n@%m:%~]$pct "
PROMPT="%{"$'\e'"[38;5;${col}m%}[%m:%~]$pct "
PROMPT2="%{"$'\e'"[38;5;${col}m%}%_%#%{"$'\e'"[m%} "
PROMPT="%{"$'\e'"[38;5;${colArr[$num]}m%}[%m:%~]$pct "
PROMPT2="%{"$'\e'"[38;5;${colArr[$num]}m%}%_%#%{"$'\e'"[m%} "
SPROMPT="%{"$'\e'"[31m%}%r is correct? [y,n,a,e]:%{"$'\e'"[m%} "

# set terminal title including current directory
Expand Down

0 comments on commit df8b61f

Please sign in to comment.