Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
74a3db75
Unverified
Commit
74a3db75
authored
Feb 07, 2022
by
Marc Cornellà
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf(bureau): remove multiple grep calls in git status check
parent
9e9831fc
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
17 deletions
+19
-17
bureau.zsh-theme
themes/bureau.zsh-theme
+19
-17
No files found.
themes/bureau.zsh-theme
View file @
74a3db75
...
@@ -16,7 +16,7 @@ ZSH_THEME_GIT_PROMPT_STAGED="%{$fg_bold[green]%}●%{$reset_color%}"
...
@@ -16,7 +16,7 @@ ZSH_THEME_GIT_PROMPT_STAGED="%{$fg_bold[green]%}●%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_UNSTAGED="%{$fg_bold[yellow]%}●%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_UNSTAGED="%{$fg_bold[yellow]%}●%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[red]%}●%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[red]%}●%{$reset_color%}"
bureau_git_
branch
() {
bureau_git_
info
() {
local ref
local ref
ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
...
@@ -30,16 +30,16 @@ bureau_git_status() {
...
@@ -30,16 +30,16 @@ bureau_git_status() {
# check status of files
# check status of files
local gitfiles="$(tail -n +2 <<< "$gitstatus")"
local gitfiles="$(tail -n +2 <<< "$gitstatus")"
if [[ -n "$gitfiles" ]]; then
if [[ -n "$gitfiles" ]]; then
if
$(echo "$gitfiles" | command grep -q '^[AMRD]. ')
; then
if
[[ "$gitfiles" =~ $'(^|\n)[AMRD]. ' ]]
; then
result+="$ZSH_THEME_GIT_PROMPT_STAGED"
result+="$ZSH_THEME_GIT_PROMPT_STAGED"
fi
fi
if
$(echo "$gitfiles" | command grep -q '^.[MTD] ')
; then
if
[[ "$gitfiles" =~ $'(^|\n).[MTD] ' ]]
; then
result+="$ZSH_THEME_GIT_PROMPT_UNSTAGED"
result+="$ZSH_THEME_GIT_PROMPT_UNSTAGED"
fi
fi
if
$(echo "$gitfiles" | command grep -q -E '^\?\? ')
; then
if
[[ "$gitfiles" =~ $'(^|\n)\\?\\? ' ]]
; then
result+="$ZSH_THEME_GIT_PROMPT_UNTRACKED"
result+="$ZSH_THEME_GIT_PROMPT_UNTRACKED"
fi
fi
if
$(echo "$gitfiles" | command grep -q '^UU ')
; then
if
[[ "$gitfiles" =~ $'(^|\n)UU ' ]]
; then
result+="$ZSH_THEME_GIT_PROMPT_UNMERGED"
result+="$ZSH_THEME_GIT_PROMPT_UNMERGED"
fi
fi
else
else
...
@@ -48,17 +48,18 @@ bureau_git_status() {
...
@@ -48,17 +48,18 @@ bureau_git_status() {
# check status of local repository
# check status of local repository
local gitbranch="$(head -n 1 <<< "$gitstatus")"
local gitbranch="$(head -n 1 <<< "$gitstatus")"
if
$(echo "$gitbranch" | command grep -q '^## .*ahead')
; then
if
[[ "$gitbranch" =~ '^## .*ahead' ]]
; then
result+="$ZSH_THEME_GIT_PROMPT_AHEAD"
result+="$ZSH_THEME_GIT_PROMPT_AHEAD"
fi
fi
if
$(echo "$gitbranch" | command grep -q '^## .*behind')
; then
if
[[ "$gitbranch" =~ '^## .*behind' ]]
; then
result+="$ZSH_THEME_GIT_PROMPT_BEHIND"
result+="$ZSH_THEME_GIT_PROMPT_BEHIND"
fi
fi
if
$(echo "$gitbranch" | command grep -q '^## .*diverged')
; then
if
[[ "$gitbranch" =~ '^## .*diverged' ]]
; then
result+="$ZSH_THEME_GIT_PROMPT_DIVERGED"
result+="$ZSH_THEME_GIT_PROMPT_DIVERGED"
fi
fi
if $(command git rev-parse --verify refs/stash &> /dev/null); then
# check if there are stashed changes
if command git rev-parse --verify refs/stash &> /dev/null; then
result+="$ZSH_THEME_GIT_PROMPT_STASHED"
result+="$ZSH_THEME_GIT_PROMPT_STASHED"
fi
fi
...
@@ -66,21 +67,22 @@ bureau_git_status() {
...
@@ -66,21 +67,22 @@ bureau_git_status() {
}
}
bureau_git_prompt() {
bureau_git_prompt() {
local gitbranch=$(bureau_git_branch)
# check git information
local gitstatus=$(bureau_git_status)
local gitinfo=$(bureau_git_info)
local info
if [[ -z "$gitinfo" ]]; then
if [[ -z "$gitbranch" ]]; then
return
return
fi
fi
info="${gitbranch:gs/%/%%}"
# quote % in git information
local output="${gitinfo:gs/%/%%}"
# check git status
local gitstatus=$(bureau_git_status)
if [[ -n "$gitstatus" ]]; then
if [[ -n "$gitstatus" ]]; then
info
+=" $gitstatus"
output
+=" $gitstatus"
fi
fi
echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${
info
}${ZSH_THEME_GIT_PROMPT_SUFFIX}"
echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${
output
}${ZSH_THEME_GIT_PROMPT_SUFFIX}"
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment