-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbetter-robbyrussell.zsh-theme
More file actions
60 lines (50 loc) · 1.92 KB
/
better-robbyrussell.zsh-theme
File metadata and controls
60 lines (50 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
aws_prompt_info() {}
aws_profile_info() {
local profile=$(agp)
if [[ -n $profile && $profile != "default" ]]; then
echo "%{$fg_bold[yellow]%}[$profile]%{$reset_color%}"
fi
}
# Function to update git and aws profile info before each prompt
precmd() {
GIT_BRANCH_INFO=$(git_prompt_info_truncated)
AWS_PROFILE_INFO=$(aws_profile_info)
DIR_NAME_INFO=$(dir_name_truncated)
}
conditional_space() {
if [[ -n "$AWS_PROFILE_INFO" || -n "$GIT_BRANCH_INFO" ]]; then
echo " "
fi
}
PROMPT="%(?:%{$fg_bold[green]%}%1{➜%}:%{$fg_bold[red]%}%1{➜%}) %{$fg[cyan]%}\$DIR_NAME_INFO%{$reset_color%} "
PROMPT+='$AWS_PROFILE_INFO$GIT_BRANCH_INFO'
PROMPT+='$(conditional_space)'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"
dir_name_truncated() {
local dir_name=$(print -P %c)
if [[ -n "$TRUNCATED_DIR_NAME_LENGTH" && ${#dir_name} -gt $TRUNCATED_DIR_NAME_LENGTH ]]; then
dir_name="${dir_name:0:$TRUNCATED_DIR_NAME_LENGTH}"
fi
echo "$dir_name"
}
git_prompt_info_truncated() {
local ref=$(git symbolic-ref HEAD 2> /dev/null)
if [[ -n $ref ]]; then
local branch_name=${ref#refs/heads/}
# If TRUNCATED_BRANCH_NAME_START_WITH is set, extract from that word onwards
if [[ -n "$TRUNCATED_BRANCH_NAME_START_WITH" ]]; then
local start_pos="${branch_name%%$TRUNCATED_BRANCH_NAME_START_WITH*}"
if [[ "$start_pos" != "$branch_name" ]]; then
# Found the start word, extract everything from it onwards
branch_name="${branch_name:${#start_pos}}"
fi
fi
# Apply truncation if configured
if [[ -n "$TRUNCATED_BRANCH_NAME_LENGTH" && ${#branch_name} -gt $TRUNCATED_BRANCH_NAME_LENGTH ]]; then
branch_name="${branch_name:0:$TRUNCATED_BRANCH_NAME_LENGTH}"
fi
echo "$ZSH_THEME_GIT_PROMPT_PREFIX$branch_name$ZSH_THEME_GIT_PROMPT_CLEAN$ZSH_THEME_GIT_PROMPT_SUFFIX"
fi
}