aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2020-06-20 19:03:23 +0800
committerAaron LI <aly@aaronly.me>2020-06-20 19:03:23 +0800
commit5e85866a81221b73407740b255b565481ceb7494 (patch)
treefd9a3f62a3155c132702fe47f9e2e6c7a4288004
parentd388c0d2dfeb66a3d459b1481dd950ee6559d668 (diff)
downloaddotfiles-5e85866a81221b73407740b255b565481ceb7494.tar.bz2
zsh: Add ip2hex() and hex2ip() functions
-rw-r--r--_zshrc9
1 files changed, 9 insertions, 0 deletions
diff --git a/_zshrc b/_zshrc
index ac5ad21..085e6c1 100644
--- a/_zshrc
+++ b/_zshrc
@@ -221,6 +221,15 @@ ccdef() {
${1:-cc} $@[2,-1] -dM -E - </dev/null
}
+## Convert IP between dotted-decimal and hexdecimal notation
+# Credit: https://stackoverflow.com/a/6149254
+ip2hex() {
+ printf '%02X' $(echo "$1" | sed 's/\./ /g')
+}
+hex2ip() {
+ printf '%d.%d.%d.%d' $(echo "${1#0[xX]}" | sed 's/\(..\)/0x\1 /g')
+}
+
#
# Terminal settings
#