Skip to content

Commit bb4c64e

Browse files
feat: Support git relative path on pure layout (#108)
1 parent fc12a6f commit bb4c64e

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

typewritten.zsh

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,48 +61,50 @@ tw_get_virtual_env() {
6161
fi;
6262
}
6363

64-
tw_get_home_relative_wd() {
65-
echo "%F{$tw_current_directory_color}%~"
66-
}
64+
tw_get_displayed_wd() {
65+
local tw_git_branch=$tw_prompt_data[tw_git_branch]
66+
local tw_git_home=$tw_prompt_data[tw_git_home]
67+
68+
local tw_home_relative_wd="%~"
69+
local tw_git_relative_wd="$tw_git_home%c"
6770

68-
tw_get_git_relative_wd() {
69-
local tw_home_relative_wd="$1"
70-
local tw_git_branch="$2"
71-
local tw_git_home="$3"
71+
local tw_displayed_wd="$tw_git_relative_wd"
7272

73-
local tw_git_relative_wd="%F{$tw_current_directory_color}$tw_git_home%c"
73+
# The pure layout defaults to home relative working directory, but allows customization
74+
if [[ "$TYPEWRITTEN_PROMPT_LAYOUT" = "pure" && "$TYPEWRITTEN_RELATIVE_PATH" = "" ]]; then
75+
tw_displayed_wd=$tw_home_relative_wd
76+
fi;
7477

7578
if [[ "$TYPEWRITTEN_RELATIVE_PATH" = "home" ]]; then
76-
tw_git_relative_wd=$tw_home_relative_wd
79+
tw_displayed_wd=$tw_home_relative_wd
7780
fi;
7881

7982
if [[ "$TYPEWRITTEN_RELATIVE_PATH" = "adaptive" ]]; then
8083
if [[ "$tw_git_branch" = "" ]]; then
81-
tw_git_relative_wd=$tw_home_relative_wd
84+
tw_displayed_wd=$tw_home_relative_wd
8285
fi;
8386
fi;
8487

85-
echo $tw_git_relative_wd
88+
echo "%F{$tw_current_directory_color}$tw_displayed_wd"
8689
}
8790

8891
tw_redraw() {
89-
tw_home_relative_wd="$(tw_get_home_relative_wd)"
90-
tw_git_relative_wd="$(tw_get_git_relative_wd $tw_home_relative_wd $tw_prompt_data[tw_git_branch] $tw_prompt_data[tw_git_home])"
92+
tw_displayed_wd="$(tw_get_displayed_wd)"
9193

9294
tw_env_prompt="$(tw_get_virtual_env)$tw_prompt"
9395

9496
tw_layout="$TYPEWRITTEN_PROMPT_LAYOUT"
9597
tw_git_info="$tw_prompt_data[tw_git_branch]$tw_prompt_data[tw_git_status]"
9698
if [ "$tw_layout" = "half_pure" ]; then
9799
PROMPT="$BREAK_LINE%F{$tw_git_branch_color}$tw_git_info$BREAK_LINE$tw_env_prompt"
98-
RPROMPT="$tw_right_prompt_prefix$tw_git_relative_wd"
100+
RPROMPT="$tw_right_prompt_prefix$tw_displayed_wd"
99101
else
100102
local tw_git_arrow_info=""
101103
if [ "$tw_git_info" != "" ]; then
102104
tw_git_arrow_info=" $tw_arrow %F{$tw_git_branch_color}$tw_git_info"
103105
fi;
104106
if [ "$tw_layout" = "pure" ]; then
105-
PROMPT="$BREAK_LINE$tw_home_relative_wd$tw_git_arrow_info$BREAK_LINE$tw_env_prompt"
107+
PROMPT="$BREAK_LINE$tw_displayed_wd$tw_git_arrow_info$BREAK_LINE$tw_env_prompt"
106108
RPROMPT=""
107109
else
108110
if [ "$tw_layout" = "singleline_verbose" ]; then
@@ -112,7 +114,7 @@ tw_redraw() {
112114
else
113115
PROMPT="$tw_env_prompt"
114116
fi;
115-
RPROMPT="$tw_right_prompt_prefix$tw_git_relative_wd$tw_git_arrow_info"
117+
RPROMPT="$tw_right_prompt_prefix$tw_displayed_wd$tw_git_arrow_info"
116118
fi;
117119
fi;
118120

0 commit comments

Comments
 (0)