简体   繁体   English

如何使用fish_prompt_pwd_dir_length 在提示中更改fish pwd 长度?

[英]How do you change fish pwd length in prompt using fish_prompt_pwd_dir_length?

I want fish shell to show full path in prompt.我希望鱼壳在提示中显示完整路径。 Looking at source of pwd_prompt I see a variable named fish_prompt_pwd_dir_length, that should do what I want if I set it to 0.查看 pwd_prompt 的来源,我看到一个名为 fish_prompt_pwd_dir_length 的变量,如果将其设置为 0,它应该可以执行我想要的操作。

But when I do set -U fish_prompt_pwd_dir_length 0 nothing happens.但是当我set -U fish_prompt_pwd_dir_length 0什么也没有发生。

Looking in fish_config variables tab I see that this var is set to 0, but still path shown reduced.查看fish_config variables 选项卡,我看到此变量设置为 0,但显示的路径仍然减少。

What am I doing wrong and can you actually do that without writing your own pwd_prompt function?我做错了什么,你真的可以在不编写自己的 pwd_prompt 函数的情况下做到这一点吗?

UPD (June 20, 2016): UPD(2016 年 6 月 20 日):

Since version 2.3.0 (which is now recent) all is working as expected自 2.3.0 版(现在是最新版本)以来,一切都按预期工作

Previous answer:上一个答案:

My workaround so far is to copy prompt_pwd into new function prompt_pwd_full and mess with it a little bit.到目前为止,我的解决方法是将prompt_pwd复制到新函数prompt_pwd_full并稍微处理一下。

prompt_pwd_full.fish: prompt_pwd_full.fish:

set -l args_pre
set args_pre $args_pre -e 's|^/private/|/|'

function prompt_pwd_full -V args_pre
  set -q fish_prompt_pwd_dir_length; or set -l fish_prompt_pwd_dir_length 1

  if [ $fish_prompt_pwd_dir_length -eq 0 ]
    set -l fish_prompt_pwd_dir_length 99999
  end

  set -l realhome ~
  echo $PWD | sed -e "s|^$realhome|~|" $args_pre -e 's-\([^/.]{'"$fish_prompt_pwd_dir_length"'}\)[^/]*/-\1/-g'
end

note: I am on OS X, so I threw out a bunch of code that wasn't related to it, so it might not work in other OS'es.注意:我在 OS X 上,所以我抛出了一堆与它无关的代码,所以它可能无法在其他操作系统上运行。

UPD: As faho noted in the comment, there is no particular reason to rewrite /private/ to / , so my function is looking like this now: UPD:正如faho在评论中指出的那样,没有特别的理由将/private/重写为/ ,所以我的函数现在看起来像这样:

function prompt_pwd_full
  set -q fish_prompt_pwd_dir_length; or set -l fish_prompt_pwd_dir_length 1

  if [ $fish_prompt_pwd_dir_length -eq 0 ]
    set -l fish_prompt_pwd_dir_length 99999
  end

  set -l realhome ~
  echo $PWD | sed -e "s|^$realhome|~|" -e 's-\([^/.]{'"$fish_prompt_pwd_dir_length"'}\)[^/]*/-\1/-g'
end

Adding set -g fish_prompt_pwd_dir_length 80 to ~/.config/fish/config.fish works for me.set -g fish_prompt_pwd_dir_length 80添加到~/.config/fish/config.fish对我~/.config/fish/config.fish My fish version is 3.0.2我的鱼版本是3.0.2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM