我可以在fish中缩短终端中的分支名称吗



我的问题基本上是这个,但对于fish来说,由于给出的解决方案不适用于这个

目前,我的鱼码头经常看起来像

><> ~r/f/d/config on LONG_APP_NAME_RELEASE_CANDIDATE_1_4 x           16:55:12

所以它几乎没有给我留下什么实际输入的空间。任何人都有任何关于如何解决这个问题的想法,也许看起来像这样:

><> ~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})' '$1...$2' $branch)
echo -n -s " on " $repository_color $branch $normal_color " "

我不确定你需要什么版本的鱼";字符串替换"——如果你有错误,你可以做

test (string length $branch) -gt 12
and set branch (echo $branch | sed -E 's/(.{6}).*(.{3})/1...2/')

最新更新