Prevent Windows Terminal Title from changing - windows

I am trying out Windows Terminal. I use bash and want the Windows Terminal Tab title to remain as cwd (which is initially set by bash) instead of changing since while using multiple tabs they become indistinguishable. If I run say npm run start in bash directly, the title (in title bar) remains as cwd but if I try to use it via Windows Terminal the tab title changes to npm which I don't want.
My .bashrc
if test -f /etc/profile.d/git-sdk.sh
then
TITLEPREFIX=SDK-${MSYSTEM#MINGW}
else
TITLEPREFIX=$MSYSTEM
fi
if test -f ~/.config/git/git-prompt.sh
then
. ~/.config/git/git-prompt.sh
else
# PS1='\[\033]0;$TITLEPREFIX:$PWD\007\]' # set window title
# PS1='\[\e]0;\W\a\]\[\033]0;$PWD\007\]' # set window title (full path)
PS1='\[\e]0;\W\a\]' # set window title (only directory name)
PS1="$PS1"'\n' # new line
PS1="$PS1"'\[\033[32m\]' # change to green
PS1="$PS1"'\u ' # user#host<space>
# PS1="$PS1"'\[\033[35m\]' # change to purple
# PS1="$PS1"'$MSYSTEM ' # show MSYSTEM
PS1="$PS1"'\[\033[33m\]' # change to brownish yellow
PS1="$PS1"'\w' # current working directory
if test -z "$WINELOADERNOEXEC"
then
GIT_EXEC_PATH="$(git --exec-path 2>/dev/null)"
COMPLETION_PATH="${GIT_EXEC_PATH%/libexec/git-core}"
COMPLETION_PATH="${COMPLETION_PATH%/lib/git-core}"
COMPLETION_PATH="$COMPLETION_PATH/share/git/completion"
if test -f "$COMPLETION_PATH/git-prompt.sh"
then
. "$COMPLETION_PATH/git-completion.bash"
. "$COMPLETION_PATH/git-prompt.sh"
PS1="$PS1"'\[\033[36m\]' # change color to cyan
PS1="$PS1"'`__git_ps1`' # bash function
fi
fi
PS1="$PS1"'\[\033[0m\]' # change color
PS1="$PS1"'\n' # new line
PS1="$PS1"'$ ' # prompt: always $
fi
MSYS2_PS1="$PS1" # for detection by MSYS2 SDK's bash.basrc
# Evaluate all user-specific Bash completion scripts (if any)
if test -z "$WINELOADERNOEXEC"
then
for c in "$HOME"/bash_completion.d/*.bash
do
# Handle absence of any scripts (or the folder) gracefully
test ! -f "$c" ||
. "$c"
done
fi
export PS1='${debian_chroot:+($debian_chroot)}\[\e]0;\W\a\]\[\033[01;32m\]\u \[\033[00m\]\[\033[01;00m\]\w\n$ '
# echo -ne '\033]0;New Title\a'
My Windows Terminal settings.json
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{00000000-0000-0000-ba54-000000000002}",
"copyOnSelect": false,
"copyFormatting": false,
"profiles": {
"defaults": {
"fontSize": 10
},
"list": [
{
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
"commandline": "powershell.exe",
"hidden": false
},
{
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "Command Prompt",
"commandline": "cmd.exe",
"hidden": false
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"hidden": false,
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure"
},
{
"guid": "{00000000-0000-0000-ba54-000000000002}",
"commandline": "%PROGRAMFILES%/git/usr/bin/bash.exe -i -l",
"icon": "%PROGRAMFILES%/Git/mingw64/share/git/git-for-windows.ico",
"name": "Bash",
"startingDirectory": "%USERPROFILE%"
}
]
},
"schemes": [],
"actions": [
{ "command": { "action": "copy", "singleLine": false }, "keys": "ctrl+c" },
{ "command": "paste", "keys": "ctrl+v" },
{ "command": "find", "keys": "ctrl+shift+f" },
{
"command": {
"action": "splitPane",
"split": "auto",
"splitMode": "duplicate"
},
"keys": "alt+shift+d"
}
]
}
How do I achieve this?

windows terminal has two tag to change this
"tabTitle": "yourtitle",
"suppressApplicationTitle": true
so in your case, maybe you can write like this
{
"guid": "{00000000-0000-0000-ba54-000000000002}",
"commandline": "%PROGRAMFILES%/git/usr/bin/bash.exe -i -l",
"icon": "%PROGRAMFILES%/Git/mingw64/share/git/git-for-windows.ico",
"name": "Bash",
"startingDirectory": "%USERPROFILE%",
"tabTitle": "cwd",
"suppressApplicationTitle": true
}

Related

VSCode: How to open two terminals on startup with different directories

I want on startup (on folder open) two terminals.
These should start with different directories and should be in split mode. Is this possible?
I have this currently in tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"presentation": {
"echo": false,
"reveal": "always",
"focus": false,
"panel": "dedicated",
"showReuseMessage": true
},
"tasks": [
{
"label": "Create terminals",
"dependsOn": [
"First",
"Second"
],
// Mark as the default build task so cmd/ctrl+shift+b will create them
"group": {
"kind": "build",
"isDefault": true
},
// Try start the task on folder open
"runOptions": {
"runOn": "folderOpen"
}
},
{
// The name that shows up in terminal tab
"label": "First",
// The task will launch a shell
"type": "shell",
"command": "/bin/bash; cd /var/fpwork/",
// Set the shell type
// Mark as a background task to avoid the spinner animation on the terminal tab
"isBackground": true,
"problemMatcher": [],
// Create the tasks in a terminal group
"presentation": {
"group": "my-group"
}
},
{
"label": "Second",
"type": "shell",
"command": "/bin/bash; cd /var/",
"isBackground": true,
"problemMatcher": [],
"presentation": {
"group": "my-group"
}
}
]
}
This opens two terminals in split mode, but how can I specify different folders for them?
The lines
"command": "/bin/bash; cd /var/fpwork/"
and
"command": "/bin/bash; cd /var/"
just seem to ignore the cd command. How to specify the terminal folders?
The thing that worked for me is
"command": "/bin/bash --rcfile <(echo '. ~/.bashrc; cd /var')"
See How to invoke bash, run commands inside the new shell, and then give control back to user?

How to use git bash in sublime text 3

I use Sublime Text 3 as my default text/code editor and I very frequently use the terminal in Sublime Text 3 with the Terminus package. And recently I've discovered git it has a really wonderful bash and I prefer using the git bash instead of using git through the default Windows terminal.
Is there any way that I can do it?
To do this, open the Terminus preferences by choosing Preferences > Package Settings > Terminus > Settings from the menu or Preferences: Terminus Settings from the command palette.
Both will open the Terminus settings in a new split window, with your settings on the right and the defaults on the left. What you need to do is add a shell_configs key to your preferences (the right pane) that includes a new configuration for using Git Bash.
That would look something like this:
"shell_configs":
[
{
"name": "Git Bash",
"cmd": ["cmd.exe", "/k", "C:/Program Files (x86)/Git/bin/bash.exe"],
"env": {},
"enable": true,
"default": false,
"platforms": ["windows"]
},
]
Replace the path to Git Bash as appropriate if it's not installed in the default location. You can also set default to true instead of false if you want to use it by default.
If you add this setting to your preferences as it appears here, then the only shell configuration that will exist will be this one. If you want to still be able to use the other configurations as well, then copy the default value of the setting from the Left pane to the right, and then add yours to the list (remember that all of the settings need to be comma separated).
OdatNurd, thank you for the idea, but cmd.exe opening git bash in separate window. I used your idea and change following settings as bellow to start git bash shell in Terminus Panel, which is appearing in Sublime text. It works for me.
{
"shell_configs":
[
{
"name": "Git Bash",
"cmd": ["C:/Program Files/Git/bin/sh.exe"],
"env": {},
"enable": true,
"default": false,
"platforms": ["windows"]
},
]
}
setup git bash/cmd terminal in sublime text editor
GOTO
preferences>
package settings>
terminus>
settings
{
"default_config" : {
"windows" : "Git Bash"
},
"shell_configs":
[
{
"name": "Git Bash",
"cmd": ["C:/Program Files/Git/bin/sh.exe"],
"env": {},
"enable": true,
"default": false,
"platforms": ["windows"]
}
]
}
Then GOTO
preferences>
package settings>
terminus>
key bindings>
[
{
//alt+1 for cmd
"keys": ["alt+1"],
"command": "terminus_open",
"args" : {
"cmd": "cmd.exe",
"cwd": "${file_path:${folder}}",
"panel_name": "Terminus"
}
},
{
//alt +2 for git bash
"keys": ["alt+2"],
"command": "terminus_open",
"args" : {
"cmd": ["C:/Program Files/Git/bin/sh.exe"],
"cwd": "${file_path:${folder}}",
"panel_name": "Terminus"
}
},
]

Create multiple terminals and run commands in VSCode

I'm on a Mac 💻. I'm trying to explore a way to create 4 Terminals as soon as I dbl-clicked on my workspace file.
I've tried to get one working, but I seem stuck
{
"folders": [
{
"path": "/Users/bheng/Sites/laravel/project"
}
],
"settings": {
"workbench.action.terminal.focus": true,
"terminal.integrated.shell.osx": "ls",
"terminal.integrated.shellArgs.osx": [
"ls -lrt"
]
},
"extensions": {}
}
My goal is to open 4 Terminals
Terminal1 : run 'npm run watch'
Terminal2 : run 'ls -lrt'
Terminal3 : run 'ssh_staging'
Terminal4 : run 'mysql'
I've been following this doc : https://code.visualstudio.com/docs/editor/integrated-terminal#_terminal-keybindings
Any hints for me ?
I've been playing around with this which seems to work. Combining the ability to run a task on folder open and to make that task depend on other tasks I came up with the following. It looks cumbersome but it is actually pretty simple and repetitive.
First, you will need a macro extension like multi-command. Put this into your settings:
"multiCommand.commands": [
{
"command": "multiCommand.runInFirstTerminal",
"sequence": [
"workbench.action.terminal.new",
{
"command": "workbench.action.terminal.renameWithArg",
"args": {
"name": "npm watch"
}
},
{
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "npm run watch\u000D" // \u000D is a return so it runs
}
}
]
},
{
"command": "multiCommand.runInSecondTerminal",
"sequence": [
"workbench.action.terminal.new",
{
"command": "workbench.action.terminal.renameWithArg",
"args": {
"name": "ls -lrt"
}
},
{
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "ls -lrt\u000D"
}
}
]
},
{
"command": "multiCommand.runInThirdTerminal",
"sequence": [
"workbench.action.terminal.new",
{
"command": "workbench.action.terminal.renameWithArg",
"args": {
"name": "ssh_staging"
}
},
{
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "ssh_staging\u000D" // however you run the ssh_staging command
}
}
]
},
{
"command": "multiCommand.runInFourthTerminal",
"sequence": [
"workbench.action.terminal.new",
{
"command": "workbench.action.terminal.renameWithArg",
"args": {
"name": "mysql"
}
},
{
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "mysql\u000D" // however you run the mysql command
}
},
// "workbench.action.focusActiveEditorGroup"
]
}
]
There is one command for each terminal. But within each of those you can do as much as you can get into a macro - which is a lot, especially thanks to the sendSequence command. You can change directories and send another sendSequence command to the same terminal instance, run all the non-terminal commands too, change focus to an editor at the end of the last terminal set-up, etc.
I added the nicety of naming each terminal based on your command using the command workbench.action.terminal.renameWithArg.
In tasks.json:
"tasks": [
{
"label": "Run 4 terminals on startup",
"runOptions": {"runOn": "folderOpen"},
"dependsOrder": "sequence", // or parallel
"dependsOn": [
"terminal1",
"terminal2",
"terminal3",
"terminal4"
]
},
{
"label": "terminal1",
"command": "${command:multiCommand.runInFirstTerminal}"
},
{
"label": "terminal2",
"command": "${command:multiCommand.runInSecondTerminal}",
},
{
"label": "terminal3",
"command": "${command:multiCommand.runInThirdTerminal}"
},
{
"label": "terminal4",
"command": "${command:multiCommand.runInFourthTerminal}"
}
]
Now whenever you open (or reload) the workspace folder this tasks.json is in the four terminals should be opened, named and run. In my experience, there is about a short delay before vscode runs any folderOpen task.
If you prefer to manually trigger the Run 4 terminals task, you can set up a keybinding like so:
{
"key": "alt+r", // whatever keybinding you want
"command": "workbench.action.tasks.runTask",
"args": "Run 4 terminals on startup"
},
Here is a demo running with the keybinding, easier to demonstrate than reloading vscode, but there is no difference. I added an interval delay to each terminal running just for demonstration purposes - otherwise it is extremely fast.
I noticed that vscode freezes if I don't interact with one of the terminals or open another before deleting them all.
There is also a Terminal Manager extension which may be of interest. I haven't tried it.
An extension for setting-up multiple terminals at once, or just
running some commands.
But it isn't obvious to me whether this extension can be configured to run on folderOpen - but it appears to contribute a run all the terminals command so you should be able to use that in a task.
I like the accepted answer. However, I prefer not to use the multi-command extension as shown in the accepted answer, I think my approach is simpler.
Please note in my case:
my project only needs three tasks and all three tasks should run in parallel (craft-server, craft-app, and craft-site) -- but this approach should work for more than three tasks
I prefer to see the output of three tasks in three separate terminals (vs combined in one terminal)
my tasks never "finish" (all three tasks "watch" for file changes, so I need the terminals to remain open)
See my tasks.json file below. You'll need to modify the "label" and "command" properties to suit your project. See my notes about the important parts, below.
{
"version": "2.0.0",
"tasks": [
/// ...other tasks...
{
"label": "runDevelopment",
"runOptions": {
"runOn": "folderOpen"
},
"dependsOrder": "parallel",
"dependsOn": [
"craft-server",
"craft-site",
"craft-app"
]
},
{
"label": "craft-server",
"type": "shell",
"command": "npx nodemon --watch . --ignore craft-angular/projects/craft-app/ --ignore craft-angular/projects/craft-site/ --ignore dist/ --ignore bin/ --ignore log/ --ignore cypress/ --ignore cypress.json ./bin/www",
"presentation": {
"panel": "dedicated"
}
},
{
"label": "craft-site",
"type": "shell",
"command": "cd ./craft-angular && node --max_old_space_size=8000 ./node_modules/#angular/cli/bin/ng build craft-site --verbose=false --progress=true --watch --output-path=\"./dist/development/craft-site\"",
"presentation": {
"panel": "dedicated"
}
},
{
"label": "craft-app",
"type": "shell",
"command": "cd ./craft-angular && node --max_old_space_size=8000 ./node_modules/#angular/cli/bin/ng build craft-app --verbose=false --progress=true --watch --output-path=\"./dist/development/craft-app\"",
"presentation": {
"panel": "dedicated"
}
}
]
}
Please note:
I only use the VS Code tasks.json / custom tasks feature (I don't use a VS Code extension)
I use the "dependsOn" approach as shown in the accepted answer, so that one task can invoke multiple other tasks in parallel (note "dependsOrder": "parallel")
I use the "runOptions": {"runOn": "folderOpen"} approach as shown in the accepted answer, so that VSCode will automatically run my "combined" task when I open my workspace/project
"runOn": "folderOpen" is convenient for me (I always want to run
my main task when I open the folder containing my project),
but it is optional; you could also use keybindings as shown in the accepted answer or here
and if you use "runOn": "folderOpen" you need give VS Code a one-time permission to do that, as described here
I don't use the "problemMatcher" property (i.e. a VS Code feature to scan output of each terminal); therefore when I run the task, I choose "Continue without scanning the task output"
I use the "presentation" property with {"panel":"dedicated"} so each of my tasks gets a separate terminal (aka separate panel)
The runDevelopment task should run automatically when I open the workspace/project/folder (i.e. the location containing the .vscode folder, and the .vscode/tasks.json file, using File > Open Folder... (Ctrl+K Ctrl+O), or File > Open Recent...)
While I want this task to run automatically , below shows how run the task manually (if needed -- like if the automatic task fails, or I kill the automatic task);
You could use Ctrl+Shift+B to run the build task, as commented by #Ruben, and described in the VSCode Keyboard Bindings here.
Or you could use a more step-by-step approach:
I use Ctrl+Shift+P (or F1) to open the "command window"/ "Show All Commands"
then type "Run Tasks"; (hit Enter)
then choose the single "combined" task (for me, it's named runDevelopment; hit Enter)
finally choose "Continue without scanning the task output" and hit Enter (because none of my tasks have a "problemMatcher", I can interpret the task output for myself):
This is how the task looks after it is run; note there are 3 separate terminals for 3 separate subtasks:
I like the second answer that only uses vscode task, but it does not work for my requirement because I cannot input other instructions in the open terminals, otherwise, it will close. I prefer to use the Restore Terminals in vscode.
After the extension installed, you can just create a restore-terminals.json file in .vscode folder:
{
"artificialDelayMilliseconds": 300,
"keepExistingTerminalsOpen": false,
"runOnStartup": true,
"terminals": [
{
"splitTerminals": [
{
"name": "server",
"commands": ["npm i", "npm run dev"]
},
{
"name": "client",
"commands": ["npm run dev:client"]
},
{
"name": "test",
"commands": ["jest --watch"]
}
]
},
{
"splitTerminals": [
{
"name": "build & e2e",
"commands": ["npm run eslint", "npm run build", "npm run e2e"],
"shouldRunCommands": false
},
{
"name": "worker",
"commands": ["npm-run-all --parallel redis tsc-watch-start worker"]
}
]
}
]
}

vscode tasks.json shell script doesn't work with arguments

I can't pass arguments to shell script in task.
I work in VSCode 1.36.0 in Ubuntu 18.04. tasks.json version 2.0.0
There is a simple task in tasks.json file:
{
"label": "cross-deploy_2",
"type": "shell",
"options": {
"cwd": "/home/${env:USERNAME}/osr-renesas/"
},
"command": ". ./cross-deploy_2.sh",
"problemMatcher": [
"$gcc"
]
},
And here is the script cross-deploy_2.sh:
ip=$1
execution_file=$2
echo $ip
echo $execution_file
. sources/poky/oe-init-build-env
devtool build glv-get-started
I need to run it from source in order to save environment variables. So in the previous example I don't see echo, but except this script runs properly.
If I add args, like this
{
"label": "cross-deploy_2",
"type": "shell",
"options": {
"cwd": "/home/${env:USERNAME}/osr-renesas/"
},
"command": ". ./cross-deploy_2.sh",
"args": [
"10.15.11.1",
"glv-get-started",
],
"problemMatcher": [
"$gcc"
]
},
The task doesn't work. And this is the output in the terminal
> Executing task: '. ./cross-deploy_2.sh' 10.15.11.1 glv-get-started <
/bin/bash: . ./cross-deploy_2.sh: No such file or directory
The terminal process command '/bin/bash -c ''. ./cross-deploy_2.sh'
10.15.11.1 glv-get-started'' failed to launch (exit code: 127)
Terminal will be reused by tasks, press any key to close it.
Please help me to run script with arguments
Thanks a lot in advance

Docker Image Download with download-frozen-image-v2.sh on Windows

I am working on downloading a Docker Image on an internet-connected Windows machine that does not have (and cannot have) Docker installed on it, to transfer to an non-internet-connected Linux machine that does have Docker. I'm using git-bash to run download-frozen-image-v2.sh. Everything is working as expected until the script begins to download the final layer of any given image. On the final layer the json file is being returned empty. Through echo statements, I'm able to see that everything is working flawlessly until lines 119-142
jq "$addJson + ." > "$dir/$layerId/json" <<-'EOJSON'
{
"created": "0001-01-01T00:00:00Z",
"container_config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": null,
"Cmd": null,
"Image": "",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": null
}
}
EOJSON
Only on the final layer, this code is resulting in an empty json file, which in-turn creates an error in line 173
jq --raw-output "$imageOldConfig + del(.history, .rootfs)" "$dir/$configFile" > "$dir/$imageId/json"
jq: error: syntax error, unexpected '+', expecting $end (Windows cmd shell quoting issues?) at <top-level>, line 1:
+ del(.history, .rootfs)
jq: 1 compile error
Update
Exact steps to replicate
Perform on Windows 10 computer.
1) Install scoop for Windows https://scoop.sh/
2) in Powershell scoop install git curl jq go tar
3) git-bash
4) in git-bash curl -o download-frozen-image-v2.sh https://raw.githubusercontent.com/moby/moby/master/contrib/download-frozen-image-v2.sh
5) bash download-frozen-image-vs.sh ubuntu ubuntu:latest
The above will result in the aforementioned error.
in response to #peak below
The command I'm using is bash download-frozen-image-v2.sh ubuntu ubuntu:latest which should download 5 layers. The first 4 download flawlessly, it is only the last layer that fails. I tried this process for several other images, and it always fails on the final layer.
addJson:
{ id: "ee6b1042efee4fb07d2fe1a5079ce498567e6f5ac849413f0e623d4582da5bc9", parent: "80a2fb00dfe137a28c24fbc39fde656650cd68028d612e6f33912902d887b108" }
dir/configFile:
ubuntu/113a43faa1382a7404681f1b9af2f0d70b182c569aab71db497e33fa59ed87e6.json
dir/configFile contents:
{
"architecture": "amd64",
"config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/bash"
],
"ArgsEscaped": true,
"Image": "sha256:c2775c69594daa3ee360d8e7bbca93c65d9c925e89bd731f12515f9bf8382164",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": null
},
"container": "6713e927cc43b61a4ce3950a69907336ff55047bae9393256e32613a54321c70",
"container_config": {
"Hostname": "6713e927cc43",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD [\"/bin/bash\"]"
],
"ArgsEscaped": true,
"Image": "sha256:c2775c69594daa3ee360d8e7bbca93c65d9c925e89bd731f12515f9bf8382164",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"created": "2018-06-05T21:20:54.310450149Z",
"docker_version": "17.06.2-ce",
"history": [
{
"created": "2018-06-05T21:20:51.286433694Z",
"created_by": "/bin/sh -c #(nop) ADD file:28c0771e44ff530dba3f237024acc38e8ec9293d60f0e44c8c78536c12f13a0b in / "
},
{
"created": "2018-06-05T21:20:52.045074543Z",
"created_by": "/bin/sh -c set -xe \t\t&& echo '#!/bin/sh' > /usr/sbin/policy-rc.d \t&& echo 'exit 101' >> /usr/sbin/policy-rc.d \t&& chmod +x /usr/sbin/policy-rc.d \t\t&& dpkg-divert --local --rename --add /sbin/initctl \t&& cp -a /usr/sbin/policy-rc.d /sbin/initctl \t&& sed -i 's/^exit.*/exit 0/' /sbin/initctl \t\t&& echo 'force-unsafe-io' > /etc/dpkg/dpkg.cfg.d/docker-apt-speedup \t\t&& echo 'DPkg::Post-Invoke { \"rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true\"; };' > /etc/apt/apt.conf.d/docker-clean \t&& echo 'APT::Update::Post-Invoke { \"rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true\"; };' >> /etc/apt/apt.conf.d/docker-clean \t&& echo 'Dir::Cache::pkgcache \"\"; Dir::Cache::srcpkgcache \"\";' >> /etc/apt/apt.conf.d/docker-clean \t\t&& echo 'Acquire::Languages \"none\";' > /etc/apt/apt.conf.d/docker-no-languages \t\t&& echo 'Acquire::GzipIndexes \"true\"; Acquire::CompressionTypes::Order:: \"gz\";' > /etc/apt/apt.conf.d/docker-gzip-indexes \t\t&& echo 'Apt::AutoRemove::SuggestsImportant \"false\";' > /etc/apt/apt.conf.d/docker-autoremove-suggests"
},
{
"created": "2018-06-05T21:20:52.712120056Z",
"created_by": "/bin/sh -c rm -rf /var/lib/apt/lists/*"
},
{
"created": "2018-06-05T21:20:53.405342638Z",
"created_by": "/bin/sh -c sed -i 's/^#\\s*\\(deb.*universe\\)$/\\1/g' /etc/apt/sources.list"
},
{
"created": "2018-06-05T21:20:54.091704323Z",
"created_by": "/bin/sh -c mkdir -p /run/systemd && echo 'docker' > /run/systemd/container"
},
{
"created": "2018-06-05T21:20:54.310450149Z",
"created_by": "/bin/sh -c #(nop) CMD [\"/bin/bash\"]",
"empty_layer": true
}
],
"os": "linux",
"rootfs": {
"type": "layers",
"diff_ids": [
"sha256:db9476e6d963ed2b6042abef1c354223148cdcdbd6c7416c71a019ebcaea0edb",
"sha256:3a89e0d8654e098e949764b1cb23018e27f299b0931c5fd41c207d610ff356c4",
"sha256:904d60939c360b5f528b886c1b534855a008f9a7fd411d4977e09aa7de74c834",
"sha256:a20a262b87bd8a00717f3b30c001bcdaf0fd85d049e6d10500597caa29c013c5",
"sha256:b6f13d447e00fba3b9bd10c1e5c6697e913462f44aa24af349bfaea2054e32f4"
]
}
}
Any help in figuring out what is occurring here would be greatly appreciated.
Thank you.
I can't tell you why this happens but it appears to be a problem with how jq parses the input file. It's segfaulting when reading the file. It's a known issue in the windows builds where the problem is triggered by the length of the paths to the files.
Fortunately, there is a way around this issue by modifying the script to go against all conventional wisdom and cat the file to jq.
The script isn't utilizing jq very well and builds some of the json manually so some additional fixes would be needed. It will have errors regarding INVALID_CHARACTER when parsing. It's probably a manifestation of this issue since the script is manually building a lot of the jq programs.
I put up a gist with the updated file that at least doesn't error out, check to see if it works as expected.
Changes start at line 172 and 342.
The way it builds the manifest is just messy. I've cleaned it up a bit removing all the string interpolations instead passing all parameters in as arguments to jq.
# munge the top layer image manifest to have the appropriate image configuration for older daemons
local imageOldConfig="$(cat "$dir/$imageId/json" | jq --raw-output --compact-output '{ id: .id } + if .parent then { parent: .parent } else {} end')"
cat "$dir/$configFile" | jq --raw-output "$imageOldConfig + del(.history, .rootfs)" > "$dir/$imageId/json"
local manifestJsonEntry="$(
jq --raw-output --compact-output -n \
--arg configFile "$configFile" \
--arg repoTags "${image#library\/}:$tag" \
--argjson layers "$(IFS=$'\n'; jq --arg a "${layerFiles[*]}" -n '$a | split("\n")')" \
'{
Config: $configFile,
RepoTags: [ $repoTags ],
Layers: $layers
}'
)"
(1) I have verified that using bash, the sequence:
addJson='{ id: "ee6b1042efee4fb07d2fe1a5079ce498567e6f5ac849413f0e623d4582da5bc9",
parent: "80a2fb00dfe137a28c24fbc39fde656650cd68028d612e6f33912902d887b108" }'
jq "$addJson + ." configFile > layerId.json
succeeds, where configFile has the contents shown in the updated question.
(2) Similarly, I have verified that the following also succeeds:
imageOldConfig="$(jq --raw-output --compact-output '{ id: .id } + if .parent then { parent: .parent } else {} end' layerId.json)"
jq --raw-output "$imageOldConfig + del(.history, .rootfs)" <<-'EOJSON'
<JSON as in the question>
EOJSON
where <JSON as in the question> stands for the JSON shown in the question.
(3) In general, it is not a good idea to pass shell $-variables into jq programs by shell string interpolation.
For example, rather than writing:
jq --raw-output "$imageOldConfig + del(.history, .rootfs)"
it would be much better to write something like:
jq --raw-output --argjson imageOldConfig "$imageOldConfig" '
$imageOldConfig + del(.history, .rootfs)'

Resources