]> git.nbdom.net Git - nb.git/commitdiff
new functions
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 17 Mar 2015 21:50:06 +0000 (21:50 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 17 Mar 2015 21:50:06 +0000 (21:50 +0000)
etc/bashrc.function

index 0e106cf639d90b4f65955a5c8e8eec978199a2e7..8596e2aebeb234a8dc2f3a73708ebf09db173f9e 100644 (file)
@@ -241,3 +241,33 @@ ls-tree() {
 find-sort-mtime() {
   find $@ -type f -printf "%As\t%p\n" | sort -k1 -r|cut -f2
 }
+
+nb-alert() {
+  local cmd
+  local host=macbook.brighton.loc
+  case "$1" in
+    led)
+      host=pi.brighton.loc
+      cmd="echo $FUNCNAME > /var/run/gpiod.sock"
+    ;;
+    sound)
+      host=pi.brighton.loc
+      cmd="play 2>/dev/null -v 5 /home/pi/python_games/beep1.ogg"
+    ;;
+    *)
+      host=macbook.brighton.loc
+      cmd="mac-xmessage $FUNCNAME:$1"
+    ;;
+  esac
+  cmd=". $NB_ROOT/etc/profile.sh && $cmd"
+  local ip=`dig +short $host`
+  [ -z "$ip" ] && echo "Can't resolve macbook.brighton.loc" && return 1
+  nb-ips | grep -qFm1 "$ip" || cmd="ssh $host '$cmd'"
+  #export -f mac-xmessage
+  [ "$USER" != "nico" ] && cmd="su - nico -c \"$cmd\""
+  eval "$cmd"
+}
+
+nb-ips() {
+  ifconfig | perl -ne '/^\s*inet (?:addr:)?([\d\.]+)/ and print "$1\n"'
+}