Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

adding new pg function for easy ping #354

Closed
wants to merge 3 commits into from

3 participants

@MartinDelille

I did already changed this but changed p to pg so you can keep your p shortcut to project.

@Tatsh

(($# == 0)) if you want to get fancy

@mathiasbynens

Thanks for the suggestion. This is really nice but I don’t need this often enough to justify adding an alias/function for it to my dotfiles. Hopefully this PR can serve as a reference for others looking for this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 17, 2014
  1. adding new p function for easy ping

    Martin Delille authored
Commits on Feb 18, 2014
  1. @MartinDelille

    fancy #$ comparison

    MartinDelille authored
Commits on Mar 6, 2014
  1. @MartinDelille

    p => pg

    MartinDelille authored
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 0 deletions.
  1. +23 −0 .functions
View
23 .functions
@@ -292,6 +292,29 @@ function o() {
fi
}
+# `pg` with no arguments ping the IP 8.8.8.8 (usefull for basic internet connection test),
+# otherwise ping the given IP. If the IP is incomplete, it is concat with the default
+# prefix 192.168.1 allowing easy local ping (eg ping 3.12 => 192.168.3.12)
+function pg() {
+ ip4regex='^[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+$'
+ ip3regex='^[0-9]+[.][0-9]+[.][0-9]+$'
+ ip2regex='^[0-9]+[.][0-9]+$'
+ ip1regex='^[0-9]+$'
+ host=$@
+ if [[ $# == 0 ]]; then
+ host="8.8.8.8"
+ elif [[ $@ =~ $ip4regex ]]; then
+ host="$@"
+ elif [[ $@ =~ $ip3regex ]]; then
+ host="192.$@"
+ elif [[ $@ =~ $ip2regex ]]; then
+ host="192.168.$@"
+ elif [[ $@ =~ $ip1regex ]]; then
+ host="192.168.1.$@"
+ fi
+ ping $host
+}
+
# `np` with an optional argument `patch`/`minor`/`major`/`<version>`
# defaults to `patch`
function np() {
Something went wrong with that request. Please try again.