VSCode formatting of command options - visual-studio-code

I am using VScode for writting shell scripts.
I specify the language of the script on VS Code and I am already enjoying the rest of the formatting.
I would like the options of my commands (that would be everything starting with one dash "-" or two dashes "--", including the dashes) to be formatted in a peculiar color for reading convenience.
Example:
example -in $file -out output.txt -mode 5 --force
I would like -in, -out, -mode and --force to all have a similar color, not a color already used in the usual shell formatting in VScode.
Screenshot of the current code in VS Code:

Related

How can I avoid that echo in Windows PowerShell creates binary files?

I am a long-time Linux user and am used to a command like:
echo 'hello' > a.txt
creating a plaintext file simply containing 'hello'.
Now, if I use the same command in Windows PowerShell, the resulting file is claimed to be binary (by git). If I inspect the file in a text editor, the file contains the text but some weird excessive characters that look like a character encoding issue.
How am I supposed to use echo instead to make it behave in a completely "ordinary" plaintext way?

Run sha256sum (from Cygwin) on file with special character and blank (quoting does not work)

I have Cygwin installed in order to use Linux command line tools on Windows. I also added it to my PATH. In general, it works fine, but I observe this weird behavior:
I want to run sha256sum on the file C:\Users\s1504gl\Desktop\Täst .txt. Note the german Umlaut ä and the whitespace before the file extension. In order to avoid problems with paths, I always quote paths in command line calls, such as:
sha256sum "C:\Users\s1504gl\Desktop\Täst .txt"
However, PowerShell returns
/usr/bin/sha256sum: '"C:\Users\s1504gl\Desktop\T'$'\303\244''st .txt"': No such file or directory
When I rename the file to either Täst.txt or Test .txt, it works. So the combination of the special character ä and the whitespace seems to cause the problem. Exchanging double quotes by single quotes does not change anything in this case.
I am pretty sure it has to to with PowerShell since the example works without any problems on my Linux machine.
Is there some other way of escaping special characters and/or blanks that I do not know?
Run from Cygwin terminal
sha256sum "/cygdrive/C/Users/s1504gl/Desktop/Täst\ .txt"
In general Cygwin program do not accept Windows paths and works surely with POSIX path
I found the following workaround:
I create a temporary file from R, containing all the necessary commands and then run this tempfile using bash which is also included in Cygwin. This way, I escape from the problem occurring due to different encodings in Windows and the Linux tools from Cygwin.

How can I convert indentation between spaces and tabs for all files in a workspace in a single action?

How can I use VS Code's Convert Indentation To Spaces or Convert Indentation to Tabs commands on all the files in my workspace in a single action instead of using the command for each file?
I'm not aware of a way to do this with VS Code (at least- not without extensions, and I don't know of any such extensions offhand).
But if you're on a posix system (not sure if I'm using "posix" right here), you can do this via command line using a modified version of this:
git ls-files | command grep -E '*.ts$' | awk '{print "expand --tabs=4 --first-only", $0, " > /tmp/e; mv /tmp/e ", $0}' | sh
The above command lists all files tracked in the git repo for the current working directory, filters for files with the .ts extension, and then uses awk and expand to replace leading indentation of a tabs to a specified number of spaces.
To go from spaces to tabs, use the unexpand command instead.
If you're not working with a git repo, you can replace git ls-files with find -type f (the advantage of git ls-files is that it won't touch anything that's not tracked).
Just change the regular expression in the grep filter to whatever you need.
The command replaces leading groups of 4 spaces with tab characters. Just change the --tabs argument to the unexpand command with whatever number of spaces your indentation is.

Can I set the VS Code default EOL based on file type?

Working with .sh files on Windows causes issues when running them in Linux Docker containers if they have EOL of CRLF. Can I make VS Code always work with LF for specific file type such as .sh while still using CRLF for all others?
I only find "files.eol": "\r\n" in settings, but this is global.
I understand you can change this in the bottom toolbar on a per-file basis, but I would like this to be the default for all .sh files.
In your settings window, go to
Settings > Text Editor > Files > Eol option. You'll fine following available options there
- \n
- \r\n
- auto (default)
Here \n represents LF, \r\n represents CRLF, and auto use the operating system specific EL operator.
Select your option and save.
VS Code: version 1.13.3
You can use EditorConfig.
Install the editorconfig extension, and then add a .editorconfig file at the root of your project with this:
[*]
end_of_line = crlf
[*.{sh}]
end_of_line = lf
But as #axiac said, I would recommend to always use lf...
EDIT : I was a bit "premature" with this answer. But it now works as of v1.40. See https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_40.md#fileseol-per-language
You can do this in vscode without an extension. You can make a language-specific setting:
In the command palette, search for "Configure language specific", select it and choose "shellscript" from the language options:
This will create the following in your settings:
"[shellscript]": {
},
Now add in whatever you want to apply to shellscript files only like (not all settings will work in there but most do):
"[shellscript]": {
"files.eol": "\n"
},
VERY, VERY IMPORTANT:
The end-of-line sequence is used for new files. For existing files,
the existing end-of-line sequence is always preserved. To change the
end-of-line sequence for an existing file, use the Change End Of Line
Sequence command.
from https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_40.md#fileseol-per-language

How to remove ansi code from output piped to VSCode?

As of November 2017 VSCode allow to pipe output directly to VSCode. I did tried with a few command until I got a bunch of ANSI codes which I'm not interested.
I'm running something like yarn info babel-core | code and getting this:
yarn info v0.24.6
{ name: [32m'babel-core'[39m,
description: [32m'A placeholder package that bridges babel-core to #babel/core.'[39m,
[32m'dist-tags'[39m:
{ latest: [32m'6.26.0'[39m,
old: [32m'5.8.38'[39m,
next: [32m'7.0.0-beta.3'[39m,
bridge: [32m'7.0.0-bridge.0'[39m },
I would like to that output without these ANSI codes.
If you NodeJS then you can globally install strip-ansi-cli which provides you the command: strip-ansi. It does exactly that.
For your case, you may use it as follow:
yarn info babel-core | strip-ansi | code
Happy coding!
Alternatively, plugins now exist, e.g. ANSI Colors, that once installed enable you to select ANSI text as the file's "language mode." You can then use VS Code's _Command Palette_ (Ctl-Sft-P) to preview the file (ANSI Text: Open Preview) with escape sequences respected, i.e. in color (and etc.)
Credit
Can I display a file with ANSI color escape sequences in Visual Studio Code?