git log --pretty=format windows strange behavior - json

I reduce the problem to its lowest terms.
Under linux a git command like this:
git log --pretty=format:{"commit":"%H"}
gives me a valid json element, so something like:
{"commit":"20cafdecc9898113ac6215ae70cd7622dc2cae3b"}
under windows I obtain a not-valid json element, because in some way windows seems to remove the double-quotes elements and I obtain:
{commit:20cafdecc9898113ac6215ae70cd7622dc2cae3b}
Do you know why, or how can I fix it making it work under both os?
Thank you!

I assume that your shell on Linux is NOT a bash shell because my bash shell on Linux gives me the same output as on Windows - without double-quotes.
The doubles-quotes are special characters for most shells - so you have to protect them either by "escaping" or by "quoting".
git log --pretty=format:{\"commit\":\"%H\"}
git log --pretty='format:{"commit":"%H"}'
This works for bash on Linux and bash on Windows. I have not tested it with cmd on Windows.

Related

Find latest available Chrome version (on Linux, eg from a shell script)

How can I find the latest version of Google Chrome from a shell script (e.g. bash) on Linux ?
For ChromeDriver, I can do this:
curl https://chromedriver.storage.googleapis.com/LATEST_RELEASE
Can I do something similar for Chrome?
Background to question
T
his needs to be done in a pipeline and there is no local install of Chrome, no tools to inspect packages (rpm, deb, and the like). The reason I want this is so that I can download the latest version as a numbered package. I could do this
wget -O https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
but that results in a file called google-chrome-stable_current_amd64.deb rather than one that is version stamped such as google-chrome-stable_73.0.3683.103-1_amd64.deb.
If I know the version in advance, I can get a version-stamped file using this:
GOOGLE_CHROME_VERSION=73.0.3683.103-1
wget http://dl.google.com/linux/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${GOOGLE_CHROME_VERSION}_amd64.deb
So what I'm really looking for is either generic URL that always returns the latest version-stamped file or a way to set GOOGLE_CHROME_VERSION in the above.
If you are using Ubuntu Desktop like mine 16.04, here is the command
google-chrome --version
ref. https://askubuntu.com/a/505532/22308

vim-rest-console displays JSON in a single line

I've found out about vim-rest-console, but after installed and run a test, I noticed the JSON it outputs is only in one line, without any indentation. This is horrible and I'd like to know if there is a way to solve this. I am using NeoVim on Xubuntu 16.04 LTS.
To fix the json indentation in Vim, put the following command to your .vimrc
nmap =j :%!python -m json.tool<CR>
and launch it via the =j command (or remap to different shortcut).

Jq doesn't highlight Docker inspect output

When executing docker-machine inspect command, instead of the expected highlighted version of JSON piped into jq:
I'm seeing the following plain output (in cmd or ConEmu):
Not sure what needs to be done to enable proper json highlighting.
This happens on Windows 10 machine on which jq ver. 1.5 was installed via Chocolatey:
Apparently, this is an idiosyncrasy of jq Windows implementation, forcing the color output with -C option, as hinted by several commenters above, resolved the issue for me:

How to reduce whitespace from JSON on the command line without installing a tool

I've used python -m json.tool to pretty print JSON and check for errors for years. It is nice because it works on just about any system with python installed. How can I take out unnecessary whitespace that JSON ignores (i.e. not in string values) without installing on mac/linux/bsd/unix systems without installing anything special? Answers that work on recent baseline mac, freebsd and debian/ubuntu would be great.
I'm not a code golfer but I puzzled out this solution which makes a nice alias with some escaping:
python '-cimport json,sys;json.dump(json.load(sys.stdin),sys.stdout,separators=(",", ":"))'

Why can't I create a Google Chrome extension from the CLI?

I'm a bit confused, but I can't create a .crx package from the CLI in Linux. In Windows 7 the script worked fine, but in Linux it seems that nothing happens. The popup window that occurs after the packaging process doesn't appear and the .crx is not created at all.
Here's the script.
#!/bin/sh
google-chrome --pack-extension=~/Web/client/ --pack-extension-key=~/Web/client.pem
exit 0
Maybe I'm missing something?
In Linux, (at least Ubuntu 10.04) google-chrome is a bash script wrapper of the chrome executable.
First, You should find where the chrome executable is. In my case: /opt/google/chrome/chrome
Then, replace it in your script:
#!/bin/sh
/opt/google/chrome/chrome --no-message-box --pack-extension=/extfolder/Web/client/ --pack-extension-key=/extfolder/Web/client.pem
exit 0
It is really important that in the script to specify the full path. For instance, /home/me/Web/client.pem rather than ~/Web/client.pem because as it is a parameter bash does not resolve it.
A better alternative would be defining a bash variable called $CHROME_PATH so it can be easily changed among different *nix platforms.
I don't know why packaging with google-chrome on Linux doesn't work, but can at least propose a workaround - use one of the officially-blessed packaging scripts listed at https://developer.chrome.com/extensions/crx#scripts. There is currently one for Bash and one for Ruby.