What have I missed in Windows Terminal settings.json? - windows

I just start to customize Windows Terminal.
I would like to add Git and it opens the git-bash.exe outside of the program.
What have I missed in the settings.json?
That's the settings.json "profiles" -> "list" array
{
"guid": "{00000000-0000-0000-0000-000000000001}",
"name" : "Git",
"commandline" : "I:/Git/git-bash.exe",
"hidden": false,
"icon" : "I:/Git/mingw64/share/git/git-for-windows.ico",
"padding": "8, 8, 8, 8",
"closeOnExit" : "always",
"snapOnInput": true,
"historySize" : 9001,
"startingDirectory": "%USERPROFILE%"
}

git-bash.exe and Windows Terminal may be the same kind of applications -- terminal. They are different from shells, such as cmd, powershell, bash, sh, zsh.
https://stackoverflow.com/a/61969136/11831045

Related

Save terminal tabs to saved workspace VSCode

Is it possible to save Terminal settings to a workspace? For most of my projects I always have two terminal tabs open. One where I do all of my git work and one where I run gulp tasks. These are two different folders and neither are the project root. When I open a saved workspace it always just opens one tab to the project root.
Look at the Restore Terminals extension. For example, in your settings.json:
"restoreTerminals.runOnStartup": false, // true is the default
// set to false if using a keybinding or command palette
"restoreTerminals.terminals": [
{
"splitTerminals": [
{
"name": "git",
"commands": [
"cd <your directory>",
"npm run test" // your git command(s)
]
}
]
},
{
"splitTerminals": [
{
"name": "gulp",
"commands": [
"cd zip",
"gulp sass"
]
}
]
}
]
will open two terminals, one for your git work and one for the gulp work. They can each take multiple commands.
Example keybinding:
{
"key": "shift+alt+t", // whatever keybinding if you wish
"command": "restore-terminals.restoreTerminals",
},
or you can it run at start-up.
The Tasks feature is the current recommended way to handle this. There is no need for an extension. See Automating launching of terminals in the VS Code documentation.
Then make sure that tasks are run automatically when the folder is opened by running command Tasks: Manage Automatic Tasks in Folder and choosing Allow Automatic Tasks in Folder (see Run behavior).
Please also see the note here that:
Task support is only available when working on a workspace folder. It is not available when editing single files."
For a Linux not-so-officially-recommended way that works. The xdotool key emulator for linux can be used. I'm sure any Windows key emulator could be used to accomplish the same thing.
First, set the Terminal: Change Color to a keyboard shortcut. Here I'm using Ctrl+Shift+C. This is done by bringing up the command pallet (Cntrl+Shift+P) and, typing Terminal: Change Color
Here is my Restore Terminals json from VS Code settings. The lengthy cli command to update the colors needs to be activated on the last tab, as it is the tab that is focused when Restore Tabs is finished restoring tabs.
We need a bit of a timeout between the setting of each tab color, as VS Code takes just about a 10th of a second to complete the command. The built in keyboard shortcut cntrl+Page_Up is used to bring the previous tabs into focus. This script is for a WorkSpace that includes a Docker-Compose enviroment that contains 3 repos.
Be sure to save this in your Workspace settings, not your user settings. For more info, visit: https://code.visualstudio.com/docs/getstarted/settings
"restoreTerminals.terminals": [
{
"splitTerminals": [
{
"name": "docker-compose",
"commands": ["cd ..", "cd docker-compose", "clear"]
},
]
},
{
"splitTerminals": [
{
"name": "api",
"commands": ["cd ..", "cd api", "clear"]
},
]
},
{
"splitTerminals": [
{
"name": "ui",
"commands": [
"cd ..",
"cd ui",
"xdotool key ctrl+shift+c && xdotool type 'cyan' && xdotool key Return && sleep .2",
"xdotool key ctrl+Page_Up && xdotool key ctrl+shift+c && xdotool type 'green' && xdotool key Return && sleep .2",
"xdotool key ctrl+Page_Up && xdotool key ctrl+shift+c && xdotool type 'yellow' && xdotool key Return",
"clear"
]
},
]
}
],
And the end result... Is that all tab colors are updated after they are restored.
Of course, anyone who has ever used keyboard emulation for automating tasks should know you can not be entering text or clicking elsewhere until the task is complete.
If you're on windows you can use powershell to create a similar effect to #CodeBloodedChris's solution.
Create a powershell script in your workspace root directory (or where ever the last terminal's final path is) and name it something like 'restore-terminal-customization.ps1' or something like that. Then add the following code to it:
# Uses windows forms to send keystrokes to customize vscode Terminals
Add-Type -AssemblyName System.Windows.Forms
$tabDelay = .6
# Last Terminal
[System.Windows.Forms.SendKeys]::SendWait("^+cRed~")
# Second to last Terminal
[System.Windows.Forms.SendKeys]::SendWait("^{PGUP}"); Start-Sleep -s $tabDelay
[System.Windows.Forms.SendKeys]::SendWait("^+cYellow~")
# Third to last Terminal
[System.Windows.Forms.SendKeys]::SendWait("^{PGUP}"); Start-Sleep -s $tabDelay
[System.Windows.Forms.SendKeys]::SendWait("^+cMagenta~")
In this script the '^+c' is ctrl+shift+c and '~' is the enter key.
Similarly I had also set up a keybinding for the icons which uses ctrl+shift+i '^+i'. Here's an example of setting both the color and the icon of a terminal:
# Fourth to last Terminal
[System.Windows.Forms.SendKeys]::SendWait("^{PGUP}"); Start-Sleep -s $tabDelay
[System.Windows.Forms.SendKeys]::SendWait("^+cGreen~^+iorganization~")
In your restoreTerminal's config call the script you created as a command in the last terminal on your list.
"restoreTerminals.terminals": [
{
"splitTerminals": [
{
"name": "docker-compose",
"commands": ["cd ..", "cd docker-compose", "clear"]
},
]
},
{
"splitTerminals": [
{
"name": "api",
"commands": ["cd ..", "cd api", "clear"]
},
]
},
{
"splitTerminals": [
{
"name": "ui",
"commands": [
"cd ..",
"cd ui",
".\restore-terminal-customization.ps1",
"clear"
]
},
]
}
],
Don't forget to set the keybindings to the Terminal: Change Color and Terminal: Change Icon commands in VsCode.

Jelastic - how to get the environment variables to a Docker container

How do I get the environment placeholders to show up inside a Docker container?
The documentation doesn't seem to be exactly clear where those can be used. I have tried to just set those inside the node env as shown in a JPS file that is added to this question.
For example, it shows the environment as env-2461411 and its name as Environment Test in the environment options
Once the environment is launched, the placeholders are still as they show in the JPS file, and not replaced by the actual values.
Result
Placeholders don't seem to be replaced, and as such the shell doesn't like the environment it gets:
-bash: ${env.appid}: bad substitution
-bash: ${env.displayName}: bad substitution
-bash: ${env.domain}: bad substitution
-bash: ${env.envName}: bad substitution
-bash: ${env.name}: bad substitution
-bash: ${env.shortdomain}: bad substitution
-bash: ${env.url}: bad substitution
-bash: ${env.appid}: bad substitution
-bash: ${env.displayName}: bad substitution
-bash: ${env.domain}: bad substitution
-bash: ${env.envName}: bad substitution
-bash: ${env.name}: bad substitution
-bash: ${env.shortdomain}: bad substitution
-bash: ${env.url}: bad substitution
Expected result
Environment variables showing in the bash environment, such as
env_domain=env-2461411
env_name=Environment Test
Example JPS file
{
"jpsType": "install",
"jpsVersion": "1.4",
"name": "Environment Test",
"description":
{
"text": "Template for testing environment variables test",
"short": "Environment variables test"
},
"logo": "https://raw.githubusercontent.com/jelastic-jps/start-stop-scheduler/master/images/logo.png",
"homepage": "https://jelastic.com/",
"categories":
[
"apps/testing"
],
"success":
{
"text": "## Environment test is up and running\nOpen the Jelastic SSH gateway and locate the test-node, see its environment with `env`"
},
"nodes":
[
{
"image": "debian",
"extip": false,
"count": 1,
"cloudlets": 16,
"fixedCloudlets": 1,
"nodeType": "docker",
"nodeGroup": "test",
"displayName": "test-node",
"volumes":
[
"/root"
],
"env":
{
"env_appid": "${env.appid}",
"env_domain": "${env.domain}",
"env_url": "${env.url}",
"env_displayname": "${env.displayName}",
"env_envname": "${env.envName}",
"env_name": "${env.name}",
"env_shortdomain": "${env.shortdomain}"
}
}
],
"onInstall":
{
"log": "${placeholders}"
}
}
During the process of environment's creation mentioned placeholders are not initialized and can't be used.
You can use the method AddContainerEnvVars.
In your case, it will be like this.

How to setup Sublime Text 3 to build script with MSYS bash?

Hi i would like to know how to setup sublime text 3 build system to execute bash script threw MSYS bash.
I have try the following build system :
{
"cmd" : ["bash", "$file"],
"selector" : "source.shell",
"path" : "C:/MinGW/msys/1.0/bin"
}
It does look to work, but it can't find gcc, i have try to add multiple path this way :
"path" : "C:/MinGW/msys/1.0/bin:C:/MinGW/bin"
But the C: looks to break the thing.
I have also try this :
"path" : ["C:/MinGW/msys/1.0/bin", "C:/MinGW/bin"]
But it fail also as path is waiting for a string only
"path" :"C\:/MinGW/msys/1.0/bin:C\:/MinGW/bin"
"path" :"C:/MinGW/msys/1.0/bin\:C:/MinGW/bin"
"path" :"${C:/MinGW/msys/1.0/bin}:${C:/MinGW/bin}"
Also fail ...
"path" : "/c/MinGW/msys/1.0/bin:/c/MinGW/bin"
"path" : "/MinGW/msys/1.0/bin:/MinGW/bin"
Same for those ...
Any working suggestion would be greatly appreciated.
To install msys bash with sublime text 3 you just have to copy this in
a new build system:
{
"cmd" : ["bash", "$file"],
"selector" : "source.shell",
"windows": {
"path" : "$path;c:\\mingw\\bin;c:\\mingw\\msys\\1.0\\bin",
"cmd" : ["bash", "--login", "-i", "-c", "cd \"$file_path\"; \"$file\""]
},
"osx": {
"path" : "$PATH:/usr/local/bin:/usr/X11R6/bin:/opt/X11/bin:/usr/texbin"
}
}
thanks to macite :
https://github.com/macite/sublimebashbuildsystem/blob/master/Bash.sublime-build

How to suppress output in Sublime Text cmd?

How can I suppress the output in Sublime Text Build System output?
I tried this but it says Error: unrecognized or incomplete command line.
{
"cmd": ["ipconfig", ">nul 2>&1"],
"name": "ipconfig",
"shell": "true"
}
{
"name": "ipconfig",
"shell_cmd": "ipconfig >nul 2>&1"
}
I always use shell_cmd because you can just write the command like you would on the command line instead of trying to figure out the multiple arguments nonsense in the array. This worked for me.

Sublime build system to open file at local server address

For a website I'm developing with the help of a local server (running at http://127.0.0.1:4000), I try to write a build system for my Sublime Text project settings.
I have access to these variables (provided by Sublime Text):
$file: Stores the absolute path to the file on disk:C:\Users\User\dev\repos\base\dir\index.html
$project_path: Stores the location of the project file (usually the root of the project):C:\Users\User\dev\repos\base
Now what I want is the content of $file but instead of the $project_path I want http://127.0.0.1:4000/~base. For that task I tried the following with Bash cmd.exe:
CALL SET result=%file:%project_path%=http://127.0.0.1:4000\~base\% && echo %result%
This gives the desired result, however I can't seem to be able to apply it to the build system inside Sublime Text.
For now, I try to generate the correct address and output it via cmd.exe:
{
"build_systems":
[
{
"name": "Preview in browser",
"selector": "text.html",
"windows":
{
"shell": true,
"cmd": [
"start", "cmd", "/k",
"CALL SET result=$file:$project_path=http://127.0.0.1:4000\\~base\\ && echo $result"
]
}
}
]
}
Result:
> echo %result%
C:\Users\Philipp\dev\repos\base\dir\index.html:C:\Users\Philipp\dev\repos
\base=http://127.0.0.1:4000\~base\
So the substitution is not working when doing it in the build system, but in cmd.exe it does. I'm confused.
You can do something like this:
{
"build_systems":
[
{
"name": "Preview in browser",
"selector": "text.html",
"windows":
{
"shell_cmd": "CALL SET filePath=$file && CALL SET result=%filePath:$project_path=http://127.0.0.1:4000\\~base% && CALL C:/Progra~2/Google/Chrome/Application/chrome.exe %result%"
}
}
]
}
The problem was with windows replacement and variable asignation rather than with sublime builds.
As it has been said in chat and comments multiple CALL are necessary to use the real value variable because if not used windows will expand their value at parse time before the wanted value is asigned at execution time. In addition, shell_cmd can be used to run a unique command in shell.

Resources