How can I make my terminal's command prompt shorter to increase line realestate?

6

4

I would like to make my terminal's command prompt shorter. Currently I am using Python 's virtualenv and virtualenvwrapper so that is causing lots of extra text to be displayed in my command prompt. I need to shorten that up to the bare minimum so I'd like to take this:

(pytutorial)sez@sez-laptop:~/.virtualenvs/nettuts/firstblog$

and ideally turn it into

(pyt)sez:~/.virtualenvs/nettuts/firstblog$

or maybe something shorter perhaps. Right now I am using Gnome Terminal 2 & bash.

Any suggestions?

max

Posted 2011-12-20T14:00:13.993

Reputation: 351

Answers

12

Your prompt can be set utilizing the PS1 envvar. For example to have a minimalist command prompt of '$" simply set PS1='$' in your .bashrc. Here are some good examples of setting a customized prompt

ennuikiller

Posted 2011-12-20T14:00:13.993

Reputation: 980

6

I guess \u:\w\$ is what you need, where \u is your username and \w is the current working directory (\W is shorter). Modify your ~/.bashrc to change the prompt.

PJ.Hades

Posted 2011-12-20T14:00:13.993

Reputation: 161

1+1 ... in the middle of typing pretty much the same thing. – Chris J – 2011-12-20T14:04:38.043

5

Edit your .bashrc and change the PS1 definition. See your own /etc/bashrc for an example, or see bash documentation.

fge

Posted 2011-12-20T14:00:13.993

Reputation: 573

3

Simply type in your terminal nano .bash_profile. Copy:

export PS1="\u@\h\w: "

Save.

Alisher Ulugbekov

Posted 2011-12-20T14:00:13.993

Reputation: 131

3

We use a consistent header across all our machines, that has the full current working directory on the line (along with hostname and user), then a line break with just the current directory name and the prompt itself.

That way, you still get plenty of width and there is a clear distinction between different lines.

Its also coloured :)

export PS1="\e[0;35m[\u@\e[0;33s\h\e[0;35m \w] \e[m \n[\W]\$ "

Eg. Which would output

[myuser@myserver /home/myuser]
[myuser]$ 

Save the line in your ~/.bashrc, ~/.bash_profile or /etc/profile to make it persistent.

Ben Lessani - Sonassi

Posted 2011-12-20T14:00:13.993

Reputation: 135

2

I like to have my prompt in a separate line so I don't miss the info and I always have the whole line to type:

PS1=\\u@\\h\ \\w\\n\\$\ 

Samus_

Posted 2011-12-20T14:00:13.993

Reputation: 176

2

Inside the '$WORKON_HOME/postactivate':

case $(basename "$VIRTUAL_ENV") in
    pytutorial) VENV="pyt";;
    *) VENV="$(basename "$VIRTUAL_ENV")";;
esac
PS1="($VENV)$_OLD_VIRTUAL_PS1"

Inside the '$HOME/.bashrc':

PS1="\u:\w\$ "

This should produce the exact output you described. Of course there are different options. I highly recommend https://wiki.archlinux.org/index.php/Color_Bash_Prompt, for more info on this topic.

The 'post_activate' file runs during virtualenv startup. The case statement allows you to replace a name with another.

Other considerations:

I personally do PS1=$_OLD_VIRTUAL_PS1 in '$WORKON_HOME/postactivate' and use $(basename "$VIRTUAL_ENV") inside my PS1.

Aaron Schif

Posted 2011-12-20T14:00:13.993

Reputation: 121