0

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
(newenv)cam@cam:~/Desktop/django-user3/superlists$ 

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

cam@cam:~$ cd $DJANGO3

I need to get here.

(newenv)cam@cam:~/Desktop/django-user3/superlists$ 

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

Ajay
  • 133

1 Answers1

0

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 $
muru
  • 197,895
  • 55
  • 485
  • 740
  • 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 '15 at 10:41
  • @Ajay I suppose you meant tweak bash? – muru Apr 10 '15 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 '15 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 '15 at 11:29
  • https://github.com/xero/dotfiles/tree/master/zsh/.zsh this is the config – Ajay Apr 10 '15 at 11:41
  • @Ajay I'm not going to wade through someone else's dotfiles. No, thanks. – muru Apr 10 '15 at 11:44