diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bf6c33..52242e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,5 +3,9 @@ All notable changes to the "vscode-ipaddress" extension will be documented in th Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. + +## [1.0.1] +- Add `ipAddress.getSelectedIPAddress` command which allows to return the selected ip address as input variables in tasks.json or launch.json file + ## [Unreleased] - Initial release \ No newline at end of file diff --git a/README.md b/README.md index aee292d..ac735d9 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,27 @@ You can also modify keyboard shortcut with JSON below. } ``` +You can alsoe insert the selected IP address into a configuration from `launch.json` or `tasks.json` using [input variables](https://code.visualstudio.com/docs/editor/variables-reference#_input-variables). For instance here for a `tasks.json` echoing the selection in the terminal: +```json +{ + "version": "2.0.0", + "tasks": [ + { + "label": "echo selected host ip", + "type": "shell", + "command": "echo 'selected host ip ${input:hostIP}'" + }, + ], + "inputs": [ + { + "type": "command", + "id": "hostIP", + "command": "ipAddress.getSelectedIPAddress" + } + ] +} +``` + ### Public IP address Public IP address is obtained from OpenDNS via [`check-ip`](https://www.npmjs.com/package/public-ip) and updated every minute. diff --git a/commands.js b/commands.js index 0331db7..888a171 100644 --- a/commands.js +++ b/commands.js @@ -4,5 +4,6 @@ const PREFIX = 'ipAddress.'; module.exports = { INSERT_IP_ADDRESS : PREFIX + 'insertIPAddress', - SHOW_NEXT_IP_ADDRESS: PREFIX + 'showNextIPAddress' + SHOW_NEXT_IP_ADDRESS: PREFIX + 'showNextIPAddress', + GET_SELECTED_IP_ADDRESS: PREFIX + 'getSelectedIPAddress' }; diff --git a/extension.js b/extension.js index ae4ac4c..911cf6f 100644 --- a/extension.js +++ b/extension.js @@ -67,6 +67,12 @@ function activate(context) { statusBarItem.nextAddress(); }) ); + + context.subscriptions.push( + vscode.commands.registerCommand(Commands.GET_SELECTED_IP_ADDRESS, () => { + return statusBarItem.currentAddress(); + }) + ); } exports.activate = activate; diff --git a/ipAddressStatusBarItem2.js b/ipAddressStatusBarItem2.js index dd4f84f..5673424 100644 --- a/ipAddressStatusBarItem2.js +++ b/ipAddressStatusBarItem2.js @@ -43,6 +43,18 @@ class IPAddressStatusBarItem { nextAddress() { this._interfaces.next(); } + + currentAddress() { + const networkInterface = this._interfaces.current(); + + if (networkInterface) { + const address = networkInterface.get('address'); + return address; + } else { + return null; + } + + } module.exports = IPAddressStatusBarItem; diff --git a/package.json b/package.json index c035160..96d9642 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-ipaddress", "displayName": "IP Address", "description": "Shows IP addresses in status bar and inserts into your text", - "version": "1.0.0", + "version": "1.0.1", "publisher": "Compulim", "engines": { "vscode": "^1.11.0"