1

Other than permanently disable it in some config file, is there some shortcut or something to toggle the visibility of the directory path before the command prompt to temporarily hide it?

I mean, ZSH seems to abbreviate the directory names when the full path is long, but it seems that it only does so for the parents of the current directory, and when the current directory's name is long, I have very little space to type commands.

enter image description here

1 Answer 1

1

You can use something like this in your ~/.zshrc:

realPS1="$PS1"
changed=false

changePS1() {

   $changed && {

      PS1="%n (normal) in %~> "
      #Or
      PS1="$realPS1"

      changed=false
      : # <-- It might be not necessary add this `:`. This one 
        #represents a zero-status code (or successful).  

   } || {
      PS1="%n (hidden)> "
      changed=true
   }
}

bindkey -s "^H" 'changePS1^M'

The code above will create a shortcut (using bindkey) with Ctrl + H to execute the changePS1 function. So basically what Ctrl + H does is to enable the hidden prompt and when you press Ctrl + H again will enable the normal prompt.

About $PS1 you should assign the values according to your needs. For example, this line PS1="%n (normal) in %~> " shows the prompt like this:

edgar (normal) in ~/Documents/Gitlab/Linux_programming>

where %n is the username and %~ the relative path of my current working directory.

However you can back up your real $PS1 (line realPS1="$PS1") and use the line PS1="$realPS1" instead of PS1="%n (normal) in %~> "

And about PS1="%n (hidden)> " that will show the following prompt:

edgar (hidden)>

and therefore you should assign your PS1 variable with your custom prompt but you don't have to use %~ to avoid printing the path.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.