Bash prompt and aliases

Configure >

Changing the bash prompt colours

 
find and uncomment the line: "force_color_prompt=yes"

Here are my example colours - using light blue user and time, dk gray >, light gray working dir, and normal input text.. edit the 'PS1' line to read:
 
with a space at the end before the closing quote mark.

http://tldp.org/HOWTO/Bash-Prompt-HOWTO/


And for root user, to set the prompt colours when you switch to root user (su)..
su to root, then open root's bashrc file,
 
(first I needed to copy everything from "force....." to the line "unset...." in my user .bashrc to the root .bashrc)

edit 'PS1' line (I use light green user and time, dk gray >, light gray working dir, cyan input)
 



Bash aliases

With a bash alias we can issue shortcuts at the prompt that trigger commands. Example make a new file for aliases:
 
add this and save,
 
then open a new terminal and type "e" and Enter - and the terminal closes.

look at the examples here http://www.cyberciti.biz/... and search for whatever you might need elsewhere.
you could glean many useful bash functions from here http://tldp.org/LDP/abs/html/sample-bashrc.html

There are endless possibilities, but be careful not to take over a real command name with an alias, and try to make them memorable (my advice).

OK, here's my alias list, and the 1st one will print the .bash_aliases file contents to remind you of what you can use!

 

find10m script line
 
find100m script line
 

Bash cd to dir and list files

add this to your .bashrc file to make "cs" cd to a dir and list all files there
 



Bash aliases for root user

You may want to make a simpler bash alias file and save it in /root so that when you su to root in a terminal, you can use certain aliases, like e for exit, which is quite handy. You'll need to sudo cp the file to /root or open Thunar as root user (but be careful). You'll have to edit /root/.bashrc again and add the bash_aliases to it so it will look up the file, i.e
 
the ~/ will not point to you home dir, but it will point to /root as it is opened by root user.
plus you can add the "function cs " code above.


Bash numbered selection

And here's a nice way to open config files, using a number selection
add this to .bash_aliases:
 
which calls this script:
 
With plain OB, you need ~/.config/openbox/autostart and ~/.config/openbox/rc.xml

Note: you use &;; at the end of each command line so that the bash terminal does not wait for you to close the file before giving the prompt back, i.e. it opens the file and the process is done. Without that the process is still going while file is open -which is not a bad idea for system files opened with gksu.

Actually you can do any process you can think of with other scripts like this.

So how about one for common bash commands...
 
add to bash_aliases something like,
 



Easier navigating directories

Tired of using cd coupled with tab auto-completion of file names? Is there a way to display a directory's contents and then select a sub-dir or file to navigate to, using keys?

1. You can use zenity or yad, which is very adaptable, e.g.
 
 

2. You can use Ranger, a fully functioning x-terminal based file browser/manager which uses simple cursor keys to travel down and up the dir tree, some native commands to yank and paste files and so forth, plus key mapping to any bash command you like, inline preview of images, pdf files, and archive contents, details of video and audio files and lots more... see my ranger page.


Next page:

Xterm - configure the x-tools



Home | Content | Site Map | TOP