0

Context:

The problem comes from the work folder location: if I should work in a subfolder of a subfolder of a subfolder et cetera... The command line of the shell bask in Linux is so long that can use two lines to be correctly printed.

Question:

Is there a way of showing only the last (or the few last) working subfolder?

Example:

What is actually printed:

user@user-pc:~/Documents/robotic_arm/Monitoring/difference/develop/component/example/subfolder/subexample/module$

What I would love to see:

user@user-pc:~/.../subexample/module$

More Info:

  • Xubuntu 16.04
  • Terminator is used instead of the default "Linux Terminal Emulator"
  • I had a look on this Stackoverflow's question but it is for the input and not for the default line printed by the shell
Leos313
  • 5,152
  • 6
  • 40
  • 69

2 Answers2

0

Have a look at the PROMPTING section of man bash. You configure the prompt by setting PS1, and I suspect your current setting is something like this:

$ echo $PS1
\u@\h:\w\$

If you change it to

$ PS1='\u@\h:\W\$ '

it will only print the basename of the current working directory.

laenkeio
  • 502
  • 2
  • 6
  • `echo $PS1` `\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$` – Leos313 May 28 '19 at 07:41
  • 1
    Yes, that's with some colors added. You need to modify it so that `\w` is replaced with `\W`. – laenkeio May 28 '19 at 07:42
  • Put the change in your `~/.bashrc` or `~/.bash_profile` with `export PS1=...` – laenkeio May 28 '19 at 07:44
  • it does not work and now: `echo $PS1` `\[\e]0;\u@\h: \W\a\]$ ...` – Leos313 May 28 '19 at 07:45
  • I have just found another solution and used as another alternative answer. Can be the use of `Terminator` my problem with your proposal? – Leos313 May 28 '19 at 08:05
0

I do not know why but the previous answer does not work on my machine. However, an alternative solution that works fine is:

PROMPT_DIRTRIM=N

where N is the number of subfolders you want to see.

Example:

user@user-pc:~/Documents/robotic_arm/difference/develop/component/ $ PROMPT_DIRTRIM=2
user@user-pc:~/.../develop/component/ $

The solution was suggested by one of the answers above this question.

Leos313
  • 5,152
  • 6
  • 40
  • 69