Opening a new WSL2 tab in Windows terminal and executing command - windows-subsystem-for-linux

I'm using WSL2 on Windows terminal. I have an app that needs front end and backend booted before it can be used, so every time I nave to open a terminal window, navigate to a folder and run a command.
I would like to set an alias that would open a new tab, navigate to a folder and do go run .
I saw suggestions for linux, but none of those work on Windows Terminal with WSL2. Anyone have experience with this setup?

You could create a profile for this. Something like
{
"commandline": "wsl.exe -d Ubuntu ping 8.8.8.8",
"name": "backend",
"startingDirectory": "\\\\wsl$\\Ubuntu\\home\\zadjii\\path\\to\\project",
},
(of course, replace ping 8.8.8.8 with the actual command you want to run, replace Ubuntu with the name of the distro you're using, and replace home\\zadjii\\path\\to\\project with your actual path, delimited by double-backslashes.)
Now, if you wanted to get really crazy, you could create an action in the Command Palette which opened up multiple commands all at once:
{
"name": "Run my project",
"command": {
"action": "multipleActions",
"actions": [
// Create a new tab with two panes
{ "action": "newTab", "tabTitle": "backend", "commandline": "wsl.exe -d Ubuntu run_my_backend", "startingDirectory": "\\\\wsl$\\Ubuntu\\home\\zadjii\\path\\to\\backend" },
{ "action": "splitPane", "tabTitle": "frontend", "commandline": "wsl.exe -d Ubuntu run_my_frontend", "startingDirectory": "\\\\wsl$\\Ubuntu\\home\\zadjii\\path\\to\\frontend" },
]
}
}
see multipleActions

Related

Windows Terminal profile not showing up

I've just installed WSL2 and am using the Windows Terminal on Win10 1909 (18363.1256). I'm trying to set up 2 different profiles, one that launches a local WSL2 Ubuntu shell, and one that launches another WSL2 shell that will automatically ssh to a specific host.
The local one works great, shows up without an issue, however I can't seem to get my 2nd profile to show up in the list of profiles.
My settings.json looks like this:
"profiles":
{
"defaults":
{
// Put settings here that you want to apply to all profiles.
"colorScheme": "One Half Dark",
"fontFace": "JetbrainsMono NF",
"fontSize": 11
},
"list":
[
{
"guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
"hidden": false,
"name": "Ubuntu",
"source": "Windows.Terminal.Wsl",
"startingDirectory": "//wsl$/Ubuntu/home/sensanaty",
"tabTitle": "WSL2"
},
{
"guid": "{15c5814b-7ed1-4cec-bc64-d165274958fa}",
"hidden": false,
"name": "External Host",
"source": "Windows.Terminal.Wsl",
"commandline": "ssh example#123.456.7.89",
"tabTitle": "External Host"
},
]
},
With the above, I only get the Ubuntu profile in my list
I thought maybe it was the guid generated or something, but I just did a simple uuidgen and pasted it into the json so it shouldn't really be causing any issues there. I've also obviously tried restarting my system, to no avail. The default profiles show up fine if I disable the option to stop auto-generating them, as well.
Any clue as to what might help me out?
The 'source' attribute is for dynamically generated profiles, for which WSL will create one for each instance installed. You can't control the command line for these dynamically generated profiles. What you need is for your new profile to extend the command line to tell Terminal to use WSL. Remove the 'source' attribute entirely, so that your new profile is static.
In your case, that should be ...
{
"guid": "{15c5814b-7ed1-4cec-bc64-d165274958fa}",
"hidden": false,
"name": "External Host",
//"source": "Windows.Terminal.Wsl",
"commandline": "wsl.exe ssh example#123.456.7.89",
"tabTitle": "External Host"
}//,
As bwolfbarn mentioned, you should also ditch that trailing comma if it really comes at the end of the "list" block.
Here are a few lines from mine as additional examples as well ...
{
"guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
"hidden": false,
"name": "Ubuntu 20.04 WSL2 tmux",
//"source": "Windows.Terminal.Wsl",
"commandline": "wsl.exe -d Ubuntu -e sh -c \"/usr/bin/tmux has-session -t main 2>/dev/null && /usr/bin/tmux attach-session -d -t main || /usr/bin/tmux -2 new-session -t main -s main -c ${HOME}\"",
"cursorShape": "filledBox"
},
{
"guid": "{4e04fa7e-76c7-4746-a322-a227e70dde6c}",
"hidden": false,
"name": "Ubuntu 20.04 WSL1 tmux",
//"commandline": "wsl.exe -d Ubuntu20.04_WSL1",
"commandline": "wsl.exe -d Ubuntu20.04_WSL1 -e sh -c \"/usr/bin/tmux has-session -t main 2>/dev/null && /usr/bin/tmux attach-session -d -t main || /usr/bin/tmux -2 new-session -t main -s main -c ${HOME}\"",
"cursorShape": "filledBox"
}
Note that you could, I believe, use "wsl.exe -e" (a.k.a. --execute), but it's not really necessary in your case.
If you want to see your "source": "Windows.Terminal.Wsl" in Windows Terminal Menu it must exist in the registry
[HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss\{UUID}]
(The registry UUID is not related to Windows Terminal UUID).
This registry entry can be created by running "wsl --import" or by cloning existing entry (if you are comfortable messing with the registry).
If you still don't see your profile after confirming that the registry entry exists, remove all entries for "generatedProfiles" in state.json file located in the same folder as settings.json. This will force Windows Terminal to update state.json. If you generated Windows Terminal profile UUID yourself, it may ignore it and create its own one. In this case you will see duplicate entries for the profile in settings.json. Remove the ones that were generated manually, and leave the one generated by the terminal.
At least the last comma should be removed (I commented it in your example) as the element "External Host" is the last of the list.
[
{
"guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
"hidden": false,
"name": "Ubuntu",
"source": "Windows.Terminal.Wsl",
"startingDirectory": "//wsl$/Ubuntu/home/sensanaty",
"tabTitle": "WSL2"
},
{
"guid": "{15c5814b-7ed1-4cec-bc64-d165274958fa}",
"hidden": false,
"name": "External Host",
"source": "Windows.Terminal.Wsl",
"commandline": "ssh example#123.456.7.89",
"tabTitle": "External Host"
}//,
]

Unable to connect to a site from Testcafe IDE on OSX

My fixtures are set up like so
{
"fixtures": [
{
"name": "login",
"pageUrl": "http:\/\/localhost:3000\/",
"tests": [
{
"name": "type name",
"commands": [
{
"type": "type-text",
"studio": {
},
"callsite": "0",
"selector": {
"type": "js-expr",
"value": "input[type=email]"
},
"options": {
},
"text": "example#email.com"
}
]
}
]
}
]
}
with one simple test to find the input and type some text but when running the command I get
testcafe chrome login.testcafe
ERROR Unable to establish one or more of the specified browser connections. This can be caused by network issues or remote device failure.
Type "testcafe -h" for help.
I've seen this issue a couple of times on their issues board one relating to CI integration on a Linux server and another which seems like a similar issue of trying to connect to localhost
https://github.com/DevExpress/testcafe-browser-provider-electron/issues/20
https://github.com/DevExpress/testcafe/issues/1133
New to testcafe any help would be appreciated!
I've found the solution some network policies don't allow access to your machine on some ports in my example it's 57501.
testcafe chrome login.testcafe --hostname localhost
adding --hostname resolves the issue
documentation
https://devexpress.github.io/testcafe/documentation/using-testcafe/command-line-interface.html#--hostname-name
I still don't know how to launch from the IDE but this resolves my main issue.
TestCafe Studio Preview does not support setting command line options (hostname in your case). The TestCafe team is going to implement this functionality in the official release.
So, for now, it is only possible to run tests via a command line.
UPDATE:
You can set the hostname option in the TestCafe Studio Settings dialog:

How do I set a Selenium node's id with Selenium Grid Extras/json config files?

I'm in the process of converting our Selenium Grid to use Selenium Grid Extras, which so far is looking great! But I'm having an issue where, before, our nodes would be represented by their machine name in the grid console (e.g. id : http://SELENIUMXX:5555, OS : WINDOWS), but now are only represented by their IP address (e.g. id : http://x.x.x.x:5556, OS : WINDOWS). Since the former are much easier to read, I'd like to know how to set the node ID attribute using SGE/json config files. The bat files for opening the nodes themselves are all dynamically constructed from the config files by SGE, so I can't set ID there.
I have a "friendlyHostName" parameter that it passes in, but that's only displayed in the console if you click over to the configuration tab.
You should find a node configuration file in the directory wherein you downloaded the Selenium Grid Extras jar. Open up that JSON file and add an attribute
"host": "MyMachineNameGoesHere"
under the key "configuration"
I decided to give Selenium Grid extras a whirl and here's how my complete node configuration file looks like
{
"capabilities": [
{
"seleniumProtocol": "WebDriver",
"browserName": "chrome",
"maxInstances": 3,
"version": "52",
"platform": "MAC"
}
],
"configuration": {
"proxy": "com.groupon.seleniumgridextras.grid.proxies.SetupTeardownProxy",
"maxSession": 3,
"port": 5555,
"register": true,
"unregisterIfStillDownAfter": 10000,
"hubPort": 4444,
"hubHost": "127.0.0.1",
"host": "dragonlair.local",
"nodeStatusCheckTimeout": 10000,
"downPollingLimit": 0
},
"loadedFromFile": "node_5555.json"
}
Went round and round on this with Selenium 3.141, trying to get json file to work. Then stumbled on solution...
Problem: My Selenium 3.x "Grid Console" is not displaying the "id" (unique node name) that I specify in the json config file.
Solution: Don't use the json config file. Instead, place "-id nodeName" in the commandline.
Example:
java.exe -jar /pathToJar/selenium-server-standalone-3.141.59.jar -id
MyNodeName -role node -nodeConfig /pathToMyConfig/nodeConfig.json
Where "MyNodeName" is whatever unique name you want the Grid Console (website) to show your Selenium node as (instead of the default IP address).
Summary: In your command line, use "-id EnterNodeNameHere".
Don't know whether order matters...but I put -id before -role parm.
I found a general way to do it so you don't have to change each one manually. In your config directory, set up a master node config file, with a "host": "HOSTNAME", line in the configuration per Krishnan Mahadevan's answer, and then run this batch file:
#echo off
set str1= "host": "HOSTNAME",
set str2= "host":
set inputfile=node_master.json
set outputfile=[YOUR OUTPUT FILE]
for /d %%v in ("*") do (
COPY %inputfile% %%v
cd %%v
>"%outputfile%" (
for /f "usebackq delims=" %%A in (%inputfile%) do (
if "%%A" equ "%str1%" (echo %str2% "%%v",) else (echo %%A)
)
)
del %inputfile%
cd ..
)

Sublime Text, SublimeREPL, Clojure & Windows 8

I've got both Leiningen & Clojure working on Windows 8 separately from Sublime Text (e.g. I can get a repl working in Windows PowerShell).
My problem is that I can't get the SublimeREPL working in SublimeText (the REPL loads up but doesn't then do anything). Are there any simple traps that I might be missing or, failing that, are there a series of steps I could follow to troubleshoot?
Please see this SublimeREPL issue for instructions on how I got a Clojure REPL to work, at least on XP (I haven't tried it on Win7 or 8 yet). Basically, I edited the menu file for Clojure, and changed the command from lein repl to lein trampoline run -m clojure.main, which for some reason did the trick. I also changed the path to $file so you can open up a REPL while your project.clj is the current tab in Sublime, and the REPL should inherit the project's settings.
For reference, the complete Packages/User/SublimeREPL/config/Clojure/Main.sublime-menu file (Packages is accessible via Preferences -> Browse Packages...) is as follows:
[
{
"id": "tools",
"children":
[{
"caption": "SublimeREPL",
"mnemonic": "r",
"id": "SublimeREPL",
"children":
[
{"caption": "Clojure",
"id": "Clojure",
"children":[
{"command": "repl_open",
"caption": "Clojure Trampoline",
"id": "repl_clojure",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": {"windows": ["lein.bat", "trampoline", "run", "-m", "clojure.main"],
"linux": ["lein", "repl"],
"osx": ["lein", "repl"]},
"soft_quit": "\n(. System exit 0)\n",
"cwd": {"windows":"$file_path",
"linux": "$file_path",
"osx": "$file_path"},
"syntax": "Packages/Clojure/Clojure.tmLanguage",
"external_id": "clojure",
"extend_env": {"INSIDE_EMACS": "1"}
}
},
{"command": "clojure_auto_telnet_repl",
"id": "repl_clojure_telnet",
"caption": "Clojure-Telnet"}]}
]
}]
}
]
I solved this problem with Git Bash Shell. I have used the shell script version of leiningen instead of lein.bat
This is the command I use:
["C:\\Program Files\\Git\\bin\\sh.exe", "-l", "--", "/d/lein.sh", "repl"]
assuming lein.sh is in d:\
lein trampoline command sometimes behaves differently from lein repl and could fail due to unknown reasons.

Creating a Sublime Text Grunt Build System for a specific target

I'm new to Grunt (and fairly new to sublime Text), but I've downloaded the excellent grunt build system and it works well every time I save. I'm on Win8 by the way.
The only problem is that it runs all tasks/targets. I have separated my tasks into "dist" and "dev" targets and I would like it to run only the dev tasks when I use it on save.
I'd then like to create a separate build task which I would use when building for production. Is this a sensible strategy?
Anyway, I just need to know how to modify the following build system file to just run tasks with the "dev" target....
{
"cmd": ["grunt", "--no-color"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${project_path:${folder:${file_path}}}",
"selector": "Gruntfile.js",
"windows":
{
"cmd": ["grunt.cmd", "--no-color"]
},
"variants":
[
{
"name": "Gruntfile",
"cmd": ["grunt", "--no-color"],
"windows":
{
"cmd": ["grunt.cmd", "--no-color"]
}
}
]
}
You first need to create an task that runs all the dev targets:
grunt.registerTask('dev', ['task:dev', 'task2:dev']);
This can be run from the command-line using: grunt dev
As for the Sublime build config, "cmd" is just an array of command-line arguments.
So it would end up like this:
{
"cmd": ["grunt", "dev", "--no-color"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${project_path:${folder:${file_path}}}",
"selector": "Gruntfile.js",
"windows":
{
"cmd": ["grunt.cmd", "dev", "--no-color"]
},
"variants":
[
{
"name": "Gruntfile",
"cmd": ["grunt", "dev", "--no-color"],
"windows":
{
"cmd": ["grunt.cmd", "dev", "--no-color"]
}
}
]
}
All you need to do is call Grunt by specifying it's complete path. Calling grunt alone fails, even though you have the grunt-cli installed and working from the cmd prompt. Note you need to have the environment variable for nodejs set.
Windows users create your my-project.sublime-builder file and put it in C:\Users\yourname\AppData\Roaming\Sublime Text\Packages\User. Apple/Unix location will be different.
The my-project.sublime-builder file looks like:
{
"cmd": "C:\\Users\\ronni\\AppData\\Roaming\\npm\\grunt.cmd",
"working_dir": "C:\\Users\\ronni\\documents\\my-project"
}