Skip to content

Commit 49263dc

Browse files
authoredMar 12, 2025
Merge pull request #230 from mr-mustash/u/pking/20250312_fish_updates_part_2
Fish 4.0 Update
2 parents 99fa5a4 + 358bca5 commit 49263dc

8 files changed

+94
-81
lines changed
 

‎tilde/.config/fish/config.fish

+10-11
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,31 @@ if status is-interactive
22
# Colors
33
source "$__fish_config_dir/colors.fish"
44

5-
# Adding my prompt configs first
5+
# Key bindings
6+
test -e $__fish_config_dir/function/fish_user_key_bindings.fish; and set fish_key_bindings fish_user_key_bindings
7+
8+
# Load custom prompt directory
69
set -gx fish_function_path $__fish_config_dir/prompt/prompt_functions/ $fish_function_path
710
set -gx fish_function_path $__fish_config_dir/prompt/ $fish_function_path
811
set -gx async_prompt_functions __fish_prompt_git __fish_prompt_screen __fish_prompt_jobs __fish_right_prompt_github_user
912
set -gx async_prompt_inherit_variables status pipestatus SHLVL CMD_DURATION fish_bind_mode __wall_clock_time_pre __wall_clock_time_post
1013
set -gx async_prompt_internal_signal SIGUSR3
1114

12-
13-
# Separate directory for shims that --wrap commands
15+
# Load shims that `--wrap` commands
1416
set -gx fish_function_path $__fish_config_dir/shims/ $fish_function_path
1517

16-
# Key bindings
17-
test -e $__fish_config_dir/function/fish_user_key_bindings.fish; and set fish_key_bindings fish_user_key_bindings
18+
# Source event handlers
19+
set -gx fish_function_path $__fish_config_dir/event_handlers $fish_function_path
20+
for event_function in $__fish_config_dir/event_handlers/*.fish
21+
source $event_function
22+
end
1823

1924
# Add private scripts to the function path
2025
set -gx fish_function_path $__fish_config_dir/private/ $fish_function_path
2126
if test -e $__fish_config_dir/private/private_env.fish
2227
source $__fish_config_dir/private/private_env.fish
2328
end
2429

25-
# Add event handlers to the function path and source them
26-
set -gx fish_function_path $__fish_config_dir/event_handlers $fish_function_path
27-
for event_function in $__fish_config_dir/event_handlers/*.fish
28-
source $event_function
29-
end
30-
3130
else
3231
set -gx fish_function_path $__fish_config_dir/prompt/prompt_functions/ $fish_function_path
3332
set -gx fish_function_path $__fish_config_dir/prompt/ $fish_function_path
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
function __fish_dirchanged_update_file_list --on-variable PWD --description "Update the current file list on a directory change"
2-
set -g __dir_file_list (command ls -1a)
3-
end
1+
#function __fish_dirchanged_update_file_list --on-variable PWD --description "Update the current file list on a directory change"
2+
# set -g __dir_file_list (command ls -1a)
3+
#end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function __fish_on_variable_pwd --on-variable PWD --description "Recalculate dir string when directory changes"
2+
set -e __fish_prompt_pwd_string
3+
end

‎tilde/.config/fish/prompt/fish_prompt.fish

+2-7
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ function fish_prompt --description 'Write out the prompt'
22
__fish_prompt_username
33
__fish_prompt_hostname
44
__fish_prompt_pwd
5-
6-
# TODO: __fish_prompt_pwd_graveyard still show graveyard files for subdirectories
75
#__fish_prompt_pwd_graveyard
86

97
__fish_prompt_git
108

11-
__fish_prompt_languages
12-
__fish_prompt_jobs
9+
#__fish_prompt_languages
10+
#__fish_prompt_jobs
1311
__fish_prompt_screen
1412

1513
# Change the color of the glyph based on vi mode
@@ -18,14 +16,11 @@ function fish_prompt --description 'Write out the prompt'
1816
# bryellow is equal to grey???
1917
set fish_color_prompt bryellow --bold
2018
case insert
21-
# This is different than the yellow that I use
22-
# for Vim but it's much more aestheticlaly pleasing.
2319
set fish_color_prompt $fish_color_user
2420
case visual
2521
set fish_color_prompt magenta --bold
2622
end
2723

2824
set -l glyph ""
2925
echo -ns (set_color $fish_color_prompt) " $glyph " (set_color normal)
30-
3126
end
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,60 @@
11
function __fish_prompt_pwd --description 'Format the current directory for the prompt'
2-
set -l max (math "round($COLUMNS / 8)") # maximum length = 1/8rd window width
2+
if not set -q __fish_prompt_pwd_string
3+
# Avoid repeated string operations by using a more direct approach
4+
set -l path_str
5+
if string match -q "$HOME/*" "$PWD"
6+
set path_str "~"(string sub -s (math 1 + (string length "$HOME")) "$PWD")
7+
else if test "$PWD" = "$HOME"
8+
set path_str "~"
9+
else
10+
set path_str "$PWD"
11+
end
312

4-
set -l short_path (pwd | string replace -r ".*/" "") # basename of current dir
5-
set -l short_path_length (string length $short_path)
13+
# Calculate max length
14+
set -l max (math "round($COLUMNS/6)")
615

7-
# if basename of $PWD is too long by itself, don't trim it
8-
if test $max -lt $short_path_length
9-
set max $short_path_length
10-
end
16+
# Quick return for short paths
17+
if test (string length -- $path_str) -le $max
18+
echo -ns (set_color $fish_color_cwd --bold) $path_str (set_color normal)
19+
return
20+
end
21+
22+
# Split path into components only once
23+
set -l components (string split / $path_str)
24+
set -l num_components (count $components)
25+
set -l truncated
26+
set -l current_len 0
27+
set -l i $num_components
28+
29+
# Process components from end until we hit length limit
30+
while test $i -gt 0
31+
set -l component $components[$i]
32+
set -l component_len (string length -- $component)
33+
34+
# Add 1 for the slash unless it's the first component
35+
if test -n "$truncated"
36+
set component_len (math $component_len + 1)
37+
end
1138

12-
# tilde-ify homedir
13-
set -l long_path (pwd | string replace -r "^$HOME" "~")
39+
if test (math $current_len + $component_len) -gt $max
40+
break
41+
end
1442

15-
# is $PWD too long, and if so, by how much?
16-
set -l long_path_length (string length $long_path)
17-
set -l excess (math "round($long_path_length - $max)")
43+
if test -n "$truncated"
44+
set truncated "$component/$truncated"
45+
else
46+
set truncated $component
47+
end
1848

19-
if test $excess -gt 0
20-
# cut to $max chars long, trim leading detritus and add leader
21-
set cut_path (string sub --start "$excess" "$long_path")
22-
set path_parts (string split --max=1 / "{$cut_path")
23-
set trimmed_path $path_parts[2]
49+
set current_len (math $current_len + $component_len)
50+
set i (math $i - 1)
51+
end
2452

25-
set long_path "…/$trimmed_path"
53+
# Add ellipsis if we didn't use all components
54+
if test $i -gt 0
55+
set __fish_prompt_pwd_string "…/$truncated"
56+
end
2657
end
2758

28-
echo -ns (set_color $fish_color_cwd --bold) $long_path (set_color normal)
59+
echo -ns (set_color $fish_color_cwd --bold) $__fish_prompt_pwd_string (set_color normal)
2960
end
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,25 @@
11
function __fish_prompt_pwd_graveyard --description 'Are there files in the pwd that are in the `rip` graveyard?'
2-
if in-path rip
3-
set -l __rip_graveyard_files (rip -s 2>/dev/null)
4-
if test $status -ne 0 -o (count $__rip_graveyard_files) -eq 0
5-
return
6-
end
2+
# Early return if no GRAVEYARD variable
3+
set -q GRAVEYARD || return
74

8-
# This whole statement is here because if you call `rip -s` it'll recurse
9-
# through every directory and see if there is a file in the graveyard.
10-
# Here I am checking to see if there is a file in the graveyard exists
11-
# in the current directory and not in any subdirectories.
5+
# Cache graveyard files
6+
set -l __rip_graveyard_files (rip -s 2>/dev/null) || return
7+
test (count $__rip_graveyard_files) -eq 0 && return
128

13-
# First, find the graveyard location.
14-
set -l _whoami (whoami)
15-
if set -q GRAVEYARD
16-
set _graveyard (echo $GRAVEYARD | string escape --style=regex | sed -e "s.\/.\\\/.g")
17-
else
18-
set _graveyard (\/tmp\/graveyard-$_whoami\/)
19-
end
9+
# Get current path
10+
set -l pwd $PWD
11+
set -l pwd_p (pwd -P)
2012

21-
# Now, find if the current directory is in the graveyard.
22-
contains -i (pwd -L) (dirname (rip -s | sed -e "s/$_graveyard//")) >/dev/null \
23-
|| contains -i (pwd -P) (dirname (rip -s | sed -e "s/$_graveyard//")) >/dev/null
24-
if test $status -eq 0
25-
set __fish_prompt_pwd_has_graveyard 0
26-
else
27-
return
28-
end
13+
# Prepare graveyard path regex once
14+
set -l _graveyard (string escape --style=regex -- $GRAVEYARD)
2915

30-
if test $__fish_prompt_pwd_has_graveyard -eq 0
31-
echo -ns (set_color normal) "("
32-
echo -ns (set_color $fish_prompt_color_graveyard) "" (set_color normal)
33-
echo -ns ")"
16+
# Process files in batch where possible
17+
for file in $__rip_graveyard_files
18+
# Do string operations only once per iteration
19+
set -l file_dir (dirname (string replace -r "^$_graveyard" "" $file))
20+
if test "$file_dir" = "$pwd" -o "$file_dir" = "$pwd_p"
21+
echo -ns (set_color normal)"("(set_color $fish_prompt_color_graveyard)""(set_color normal)")"
22+
return
3423
end
3524
end
36-
3725
end
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
function __fish_prompt_screen --description 'Helper function for fish_prompt'
2-
# Yes this grep could be nicer, but it's easier to just have both the
3-
# single and plural options.
4-
set -l screen_count (command screen -ls | egrep -v 'Socket|Sockets|There is a screen|There are screens|^[[:space:]]*$' | wc -l)
5-
if test $screen_count = 0
2+
if not set -q __screen_session_count
3+
set -g __screen_session_count (command screen -ls | egrep -v 'Socket|Sockets|There is a screen|There are screens|^[[:space:]]*$' | wc -l)
4+
end
5+
6+
if test $__screen_session_count = 0
67
return
78
end
89

910
set -l sty (echo $STY)
1011
if test -n "$sty"
11-
echo -ns (set_color $fish_prompt_color_in_screen) " 󰊓 " (set_color normal) $screen_count (set_color normal)
12+
echo -ns (set_color $fish_prompt_color_in_screen) " 󰊓 " (set_color normal) $__screen_session_count (set_color normal)
1213
else
13-
echo -ns (set_color $fish_prompt_color_screen) " 󰊓 " (set_color normal) $screen_count (set_color normal)
14+
echo -ns (set_color $fish_prompt_color_screen) " 󰊓 " (set_color normal) $__screen_session_count (set_color normal)
1415
end
1516
end

‎tilde/.config/fish/shims/screen.fish

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
function screen --wraps screen -d "Make screen more useful by asking what to connect to."
2-
if status is-interactive
3-
command screen $argv
4-
if test $status -ne 0
5-
echo "Fix this function."
6-
end
7-
end
2+
set -e __screen_session_count
3+
command screen $argv
84
end

0 commit comments

Comments
 (0)
Failed to load comments.