]> git.nbdom.net Git - nb.git/commitdiff
cat_stty
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Fri, 8 Mar 2024 19:03:52 +0000 (20:03 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Fri, 8 Mar 2024 19:03:52 +0000 (20:03 +0100)
etc/profile.d/functions

index 485985d95617e08d6a3b665628baad862f16ed5e..54b0955c1497bb42dc17b5eb62460a83bc1d61ec 100755 (executable)
@@ -5,6 +5,13 @@
 #################################################################################
 type -P which > /dev/null || which() { type -P "$1" 2>&1; }
 
+cat_stty() {
+       usage="cat_stty DEVICE [BAUD=9600]"
+       local dev="${1?$usage}"
+       local baud="${2:-9600}"
+       echo cat "$dev" "$baud"
+}
+
 which nproc > /dev/null || nproc() {
        case "$OSTYPE" in
                darwin*) sysctl -n hw.ncpu ;;
@@ -578,8 +585,6 @@ myip() {
        local url='';
        for url in http://nicolas.boisselier.free.fr/myip/ http://nbdom.net/myip http://ipinfo.io/ip http://www.ipchicken.com http://icanhazip.com http://ident.me
        do
-               #http_get "$url" 2> /dev/null | awk 'match($0, /([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})/) {print substr($0, RSTART, RLENGTH); exit 64}'
-               #http_get "$url" | perl -ne 'print "$1\n" and exit 64 if /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/';
                http_get "$url" | sed -n '/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/p; q' | awk '{print $1; exit 64}'
 
                [ "$?" == "64" ] && return 0;
@@ -589,7 +594,7 @@ myip() {
 
 http_get() {
        if which curl 1>/dev/null; then
-               curl -sk $*
+               curl -sk --netrc $*
 
        elif which wget 1>/dev/null; then
                wget -O - --quiet --no-verbose --no-check-certificate --timeout 10 --tries 1 $*
@@ -605,13 +610,13 @@ http_get() {
 
 http_head() {
        if which curl 1>/dev/null; then
-               curl -sk --head $*
+               http_get --head $*
 
        elif which wget 1>/dev/null; then
                http_get --save-headers - $* | perl -ne '/^\s*$/ and last;print'
 
        elif which lynx 1>/dev/null; then
-               lynx --head -dump $*
+               http_get --head $*
 
        else
                echo "Can't find web client" 1>&2