Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

shell

fish

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.

But when I do set -U fish_prompt_pwd_dir_length 0 nothing happens.

Looking in fish_config variables tab I see that this var is set to 0, but still path shown reduced.

What am I doing wrong and can you actually do that without writing your own pwd_prompt function?

like image 922
alice kibin Avatar asked Nov 14 '15 22:11

alice kibin


2 Answers

UPD (June 20, 2016):

Since version 2.3.0 (which is now recent) all is working as expected

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_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.

UPD: As faho noted in the comment, there is no particular reason to rewrite /private/ to /, so my function is looking like this now:

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
like image 109
alice kibin Avatar answered Oct 22 '22 18:10

alice kibin


Adding set -g fish_prompt_pwd_dir_length 80 to ~/.config/fish/config.fish works for me. My fish version is 3.0.2

like image 2
S. Zhang Avatar answered Oct 22 '22 18:10

S. Zhang