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
Related
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
This question already has answers here:
Parsing JSON with Unix tools
(45 answers)
Closed 3 years ago.
I have an automation script that I'm writing in Bash. I need to execute a perl script from within this and capture/parse one specific part of it's output and use it as a variable in order to complete the bash script's tasks.
For example:
echo "Creating database for "$custname
perl /home/dib/testing/addCustomer.cgi name=$custname prefix=$customerno
The perl script "addCustomer.cgi" will return JSON output of:
Content-Type: application/json; charset=UTF-8
{
"recordcount" : 1,
"status" : "OK",
"statusText" : "Add Customer: 40:Testing",
"customer" : [
{
"address" : "",
"city" : "",
"country" : "US",
"description" : "",
"email" : "",
"endDate" : "0000-00-00 00:00:00",
"frontendurl" : "",
"phone" : "",
"prefix" : "testing",
"startDate" : "0000-00-00 00:00:00",
"state" : "",
"customerID" : "40",
"subscriberName" : "Testing",
"url" : "",
"zip" : ""
}
],
"timestamp" : 1559163419
}
What I need to capture is the customerID number, stick it into a variable, and use it to finish the bash script. Is something like this possible? I always see parsing or passing from bash to perl but not the other way around.
Append this to your Perl command:
| sed 1d | jq -r '.customer[].customerID'
Output:
40
I assume there's one header line.
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.
My document structure looks like this:
{"name":"John", "age":32, ...other fields}
All other fields need not be initialized, only name and age. I want to make a script that takes in name and number
./client.sh John 32
and in the script, it will do something like
db.client.insert({"name":$1,"age":$2});
how to achieve this?
Here is a simple example script that works
#!/bin/bash
if [ $# -lt 2 ]
then
echo "USAGE: $0 name age"
exit 1
fi
mongo <<EOF
use test
db.client.insert({"name":"$1", "age":$2})
db.client.find()
EOF
It assumes that mongo is installed and in your path and that you have the client collection in the test database.
A sample run below
hduser#localhost:~/temp$ ./mongo_ins.sh "overflow" 20
MongoDB shell version: 2.6.10
connecting to: test
switched to db test
WriteResult({ "nInserted" : 1 })
{ "_id" : ObjectId("56b35d134c24bf7c1190cfb3"), "name" : "Stack", "age" : 1 }
{ "_id" : ObjectId("56b35dabe23223802ea3fa61"), "name" : { }, "age" : 10 }
{ "_id" : ObjectId("56b35ebbd69a0abeeb817fe3"), "name" : "overflow", "age" : 20 }
bye
Hope this helps
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.