mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-13 05:59:46 +08:00
Compare commits
5 Commits
c74f2a1be9
...
6a7aab47dd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a7aab47dd | ||
|
|
331f3c8b2e | ||
|
|
76e541a3fe | ||
|
|
8e8ec1348b | ||
|
|
bae577d6b2 |
@ -1,10 +1,11 @@
|
|||||||
_register() {
|
function _git_commit_register {
|
||||||
if ! git config --global --get-all alias.$1 &>/dev/null; then
|
if ! git config --global --get-all alias.$1 >/dev/null 2>&1; then
|
||||||
git config --global alias.$1 '!a() { if [[ "$1" == "-s" || "$1" == "--scope" ]]; then git commit -m "'$1'(${2}): ${@:3}"; else git commit -m "'$1': ${@}"; fi }; a'
|
git config --global alias.$1 '!a() { if [[ "$1" == "-s" || "$1" == "--scope" ]]; then git commit -m "'$1'(${2}): ${@:3}"; else git commit -m "'$1': ${@}"; fi }; a'
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
aliases=(
|
local -a _git_commit_aliases
|
||||||
|
_git_commit_aliases=(
|
||||||
'build'
|
'build'
|
||||||
'chore'
|
'chore'
|
||||||
'ci'
|
'ci'
|
||||||
@ -18,6 +19,9 @@ aliases=(
|
|||||||
'test'
|
'test'
|
||||||
)
|
)
|
||||||
|
|
||||||
for alias in "${aliases[@]}"; do
|
for _alias in "${_git_commit_aliases[@]}"; do
|
||||||
_register $alias
|
_git_commit_register $_alias
|
||||||
done
|
done
|
||||||
|
|
||||||
|
unfunction _git_commit_register
|
||||||
|
unset _alias
|
||||||
|
|||||||
@ -32,9 +32,11 @@ plugins=(... git)
|
|||||||
| gbs | git bisect |
|
| gbs | git bisect |
|
||||||
| gbsb | git bisect bad |
|
| gbsb | git bisect bad |
|
||||||
| gbsg | git bisect good |
|
| gbsg | git bisect good |
|
||||||
|
| gbsn | git bisect new |
|
||||||
|
| gbso | git bisect old |
|
||||||
| gbsr | git bisect reset |
|
| gbsr | git bisect reset |
|
||||||
| gbss | git bisect start |
|
| gbss | git bisect start |
|
||||||
| gbl | git blame -b -w |
|
| gbl | git blame -w |
|
||||||
| gb | git branch |
|
| gb | git branch |
|
||||||
| gba | git branch --all |
|
| gba | git branch --all |
|
||||||
| gbd | git branch --delete |
|
| gbd | git branch --delete |
|
||||||
|
|||||||
@ -113,9 +113,11 @@ alias gapt='git apply --3way'
|
|||||||
alias gbs='git bisect'
|
alias gbs='git bisect'
|
||||||
alias gbsb='git bisect bad'
|
alias gbsb='git bisect bad'
|
||||||
alias gbsg='git bisect good'
|
alias gbsg='git bisect good'
|
||||||
|
alias gbsn='git bisect new'
|
||||||
|
alias gbso='git bisect old'
|
||||||
alias gbsr='git bisect reset'
|
alias gbsr='git bisect reset'
|
||||||
alias gbss='git bisect start'
|
alias gbss='git bisect start'
|
||||||
alias gbl='git blame -b -w'
|
alias gbl='git blame -w'
|
||||||
alias gb='git branch'
|
alias gb='git branch'
|
||||||
alias gba='git branch --all'
|
alias gba='git branch --all'
|
||||||
alias gbd='git branch --delete'
|
alias gbd='git branch --delete'
|
||||||
|
|||||||
@ -1,24 +1,140 @@
|
|||||||
# Depends on the git plugin for work_in_progress()
|
# Depends on the git plugin for work_in_progress()
|
||||||
(( $+functions[work_in_progress] )) || work_in_progress() {}
|
(( $+functions[work_in_progress] )) || work_in_progress() {}
|
||||||
|
|
||||||
ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}["
|
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[cyan]%}[%{$fg[green]%}"
|
||||||
ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$reset_color%}"
|
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$fg[cyan]%}]"
|
||||||
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}"
|
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}"
|
||||||
ZSH_THEME_GIT_PROMPT_CLEAN=""
|
ZSH_THEME_GIT_PROMPT_CLEAN=""
|
||||||
|
|
||||||
# Customized git status, oh-my-zsh currently does not allow render dirty status before branch
|
# Customized git status, oh-my-zsh currently does not allow render dirty status before branch
|
||||||
git_custom_status() {
|
git_custom_status() {
|
||||||
local branch=$(git_current_branch)
|
local branch=$(git_current_branch)
|
||||||
[[ -n "$branch" ]] || return 0
|
[[ -n "$branch" ]] || return 0
|
||||||
echo "$(parse_git_dirty)\
|
print "%{${fg_bold[yellow]}%}$(work_in_progress)%{$reset_color%}\
|
||||||
%{${fg_bold[yellow]}%}$(work_in_progress)%{$reset_color%}\
|
${ZSH_THEME_GIT_PROMPT_PREFIX}$(parse_git_dirty)${branch}\
|
||||||
${ZSH_THEME_GIT_PROMPT_PREFIX}${branch}${ZSH_THEME_GIT_PROMPT_SUFFIX}"
|
${ZSH_THEME_GIT_PROMPT_SUFFIX}"
|
||||||
|
}
|
||||||
|
autoload -U colors && colors
|
||||||
|
|
||||||
|
#export VCS_PROMPT=hg_prompt_info
|
||||||
|
export VCS_PROMPT=git_custom_status
|
||||||
|
|
||||||
|
base_prompt="%{$fg[cyan]%}[%~% ]%(?.%{$fg[green]%}.%{$fg[red]%})%B$%b "
|
||||||
|
custom_prompt=""
|
||||||
|
last_run_time=""
|
||||||
|
last_vcs_info=""
|
||||||
|
|
||||||
|
|
||||||
|
function pipestatus_parse {
|
||||||
|
PIPESTATUS="$pipestatus"
|
||||||
|
ERROR=0
|
||||||
|
for i in "${(z)PIPESTATUS}"; do
|
||||||
|
if [[ "$i" -ne 0 ]]; then
|
||||||
|
ERROR=1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ "$ERROR" -ne 0 ]]; then
|
||||||
|
print "[%{$fg[red]%}$PIPESTATUS%{$fg[cyan]%}]"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# RVM component of prompt
|
|
||||||
ZSH_THEME_RUBY_PROMPT_PREFIX="%{$fg[red]%}["
|
|
||||||
ZSH_THEME_RUBY_PROMPT_SUFFIX="]%{$reset_color%}"
|
|
||||||
|
|
||||||
# Combine it all into a final right-side prompt
|
# Combine it all into a final right-side prompt
|
||||||
RPS1="\$(git_custom_status)\$(ruby_prompt_info)${RPS1:+ $RPS1}"
|
|
||||||
PROMPT='%{$fg[cyan]%}[%~% ]%(?.%{$fg[green]%}.%{$fg[red]%})%B$%b '
|
PROMPT='%{$fg[cyan]%}[%~% ]%(?.%{$fg[green]%}.%{$fg[red]%})%B$%b '
|
||||||
|
function preexec() {
|
||||||
|
last_run_time=$(perl -MTime::HiRes=time -e 'printf "%.9f\n", time')
|
||||||
|
}
|
||||||
|
|
||||||
|
function duration() {
|
||||||
|
local duration
|
||||||
|
local now=$(perl -MTime::HiRes=time -e 'printf "%.9f\n", time')
|
||||||
|
local last=$1
|
||||||
|
local last_split=("${(@s/./)last}")
|
||||||
|
local now_split=("${(@s/./)now}")
|
||||||
|
local T=$((now_split[1] - last_split[1]))
|
||||||
|
local D=$((T/60/60/24))
|
||||||
|
local H=$((T/60/60%24))
|
||||||
|
local M=$((T/60%60))
|
||||||
|
local S=$((T%60))
|
||||||
|
local s=$(((now_split[2] - last_split[2]) / 1000000000.))
|
||||||
|
local m=$(((now_split[2] - last_split[2]) / 1000000.))
|
||||||
|
|
||||||
|
(( $D > 0 )) && duration+="${D}d"
|
||||||
|
(( $H > 0 )) && duration+="${H}h"
|
||||||
|
(( $M > 0 )) && duration+="${M}m"
|
||||||
|
|
||||||
|
if [[ $S -le 0 ]]; then
|
||||||
|
printf "%ims" "$m"
|
||||||
|
else
|
||||||
|
if ! [[ -z $duration ]] && printf "%s" "$duration"
|
||||||
|
local sec_milli=$((S + s))
|
||||||
|
printf "%.3fs" "$sec_milli"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function precmd() {
|
||||||
|
RETVAL=$(pipestatus_parse)
|
||||||
|
local info=""
|
||||||
|
|
||||||
|
if [ ! -z "$last_run_time" ]; then
|
||||||
|
local elapsed=$(duration $last_run_time)
|
||||||
|
last_run_time=$(print $last_run_time | tr -d ".")
|
||||||
|
if [ $(( $(perl -MTime::HiRes=time -e 'printf "%.9f\n", time' | tr -d ".") - $last_run_time )) -gt $(( 120 * 1000 * 1000 * 1000 )) ]; then
|
||||||
|
local elapsed_color="%{$fg[magenta]%}"
|
||||||
|
elif [ $(( $(perl -MTime::HiRes=time -e 'printf "%.9f\n", time' | tr -d ".") - $last_run_time )) -gt $(( 60 * 1000 * 1000 * 1000 )) ]; then
|
||||||
|
local elapsed_color="%{$fg[red]%}"
|
||||||
|
elif [ $(( $(perl -MTime::HiRes=time -e 'printf "%.9f\n", time' | tr -d ".") - $last_run_time )) -gt $(( 10 * 1000 * 1000 * 1000 )) ]; then
|
||||||
|
local elapsed_color="%{$fg[yellow]%}"
|
||||||
|
else
|
||||||
|
local elapsed_color="%{$fg[green]%}"
|
||||||
|
fi
|
||||||
|
info=$(printf "%s%s%s%s%s" "%{$fg[cyan]%}[" "$elapsed_color" "$elapsed" "%{$fg[cyan]%}]" "$RETVAL")
|
||||||
|
unset last_run_time
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$info" -a ! -z "$last_vcs_info" ]; then
|
||||||
|
custom_prompt="$last_vcs_info$base_prompt"
|
||||||
|
return;
|
||||||
|
fi
|
||||||
|
|
||||||
|
if (( ${+VCS_PROMPT} )); then
|
||||||
|
last_vcs_info=$($VCS_PROMPT)
|
||||||
|
if [ ! -z "$last_vcs_info" ]; then
|
||||||
|
[ -z "$info" ] && info=$last_vcs_info || info="$info$last_vcs_info"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ -z "$info" ] && custom_prompt="$base_prompt" || custom_prompt="$info$base_prompt"
|
||||||
|
}
|
||||||
|
|
||||||
|
function hg_prompt_info() {
|
||||||
|
unset output info parts branch_parts branch
|
||||||
|
|
||||||
|
local output=""
|
||||||
|
if ! output="$(hg status 2> /dev/null)"; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
local info=$(hg log -l1 --template '{author}:{node|short}:{remotenames}:{phabdiff}')
|
||||||
|
local parts=(${(@s/:/)info})
|
||||||
|
local branch_parts=(${(@s,/,)parts[3]})
|
||||||
|
local branch=${branch_parts[-1]}
|
||||||
|
[ ! -z "${parts[3]}" ] && [[ "${parts[1]}" =~ "$USER@" ]] && branch=${parts[3]}
|
||||||
|
[ -z "${parts[3]}" ] && branch=${parts[2]}
|
||||||
|
|
||||||
|
if [[ ! -z "$output" ]]; then
|
||||||
|
local color="%{$fg[red]%}"
|
||||||
|
elif [[ "${branch}" == "master" || "${branch}" == "warm" ]]; then
|
||||||
|
local color="%{$fg[yellow]%}"
|
||||||
|
else
|
||||||
|
local color="%{$fg[green]%}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
print "%{$fg[cyan]%}[${color}${branch}%{$fg[cyan]%}]"
|
||||||
|
}
|
||||||
|
|
||||||
|
setopt PROMPT_SUBST
|
||||||
|
PROMPT='$custom_prompt'
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user