我可以在 fish 的终端中缩短分支名称吗
Can I shorten branch names in my terminal in fish
我的问题基本上是,但是对于鱼来说,因为那里给出的解决方案不适用于这个
目前我的fish terminal经常长这样
><> ~r/f/d/config on LONG_APP_NAME_RELEASE_CANDIDATE_1_4 x 16:55:12
所以我几乎没有 space 实际输入。任何人对如何解决这个问题有任何想法,可能看起来像这样:
><> ~r/f/d/config on LONG_A...1_4 x 16:55:12
正如@glenn 在评论中提出的那样,我输入了 type fish_prompt
得到一个函数
1 fish_prompt is a function with definition
2 # Defined in /Users/mge/.config/fish/functions/fish_prompt.fish @ line 5
3 function fish_prompt
4 set -l last_command_status $status
5 set -l cwd
6
7 if test "$theme_short_path" = 'yes'
8 set cwd (basename (prompt_pwd))
9 else
10 set cwd (prompt_pwd)
11 end
12
13 set -l fish "⋊>"
14 set -l ahead "↑"
15 set -l behind "↓"
16 set -l diverged "⥄ "
17 set -l dirty "⨯"
18 set -l none "◦"
19
20 set -l normal_color (set_color normal)
21 set -l success_color (set_color $fish_pager_color_progress 2> /dev/null ; or set_color cyan)
22 set -l error_color (set_color $fish_color_error 2> /dev/null; or set_ color red --bold)
23 set -l directory_color (set_color $fish_color_quote 2> /dev/null; or set_ color brown)
24 set -l repository_color (set_color $fish_color_cwd 2> /dev/null; or set_co lor green)
25
26 if test $last_command_status -eq 0
27 echo -n -s $success_color $fish $normal_color
28 else
29 echo -n -s $error_color $fish $normal_color
30 end
31
32 if git_is_repo
33 if test "$theme_short_path" = 'yes'
34 set root_folder (command git rev-parse --show-toplevel 2> /dev/null)
35 set parent_root_folder (dirname $root_folder)
36 set cwd (echo $PWD | sed -e "s|$parent_root_folder/||")
37 end
38
39 echo -n -s " " $directory_color $cwd $normal_color
40 echo -n -s " on " $repository_color (git_branch_name) $normal_color " "
41
42 if git_is_touched
43 echo -n -s $dirty
44 else
45 echo -n -s (git_ahead $ahead $behind $diverged $none)
46 end
47 else
48 echo -n -s " " $directory_color $cwd $normal_color
49 end
50
51 echo -n -s " "
52 end
这几乎给了我解决这个问题的正确想法,但我不会说鱼,所以我不确定如何编辑它
这是显示长分支名称的违规行
echo -n -s " on " $repository_color (git_branch_name) $normal_color " "
根据您的要求缩短:
set branch (git_branch_name)
test (string length $branch) -gt 12
and set branch (string replace -r '(.{6}).*(.{3})' '...' $branch)
echo -n -s " on " $repository_color $branch $normal_color " "
我不确定“字符串替换”需要什么版本的 fish -- 如果出现错误,您可以这样做
test (string length $branch) -gt 12
and set branch (echo $branch | sed -E 's/(.{6}).*(.{3})/.../')
我的问题基本上是
目前我的fish terminal经常长这样
><> ~r/f/d/config on LONG_APP_NAME_RELEASE_CANDIDATE_1_4 x 16:55:12
所以我几乎没有 space 实际输入。任何人对如何解决这个问题有任何想法,可能看起来像这样:
><> ~r/f/d/config on LONG_A...1_4 x 16:55:12
正如@glenn 在评论中提出的那样,我输入了 type fish_prompt
得到一个函数
1 fish_prompt is a function with definition
2 # Defined in /Users/mge/.config/fish/functions/fish_prompt.fish @ line 5
3 function fish_prompt
4 set -l last_command_status $status
5 set -l cwd
6
7 if test "$theme_short_path" = 'yes'
8 set cwd (basename (prompt_pwd))
9 else
10 set cwd (prompt_pwd)
11 end
12
13 set -l fish "⋊>"
14 set -l ahead "↑"
15 set -l behind "↓"
16 set -l diverged "⥄ "
17 set -l dirty "⨯"
18 set -l none "◦"
19
20 set -l normal_color (set_color normal)
21 set -l success_color (set_color $fish_pager_color_progress 2> /dev/null ; or set_color cyan)
22 set -l error_color (set_color $fish_color_error 2> /dev/null; or set_ color red --bold)
23 set -l directory_color (set_color $fish_color_quote 2> /dev/null; or set_ color brown)
24 set -l repository_color (set_color $fish_color_cwd 2> /dev/null; or set_co lor green)
25
26 if test $last_command_status -eq 0
27 echo -n -s $success_color $fish $normal_color
28 else
29 echo -n -s $error_color $fish $normal_color
30 end
31
32 if git_is_repo
33 if test "$theme_short_path" = 'yes'
34 set root_folder (command git rev-parse --show-toplevel 2> /dev/null)
35 set parent_root_folder (dirname $root_folder)
36 set cwd (echo $PWD | sed -e "s|$parent_root_folder/||")
37 end
38
39 echo -n -s " " $directory_color $cwd $normal_color
40 echo -n -s " on " $repository_color (git_branch_name) $normal_color " "
41
42 if git_is_touched
43 echo -n -s $dirty
44 else
45 echo -n -s (git_ahead $ahead $behind $diverged $none)
46 end
47 else
48 echo -n -s " " $directory_color $cwd $normal_color
49 end
50
51 echo -n -s " "
52 end
这几乎给了我解决这个问题的正确想法,但我不会说鱼,所以我不确定如何编辑它
这是显示长分支名称的违规行
echo -n -s " on " $repository_color (git_branch_name) $normal_color " "
根据您的要求缩短:
set branch (git_branch_name)
test (string length $branch) -gt 12
and set branch (string replace -r '(.{6}).*(.{3})' '...' $branch)
echo -n -s " on " $repository_color $branch $normal_color " "
我不确定“字符串替换”需要什么版本的 fish -- 如果出现错误,您可以这样做
test (string length $branch) -gt 12
and set branch (echo $branch | sed -E 's/(.{6}).*(.{3})/.../')