-1

When I am getting into my working directory, I have the next pathname in the console:

kravcneger@kravcneger-X751L:~/projects/gcc/my_project

That path is very long, and it increases the width of the terminal window. How can I make the pathname shorter, so that I wouldn't have to expand the terminal for comfortable work? A critical condition: to change the machine name and the working directory is prohibited. :)

Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47
kravcneger
  • 61
  • 5

1 Answers1

1

Add (or change) in your ~/.bashrc file PS1 variable:

PS1='\h \W\$ '

Here, \h is the machine name, \W is the basename of the current directory, and \$ is the literal $.

SEE ALSO:

Controlling the Prompt (Bash Reference Manual)

Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47
  • Thanks a lot, Timur. Can you give advice, how can I do a dynamic solution if it is even possible? For example, I would open a terminal, get into the working directory, and execute my bash command and get a new view, but in other terminal windows is staying the old look. – kravcneger Nov 11 '20 at 18:06
  • 1
    @kravcneger For terminal windows already open, execute the command in each terminal. For newly opened windows: (a) Add the above command to `~/.bashrc` file. Save the file. You only need to do it once. (b) Then every time you open a new terminal window, you will get the newly specified (shorter) prompt. – Timur Shtatland Nov 11 '20 at 22:11