I've checked this.

But right now I'm working in a virtual env.

cam@cam:~$ cd Desktop/django-user3
cam@cam:~/Desktop/django-user3$ source newenv/bin/activate
(newenv)cam@cam:~/Desktop/django-user3$ cd superlists

Now i need to add an alias so that when i enter

cam@cam:~$ cd $DJANGO3

I need to get here.


but instead of this long path i need to see a shorter one.

  • So, what is it you want? An alias, or a way to make the prompt shorter?
    – muru
    Apr 10, 2015 at 3:30
  • alias with shorter prompt
    – Ajay
    Apr 10, 2015 at 7:58

1 Answer 1


To shorten the prompt, one way is to set PROMPT_DIRTRIM:

$ cd /usr/share/man/man1
/usr/share/man/man1 $ PROMPT_DIRTRIM=3
.../share/man/man1 $

PROMPT_DIRTRIM, when set, limits the number of directories shown in the prompt path, replacing earlier parts with ....

There are other ways, such as removing unnecessary elements from them (such as the hostname). For that you'd need to edit PS1 in your .bashrc.

To create an alias, just string all your commands together. Aliasing cd just for this purpose isn't a very good idea. I'd use some other name, like django3:

alias django3='cd ~/Desktop/django-user3; source newenv/bin/activate; cd superlists; PROMPT_DIRTRIM=1'

Then you can do:

cam@cam:~ $ django3
(newenv)cam@cam:.../django-user3/superlists $
  • i've installed zsh. I've seen oh-my-zsh.It displays only current directory.Can i tweak zsh so that is displays only current directory rather long paths..
    – Ajay
    Apr 10, 2015 at 10:41
  • @Ajay I suppose you meant tweak bash?
    – muru
    Apr 10, 2015 at 11:10
  • I've installed zsh and downloaded dot files from github.It has customised seetings.Now PROMPT_DIRTRIM doesn't work
    – Ajay
    Apr 10, 2015 at 11:15
  • @Ajay PROMPT_DIRTRIM is for bash. With zsh, find where PROMPT is defined, and find %~ and insert a number, like %2~.
    – muru
    Apr 10, 2015 at 11:29
  • github.com/xero/dotfiles/tree/master/zsh/.zsh this is the config
    – Ajay
    Apr 10, 2015 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.