summaryrefslogtreecommitdiff
path: root/home-config/fish/functions/fish_prompt.fish
diff options
context:
space:
mode:
Diffstat (limited to 'home-config/fish/functions/fish_prompt.fish')
-rw-r--r--home-config/fish/functions/fish_prompt.fish171
1 files changed, 171 insertions, 0 deletions
diff --git a/home-config/fish/functions/fish_prompt.fish b/home-config/fish/functions/fish_prompt.fish
new file mode 100644
index 0000000..3b58b7b
--- /dev/null
+++ b/home-config/fish/functions/fish_prompt.fish
@@ -0,0 +1,171 @@
1function fish_prompt
2end # In case this file gets loaded non-interactively, e.g by conda
3status is-interactive || exit
4
5_tide_remove_unusable_items
6_tide_cache_variables
7_tide_parent_dirs
8source (functions --details _tide_pwd)
9
10set -l prompt_var _tide_prompt_$fish_pid
11set -U $prompt_var # Set var here so if we erase $prompt_var, bg job won't set a uvar
12
13set_color normal | read -l color_normal
14status fish-path | read -l fish_path
15
16# _tide_repaint prevents us from creating a second background job
17function _tide_refresh_prompt --on-variable $prompt_var --on-variable COLUMNS
18 set -g _tide_repaint
19 commandline -f repaint
20end
21
22if contains newline $_tide_left_items # two line prompt initialization
23 test "$tide_prompt_add_newline_before" = true && set -l add_newline '\n'
24
25 set_color $tide_prompt_color_frame_and_connection -b normal | read -l prompt_and_frame_color
26
27 set -l column_offset 5
28 test "$tide_left_prompt_frame_enabled" = true &&
29 set -l top_left_frame "$prompt_and_frame_color╭─" &&
30 set -l bot_left_frame "$prompt_and_frame_color╰─" &&
31 set column_offset (math $column_offset-2)
32 test "$tide_right_prompt_frame_enabled" = true &&
33 set -l top_right_frame "$prompt_and_frame_color─╮" &&
34 set -l bot_right_frame "$prompt_and_frame_color─╯" &&
35 set column_offset (math $column_offset-2)
36
37 if test "$tide_prompt_transient_enabled" = true
38 eval "
39function fish_prompt
40 _tide_status=\$status _tide_pipestatus=\$pipestatus if not set -e _tide_repaint
41 jobs -q && jobs -p | count | read -lx _tide_jobs
42 $fish_path -c \"set _tide_pipestatus \$_tide_pipestatus
43set _tide_parent_dirs \$_tide_parent_dirs
44PATH=\$(string escape \"\$PATH\") CMD_DURATION=\$CMD_DURATION fish_bind_mode=\$fish_bind_mode set $prompt_var (_tide_2_line_prompt)\" &
45 builtin disown
46
47 command kill \$_tide_last_pid 2>/dev/null
48 set -g _tide_last_pid \$last_pid
49 end
50
51 if not set -q _tide_transient
52 math \$COLUMNS-(string length -V \"\$$prompt_var[1][1]\$$prompt_var[1][3]\")+$column_offset | read -lx dist_btwn_sides
53
54 echo -n $add_newline'$top_left_frame'(string replace @PWD@ (_tide_pwd) \"\$$prompt_var[1][1]\")'$prompt_and_frame_color'
55 string repeat -Nm(math max 0, \$dist_btwn_sides-\$_tide_pwd_len) '$tide_prompt_icon_connection'
56
57 echo \"\$$prompt_var[1][3]$top_right_frame\"
58 end
59 echo -n \e\[0J\"$bot_left_frame\$$prompt_var[1][2]$color_normal \"
60end
61
62function fish_right_prompt
63 set -e _tide_transient || string unescape \"\$$prompt_var[1][4]$bot_right_frame$color_normal\"
64end"
65 else
66 eval "
67function fish_prompt
68 _tide_status=\$status _tide_pipestatus=\$pipestatus if not set -e _tide_repaint
69 jobs -q && jobs -p | count | read -lx _tide_jobs
70 $fish_path -c \"set _tide_pipestatus \$_tide_pipestatus
71set _tide_parent_dirs \$_tide_parent_dirs
72PATH=\$(string escape \"\$PATH\") CMD_DURATION=\$CMD_DURATION fish_bind_mode=\$fish_bind_mode set $prompt_var (_tide_2_line_prompt)\" &
73 builtin disown
74
75 command kill \$_tide_last_pid 2>/dev/null
76 set -g _tide_last_pid \$last_pid
77 end
78
79 math \$COLUMNS-(string length -V \"\$$prompt_var[1][1]\$$prompt_var[1][3]\")+$column_offset | read -lx dist_btwn_sides
80
81 echo -ns $add_newline'$top_left_frame'(string replace @PWD@ (_tide_pwd) \"\$$prompt_var[1][1]\")'$prompt_and_frame_color'
82 string repeat -Nm(math max 0, \$dist_btwn_sides-\$_tide_pwd_len) '$tide_prompt_icon_connection'
83 echo -ns \"\$$prompt_var[1][3]$top_right_frame\"\n\"$bot_left_frame\$$prompt_var[1][2]$color_normal \"
84end
85
86function fish_right_prompt
87 string unescape \"\$$prompt_var[1][4]$bot_right_frame$color_normal\"
88end"
89 end
90else # one line prompt initialization
91 test "$tide_prompt_add_newline_before" = true && set -l add_newline '\0'
92
93 math 5 -$tide_prompt_min_cols | read -l column_offset
94 test $column_offset -ge 0 && set column_offset "+$column_offset"
95
96 if test "$tide_prompt_transient_enabled" = true
97 eval "
98function fish_prompt
99 set -lx _tide_status \$status
100 _tide_pipestatus=\$pipestatus if not set -e _tide_repaint
101 jobs -q && jobs -p | count | read -lx _tide_jobs
102 $fish_path -c \"set _tide_pipestatus \$_tide_pipestatus
103set _tide_parent_dirs \$_tide_parent_dirs
104PATH=\$(string escape \"\$PATH\") CMD_DURATION=\$CMD_DURATION fish_bind_mode=\$fish_bind_mode set $prompt_var (_tide_1_line_prompt)\" &
105 builtin disown
106
107 command kill \$_tide_last_pid 2>/dev/null
108 set -g _tide_last_pid \$last_pid
109 end
110
111 if set -q _tide_transient
112 echo -n \e\[0J
113 add_prefix= _tide_item_character
114 echo -n '$color_normal '
115 else
116 math \$COLUMNS-(string length -V \"\$$prompt_var[1][1]\$$prompt_var[1][2]\")$column_offset | read -lx dist_btwn_sides
117 string replace @PWD@ (_tide_pwd) $add_newline \$$prompt_var[1][1]'$color_normal '
118 end
119end
120
121function fish_right_prompt
122 set -e _tide_transient || string unescape \"\$$prompt_var[1][2]$color_normal\"
123end"
124 else
125 eval "
126function fish_prompt
127 _tide_status=\$status _tide_pipestatus=\$pipestatus if not set -e _tide_repaint
128 jobs -q && jobs -p | count | read -lx _tide_jobs
129 $fish_path -c \"set _tide_pipestatus \$_tide_pipestatus
130set _tide_parent_dirs \$_tide_parent_dirs
131PATH=\$(string escape \"\$PATH\") CMD_DURATION=\$CMD_DURATION fish_bind_mode=\$fish_bind_mode set $prompt_var (_tide_1_line_prompt)\" &
132 builtin disown
133
134 command kill \$_tide_last_pid 2>/dev/null
135 set -g _tide_last_pid \$last_pid
136 end
137
138 math \$COLUMNS-(string length -V \"\$$prompt_var[1][1]\$$prompt_var[1][2]\")$column_offset | read -lx dist_btwn_sides
139 string replace @PWD@ (_tide_pwd) $add_newline \$$prompt_var[1][1]'$color_normal '
140end
141
142function fish_right_prompt
143 string unescape \"\$$prompt_var[1][2]$color_normal\"
144end"
145 end
146end
147
148eval "function _tide_on_fish_exit --on-event fish_exit
149 set -e $prompt_var
150end"
151
152if test "$tide_prompt_transient_enabled" = true
153 function _tide_enter_transient
154 # If the commandline will be executed, or is empty
155 if commandline --is-valid || test -z "$(commandline)"
156 # Pager open usually means selecting, not running
157 # Can be untrue, but it's better than the alternative
158 if not commandline --paging-mode
159 set -g _tide_transient
160 set -g _tide_repaint
161 commandline -f repaint
162 end
163 end
164 commandline -f execute
165 end
166
167 bind \r _tide_enter_transient
168 bind \n _tide_enter_transient
169 bind -M insert \r _tide_enter_transient
170 bind -M insert \n _tide_enter_transient
171end