Ultimate Prompt and bashrc. File
I've been working on my .bashrc file on and off for years. Over the years, I have searched through scores of others' .bashrc files and command prompts.
I think this is the most amazing and ultimate command prompt and .bashrc file I have ever seen, and I wanted to share it with anyone who wanted to use it. I wanted this script to work on any machine running bash just "out of the box" without any needed modifications. And it's very friendly for new people coming to Linux. To download it, simply go here: http://mindnugget.com/bashrc/bashrc.tar.gz Or, you can just execute this and reboot (backup your existing .bashrc file first if you need it): Code:
/bin/rm -f ~/.bashrc* && cd ~ && wget http://mindnugget.com/bashrc/.bashrc && wget http://mindnugget.com/bashrc/.bashrc_help Code:
hlp First, here's the command prompt: Dark background: http://mindnugget.com/bashrc/prompt_dark.png Light background: http://mindnugget.com/bashrc/prompt_light.png Solarized dark: http://mindnugget.com/bashrc/prompt_solarized_dark.png Solarized light: http://mindnugget.com/bashrc/prompt_solarized_light.png Black and white: http://mindnugget.com/bashrc/prompt_black_white.png It has a lot of useful information on it including the date, time, cpu usage, jobs, network connections to your machine, current user, server (if logged in SSH), your current directory, the size of all the files, the file count, and any errors with lookup text descriptions for those exit codes. http://mindnugget.com/bashrc/prompt.png The ONLY feature this prompt does not contain (out of every prompt I've ever seen) is a timer for the last command executed. I did have the code working for this, but it requires debug, and it's just not very accurate. Also, it would stop working correctly if scripts gave weird exit codes. I removed it and may add it back in at some point. Please note: The editor used in this script is nano, pico, or joe (it will automatically use what you have installed without any configuration). I use a graphical UI editor for most of my coding, so I have no need for the power of Emacs or even Vim. To change it, just change the alias and modify the edit function. If you install joe (available in almost all repositories and Joe's Own Editor), the scripts will automatically use it immediately instead without any configuration or reboot. This script also uses multitail and tree for a couple of commands. To automatically install them on Mint, Ubuntu, Debian, Red Hat, Fedora, SuSE, Gentoo, or Mandriva, just type: install_bashrc_support So what are some of the new lazy/helpful commands? hlp - Show's a full color help file with these commands and other nice shortcuts Configuration (These will find your configuration files for you! There is no need to modify the script.) ebrc - Edit the .bashrc file phpconfig - Edit the PHP configuration apacheconfig - Edit Apache web server configuration mysqlconfig - Edit MySQL database configuration Searching h - Search command line history (also CTRL-S and CTRL-R) p - Search running processes f - Search filenames in the current folder ftext - Searches for text in all files in the current folder Information da - Show the date ver - Show the current version of the operating system checkcommand - Show if a command is aliased, a file, or a built-in command cpu - Shows the CPU usage topcpu - Show the top 10 CPU processes logs - Show all logs in /var/log apachelog - View Apache web server logs (requires multitail) rot13 - Rot13 conversion Folders la - Directory listing: show hidden files ls - Directory listing: add colors and file type extensions lx - Directory listing: sort by extension lk - Directory listing: sort by size lc - Directory listing: sort by change time lu - Directory listing: sort by access time lr - Directory listing: recursive ls lt - Directory listing: sort by date lm - Directory listing: pipe through 'more' lw - Directory listing: wide listing format ll - Directory listing: long listing format labc - Directory listing: alphabetical sort lf - Directory listing: files only ldir - Directory listing: directories only .. - go back 1 folder ... - go back 2 folders .... - go back 3 folders ..... - go back 4 folders up - go up a specified number of folders bd - change into your previous folder (also cd -) cpp - Copy file with a progress bar cpg - Copy and go to the directory mvg - Move and go to the directory mkdirg - Create and go to the directory rmd - Remove a directory, all sub folders, and files pwd - Show the current directory (not an alias) oldpwd - Show the previous directory (not an alias) pwdtail - Returns the last 2 fields of the working directory countfiles - Count all files (recursively) in the current folder diskspace - Show how disk space is being used folders - Show subfolders and disk space folderssort - Show subfolders sorted with disk space tree - Show a folder and file tree treed - Show a folder tree mountedinfo - Show mounted information home - go to your home folder web - Change into your Apache web folder File Permissions 000 - Change permissions to no read/write/execute 644 - Change permissions to read only/write for owner 666 - Change permissions to read only 755 - Change permissions to read only and execute/write for owner 777 - Change permissions to read, write, and execute mx - make files executable Archives extract - Extract any archive(s) (does everything unp does without the need to install it) mktar - Create a tar file mkbz2 - Created a bzip2 archive file mkgz - Create a gzip archive file untar - Extract a tar file unbz2 - Extract a bzip2 archive file ungz - Extract a gzip archive file Network netinfo - Show current network information whatsmyip - Internal and external IP address lookup ipview - Show the number of connections to the web server openports - Show open ports Reboot rebootsafe - reboot safely rebootforce - force reboot I really recommend adding bash completion to your system. http://www.caliban.org/bash/index.shtml Download and then copy the bash_completion/bash_completion file to /etc - the script will automatically pick it up if installed. You probably will want to make a /etc/bash_completion.d directory for any additional completion scripts. If you have any comments or useful things you'd like to see added, let me know in the comments below. Enjoy! |
Ultimate Prompt and bashrc. File
For those who don't want to download but would like to look at the code:
Code:
#!/bin/bash |
Very cool!
You might ask the mods to move this thread to a more prominent place, such as the Member Success Stories forum. |
Quote:
|
I forgot to say, the script used multitail and tree (both awesome commands), but you can find those in almost all repositories.
For example: Code:
sudo apt-get install multitail tree Code:
yum install multitail tree |
That is pretty cool, I'll give it a shot and see how I like it.
I did notice a small problem though. At the top it's trying to source global definitions and programmable completion, but it's missing a "source" or ".". As-written it's trying to execute those files, which results in a permission denied error. I also tried to use it on a very old machine I have here, and it resulted in an infinite loop of errors. I actually had to ssh into the machine as another user, su to root, and restore my original .bashrc from there because I couldn't get to a prompt as me. Not a huge deal, but maybe there should be some version checking to make it more robust. If you're interested, the actual error was: Code:
-bash: PS1+=\[\033[1;30m\](\[\033[0;36m\]$(date +%a) Sep-9: command not found |
Also, the stty and bind commands fail when opening a non-interactive session, eg:
Code:
> ssh server ls Code:
iatest=$(expr index "$-" i) Code:
if [[ $iatest > 0 ]]; then bind "set bell-style visible"; fi |
Awesome input. Thank you, suicidaleggroll!
Okay, I made all the changes you recommended except the concatenations for really old versions of bash. I might do that at a later date. Thanks for the help and input!! To "upgrade" to the latest version, just type: Code:
rm -f ~/.bashrc* && cd ~ && wget http://mindnugget.com/bashrc/.bashrc |
Quote:
I use Code:
bind '"\e[A": history-search-backward' Is there a similar snippet that I can use outside of jeffguys' .bashrc to suppress this warning during non-interactive shells? Thanks. |
The same one I posted above should work.
$- is a special flag passed to bash at runtime. The presence of an "i" in the result means it's interactive, which is what that "iatest=$(expr index "$-" i)" snip is looking for. The result is the index of the letter "i" in the output of "$-". A value >0 means it was there, a value of zero means it wasn't. So if you then stick a "if [[ $iatest > 0 ]]" around all of your interactive-only commands, you should be set. It's not perfect, as scripts/shells can be forced to run in interactive mode even if it's not an interactive session (by adding a -i to the bash flags or putting a "#!/bin/bash -i" for the header, but for a .bashrc file it's good enough. Another option is to test PS1, but I don't like that because some .bashrc files will set PS1 regardless of it being an interactive session or not. http://tldp.org/LDP/abs/html/intandnonint.html#IITEST |
Thanks, I'll try it.
|
Habitual, what you want is:
Code:
if [[ $iatest > 0 ]]; then bind '"\e[A": history-search-backward'; fi |
Thanks Jeff!
|
Couple of points (from my systems point of view):
1. Probably not a biggee for some, but several of my machines, including my main pc at home, does not have ifconfig installed and hence all of the net based parts fail. Now I know IPv6 is still working it way through, but all my machines are using iproute2 (hence ip command) for net based actions. 2. I found the below comment and resulting code to be a little ambiguous as a new directory on my system with no files in it will return '8.0K' Quote:
4. 'f' alias says it searches for files but there is no -type option to indicate this (ie directories will also be returned) 5. netstat commands are not available for me ... is there something to advise (maybe it is in help) what packages need to be installed 6. With aliases like countfiles, I find it cleaner (IMO) to use a function in place of trying to put it all on one line and be concerned about escaping Code:
countfiles() Code:
for archive 9. pwdtail - in awk you can simply call $(NF-1) instead of setting the variable 10. distribution has no solution for Arch based systems :( 11. The big 'if' for setting PS1 would maybe look nicer as a case?? Hopefully some helpful feedback :) |
Quote:
Thanks for this nugget! It solves the issue and works both locally and remotely. I posted it at Improved ~./bashrc history search with credit, of course. Have a Great Day. You rock! Edit: Fri Sep 19, 2014 - 11:14:49 AM EDT I had to revert to the former entries in my local ~/.bashrc for "some" reason. |
My humble :twocents: .
After some time of using Linux I lost interest in complicated bloated prompts. They distract a lot and you rarely really read data those prompts provide before any new command. I find simple Code:
user@machine: $ Also, prompt with only current dir and type of user is nice. Code:
~/downloads $ |
I agree- I couldn't work with that much info on my prompt...I would get completely lost...
I really like Debian's defauld bash prompt. Hostname, username, working directory. I really need to look at it to make my Arch laptop look the same way, so that it displays the full path to the current directory... |
I like my yellow-on-blue retro prompt:
|
Quote:
|
Quote:
Code:
DOS='C:${PWD//\//\\\}>' |
Here's a site where you can experiment with your prompt:
http://bashrcgenerator.com/ |
Quote:
|
Grail, awesome post. I took a look and will probably make some changes when I get time. I'm not the ultimate at shell scripting. I have collected a lot of this stuff over the years.
Habitual, that is an awesome blog! And I'm adding your up and down arrow search to my .bashrc because it's awesome. And I laughed at the C: on your prompt. BrianL, nice link. I used to have a page like that where you could created different date formats and can't find it anymore. |
Quote:
"warning: line editing not enabled" messages, but I am then unable to use that 'feature' interactively. So I am just kind of in the middle on it being "the solution" for me, atm. But that's what I LOVE about Linux, there's always a 'way', we just have to be creative. :) Have a Great Day. |
Quote:
Code:
iatest=$(expr index "$-" i) |
Quote:
NOW it's fixed. ;) Thanks. |
Why not put this on GitHub, jeffguy77?
|
Quote:
Habitual, I'm glad it's working for you. And your blog has some interesting stuff. I didn't know you could put random times into a cron job. |
This does not work with the ultimate bashrc script
I am trying to use autojump, but it will not autoload the directories to the autojump list as the custom prompt is not compatible. Here is the thread on the issue from other users. askubuntu.com/questions/185962/autojump-in-12-04-doesnt-work I tried using the change and adding to my .bashrc, but it does not work. Any ideas on what to add to the ultimate .bashrc to make autojump work? |
Just want to add that I absolutely love this script! Thanks for sharing!
|
Quote:
It's all good. |
New version of this project
I have created a much more recent huge upgrade to my original ultimate .bashrc file.
It is up on Source Forge. https://sourceforge.net/projects/ultimate-bashrc/files/ Thank you for all your kind words of support! |
All times are GMT -5. The time now is 06:24 AM. |