Change prompt and enable command auto-completion [updated]
I really like some simple extensions and changes to command line in Linux. An ability to enable command auto-complete, commands history navigation and changing prompts look in particular.
However, not every console is suited with these changes, so I wrote this simple article to keep all my how-tos around Linux command line in one place.
Contents
Windows: Change prompt (Git Bash)
In Git for Windows (Git Bash) changing prompt is much, much easier than for Linux (described below).
All you have to do (After Git for Windows installation) is to create a new .bashrc
file in your home directory (i.e. c:\Users\[username]
(because it most like does not exist) and put there:
PS1='[$PWD] # '
or any other prompt format (see below and in enormous number of sources in the Internet).
When running Git Bash for the first time after saving this file you will see a warning message about missing .bash_profile
file. It will be created for you and starting from this moment you’ll have your prompt in Git Bash changed permanently.
Linux: Change prompt
In this example, we’ll be changing prompt to show current path closed in square brackets, followed by #
symbol. For example [/root] #
. Bash configuration string for this is '[$PWD] # '
. Feel free to change it to anything you want.
First check, if it is OK, by changing prompt for this session only
export PS1='[$PWD] # '
If everything is correct, make these changes permanent. Edit your .bashrc
file in nano
, mcedit
(if you have Midnight Commander installed) or any editor of your choice. mcedit
seems to be more flexible and convenient to use, but nano
offers copy&paste operations just like in pure terminal, by selecting text and clicking window with right mouse button. So:
nano .bashrc
Locate (for example Ctrl+W
in nano
or F7
in mcedit
) any occurence of PS1=
. Comment-out that line, by adding #
in front of it. Then enter new line below and add:
PS1='[$PWD] # '
In default or standard Bash configuration file, you should do this change three times. Twice in if [ "$color_prompt" = yes ]; then
section and once in # If this is an xterm set the title to user@host:dir
section.
That is all. Save .bashrc
file by pressing Ctrl + O, logoff and login again to see the results.
If you need more details, then take a look at this askubuntu.com answer or to this lindesk.com post.
Linux: Change shell (enable paths auto-complete)
To have paths auto-complete (write first few letters and press Tab) or possibility to navigate commands history using up and down arrows, simply change your shell from current to bash:
chsh -s /bin/bash
This is permanent, but will be available starting from next session. Logout and login again.
More info in this superuser.com answer.