我可以在鱼类的航站楼中缩短分支机构

问题描述 投票:0回答:2
目前我的鱼终端通常看起来像

><> ~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 " "
macos shell terminal fish
2个回答
1
投票
按照您的要求缩短它:

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/')
    

我目前运行

fish --version

3.7.0。我发现我能够进入
~/.config/fish/config.fish
并添加此行以将分支限制为20个字符:

0
投票
set __fish_git_prompt_shorten_branch_len 20

它只是截断了文本,因此“ long_app_name_release_candidate_1_4”变为“ long_app_name_relea…”
我通过遵循Fish_prompt定义找到了这一点。
当我运行
type fish_prompt

时,我会看到这个片段:
    (fish_vcs_prompt)

当我跑步时,我看到这一行:

type fish_vcs_prompt

当我运行时,我会得到一个巨大的功能,有一些类似的行:

    fish_git_prompt $argv


最新问题
© www.soinside.com 2019 - 2025. All rights reserved.