add zsh config
This commit is contained in:
parent
35674f2e8a
commit
ffe0142fed
340
.zsh/func/prompt_grb_setup
Normal file
340
.zsh/func/prompt_grb_setup
Normal file
|
@ -0,0 +1,340 @@
|
|||
# grb prompt theme
|
||||
# copied from wunjo prompt theme and modified
|
||||
|
||||
autoload -U zgitinit
|
||||
zgitinit
|
||||
|
||||
prompt_grb_help () {
|
||||
cat <<'EOF'
|
||||
|
||||
prompt grb
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
revstring() {
|
||||
git describe --always $1 2>/dev/null ||
|
||||
git rev-parse --short $1 2>/dev/null
|
||||
}
|
||||
|
||||
coloratom() {
|
||||
local off=$1 atom=$2
|
||||
if [[ $atom[1] == [[:upper:]] ]]; then
|
||||
off=$(( $off + 60 ))
|
||||
fi
|
||||
echo $(( $off + $colorcode[${(L)atom}] ))
|
||||
}
|
||||
colorword() {
|
||||
local fg=$1 bg=$2 att=$3
|
||||
local -a s
|
||||
|
||||
if [ -n "$fg" ]; then
|
||||
s+=$(coloratom 30 $fg)
|
||||
fi
|
||||
if [ -n "$bg" ]; then
|
||||
s+=$(coloratom 40 $bg)
|
||||
fi
|
||||
if [ -n "$att" ]; then
|
||||
s+=$attcode[$att]
|
||||
fi
|
||||
|
||||
echo "%{"$'\e['${(j:;:)s}m"%}"
|
||||
}
|
||||
|
||||
function minutes_since_last_commit {
|
||||
now=`date +%s`
|
||||
last_commit=`git log --pretty=format:'%at' -1 2>/dev/null`
|
||||
if $lastcommit ; then
|
||||
seconds_since_last_commit=$((now-last_commit))
|
||||
minutes_since_last_commit=$((seconds_since_last_commit/60))
|
||||
echo $minutes_since_last_commit
|
||||
else
|
||||
echo "-1"
|
||||
fi
|
||||
}
|
||||
|
||||
function prompt_grb_scm_time_since_commit() {
|
||||
local -A pc
|
||||
pc=(${(kv)wunjo_prompt_colors})
|
||||
|
||||
if zgit_inworktree; then
|
||||
local MINUTES_SINCE_LAST_COMMIT=`minutes_since_last_commit`
|
||||
if [ "$MINUTES_SINCE_LAST_COMMIT" -eq -1 ]; then
|
||||
COLOR="$pc[scm_time_uncommitted]"
|
||||
local SINCE_LAST_COMMIT="${COLOR}uncommitted$pc[reset]"
|
||||
else
|
||||
if [ "$MINUTES_SINCE_LAST_COMMIT" -gt 30 ]; then
|
||||
COLOR="$pc[scm_time_long]"
|
||||
elif [ "$MINUTES_SINCE_LAST_COMMIT" -gt 10 ]; then
|
||||
COLOR="$pc[scm_time_medium]"
|
||||
else
|
||||
COLOR="$pc[scm_time_short]"
|
||||
fi
|
||||
local SINCE_LAST_COMMIT="${COLOR}$(minutes_since_last_commit)m$pc[reset]"
|
||||
fi
|
||||
echo $SINCE_LAST_COMMIT
|
||||
fi
|
||||
}
|
||||
|
||||
function prompt_grb_scm_info() {
|
||||
if zgit_inworktree; then
|
||||
echo "($(prompt_wunjo_scm_branch))"
|
||||
fi
|
||||
}
|
||||
|
||||
prompt_grb_setup() {
|
||||
local verbose
|
||||
if [[ $TERM == screen* ]] && [ -n "$STY" ]; then
|
||||
verbose=
|
||||
else
|
||||
verbose=1
|
||||
fi
|
||||
|
||||
typeset -A colorcode
|
||||
colorcode[black]=0
|
||||
colorcode[red]=1
|
||||
colorcode[green]=2
|
||||
colorcode[yellow]=3
|
||||
colorcode[blue]=4
|
||||
colorcode[magenta]=5
|
||||
colorcode[cyan]=6
|
||||
colorcode[white]=7
|
||||
colorcode[default]=9
|
||||
colorcode[k]=$colorcode[black]
|
||||
colorcode[r]=$colorcode[red]
|
||||
colorcode[g]=$colorcode[green]
|
||||
colorcode[y]=$colorcode[yellow]
|
||||
colorcode[b]=$colorcode[blue]
|
||||
colorcode[m]=$colorcode[magenta]
|
||||
colorcode[c]=$colorcode[cyan]
|
||||
colorcode[w]=$colorcode[white]
|
||||
colorcode[.]=$colorcode[default]
|
||||
|
||||
typeset -A attcode
|
||||
attcode[none]=00
|
||||
attcode[bold]=01
|
||||
attcode[faint]=02
|
||||
attcode[standout]=03
|
||||
attcode[underline]=04
|
||||
attcode[blink]=05
|
||||
attcode[reverse]=07
|
||||
attcode[conceal]=08
|
||||
attcode[normal]=22
|
||||
attcode[no-standout]=23
|
||||
attcode[no-underline]=24
|
||||
attcode[no-blink]=25
|
||||
attcode[no-reverse]=27
|
||||
attcode[no-conceal]=28
|
||||
|
||||
local -A pc
|
||||
pc[default]='default'
|
||||
pc[date]='cyan'
|
||||
pc[time]='Blue'
|
||||
pc[host]='Green'
|
||||
pc[user]='cyan'
|
||||
pc[punc]='yellow'
|
||||
pc[line]='magenta'
|
||||
pc[hist]='green'
|
||||
pc[path]='Cyan'
|
||||
pc[shortpath]='default'
|
||||
pc[rc]='red'
|
||||
pc[scm_branch]='green'
|
||||
pc[scm_commitid]='Yellow'
|
||||
pc[scm_status_dirty]='Red'
|
||||
pc[scm_status_staged]='Green'
|
||||
pc[scm_time_short]='green'
|
||||
pc[scm_time_medium]='yellow'
|
||||
pc[scm_time_long]='red'
|
||||
pc[scm_time_uncommitted]='Magenta'
|
||||
pc[#]='Yellow'
|
||||
for cn in ${(k)pc}; do
|
||||
pc[${cn}]=$(colorword $pc[$cn])
|
||||
done
|
||||
pc[reset]=$(colorword . . 00)
|
||||
|
||||
typeset -Ag wunjo_prompt_colors
|
||||
wunjo_prompt_colors=(${(kv)pc})
|
||||
|
||||
local p_date p_line p_rc
|
||||
|
||||
p_date="$pc[date]%D{%Y-%m-%d} $pc[time]%D{%T}$pc[reset]"
|
||||
|
||||
p_line="$pc[line]%y$pc[reset]"
|
||||
|
||||
PROMPT=
|
||||
if [ $verbose ]; then
|
||||
PROMPT+="$pc[host]%m$pc[reset]"
|
||||
fi
|
||||
#PROMPT+="$pc[path]%(2~.%~.%/)$pc[reset]"
|
||||
#PROMPT+="\$(prompt_wunjo_scm_status)"
|
||||
#PROMPT+="%(?.. $pc[rc]exited %1v$pc[reset])"
|
||||
# PROMPT+="
|
||||
#"
|
||||
#PROMPT+="($pc[hist]%h$pc[reset])"
|
||||
PROMPT+=":$pc[shortpath]%1~$pc[reset]"
|
||||
PROMPT+="($pc[scm_branch]\$(prompt_wunjo_scm_branch)$pc[reset])"
|
||||
PROMPT+=" $pc[#]\$$pc[reset] "
|
||||
|
||||
#RPROMPT=
|
||||
#if [ $verbose ]; then
|
||||
# RPROMPT+="$p_date "
|
||||
#fi
|
||||
#RPROMPT+="$pc[user]%n$pc[reset]"
|
||||
#RPROMPT+=" $p_line"
|
||||
|
||||
export PROMPT RPROMPT
|
||||
precmd_functions+='prompt_wunjo_precmd'
|
||||
}
|
||||
|
||||
prompt_wunjo_precmd() {
|
||||
local ex=$?
|
||||
psvar=()
|
||||
|
||||
if [[ $ex -ge 128 ]]; then
|
||||
sig=$signals[$ex-127]
|
||||
psvar[1]="sig${(L)sig}"
|
||||
else
|
||||
psvar[1]="$ex"
|
||||
fi
|
||||
}
|
||||
|
||||
prompt_wunjo_scm_status() {
|
||||
zgit_isgit || return
|
||||
local -A pc
|
||||
pc=(${(kv)wunjo_prompt_colors})
|
||||
|
||||
head=$(zgit_head)
|
||||
gitcommit=$(revstring $head)
|
||||
|
||||
local -a commits
|
||||
|
||||
if zgit_rebaseinfo; then
|
||||
orig_commit=$(revstring $zgit_info[rb_head])
|
||||
orig_name=$(git name-rev --name-only $zgit_info[rb_head])
|
||||
orig="$pc[scm_branch]$orig_name$pc[punc]($pc[scm_commitid]$orig_commit$pc[punc])"
|
||||
onto_commit=$(revstring $zgit_info[rb_onto])
|
||||
onto_name=$(git name-rev --name-only $zgit_info[rb_onto])
|
||||
onto="$pc[scm_branch]$onto_name$pc[punc]($pc[scm_commitid]$onto_commit$pc[punc])"
|
||||
|
||||
if [ -n "$zgit_info[rb_upstream]" ] && [ $zgit_info[rb_upstream] != $zgit_info[rb_onto] ]; then
|
||||
upstream_commit=$(revstring $zgit_info[rb_upstream])
|
||||
upstream_name=$(git name-rev --name-only $zgit_info[rb_upstream])
|
||||
upstream="$pc[scm_branch]$upstream_name$pc[punc]($pc[scm_commitid]$upstream_commit$pc[punc])"
|
||||
commits+="rebasing $upstream$pc[reset]..$orig$pc[reset] onto $onto$pc[reset]"
|
||||
else
|
||||
commits+="rebasing $onto$pc[reset]..$orig$pc[reset]"
|
||||
fi
|
||||
|
||||
local -a revs
|
||||
revs=($(git rev-list $zgit_info[rb_onto]..HEAD))
|
||||
if [ $#revs -gt 0 ]; then
|
||||
commits+="\n$#revs commits in"
|
||||
fi
|
||||
|
||||
if [ -f $zgit_info[dotest]/message ]; then
|
||||
mess=$(head -n1 $zgit_info[dotest]/message)
|
||||
commits+="on $mess"
|
||||
fi
|
||||
elif [ -n "$gitcommit" ]; then
|
||||
commits+="on $pc[scm_branch]$head$pc[punc]($pc[scm_commitid]$gitcommit$pc[punc])$pc[reset]"
|
||||
local track_merge=$(zgit_tracking_merge)
|
||||
if [ -n "$track_merge" ]; then
|
||||
if git rev-parse --verify -q $track_merge >/dev/null; then
|
||||
local track_remote=$(zgit_tracking_remote)
|
||||
local tracked=$(revstring $track_merge 2>/dev/null)
|
||||
|
||||
local -a revs
|
||||
revs=($(git rev-list --reverse $track_merge..HEAD))
|
||||
if [ $#revs -gt 0 ]; then
|
||||
local base=$(revstring $revs[1]~1)
|
||||
local base_name=$(git name-rev --name-only $base)
|
||||
local base_short=$(revstring $base)
|
||||
local word_commits
|
||||
if [ $#revs -gt 1 ]; then
|
||||
word_commits='commits'
|
||||
else
|
||||
word_commits='commit'
|
||||
fi
|
||||
|
||||
local conj="since"
|
||||
if [[ "$base" == "$tracked" ]]; then
|
||||
conj+=" tracked"
|
||||
tracked=
|
||||
fi
|
||||
commits+="$#revs $word_commits $conj $pc[scm_branch]$base_name$pc[punc]($pc[scm_commitid]$base_short$pc[punc])$pc[reset]"
|
||||
fi
|
||||
|
||||
if [ -n "$tracked" ]; then
|
||||
local track_name=$track_merge
|
||||
if [[ $track_remote == "." ]]; then
|
||||
track_name=${track_name##*/}
|
||||
fi
|
||||
tracked=$(revstring $tracked)
|
||||
commits+="tracking $pc[scm_branch]$track_name$pc[punc]"
|
||||
if [[ "$tracked" != "$gitcommit" ]]; then
|
||||
commits[$#commits]+="($pc[scm_commitid]$tracked$pc[punc])"
|
||||
fi
|
||||
commits[$#commits]+="$pc[reset]"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
gitsvn=$(git rev-parse --verify -q --short git-svn)
|
||||
if [ $? -eq 0 ]; then
|
||||
gitsvnrev=$(zgit_svnhead $gitsvn)
|
||||
gitsvn=$(revstring $gitsvn)
|
||||
if [ -n "$gitsvnrev" ]; then
|
||||
local svninfo=''
|
||||
local -a revs
|
||||
svninfo+="$pc[default]svn$pc[punc]:$pc[scm_branch]r$gitsvnrev"
|
||||
revs=($(git rev-list git-svn..HEAD))
|
||||
if [ $#revs -gt 0 ]; then
|
||||
svninfo+="$pc[punc]@$pc[default]HEAD~$#revs"
|
||||
svninfo+="$pc[punc]($pc[scm_commitid]$gitsvn$pc[punc])"
|
||||
fi
|
||||
commits+=$svninfo
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $#commits -gt 0 ]; then
|
||||
echo -n " ${(j: :)commits}"
|
||||
fi
|
||||
}
|
||||
|
||||
prompt_wunjo_scm_branch() {
|
||||
zgit_isgit || return
|
||||
local -A pc
|
||||
pc=(${(kv)wunjo_prompt_colors})
|
||||
|
||||
echo -n "$pc[punc]$pc[scm_branch]$(zgit_head)"
|
||||
|
||||
if zgit_inworktree; then
|
||||
if ! zgit_isindexclean; then
|
||||
echo -n "$pc[scm_status_staged]+"
|
||||
fi
|
||||
|
||||
local -a dirty
|
||||
if ! zgit_isworktreeclean; then
|
||||
dirty+='!'
|
||||
fi
|
||||
|
||||
if zgit_hasunmerged; then
|
||||
dirty+='*'
|
||||
fi
|
||||
|
||||
if zgit_hasuntracked; then
|
||||
dirty+='?'
|
||||
fi
|
||||
|
||||
if [ $#dirty -gt 0 ]; then
|
||||
echo -n "$pc[scm_status_dirty]${(j::)dirty}"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo $pc[reset]
|
||||
}
|
||||
|
||||
prompt_grb_setup "$@"
|
||||
|
||||
# vim:set ft=zsh:
|
294
.zsh/func/prompt_wunjo_setup
Executable file
294
.zsh/func/prompt_wunjo_setup
Executable file
|
@ -0,0 +1,294 @@
|
|||
# wunjo prompt theme
|
||||
|
||||
autoload -U zgitinit
|
||||
zgitinit
|
||||
|
||||
prompt_wunjo_help () {
|
||||
cat <<'EOF'
|
||||
|
||||
prompt wunjo
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
revstring() {
|
||||
git describe --always $1 2>/dev/null ||
|
||||
git rev-parse --short $1 2>/dev/null
|
||||
}
|
||||
|
||||
coloratom() {
|
||||
local off=$1 atom=$2
|
||||
if [[ $atom[1] == [[:upper:]] ]]; then
|
||||
off=$(( $off + 60 ))
|
||||
fi
|
||||
echo $(( $off + $colorcode[${(L)atom}] ))
|
||||
}
|
||||
colorword() {
|
||||
local fg=$1 bg=$2 att=$3
|
||||
local -a s
|
||||
|
||||
if [ -n "$fg" ]; then
|
||||
s+=$(coloratom 30 $fg)
|
||||
fi
|
||||
if [ -n "$bg" ]; then
|
||||
s+=$(coloratom 40 $bg)
|
||||
fi
|
||||
if [ -n "$att" ]; then
|
||||
s+=$attcode[$att]
|
||||
fi
|
||||
|
||||
echo "%{"$'\e['${(j:;:)s}m"%}"
|
||||
}
|
||||
|
||||
prompt_wunjo_setup() {
|
||||
local verbose
|
||||
if [[ $TERM == screen* ]] && [ -n "$STY" ]; then
|
||||
verbose=
|
||||
else
|
||||
verbose=1
|
||||
fi
|
||||
|
||||
typeset -A colorcode
|
||||
colorcode[black]=0
|
||||
colorcode[red]=1
|
||||
colorcode[green]=2
|
||||
colorcode[yellow]=3
|
||||
colorcode[blue]=4
|
||||
colorcode[magenta]=5
|
||||
colorcode[cyan]=6
|
||||
colorcode[white]=7
|
||||
colorcode[default]=9
|
||||
colorcode[k]=$colorcode[black]
|
||||
colorcode[r]=$colorcode[red]
|
||||
colorcode[g]=$colorcode[green]
|
||||
colorcode[y]=$colorcode[yellow]
|
||||
colorcode[b]=$colorcode[blue]
|
||||
colorcode[m]=$colorcode[magenta]
|
||||
colorcode[c]=$colorcode[cyan]
|
||||
colorcode[w]=$colorcode[white]
|
||||
colorcode[.]=$colorcode[default]
|
||||
|
||||
typeset -A attcode
|
||||
attcode[none]=00
|
||||
attcode[bold]=01
|
||||
attcode[faint]=02
|
||||
attcode[standout]=03
|
||||
attcode[underline]=04
|
||||
attcode[blink]=05
|
||||
attcode[reverse]=07
|
||||
attcode[conceal]=08
|
||||
attcode[normal]=22
|
||||
attcode[no-standout]=23
|
||||
attcode[no-underline]=24
|
||||
attcode[no-blink]=25
|
||||
attcode[no-reverse]=27
|
||||
attcode[no-conceal]=28
|
||||
|
||||
local -A pc
|
||||
pc[default]='default'
|
||||
pc[date]='cyan'
|
||||
pc[time]='Blue'
|
||||
pc[host]='Green'
|
||||
pc[user]='cyan'
|
||||
pc[punc]='yellow'
|
||||
pc[line]='magenta'
|
||||
pc[hist]='green'
|
||||
pc[path]='Cyan'
|
||||
pc[shortpath]='default'
|
||||
pc[rc]='red'
|
||||
pc[scm_branch]='Cyan'
|
||||
pc[scm_commitid]='Yellow'
|
||||
pc[scm_status_dirty]='Red'
|
||||
pc[scm_status_staged]='Green'
|
||||
pc[#]='Yellow'
|
||||
for cn in ${(k)pc}; do
|
||||
pc[${cn}]=$(colorword $pc[$cn])
|
||||
done
|
||||
pc[reset]=$(colorword . . 00)
|
||||
|
||||
typeset -Ag wunjo_prompt_colors
|
||||
wunjo_prompt_colors=(${(kv)pc})
|
||||
|
||||
local p_date p_line p_rc
|
||||
|
||||
p_date="$pc[date]%D{%Y-%m-%d} $pc[time]%D{%T}$pc[reset]"
|
||||
|
||||
p_line="$pc[line]%y$pc[reset]"
|
||||
|
||||
PROMPT=
|
||||
if [ $verbose ]; then
|
||||
PROMPT+="$pc[host]%m$pc[reset] "
|
||||
fi
|
||||
PROMPT+="$pc[path]%(2~.%~.%/)$pc[reset]"
|
||||
PROMPT+="\$(prompt_wunjo_scm_status)"
|
||||
PROMPT+="%(?.. $pc[rc]exited %1v$pc[reset])"
|
||||
PROMPT+="
|
||||
"
|
||||
PROMPT+="$pc[hist]%h$pc[reset] "
|
||||
PROMPT+="$pc[shortpath]%1~$pc[reset]"
|
||||
PROMPT+="\$(prompt_wunjo_scm_branch)"
|
||||
PROMPT+=" $pc[#]%#$pc[reset] "
|
||||
|
||||
RPROMPT=
|
||||
if [ $verbose ]; then
|
||||
RPROMPT+="$p_date "
|
||||
fi
|
||||
RPROMPT+="$pc[user]%n$pc[reset]"
|
||||
RPROMPT+=" $p_line"
|
||||
|
||||
export PROMPT RPROMPT
|
||||
precmd_functions+='prompt_wunjo_precmd'
|
||||
}
|
||||
|
||||
prompt_wunjo_precmd() {
|
||||
local ex=$?
|
||||
psvar=()
|
||||
|
||||
if [[ $ex -ge 128 ]]; then
|
||||
sig=$signals[$ex-127]
|
||||
psvar[1]="sig${(L)sig}"
|
||||
else
|
||||
psvar[1]="$ex"
|
||||
fi
|
||||
}
|
||||
|
||||
prompt_wunjo_scm_status() {
|
||||
zgit_isgit || return
|
||||
local -A pc
|
||||
pc=(${(kv)wunjo_prompt_colors})
|
||||
|
||||
head=$(zgit_head)
|
||||
gitcommit=$(revstring $head)
|
||||
|
||||
local -a commits
|
||||
|
||||
if zgit_rebaseinfo; then
|
||||
orig_commit=$(revstring $zgit_info[rb_head])
|
||||
orig_name=$(git name-rev --name-only $zgit_info[rb_head])
|
||||
orig="$pc[scm_branch]$orig_name$pc[punc]($pc[scm_commitid]$orig_commit$pc[punc])"
|
||||
onto_commit=$(revstring $zgit_info[rb_onto])
|
||||
onto_name=$(git name-rev --name-only $zgit_info[rb_onto])
|
||||
onto="$pc[scm_branch]$onto_name$pc[punc]($pc[scm_commitid]$onto_commit$pc[punc])"
|
||||
|
||||
if [ -n "$zgit_info[rb_upstream]" ] && [ $zgit_info[rb_upstream] != $zgit_info[rb_onto] ]; then
|
||||
upstream_commit=$(revstring $zgit_info[rb_upstream])
|
||||
upstream_name=$(git name-rev --name-only $zgit_info[rb_upstream])
|
||||
upstream="$pc[scm_branch]$upstream_name$pc[punc]($pc[scm_commitid]$upstream_commit$pc[punc])"
|
||||
commits+="rebasing $upstream$pc[reset]..$orig$pc[reset] onto $onto$pc[reset]"
|
||||
else
|
||||
commits+="rebasing $onto$pc[reset]..$orig$pc[reset]"
|
||||
fi
|
||||
|
||||
local -a revs
|
||||
revs=($(git rev-list $zgit_info[rb_onto]..HEAD))
|
||||
if [ $#revs -gt 0 ]; then
|
||||
commits+="\n$#revs commits in"
|
||||
fi
|
||||
|
||||
if [ -f $zgit_info[dotest]/message ]; then
|
||||
mess=$(head -n1 $zgit_info[dotest]/message)
|
||||
commits+="on $mess"
|
||||
fi
|
||||
elif [ -n "$gitcommit" ]; then
|
||||
commits+="on $pc[scm_branch]$head$pc[punc]($pc[scm_commitid]$gitcommit$pc[punc])$pc[reset]"
|
||||
local track_merge=$(zgit_tracking_merge)
|
||||
if [ -n "$track_merge" ]; then
|
||||
if git rev-parse --verify -q $track_merge >/dev/null; then
|
||||
local track_remote=$(zgit_tracking_remote)
|
||||
local tracked=$(revstring $track_merge 2>/dev/null)
|
||||
|
||||
local -a revs
|
||||
revs=($(git rev-list --reverse $track_merge..HEAD))
|
||||
if [ $#revs -gt 0 ]; then
|
||||
local base=$(revstring $revs[1]~1)
|
||||
local base_name=$(git name-rev --name-only $base)
|
||||
local base_short=$(revstring $base)
|
||||
local word_commits
|
||||
if [ $#revs -gt 1 ]; then
|
||||
word_commits='commits'
|
||||
else
|
||||
word_commits='commit'
|
||||
fi
|
||||
|
||||
local conj="since"
|
||||
if [[ "$base" == "$tracked" ]]; then
|
||||
conj+=" tracked"
|
||||
tracked=
|
||||
fi
|
||||
commits+="$#revs $word_commits $conj $pc[scm_branch]$base_name$pc[punc]($pc[scm_commitid]$base_short$pc[punc])$pc[reset]"
|
||||
fi
|
||||
|
||||
if [ -n "$tracked" ]; then
|
||||
local track_name=$track_merge
|
||||
if [[ $track_remote == "." ]]; then
|
||||
track_name=${track_name##*/}
|
||||
fi
|
||||
tracked=$(revstring $tracked)
|
||||
commits+="tracking $pc[scm_branch]$track_name$pc[punc]"
|
||||
if [[ "$tracked" != "$gitcommit" ]]; then
|
||||
commits[$#commits]+="($pc[scm_commitid]$tracked$pc[punc])"
|
||||
fi
|
||||
commits[$#commits]+="$pc[reset]"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
gitsvn=$(git rev-parse --verify -q --short git-svn)
|
||||
if [ $? -eq 0 ]; then
|
||||
gitsvnrev=$(zgit_svnhead $gitsvn)
|
||||
gitsvn=$(revstring $gitsvn)
|
||||
if [ -n "$gitsvnrev" ]; then
|
||||
local svninfo=''
|
||||
local -a revs
|
||||
svninfo+="$pc[default]svn$pc[punc]:$pc[scm_branch]r$gitsvnrev"
|
||||
revs=($(git rev-list git-svn..HEAD))
|
||||
if [ $#revs -gt 0 ]; then
|
||||
svninfo+="$pc[punc]@$pc[default]HEAD~$#revs"
|
||||
svninfo+="$pc[punc]($pc[scm_commitid]$gitsvn$pc[punc])"
|
||||
fi
|
||||
commits+=$svninfo
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $#commits -gt 0 ]; then
|
||||
echo -n " ${(j: :)commits}"
|
||||
fi
|
||||
}
|
||||
|
||||
prompt_wunjo_scm_branch() {
|
||||
zgit_isgit || return
|
||||
local -A pc
|
||||
pc=(${(kv)wunjo_prompt_colors})
|
||||
|
||||
echo -n "$pc[punc]:$pc[scm_branch]$(zgit_head)"
|
||||
|
||||
if zgit_inworktree; then
|
||||
if ! zgit_isindexclean; then
|
||||
echo -n "$pc[scm_status_staged]+"
|
||||
fi
|
||||
|
||||
local -a dirty
|
||||
if ! zgit_isworktreeclean; then
|
||||
dirty+='!'
|
||||
fi
|
||||
|
||||
if zgit_hasunmerged; then
|
||||
dirty+='*'
|
||||
fi
|
||||
|
||||
if zgit_hasuntracked; then
|
||||
dirty+='?'
|
||||
fi
|
||||
|
||||
if [ $#dirty -gt 0 ]; then
|
||||
echo -n "$pc[scm_status_dirty]${(j::)dirty}"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo $pc[reset]
|
||||
}
|
||||
|
||||
prompt_wunjo_setup "$@"
|
||||
|
||||
# vim:set ft=zsh:
|
248
.zsh/func/zgitinit
Executable file
248
.zsh/func/zgitinit
Executable file
|
@ -0,0 +1,248 @@
|
|||
##
|
||||
## Load with `autoload -U zgitinit; zgitinit'
|
||||
##
|
||||
|
||||
typeset -gA zgit_info
|
||||
zgit_info=()
|
||||
|
||||
zgit_chpwd_hook() {
|
||||
zgit_info_update
|
||||
}
|
||||
|
||||
zgit_preexec_hook() {
|
||||
if [[ $2 == git\ * ]] || [[ $2 == *\ git\ * ]]; then
|
||||
zgit_precmd_do_update=1
|
||||
fi
|
||||
}
|
||||
|
||||
zgit_precmd_hook() {
|
||||
if [ $zgit_precmd_do_update ]; then
|
||||
unset zgit_precmd_do_update
|
||||
zgit_info_update
|
||||
fi
|
||||
}
|
||||
|
||||
zgit_info_update() {
|
||||
zgit_info=()
|
||||
|
||||
local gitdir="$(git rev-parse --git-dir 2>/dev/null)"
|
||||
if [ $? -ne 0 ] || [ -z "$gitdir" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
zgit_info[dir]=$gitdir
|
||||
zgit_info[bare]=$(git rev-parse --is-bare-repository)
|
||||
zgit_info[inwork]=$(git rev-parse --is-inside-work-tree)
|
||||
}
|
||||
|
||||
zgit_isgit() {
|
||||
if [ -z "$zgit_info[dir]" ]; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
zgit_inworktree() {
|
||||
zgit_isgit || return
|
||||
if [ "$zgit_info[inwork]" = "true" ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
zgit_isbare() {
|
||||
zgit_isgit || return
|
||||
if [ "$zgit_info[bare]" = "true" ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
zgit_head() {
|
||||
zgit_isgit || return 1
|
||||
|
||||
if [ -z "$zgit_info[head]" ]; then
|
||||
local name=''
|
||||
name=$(git symbolic-ref -q HEAD)
|
||||
if [ $? -eq 0 ]; then
|
||||
if [[ $name == refs/(heads|tags)/* ]]; then
|
||||
name=${name#refs/(heads|tags)/}
|
||||
fi
|
||||
else
|
||||
name=$(git name-rev --name-only --no-undefined --always HEAD)
|
||||
if [ $? -ne 0 ]; then
|
||||
return 1
|
||||
elif [[ $name == remotes/* ]]; then
|
||||
name=${name#remotes/}
|
||||
fi
|
||||
fi
|
||||
zgit_info[head]=$name
|
||||
fi
|
||||
|
||||
echo $zgit_info[head]
|
||||
}
|
||||
|
||||
zgit_branch() {
|
||||
zgit_isgit || return 1
|
||||
zgit_isbare && return 1
|
||||
|
||||
if [ -z "$zgit_info[branch]" ]; then
|
||||
local branch=$(git symbolic-ref HEAD 2>/dev/null)
|
||||
if [ $? -eq 0 ]; then
|
||||
branch=${branch##*/}
|
||||
else
|
||||
branch=$(git name-rev --name-only --always HEAD)
|
||||
fi
|
||||
zgit_info[branch]=$branch
|
||||
fi
|
||||
|
||||
echo $zgit_info[branch]
|
||||
return 0
|
||||
}
|
||||
|
||||
zgit_tracking_remote() {
|
||||
zgit_isgit || return 1
|
||||
zgit_isbare && return 1
|
||||
|
||||
local branch
|
||||
if [ -n "$1" ]; then
|
||||
branch=$1
|
||||
elif [ -z "$zgit_info[branch]" ]; then
|
||||
branch=$(zgit_branch)
|
||||
[ $? -ne 0 ] && return 1
|
||||
else
|
||||
branch=$zgit_info[branch]
|
||||
fi
|
||||
|
||||
local k="tracking_$branch"
|
||||
local remote
|
||||
if [ -z "$zgit_info[$k]" ]; then
|
||||
remote=$(git config branch.$branch.remote)
|
||||
zgit_info[$k]=$remote
|
||||
fi
|
||||
|
||||
echo $zgit_info[$k]
|
||||
return 0
|
||||
}
|
||||
|
||||
zgit_tracking_merge() {
|
||||
zgit_isgit || return 1
|
||||
zgit_isbare && return 1
|
||||
|
||||
local branch
|
||||
if [ -z "$zgit_info[branch]" ]; then
|
||||
branch=$(zgit_branch)
|
||||
[ $? -ne 0 ] && return 1
|
||||
else
|
||||
branch=$zgit_info[branch]
|
||||
fi
|
||||
|
||||
local remote=$(zgit_tracking_remote $branch)
|
||||
[ $? -ne 0 ] && return 1
|
||||
if [ -n "$remote" ]; then # tracking branch
|
||||
local merge=$(git config branch.$branch.merge)
|
||||
if [ $remote != "." ]; then
|
||||
merge=$remote/$(basename $merge)
|
||||
fi
|
||||
echo $merge
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
zgit_isindexclean() {
|
||||
zgit_isgit || return 1
|
||||
if git diff --quiet --cached 2>/dev/null; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
zgit_isworktreeclean() {
|
||||
zgit_isgit || return 1
|
||||
if git diff --quiet 2>/dev/null; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
zgit_hasuntracked() {
|
||||
zgit_isgit || return 1
|
||||
local -a flist
|
||||
flist=($(git ls-files --others --exclude-standard))
|
||||
if [ $#flist -gt 0 ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
zgit_hasunmerged() {
|
||||
zgit_isgit || return 1
|
||||
local -a flist
|
||||
flist=($(git ls-files -u))
|
||||
if [ $#flist -gt 0 ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
zgit_svnhead() {
|
||||
zgit_isgit || return 1
|
||||
|
||||
local commit=$1
|
||||
if [ -z "$commit" ]; then
|
||||
commit='HEAD'
|
||||
fi
|
||||
|
||||
git show --raw $commit | \
|
||||
grep git-svn-id | \
|
||||
sed -re 's/^\s*git-svn-id: .*@([0-9]+).*$/\1/'
|
||||
}
|
||||
|
||||
zgit_rebaseinfo() {
|
||||
zgit_isgit || return 1
|
||||
if [ -d $zgit_info[dir]/rebase-merge ]; then
|
||||
dotest=$zgit_info[dir]/rebase-merge
|
||||
elif [ -d $zgit_info[dir]/.dotest-merge ]; then
|
||||
dotest=$zgit_info[dir]/.dotest-merge
|
||||
elif [ -d .dotest ]; then
|
||||
dotest=.dotest
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
|
||||
zgit_info[dotest]=$dotest
|
||||
|
||||
zgit_info[rb_onto]=$(cat "$dotest/onto")
|
||||
zgit_info[rb_upstream]=$(cat "$dotest/upstream")
|
||||
if [ -f "$dotest/orig-head" ]; then
|
||||
zgit_info[rb_head]=$(cat "$dotest/orig-head")
|
||||
elif [ -f "$dotest/head" ]; then
|
||||
zgit_info[rb_head]=$(cat "$dotest/head")
|
||||
fi
|
||||
zgit_info[rb_head_name]=$(cat "$dotest/head-name")
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
zgitinit() {
|
||||
typeset -ga chpwd_functions
|
||||
typeset -ga preexec_functions
|
||||
typeset -ga precmd_functions
|
||||
chpwd_functions+='zgit_chpwd_hook'
|
||||
preexec_functions+='zgit_preexec_hook'
|
||||
precmd_functions+='zgit_precmd_hook'
|
||||
}
|
||||
|
||||
zgitinit
|
||||
zgit_info_update
|
||||
|
||||
# vim:set ft=zsh:
|
72
.zsh/lib/completion.zsh
Normal file
72
.zsh/lib/completion.zsh
Normal file
|
@ -0,0 +1,72 @@
|
|||
# fixme - the load process here seems a bit bizarre
|
||||
|
||||
unsetopt menu_complete # do not autoselect the first completion entry
|
||||
unsetopt flowcontrol
|
||||
setopt auto_menu # show completion menu on succesive tab press
|
||||
setopt complete_in_word
|
||||
setopt always_to_end
|
||||
|
||||
WORDCHARS=''
|
||||
|
||||
zmodload -i zsh/complist
|
||||
|
||||
## case-insensitive (all),partial-word and then substring completion
|
||||
if [ "x$CASE_SENSITIVE" = "xtrue" ]; then
|
||||
zstyle ':completion:*' matcher-list 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
|
||||
unset CASE_SENSITIVE
|
||||
else
|
||||
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
|
||||
fi
|
||||
|
||||
zstyle ':completion:*' list-colors ''
|
||||
|
||||
# should this be in keybindings?
|
||||
bindkey -M menuselect '^o' accept-and-infer-next-history
|
||||
|
||||
zstyle ':completion:*:*:*:*:*' menu select
|
||||
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
|
||||
zstyle ':completion:*:*:*:*:processes' command "ps -u `whoami` -o pid,user,comm -w -w"
|
||||
|
||||
# disable named-directories autocompletion
|
||||
zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories
|
||||
cdpath=(.)
|
||||
|
||||
# use /etc/hosts and known_hosts for hostname completion
|
||||
[ -r /etc/ssh/ssh_known_hosts ] && _global_ssh_hosts=(${${${${(f)"$(</etc/ssh/ssh_known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=()
|
||||
[ -r ~/.ssh/known_hosts ] && _ssh_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=()
|
||||
[ -r /etc/hosts ] && : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}} || _etc_hosts=()
|
||||
hosts=(
|
||||
"$_global_ssh_hosts[@]"
|
||||
"$_ssh_hosts[@]"
|
||||
"$_etc_hosts[@]"
|
||||
"$HOST"
|
||||
localhost
|
||||
)
|
||||
zstyle ':completion:*:hosts' hosts $hosts
|
||||
|
||||
# Use caching so that commands like apt and dpkg complete are useable
|
||||
zstyle ':completion::complete:*' use-cache 1
|
||||
zstyle ':completion::complete:*' cache-path $ZSH/cache/
|
||||
|
||||
# Don't complete uninteresting users
|
||||
zstyle ':completion:*:*:*:users' ignored-patterns \
|
||||
adm amanda apache avahi beaglidx bin cacti canna clamav daemon \
|
||||
dbus distcache dovecot fax ftp games gdm gkrellmd gopher \
|
||||
hacluster haldaemon halt hsqldb ident junkbust ldap lp mail \
|
||||
mailman mailnull mldonkey mysql nagios \
|
||||
named netdump news nfsnobody nobody nscd ntp nut nx openvpn \
|
||||
operator pcap postfix postgres privoxy pulse pvm quagga radvd \
|
||||
rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs
|
||||
|
||||
# ... unless we really want to.
|
||||
zstyle '*' single-ignored show
|
||||
|
||||
if [ "x$COMPLETION_WAITING_DOTS" = "xtrue" ]; then
|
||||
expand-or-complete-with-dots() {
|
||||
echo -n "\e[31m......\e[0m"
|
||||
zle expand-or-complete
|
||||
zle redisplay
|
||||
}
|
||||
zle -N expand-or-complete-with-dots
|
||||
bindkey "^I" expand-or-complete-with-dots
|
||||
fi
|
46
.zsh/tools/check_for_upgrade.sh
Normal file
46
.zsh/tools/check_for_upgrade.sh
Normal file
|
@ -0,0 +1,46 @@
|
|||
#!/bin/sh
|
||||
|
||||
function _current_epoch() {
|
||||
echo $(($(date +%s) / 60 / 60 / 24))
|
||||
}
|
||||
|
||||
function _update_zsh_update() {
|
||||
echo "LAST_EPOCH=$(_current_epoch)" > ~/.zsh-update
|
||||
}
|
||||
|
||||
function _upgrade_zsh() {
|
||||
/usr/bin/env ZSH=$ZSH /bin/sh $ZSH/tools/upgrade.sh
|
||||
# update the zsh file
|
||||
_update_zsh_update
|
||||
}
|
||||
|
||||
if [ -f ~/.zsh-update ]
|
||||
then
|
||||
. ~/.zsh-update
|
||||
|
||||
if [[ -z "$LAST_EPOCH" ]]; then
|
||||
_update_zsh_update && return 0;
|
||||
fi
|
||||
|
||||
epoch_diff=$(($(_current_epoch) - $LAST_EPOCH))
|
||||
if [ $epoch_diff -gt 13 ]
|
||||
then
|
||||
if [ "$DISABLE_UPDATE_PROMPT" = "true" ]
|
||||
then
|
||||
_upgrade_zsh
|
||||
else
|
||||
echo "[Oh My Zsh] Would you like to check for updates?"
|
||||
echo "Type Y to update oh-my-zsh: \c"
|
||||
read line
|
||||
if [ "$line" = Y ] || [ "$line" = y ]; then
|
||||
_upgrade_zsh
|
||||
else
|
||||
_update_zsh_update
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
else
|
||||
# create the zsh file
|
||||
_update_zsh_update
|
||||
fi
|
||||
|
39
.zsh/tools/install.sh
Executable file
39
.zsh/tools/install.sh
Executable file
|
@ -0,0 +1,39 @@
|
|||
if [ -d ~/.oh-my-zsh ]
|
||||
then
|
||||
echo "\033[0;33mYou already have Oh My Zsh installed.\033[0m You'll need to remove ~/.oh-my-zsh if you want to install"
|
||||
exit
|
||||
fi
|
||||
|
||||
echo "\033[0;34mCloning Oh My Zsh...\033[0m"
|
||||
hash git >/dev/null && /usr/bin/env git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh || {
|
||||
echo "git not installed"
|
||||
exit
|
||||
}
|
||||
|
||||
echo "\033[0;34mLooking for an existing zsh config...\033[0m"
|
||||
if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]
|
||||
then
|
||||
echo "\033[0;33mFound ~/.zshrc.\033[0m \033[0;32]Backing up to ~/.zshrc.pre-oh-my-zsh\033[0m";
|
||||
cp ~/.zshrc ~/.zshrc.pre-oh-my-zsh;
|
||||
rm ~/.zshrc;
|
||||
fi
|
||||
|
||||
echo "\033[0;34mUsing the Oh My Zsh template file and adding it to ~/.zshrc\033[0m"
|
||||
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
|
||||
|
||||
echo "\033[0;34mCopying your current PATH and adding it to the end of ~/.zshrc for you.\033[0m"
|
||||
echo "export PATH=$PATH" >> ~/.zshrc
|
||||
|
||||
echo "\033[0;34mTime to change your default shell to zsh!\033[0m"
|
||||
chsh -s `which zsh`
|
||||
|
||||
echo "\033[0;32m"' __ __ '"\033[0m"
|
||||
echo "\033[0;32m"' ____ / /_ ____ ___ __ __ ____ _____/ /_ '"\033[0m"
|
||||
echo "\033[0;32m"' / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ '"\033[0m"
|
||||
echo "\033[0;32m"'/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / / '"\033[0m"
|
||||
echo "\033[0;32m"'\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ '"\033[0m"
|
||||
echo "\033[0;32m"' /____/ '"\033[0m"
|
||||
|
||||
echo "\n\n \033[0;32m....is now installed.\033[0m"
|
||||
/usr/bin/env zsh
|
||||
source ~/.zshrc
|
161
.zsh/tools/require_tool.sh
Executable file
161
.zsh/tools/require_tool.sh
Executable file
|
@ -0,0 +1,161 @@
|
|||
__require_tool_version_compare ()
|
||||
{
|
||||
(
|
||||
# Locally ignore failures, otherwise we'll exit whenever $1 and $2
|
||||
# are not equal!
|
||||
set +e
|
||||
|
||||
awk_strverscmp='
|
||||
# Use only awk features that work with 7th edition Unix awk (1978).
|
||||
# My, what an old awk you have, Mr. Solaris!
|
||||
END {
|
||||
while (length(v1) || length(v2)) {
|
||||
# Set d1 to be the next thing to compare from v1, and likewise for d2.
|
||||
# Normally this is a single character, but if v1 and v2 contain digits,
|
||||
# compare them as integers and fractions as strverscmp does.
|
||||
if (v1 ~ /^[0-9]/ && v2 ~ /^[0-9]/) {
|
||||
# Split v1 and v2 into their leading digit string components d1 and d2,
|
||||
# and advance v1 and v2 past the leading digit strings.
|
||||
for (len1 = 1; substr(v1, len1 + 1) ~ /^[0-9]/; len1++) continue
|
||||
for (len2 = 1; substr(v2, len2 + 1) ~ /^[0-9]/; len2++) continue
|
||||
d1 = substr(v1, 1, len1); v1 = substr(v1, len1 + 1)
|
||||
d2 = substr(v2, 1, len2); v2 = substr(v2, len2 + 1)
|
||||
if (d1 ~ /^0/) {
|
||||
if (d2 ~ /^0/) {
|
||||
# Compare two fractions.
|
||||
while (d1 ~ /^0/ && d2 ~ /^0/) {
|
||||
d1 = substr(d1, 2); len1--
|
||||
d2 = substr(d2, 2); len2--
|
||||
}
|
||||
if (len1 != len2 && ! (len1 && len2 && substr(d1, 1, 1) == substr(d2, 1, 1))) {
|
||||
# The two components differ in length, and the common prefix
|
||||
# contains only leading zeros. Consider the longer to be less.
|
||||
d1 = -len1
|
||||
d2 = -len2
|
||||
} else {
|
||||
# Otherwise, compare as strings.
|
||||
d1 = "x" d1
|
||||
d2 = "x" d2
|
||||
}
|
||||
} else {
|
||||
# A fraction is less than an integer.
|
||||
exit 1
|
||||
}
|
||||
} else {
|
||||
if (d2 ~ /^0/) {
|
||||
# An integer is greater than a fraction.
|
||||
exit 2
|
||||
} else {
|
||||
# Compare two integers.
|
||||
d1 += 0
|
||||
d2 += 0
|
||||
}
|
||||
}
|
||||
} else {
|
||||
# The normal case, without worrying about digits.
|
||||
if (v1 == "") d1 = v1; else { d1 = substr(v1, 1, 1); v1 = substr(v1,2) }
|
||||
if (v2 == "") d2 = v2; else { d2 = substr(v2, 1, 1); v2 = substr(v2,2) }
|
||||
}
|
||||
if (d1 < d2) exit 1
|
||||
if (d1 > d2) exit 2
|
||||
}
|
||||
}
|
||||
'
|
||||
awk "$awk_strverscmp" v1="$1" v2="$2" /dev/null
|
||||
case $? in
|
||||
1) echo '<';;
|
||||
0) echo '=';;
|
||||
2) echo '>';;
|
||||
esac
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
__require_tool_fatal ()
|
||||
{
|
||||
echo $@ >/dev/stderr
|
||||
return 1
|
||||
}
|
||||
|
||||
# Usage: require_tool program version
|
||||
# Returns: 0 if $1 version if greater equals than $2, 1 otherwise.
|
||||
# In case of error, message is written on error output.
|
||||
#
|
||||
# Example: require_tool gcc 4.6
|
||||
# Use GCC environment variable if defined instead of lookup for the tool
|
||||
# in the environment.
|
||||
require_tool ()
|
||||
{
|
||||
envvar_name=$(echo $1 | tr '[:lower:]' '[:upper:]')
|
||||
tool=$(printenv $envvar_name || echo $1)
|
||||
local version=$($tool --version 2>/dev/null| \
|
||||
sed -n 's/.*[^0-9.]\([0-9]*\.[0-9.]*\).*/\1/p;q')
|
||||
if test x"$version" = x ; then
|
||||
echo "$tool is required" >/dev/stderr
|
||||
return 1
|
||||
fi
|
||||
case $(__require_tool_version_compare "$2" "$version") in
|
||||
'>')
|
||||
echo "$1 $2 or better is required: this is $tool $version" >/dev/stderr
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
NAME
|
||||
require_tool.sh - Ensure version of a tool is greater than the one expected
|
||||
|
||||
SYNOPSYS
|
||||
require_tool.sh [ -h ]
|
||||
[ --help ]
|
||||
[ TOOL MIN_VERSION ]
|
||||
|
||||
DESCRIPTION
|
||||
TOOL is the name or path of the program to check. If the name is specified, its
|
||||
path is deduced from PATH environment variable. If environment variable TOOL
|
||||
(in upper-case characters) is defined, considers its value as path to the tool.
|
||||
|
||||
MIN_VERSION is a string representing the minimum required version.
|
||||
|
||||
BEHAVIOR
|
||||
* locate path to the program.
|
||||
* execute $ TOOL_PATH --version
|
||||
* extract version from standard output.
|
||||
* compare this version to the expected one.
|
||||
|
||||
OPTIONS
|
||||
-h --help
|
||||
Display this message and exit 0
|
||||
|
||||
ERRORS
|
||||
if program is not found or its version is prior to expected version,
|
||||
a message is written to error output.
|
||||
|
||||
EXIT VALUE
|
||||
returns 0 if program version if greater equals than expected version,
|
||||
returns 1 otherwise.
|
||||
|
||||
EXAMPLE
|
||||
$ require_tool.sh emacs 23
|
||||
$ CC=g++ require_tool.sh cc 4.6
|
||||
$ require_tool.sh zsh 4.5
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
for arg in $@; do
|
||||
case $arg in
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
if [ $# -gt 2 ] ; then
|
||||
echo "ERROR: expecting 2 parameters. Please see option --help"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
require_tool $@
|
96
.zsh/tools/theme_chooser.sh
Executable file
96
.zsh/tools/theme_chooser.sh
Executable file
|
@ -0,0 +1,96 @@
|
|||
#!/bin/zsh
|
||||
|
||||
# Zsh Theme Chooser by fox (fox91 at anche dot no)
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
THEMES_DIR="$ZSH/themes"
|
||||
FAVLIST="${HOME}/.zsh_favlist"
|
||||
source $ZSH/oh-my-zsh.sh
|
||||
|
||||
function noyes() {
|
||||
read "a?$1 [y/N] "
|
||||
if [[ $a == "N" || $a == "n" || $a = "" ]]; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
function theme_preview() {
|
||||
THEME=$1
|
||||
THEME_NAME=`echo $THEME | sed s/\.zsh-theme$//`
|
||||
print "$fg[blue]${(l.((${COLUMNS}-${#THEME_NAME}-5))..─.)}$reset_color $THEME_NAME $fg[blue]───$reset_color"
|
||||
source "$THEMES_DIR/$THEME"
|
||||
print -P $PROMPT
|
||||
}
|
||||
|
||||
function banner() {
|
||||
echo
|
||||
echo "[0;1;35;95m╺━[0;1;31;91m┓┏[0;1;33;93m━┓[0;1;32;92m╻[0m [0;1;36;96m╻[0m [0;1;35;95m╺┳[0;1;31;91m╸╻[0m [0;1;33;93m╻[0;1;32;92m┏━[0;1;36;96m╸┏[0;1;34;94m┳┓[0;1;35;95m┏━[0;1;31;91m╸[0m [0;1;32;92m┏━[0;1;36;96m╸╻[0m [0;1;34;94m╻[0;1;35;95m┏━[0;1;31;91m┓┏[0;1;33;93m━┓[0;1;32;92m┏━[0;1;36;96m┓┏[0;1;34;94m━╸[0;1;35;95m┏━[0;1;31;91m┓[0m"
|
||||
echo "[0;1;31;91m┏━[0;1;33;93m┛┗[0;1;32;92m━┓[0;1;36;96m┣━[0;1;34;94m┫[0m [0;1;31;91m┃[0m [0;1;33;93m┣[0;1;32;92m━┫[0;1;36;96m┣╸[0m [0;1;34;94m┃[0;1;35;95m┃┃[0;1;31;91m┣╸[0m [0;1;36;96m┃[0m [0;1;34;94m┣[0;1;35;95m━┫[0;1;31;91m┃[0m [0;1;33;93m┃┃[0m [0;1;32;92m┃[0;1;36;96m┗━[0;1;34;94m┓┣[0;1;35;95m╸[0m [0;1;31;91m┣┳[0;1;33;93m┛[0m"
|
||||
echo "[0;1;33;93m┗━[0;1;32;92m╸┗[0;1;36;96m━┛[0;1;34;94m╹[0m [0;1;35;95m╹[0m [0;1;33;93m╹[0m [0;1;32;92m╹[0m [0;1;36;96m╹[0;1;34;94m┗━[0;1;35;95m╸╹[0m [0;1;31;91m╹[0;1;33;93m┗━[0;1;32;92m╸[0m [0;1;34;94m┗━[0;1;35;95m╸╹[0m [0;1;31;91m╹[0;1;33;93m┗━[0;1;32;92m┛┗[0;1;36;96m━┛[0;1;34;94m┗━[0;1;35;95m┛┗[0;1;31;91m━╸[0;1;33;93m╹┗[0;1;32;92m╸[0m"
|
||||
echo
|
||||
}
|
||||
|
||||
function usage() {
|
||||
echo "Usage: $0 [options] [theme]"
|
||||
echo
|
||||
echo "Options"
|
||||
echo " -l List available themes"
|
||||
echo " -s Show all themes"
|
||||
echo " -h Get this help message"
|
||||
exit 1
|
||||
}
|
||||
|
||||
function list_themes() {
|
||||
for THEME in $(ls $THEMES_DIR); do
|
||||
THEME_NAME=`echo $THEME | sed s/\.zsh-theme$//`
|
||||
echo $THEME_NAME
|
||||
done
|
||||
}
|
||||
|
||||
function insert_favlist() {
|
||||
if grep -q "$THEME_NAME" $FAVLIST 2> /dev/null ; then
|
||||
echo "Already in favlist"
|
||||
else
|
||||
echo $THEME_NAME >> $FAVLIST
|
||||
echo "Saved to favlist"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
function theme_chooser() {
|
||||
for THEME in $(ls $THEMES_DIR); do
|
||||
echo
|
||||
theme_preview $THEME
|
||||
echo
|
||||
if [[ -z $1 ]]; then
|
||||
noyes "Do you want to add it to your favourite list ($FAVLIST)?" || \
|
||||
insert_favlist $THEME_NAME
|
||||
echo
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
while getopts ":lhs" Option
|
||||
do
|
||||
case $Option in
|
||||
l ) list_themes ;;
|
||||
s ) theme_chooser 0 ;;
|
||||
h ) usage ;;
|
||||
* ) usage ;; # Default.
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z $Option ]]; then
|
||||
if [[ -z $1 ]]; then
|
||||
banner
|
||||
echo
|
||||
theme_chooser
|
||||
else
|
||||
theme_preview $1".zsh-theme"
|
||||
fi
|
||||
fi
|
20
.zsh/tools/uninstall.sh
Normal file
20
.zsh/tools/uninstall.sh
Normal file
|
@ -0,0 +1,20 @@
|
|||
echo "Removing ~/.oh-my-zsh"
|
||||
if [[ -d ~/.oh-my-zsh ]]
|
||||
then
|
||||
rm -rf ~/.oh-my-zsh
|
||||
fi
|
||||
|
||||
echo "Looking for an existing zsh config..."
|
||||
if [ -f ~/.zshrc.pre-oh-my-zsh ] || [ -h ~/.zshrc.pre-oh-my-zsh ]
|
||||
then
|
||||
echo "Found ~/.zshrc. Backing up to ~/.zshrc.pre-oh-my-zsh";
|
||||
rm ~/.zshrc;
|
||||
cp ~/.zshrc.pre-oh-my-zsh ~/.zshrc;
|
||||
source ~/.zshrc;
|
||||
else
|
||||
echo "Switching back to bash"
|
||||
chsh -s /bin/bash
|
||||
source /etc/profile
|
||||
fi
|
||||
|
||||
echo "Thanks for trying out Oh My Zsh. It's been uninstalled."
|
19
.zsh/tools/upgrade.sh
Normal file
19
.zsh/tools/upgrade.sh
Normal file
|
@ -0,0 +1,19 @@
|
|||
current_path=`pwd`
|
||||
printf '\033[0;34m%s\033[0m\n' "Upgrading Oh My Zsh"
|
||||
cd $ZSH
|
||||
|
||||
if git pull origin master
|
||||
then
|
||||
printf '\033[0;32m%s\033[0m\n' ' __ __ '
|
||||
printf '\033[0;32m%s\033[0m\n' ' ____ / /_ ____ ___ __ __ ____ _____/ /_ '
|
||||
printf '\033[0;32m%s\033[0m\n' ' / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ '
|
||||
printf '\033[0;32m%s\033[0m\n' '/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / / '
|
||||
printf '\033[0;32m%s\033[0m\n' '\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ '
|
||||
printf '\033[0;32m%s\033[0m\n' ' /____/ '
|
||||
printf '\033[0;34m%s\033[0m\n' 'Hooray! Oh My Zsh has been updated and/or is at the current version.'
|
||||
printf '\033[0;34m%s\033[1m%s\033[0m\n' 'To keep up on the latest, be sure to follow Oh My Zsh on twitter: ' 'http://twitter.com/ohmyzsh'
|
||||
else
|
||||
printf '\033[0;31m%s\033[0m\n' 'There was an error updating. Try again later?'
|
||||
fi
|
||||
|
||||
cd "$current_path"
|
64
.zshrc
Normal file
64
.zshrc
Normal file
|
@ -0,0 +1,64 @@
|
|||
# Path to your oh-my-zsh configuration.
|
||||
ZSH=$HOME/.zsh
|
||||
|
||||
fpath=($fpath $HOME/.zsh/func)
|
||||
typeset -U fpath
|
||||
|
||||
setopt promptsubst
|
||||
autoload -U promptinit
|
||||
promptinit
|
||||
prompt grb
|
||||
|
||||
autoload -U compinit
|
||||
compinit
|
||||
|
||||
# Check for updates on initial load...
|
||||
if [ "$DISABLE_AUTO_UPDATE" != "true" ]
|
||||
then
|
||||
/usr/bin/env ZSH=$ZSH zsh $ZSH/tools/check_for_upgrade.sh
|
||||
fi
|
||||
|
||||
# Load all of the config files that end in .zsh
|
||||
for config_file ($ZSH/lib/*.zsh) source $config_file
|
||||
|
||||
# Customize to your needs...
|
||||
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin:/usr/X11/bin:/usr/local/git/bin
|
||||
export PATH="$HOME/bin:$PATH"
|
||||
|
||||
# Unbreak broken, non-colored terminal
|
||||
alias ls='ls -G'
|
||||
alias ll='ls -lG'
|
||||
alias l='ls -laG'
|
||||
alias duh='du -csh'
|
||||
export GREP_OPTIONS="--color"
|
||||
|
||||
# Unbreak history
|
||||
export HISTSIZE=10000
|
||||
export HISTFILE="$HOME/.history"
|
||||
export SAVEHIST=$HISTSIZE
|
||||
|
||||
# Alias
|
||||
alias r=rails
|
||||
alias g=git
|
||||
alias cls=clear
|
||||
alias sl=ls # often screw this up
|
||||
alias history='fc -l 1'
|
||||
alias ..='cd ../'
|
||||
alias ...='cd ../..'
|
||||
alias cd..='cd ..'
|
||||
alias cd...='cd ../..'
|
||||
alias cd....='cd ../../..'
|
||||
alias cd.....='cd ../../../..'
|
||||
alias cd/='cd /'
|
||||
|
||||
|
||||
# Misc
|
||||
activate_virtualenv() {
|
||||
if [ -f env/bin/activate ]; then . env/bin/activate;
|
||||
elif [ -f ../env/bin/activate ]; then . ../env/bin/activate;
|
||||
elif [ -f ../../env/bin/activate ]; then . ../../env/bin/activate;
|
||||
elif [ -f ../../../env/bin/activate ]; then . ../../../env/bin/activate;
|
||||
fi
|
||||
}
|
||||
|
||||
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
|
Loading…
Reference in New Issue
Block a user