0

I have cloned a git repository to a folder in my workspace: /home/jose/workspace/very-very-very-long-repository-name/

so when i browse to it in my terminal it looks like

jose@jose-Vostro-1500:~/workspace/very-very-very-long-repository-name$ 

Is there a way of changing/editing/abbreviating the terminal prompt so that it doesn't fill the terminal!??

e.g

~/abbreviated/prompt$ 

Thanks, W

3 Answers 3

2

The prompt is controlled by the PS1 environment variable.

echo $PS1 to see what you have now. It'll be a combination of actual characters like @ and escape characters like \u for user and \h for hostname.

This generator helps you make your own

This script gives a nice method of shortening the directory path.

Put this PS1="whatever" into the last line of your ~/.bashrc, then either log out and log in, or source ~/.bashrc to apply.

There are also PS2, PS3 and PS4 variables that define various other behaviours. You can read about them on thegeekstuff.com.

1
  • Great, thanks for the tip... i just edited PS1 in .bashrc to be "$ "... Commented Jun 28, 2013 at 22:28
0

In Bash 4 and later, you can use the special variable PROMPT_DIRTRIM. The escapes \w or \W are available in at least Bash 3.2 and later. These features can be used to control the length of the current directory as displayed in your prompt.

PROMPT_DIRTRIM
If set to a number greater than zero, the value is used as the number of trailing directory components to retain when expanding the \w and \W prompt string escapes (see PROMPTING below). Characters removed are replaced with an ellipsis.

\w
the current working directory, with $HOME abbreviated with a tilde (uses the value of the PROMPT_DIRTRIM variable)

\W
the basename of the current working directory, with $HOME abbreviated with a tilde

0

To solve the problem of log folder names (or deep nested folders) remeber that in Bash you can put a new line (\n) into the $PS1 prompt like this:

export PS1="[\u@\h \W]\n$ " 

This will give you a two line prompt like this :

[user@host ~/workspace/very-very-very-long-repository-name$] $ 

The prompt will be on the second line after the $.

You must log in to answer this question.