只显示当前目录名称而不是在fish/tile提示中显示整个路径(pwd)。

huangapple go评论62阅读模式
英文:

How do I display only the current directory name and not the entire path (pwd) shown in fish/tile prompt?

问题

早上好,请问我在Debian上安装了fish(版本3.6.1)和tide(版本5.5.1)。我使用以下选项配置了tide...
提示样式 (3) 彩虹
提示颜色 (1) 真彩色
显示当前时间? (1) 否
提示分隔符 (2) 垂直
提示头部 (2) 模糊
提示尾部 (2) 模糊
提示高度 (1) 单行
提示间距 (2) 稀疏
图标 (2) 许多图标

对我来说,一切都很好,直到我进入了一些目录,比如
cd ~/Development/freecodecamp/ResponsiveWebDesign/C01\ Learn\ HTML/
结果是
░▒▓    ~/Development/freecodecamp/ResponsiveWebDesign/C01 Learn HTML   master ▓▒░
我希望得到... ░▒▓    C01 Learn HTML   master ▓▒░

唯一的修改来自默认的fish/tide安装

cat ~/.config/fish/conf.d/10-camechi-config.fish
# 我的fish shell配置   20230615

function fish_greeting
    fortune
end

if type -q exa
    alias ll "exa -l -g --icons"
    alias lla "ll -a"
end

set -gx PATH $HOME/bin $HOME/.local/bin $PATH

我的屏幕
我需要必要的帮助来获得所需的提示。

我已经阅读了文档并尝试了一些来自论坛/网站的旧提示。
使用basename (pwd)或basename ($PWD)会给我一个类似文本的提示。

我希望在图像中只有当前目录和漂亮的提示;)

谢谢您

英文:

Good morning, please I installed fish (version 3.6.1) with tide (version 5.5.1) on Debian.
I configured tide with the following options selected ...
Prompt Style (3) Rainbow
Prompt Colors (1) True color
Show current time? (1) No
Prompt Separators (2) Vertical
Prompt Heads (2) Blurred
Prompt Tails (2) Blurred
Prompt Height (1) One line
Prompt Spacing (2) Sparse
Icons (2) Many icons

All is well with this prompt for me until I go into several directories, like
cd ~/Development/freecodecamp/ResponsiveWebDesign/C01\ Learn\ HTML/
and the result is
░▒▓    ~/Development/freecodecamp/ResponsiveWebDesign/C01 Learn HTML   master ▓▒░
I would desire to have ... ░▒▓    C01 Learn HTML   master ▓▒░

The only modification from the default fish/tide installation

cat ~/.config/fish/conf.d/10-camechi-config.fish
# My configurations for fish shell   20230615

function fish_greeting
    fortune
end

if type -q exa
    alias ll "exa -l -g --icons"
    alias lla "ll -a"
end

set -gx PATH $HOME/bin $HOME/.local/bin $PATH

My Screen
I would need necessary assistance to get the desired prompt.

I have read the documentations and tried some old hints from the forums/websites.
Using basename (pwd) or basename ($PWD) give me a text-like prompt.

I desire the current directory only with the fancy prompt in the image 只显示当前目录名称而不是在fish/tile提示中显示整个路径(pwd)。

Thank you

答案1

得分: 1

这不是潮汐能够做的事情。它没有相应的选项 - 请查看它们的wiki

话虽如此,潮汐只是一堆fish脚本,所以如果你愿意,你可以进行调整。然而,它的编写风格相当独特,不太适合覆盖特定函数。

你可以尝试_tide_pwd修改为:

function _tide_pwd
    path basename -- $PWD
end

(使用fish的path内建命令来避免通常会出现意外缓慢的basename命令)

最简单的方法是在它生效后执行funced _tide_pwdfuncsave _tide_pwd

除非潮汐在中途出现问题,否则这可能有效。

除此之外,考虑在tide仓库上提出一个问题。

英文:

This is not a thing that tide does. It doesn't have an option for it - see their wiki.

That being said, tide is just a bunch of fish script, so you can adjust it if you want. However, it's written in a fairly peculiar style that isn't very amenable to overriding specific functions.

You can try changing _tide_pwd to

function _tide_pwd
    path basename -- $PWD
end

(using fish's path builtin to avoid the often surprisingly slow basename command)

The easiest way to do this is funced _tide_pwd and funcsave _tide_pwd once it works.

This might work unless tide throws a wrench in the way.

Other than that, consider opening an issue on the tide repo.

答案2

得分: 1

我成功获得了我想要的提示,仅显示当前目录名称。感谢 @faho 提供的有用提示。

我创建了一个 fish 脚本,15-camechi_tide_pwd.fish,在 conf.d 目录中,而不是直接修改 functions 目录中的 _tide_pwd.fish。以下是15-camechi_tide_pwd.fish的内容:

set_color -o $tide_pwd_color_anchors | read -l color_anchors
set_color $tide_pwd_color_truncated_dirs | read -l color_truncated
set -l reset_to_color_dirs (set_color normal -b $tide_pwd_bg_color; set_color $tide_pwd_color_dirs)

set -l unwritable_icon $tide_pwd_icon_unwritable' '
set -l home_icon $tide_pwd_icon_home' '
set -l pwd_icon $tide_pwd_icon' '

eval "function _tide_pwd
    if set -l split_pwd (string replace -r '^$HOME' '' -- $PWD | string split /)
        test -w . && set -f split_output \"$pwd_icon$split_pwd[1]\" ||
            set -f split_output \"$unwritable_icon$split_pwd[1]\"
        set split_output[-1] \"$color_anchors$split_output[-1]$reset_to_color_dirs\"
    else
        set -f split_output \"$home_icon$color_anchors\"
    end
    string join -- / \"$reset_to_color_dirs$split_output[1]$(basename (prompt_pwd))\"
end"

我的终端图片

英文:

I succeeded in getting my desired prompt, showing only the current directory name. Thanks to @faho for the helpful hint.

I created a fish script, 15-camechi_tide_pwd.fish, in the conf.d directory rather than directly changing the _tide_pwd.fish in functions directory.
Below is the content of 15-camechi_tide_pwd.fish

set_color -o $tide_pwd_color_anchors | read -l color_anchors
set_color $tide_pwd_color_truncated_dirs | read -l color_truncated
set -l reset_to_color_dirs (set_color normal -b $tide_pwd_bg_color; set_color $tide_pwd_color_dirs)

set -l unwritable_icon $tide_pwd_icon_unwritable' '
set -l home_icon $tide_pwd_icon_home' '
set -l pwd_icon $tide_pwd_icon' '

eval "function _tide_pwd
    if set -l split_pwd (string replace -r '^$HOME' '' -- $PWD | string split /)
        test -w . && set -f split_output \"$pwd_icon$split_pwd[1]\" ||
            set -f split_output \"$unwritable_icon$split_pwd[1]\"
        set split_output[-1] \"$color_anchors$split_output[-1]$reset_to_color_dirs\"
    else
        set -f split_output \"$home_icon$color_anchors\"
    end
    string join -- / \"$reset_to_color_dirs$split_output[1]$(basename (prompt_pwd))\"
end"

Image of my terminal

huangapple
  • 本文由 发表于 2023年6月15日 18:30:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76481606.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定