Created
March 30, 2014 11:29
-
-
Save rhenium/9871466 to your computer and use it in GitHub Desktop.
Powerline 的なやつ(Powerline 重いっす)
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
function weakline_precmd() { | |
last_code=$? | |
export PROMPT="$(/srv/sh/weakline-zsh/weakline -m left -l $last_code)" | |
export RPROMPT="$(/srv/sh/weakline-zsh/weakline -m right -l $last_code)" | |
} | |
precmd_functions+=(weakline_precmd) |
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
#!/bin/sh | |
SEGMENTS_LEFT=(last hostname_if_ssh username readonlydir pwd prompt) | |
SEGMENTS_RIGHT=(jobs) | |
PROMPT_END="" | |
SEPARATOR_LEFT="" | |
SEPARATOR_RIGHT="" | |
READONLY_MARK="" | |
# SEGMENTS {{{ | |
hostname_if_ssh() { | |
if [ $SSH_TTY ]; then | |
setfgcolor 254 | |
setbgcolor 166 | |
echo -n " %m " | |
fi | |
} | |
username() { | |
setfgcolor 250 | |
if [ $USER = "root" ]; then | |
setbgcolor 124 | |
else | |
setbgcolor 240 | |
fi | |
echo -n " %n " | |
} | |
pwd() { | |
name="$PWD" | |
[[ "$name" =~ ^"$HOME"(/|$) ]] && name="~${name#$HOME}" || name="${name#/}" | |
setfgcolor 250 | |
setbgcolor 237 | |
echo -n " ${name//\// $(setfgcolor 244)$SEPARATOR$(setfgcolor 250) } " | |
} | |
jobs() { | |
ppid=$(ps -p$$ -oppid=) | |
c=0 | |
for q in `ps -aoppid=`; do | |
if [ $q = $ppid ]; then | |
let c=$c+1 | |
fi | |
done | |
if [ $c -gt 1 ]; then | |
setfgcolor 39 | |
setbgcolor 238 | |
echo -n " $(expr $c - 1) " | |
fi | |
} | |
last() { | |
if [ $LASTCODE -ne 0 ]; then | |
setfgcolor 15 | |
setbgcolor 161 | |
echo -n " $LASTCODE " | |
fi | |
} | |
prompt() { | |
resetcolor | |
setfgcolor 237 | |
echo -n $PROMPT_END | |
} | |
readonlydir() { | |
if [ ! -w "$PWD" ]; then | |
setfgcolor 254 | |
setbgcolor 124 | |
echo -n " $READONLY_MARK " | |
fi | |
} | |
# }}} | |
setfgcolor() { | |
echo -ne "%{\x1B[38;5;$1m%}" | |
} | |
setbgcolor() { | |
echo -ne "%{\x1B[48;5;$1m%}" | |
} | |
resetcolor() { | |
echo -ne "%{\x1B[0m%}" | |
} | |
while getopts m:l: OPT; do | |
case $OPT in | |
m) MODE=$OPTARG ;; | |
l) LASTCODE=$OPTARG ;; | |
esac | |
done | |
case $MODE in | |
left) | |
SEPARATOR=$SEPARATOR_LEFT | |
for seg in ${SEGMENTS_LEFT[@]}; do $seg; done | |
resetcolor | |
;; | |
right) | |
SEPARATOR=$SEPARATOR_RIGHT | |
for seg in ${SEGMENTS_RIGHT[@]}; do $seg; done | |
resetcolor | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment