3

I would like to shorten the file path that is currently active in the terminal to allow more space. This is a shortened example but I sometimes have filepaths that I am working with that are 6 levels deep and it would be nice to hide that.

test@ubuntu:~$ cd code/helloworld
test@ubuntu:~/code/helloworld$ 

would like to just see somehting like

helloworld:

Any ideas?

Thanks!

2 Answers2

4

Add to your .bashrc or run at a prompt:

PS1='\W: '

For background information, run man bash and search for PROMPTING.

Paul
  • 7,007
  • 3
  • 23
  • 30
0

I am on Ubuntu 19:10 and there is a file called .bashrc in my home directory. I can see it with the file-explorer by showing hidden files with CTRL+H and open it with my default text editor via double click (my default user permissions are good - no sudo stuff needed in home).

There is a lot of configuration script and in between this:

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi

based on Pauls answer I changed the lower-case \w to capital \W. It now looks like this…

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\W\$ '
fi

… and the terminal prefix is now user@my-laptop:some_folder$


Sidenote: [\033[01;32m\] these things are color codes

Hope this helps some GUI veterans :)

Breaker222
  • 226
  • 3
  • 11