Code Monkey home page Code Monkey logo

wttab's Introduction

wttab - Programmatically open Windows Terminal tab or window

Install

npm install wttab

* Make sure you have Windows Terminal installed

Usage

The package is mostly in line with ttab so you can quickly use existing commands/scripts by putting a w in front of ttab.

$ wttab --help

Usage: wttab [options] [cmd...]

Opens a new terminal tab or window on Windows Terminal, from WSL or Windows.

Options:
  -w, --window [window-id]   Open new tab in new terminal window
                             (window-id only available with preview)
  -s, --settings <settings>  Assign a settings set (profile).
  -t, --title <title>        Specify title for new tab.
  -q                         Clear the new tab's screen.
  --preview                  Use the preview version of Windows Terminal (allows using a
                             existing terminal since v1.7.572.0)
  -p, --profile [terminal]   Choose a profile to launch
  --color <#hexcode>         set color of tab
  --debug                    Enable debugging, outputs the command executed
  -h, --help                 display help for command

Contributing

Always welcome, if you are planning on adding/changing code please open an issue first. See also https://github.com/microsoft/terminal many features are still being added, especially to wt.exe (Windows Terminal Cli).

Sources & Inspiration

Recent feature of executing commands in an existing Terminal Window microsoft/terminal/issues/4472

Commands taken from Official Windows Terminal docs

Inspiration taken from ttab (macOS/Linux)

Ttab has no plans to add support for other platforms

wttab's People

Contributors

lalilaloe avatar dependabot[bot] avatar

Stargazers

Omran Jamal avatar Angelos Pikoulas avatar Michael Klement avatar

Watchers

James Cloos avatar  avatar

Forkers

nmaj3 anodynos

wttab's Issues

file:///C:/Users/pucci/AppData/Roaming/npm/node_modules/wttab/index.js:145 return profile.source.split(".").pop().decapitalize();

pucci@LeoPc MINGW64 /c/Arctica/infra (leonardo.pucci-feature#1727-fluxo-checkout)
$ wttab
file:///C:/Users/pucci/AppData/Roaming/npm/node_modules/wttab/index.js:145
    return profile.source.split(".").pop().decapitalize();
                          ^

TypeError: Cannot read properties of undefined (reading 'split')
    at getProfileCommand (file:///C:/Users/pucci/AppData/Roaming/npm/node_modules/wttab/index.js:145:27)
    at file:///C:/Users/pucci/AppData/Roaming/npm/node_modules/wttab/index.js:150:58
    at Array.map (<anonymous>)
    at availableProfiles (file:///C:/Users/pucci/AppData/Roaming/npm/node_modules/wttab/index.js:150:33)
    at file:///C:/Users/pucci/AppData/Roaming/npm/node_modules/wttab/index.js:178:33
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)

Node.js v19.8.1

Unable to run more than one word commands properly

First of all, I am sorry if this is me being unable to grasp something basic about the functionality of "wttab".

Essentially, I had a script in my "package.json file" to do the following bit of code.

image

The first script ("tab:launch:bot1") that used only the "ls" command worked fine, however, the second ("tab:launch:bot2") that ran a command separated by spaces was getting messed up, as the Powershell was separating them commas. I tried to escape the spaces, to put the command between (') and none of it seemed to work. Once again, I am sorry if this is me being unable to grasp anything obvious.

I ended up adding a little bit of a hacky solution (seen below, highlighted), that essentially checks if the command has content separated by spaces and interprets it as a single, joint command.
image

I'm sure this is not the way to do it, and it may even cause problems for other cases, I just found a way to fix it for what I wanted.

Anyways, I would like to know if this had a simpler and more elegant solution, if it was something I missed, or if there was another way to workaround it.

Thanks in advance!

Error "UNC paths are not supported. Defaulting to Windows directory."

This is is the same error as #17 but in WSL 1, therefore I'\m opening as a new error:

anodynos@Dellino:~$ wttab
'\\wsl$\Ubuntu-22.04\home\anodynos'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
file:///home/anodynos/.asdf/installs/nodejs/16.18.0/lib/node_modules/wttab/index.js:145
    return profile.source.split(".").pop().decapitalize();
                          ^

TypeError: Cannot read properties of undefined (reading 'split')
    at getProfileCommand (file:///home/anodynos/.asdf/installs/nodejs/16.18.0/lib/node_modules/wttab/index.js:145:27)
    at file:///home/anodynos/.asdf/installs/nodejs/16.18.0/lib/node_modules/wttab/index.js:150:58
    at Array.map (<anonymous>)
    at availableProfiles (file:///home/anodynos/.asdf/installs/nodejs/16.18.0/lib/node_modules/wttab/index.js:150:33)
    at file:///home/anodynos/.asdf/installs/nodejs/16.18.0/lib/node_modules/wttab/index.js:178:33
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:526:24)
    at async loadESM (node:internal/process/esm_loader:91:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)

Details:

  • Ubuntu-22.04 on WSL 1
  • Windows 10 Pro 22H2 OS Build 19045.2673

Error: "Could not read Windows Terminal settings.json"

With the following package.json:

{
  "name": "demo",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "dev:client": "cd client && yarn start",
    "dev:server": "cd server && yarn start",
    "dev": "run-script-os",
    "dev:default": "ttab -t 'Server' yarn dev:server && ttab -t 'Client' yarn dev:client",
    "dev:win32": "wttab -t 'Server' yarn dev:server && wttab -t 'Client' yarn dev:client"
    // ...
  },
  "dependencies": {
    "npm-run-all": "^4.1.5",
    "run-script-os": "^1.1.6",
    "shx": "^0.3.3"
  },
  "optionalDependencies": {
    "ttab": "^0.7.1",
    "wttab": "1.2.2"
  }
}

I get the following error if I run yarn dev:

$ run-script-os
$ wttab -t 'Server' yarn dev:server && wttab -t 'Client' yarn dev:client
file:///H:/Repo/unbox/demo/node_modules/wttab/index.js:135
    throw Error("Could not read Windows Terminal settings.json", err);
          ^

Error: Could not read Windows Terminal settings.json
    at wtSettings (file:///H:/Repo/unbox/demo/node_modules/wttab/index.js:135:11)
    at file:///H:/Repo/unbox/demo/node_modules/wttab/index.js:161:18
    at ModuleJob.run (internal/modules/esm/module_job.js:146:23)
    at async Loader.import (internal/modules/esm/loader.js:165:24)
    at async Object.loadESM (internal/process/esm_loader.js:68:5)
error Command failed with exit code 1.

WSL 2 errors

When starting wttab from wsl terminal. Several warning messages are shown

'\\wsl.localhost\Ubuntu\home\user' CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows directory. stderr: '\\wsl.localhost\Ubuntu\home\user' CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows directory.

Windows path when launching wsl

Launching wsl from powershell in a folder results in an error
/bin/bash: line 0: cd: C:pathtofolder: No such file or directory

It needs to translate to, for example: /mnt/c/path/to/folder

Error: Command failed: cmd.exe /c "echo %LocalAppData%" /bin/sh: 1: cmd.exe: not found

Hi, I'm getting this, I'm not sure if I'm using it in the proper environment:

I've tried through normal bash and zsh - result is the same:

anodynos@Dellino:~$ wttab -w "Foobar"
/bin/sh: 1: cmd.exe: not found
node:child_process:828
    err = new Error(msg);
          ^

Error: Command failed: cmd.exe /c "echo %LocalAppData%"
/bin/sh: 1: cmd.exe: not found

    at checkExecSyncError (node:child_process:828:11)
    at execSync (node:child_process:902:15)
    at wtSettings (file:///home/anodynos/.asdf/installs/nodejs/16.14.0/.npm/lib/node_modules/wttab/index.js:123:22)
    at file:///home/anodynos/.asdf/installs/nodejs/16.14.0/.npm/lib/node_modules/wttab/index.js:161:18
    at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:61:12) {

I'm using Windows 10, with WSL 1 (cause its so much faster in I/O) & Ubuntu 20.04

PS C:\Users\dell>  wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu-20.04           Running         1

Incorrect syntax for powershell.

Just started using this library and I am sorry if this is incorrect but tried running the code from package.json "wttab -t 'Run API' npm run run:api" and when windows terminal opens it throws an error:
image
When added debug statement "wttab -t 'Run API' npm run run:api --debug" i see that it tried running a command:
"wt.exe" -w 0 --title "'Run" -p "Windows PowerShell" -d "dir/path" API',npm,run,run:api
While testing the wt command I found out that the correct syntax should have been:
wt.exe -w 0 --title "Run API" -p "Windows PowerShell" -d "dir/path" powershell npm run run:api
This runs the code nicely.

Is it just my mistake or something is actually wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.