From 8bfe040fff22c3a54ae0c50a8e4961a806fca344 Mon Sep 17 00:00:00 2001
From: Bryan Henry <bryanhenry@google.com>
Date: Wed, 8 May 2019 23:23:15 +0000
Subject: [PATCH] [fx] Add get-device and get-device-addr commands

Useful both for scripts and for interactive use (like in fx scp or
sftp).

Change-Id: I8bd3dc398b8fb0547dda44b3e8ca9ee4e3b923ec
---
 tools/devshell/get-device      | 10 ++++++++++
 tools/devshell/get-device-addr | 11 +++++++++++
 tools/devshell/scp             |  2 +-
 tools/devshell/sftp            |  2 +-
 4 files changed, 23 insertions(+), 2 deletions(-)
 create mode 100755 tools/devshell/get-device
 create mode 100755 tools/devshell/get-device-addr

diff --git a/tools/devshell/get-device b/tools/devshell/get-device
new file mode 100755
index 00000000000..b2306274033
--- /dev/null
+++ b/tools/devshell/get-device
@@ -0,0 +1,10 @@
+#!/bin/bash
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+### print the current selected device name
+
+source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $?
+
+get-device-name
diff --git a/tools/devshell/get-device-addr b/tools/devshell/get-device-addr
new file mode 100755
index 00000000000..b7dc2c85985
--- /dev/null
+++ b/tools/devshell/get-device-addr
@@ -0,0 +1,11 @@
+#!/bin/bash
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+### print the Fuchsia IPv6 address of the current selected device
+
+source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $?
+fx-config-read
+
+get-fuchsia-device-addr
diff --git a/tools/devshell/scp b/tools/devshell/scp
index b86dbfb21a2..d82f51cec8e 100755
--- a/tools/devshell/scp
+++ b/tools/devshell/scp
@@ -12,7 +12,7 @@
 ##
 ## Example usage:
 ##
-##   fx scp "[$(fx netaddr --fuchsia)]:source_file" dest_file
+##   fx scp "[$(fx get-device-addr)]:source_file" dest_file
 
 source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $?
 fx-config-read
diff --git a/tools/devshell/sftp b/tools/devshell/sftp
index 4f5d956c725..6d3799bf29a 100755
--- a/tools/devshell/sftp
+++ b/tools/devshell/sftp
@@ -13,7 +13,7 @@
 ##
 ## Example usage:
 ##
-##   fx sftp "[$(fx netaddr --fuchsia)]:source_file" dest_file
+##   fx sftp "[$(fx get-device-addr)]:source_file" dest_file
 
 source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $?
 fx-config-read
-- 
GitLab