【发布时间】:2020-05-21 03:39:13
【问题描述】:
我最近切换到 fish 并修改了 fish_config 提供的提示之一,使其看起来像这样。
function fish_greeting
fortune
end
function fish_prompt
echo
set -l retc brblack
test $status = 0; and set retc bryellow
set -q __fish_git_prompt_showupstream
or set -g __fish_git_prompt_showupstream auto
function _nim_prompt_wrapper
set retc $argv[1]
set cust $argv[4]
set field_name $argv[2]
set field_value $argv[3]
set_color normal
set_color $retc
echo
echo -n ' ├─'
echo -n '[ '
set_color normal
test -n $field_name
and echo -n $field_name
set_color -o brblack
echo -n ' ▶ '
set_color $retc
set_color $cust
echo -n $field_value
set_color $retc
echo -n ' ]'
end
set_color $retc
echo -n '─┬─'
echo -n '[ '
set_color -o red
echo -n (prompt_hostname)
echo -n ': '
if test "$USER" = root -o "$USER" = toor
set_color -o brred
else
set_color -o brwhite
end
echo -n $USER
set_color -o brblack
echo -n ' ▶ '
set_color -o brcyan
echo -n (pwd)
set_color $retc
echo -n ' ]'
# Virtual Environment
set -q VIRTUAL_ENV_DISABLE_PROMPT
or set -g VIRTUAL_ENV_DISABLE_PROMPT true
set -q VIRTUAL_ENV
and _nim_prompt_wrapper $retc '???? ' (basename "$VIRTUAL_ENV") cyan
# git
set prompt_git (fish_git_prompt | string trim -c ' ()')
test -n "$prompt_git"
and _nim_prompt_wrapper $retc (basename -s .git (git config --get remote.origin.url) 2> /dev/null) $prompt_git
# New line
echo
# Background jobs
set_color normal
for job in (jobs)
set_color $retc
echo -n ' │ '
set_color brown
echo $job
end
set_color normal
set_color $retc
echo -n ' ╰─> '
set_color normal
end
我的提示的总体布局:
─┬─[ hostname: user ▶ pwd ]
╰─> _
我想要的是而不是而不是>:
─┬─[ hostname: user ]
├─[ pwd ]
╰─> _
或
─┬─[ hostname: username ]
├─⎡ as_much_as_possible ⎤
├─⎣ the_rest_of_PWD ⎦
╰─> _
但是,当$PWD 长于窗口的列大小时,整个提示只是>。我觉得使用$COLUMNS 应该可以,但是我不知道如何在回显之前检查pwd 的长度。
我不想使用prompt_pwd。
提前致谢! ;)
【问题讨论】:
标签: fish