As a network engineer I copy and paste IPs into the terminal daily. I usually forget to add the command I'm trying to run before I copy and paste the IP which would result in:
Jonathans-MacBook:~ jonathansmith$ 10.0.0.0
-bash: 10.0.0.0: command not found
Me being a lazy and a programmer (usually goes hand in hand) wanted my terminal to be smarter, so I wrote this little bash script that over rights the command_not_found_handle()
function in bash
that checks to see if it's an IP.
Now I can enter in just an IP at the bash prompt and it will ask what want to do with it i.e ssh, ping, host or telnet
You need at least version 4 of bash for this to work
echo $BASH_VERSION
4.4.5(1)-release
If you don’t have version 4 follow these steps to upgrade
###Mac Install homebrew if you don’t have it already
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Run these
brew install bash
sudo bash -c 'echo /usr/local/bin/bash >> /etc/shells'
chsh -s /usr/local/bin/bash
Relaunch terminal
###Linux
apt-get autoclean
apt-get install --only-upgrade bash
apt-get upgrade
Once you have bash version 4 you are ready to overide the command_not_found_handle()
function
###Install
Copy the contents of the bashrc file to your .bash_profile
or .bashrc
file. Mac uses .bash_profile
and Linux uses .bashrc
. After copying it relaunch terminal
###Success! Now when you type just an IP into the terminal you'll get this
Jonathans-MacBook:~ jonathansmith$ 10.0.0.0
1) ssh
2) ping
3) telnet
4) host
5) Quit
Please enter your choice:
Instead of this
Jonathans-MacBook:~ jonathansmith$ 10.0.0.0
-bash: 10.0.0.0: command not found
Just pick what you want and off you go
####Future? Maybe in the future I'll add the ability to recognize domain names. Not too hard just don't run into that as much.