Rather than list my opinion of all the pros and cons of Cmder and trying to sell you on using it. I will let the software speak for itself if you decide to use it. Simply put, I prefer using the full version of Cmder bundled with git-for-windows because I find it to be robust, fast, and have easy access to the Windows filesystem. Cmder runs nativley, unlike WSL (Windows Subsystem for Linux) which runs in a sandbox and makes access to the Windows file system convoluted. Allthough WSL is more robust for using *NIX style tools, I find that being confined to a Linux sandbox in the Windows environment for all my daily development tasks to be slower on the I\O side of things and somewhat defeats the purpose of using Windows 10 in the first place.
If you are working in the Windows environment then why use Unix style tools at all? Personally I find the Powershell syntax, learning curve and encoding caveats a bit of a hurdle and just not as versatile as *NIX tools. At times I do find myself working with Powershell in Cmder and I will say that the more I learn the better off I am because of it. I will be sharing what I have learned about Powershell here on this page and you will find some powershell scripts in the repository. TLDR; Powershell is awesome and can be integrated with Cmder. A well rounded scripter will be fluent in as many tools as possible.
Not that anyone will ever really need all 16 million colors in their terminal at once, however being able to choose from a wider pallette of colors has its advantages and it is just plain more fun. Cmder does NOT support true color. The bash shell that comes with Cmder also does NOT support true color. If you try to use powershell with Cmder as its terminal you will NOT get true color. If you want true color in your terminal on Windows or WSL there many ways to do it and there can be many caveats as well. Powershell is a shell and scripting language with true color support so you can use 24-bit color escape sequences and get any color you want but typically not when running powershell in the Cmder standalone console/terminal/terminal emulator. There are bash shells running in WSL for windows such as Ubuntu's bash that you can use but they have a decent amount of weight to them such as installing an entire Linux distro.
Long story short true color support is pretty much dictacted by your console/terminal emulator and shell combination. I have found the following combinations to work easily for true color without dealing with WSL bash.
- Straight powershell
- VSCode terminal with powershell
- VSCode terminal running Cmder with powershell
- Windows Terminal with powershell
- Windows Terminal running Cmder with powershell
It suggested that you perouse this document however you see fit. You may also download or copy and paste any portion of any of the files in this repository to fit your needs. Much of this document may be crafted for beginner and intermediate developers in the form of linear step lists, however I am sure that expert developers can probably gleam a few gems from this repository.
This repository is meant to be a relatively random compilation, a somewhat organized mishmosh if you will, of scripts, resources, learning materials, personal findings and revelations that may or may not be 'correct' or optimized but could easily help one learn alot and hopefully help ones workflow to solve some daily challenges that one may encounter.
Anyone that may have an opinion on how to do things better (optimize) or to add any resources to this repository please feel free to open pull requests anywhere you like.
- General
- Cmder
- Link Windows executables such as
find
to the console commands in Cmder.- Add the following to your
\Cmder\config\user_profile.cmd
file:set "PATH=%GIT_INSTALL_ROOT%\usr\bin;%PATH%"
. Reference.
- Add the following to your
- Link Windows executables such as
- Bash Scripting
- Shell Style Guide Authored, revised and maintained by many Googlers.
- Bash Scripting Snippets
- Bash Cheat Sheet 1
- *NIX Tools
- General
- Advanced Bash-Scripting Guide: Why Shell Programming?
- Text Sculpting: A brief introduction to grep, awk & sed
- TLDR pages: Simplified and community-driven man pages
- TLDR pages give multiple usage examples of each *NIX style command that the console supports.
sed
: Stands for Stream Editor.sed
works with streams of characters for searching, filtering and text processing and despite its power,sed
is considered a 'simpleton' when compared toawk
. It is recommended to usesed
for simple regex type operations and one-liners assed
syntax is more terse and compact thanawk
syntax. Complex multilinesed
scripts can look noisy and be harder to read thanawk
programs.- Reference
- Probably the best
sed
guide out there - Practice
sed
in real-time using ased
REPL (sandbox) online editor. - The more formal GNU
sed
documentation. - converting to uppercase lowercase in sed
- Probably the best
- One-liners
- Count the number of newlines
- In a file:
sed -n '$=' file.txt
- From a pipe:
ls | sed '$='
- In a file:
- Count the number of newlines
- Reference
awk
: Is a text pattern scanning and processing language, which was created by Aho, Weinberger & Kernighan.awk
is mostly used for data extraction and reporting, was built around processing .csv files.awk
is considered more robust thansed
.awk
can do everything thatsed
can do and much more sinceawk
is essentially a full fledged programming language complete with system calls, and sophisticated constructs such as if/else, while, do/while, etc.- Reference
- urls TBD
- One-liners
- Count the number of newlines
- In a file:
awk 'END {print NR}' file.txt
- From a pipe:
awk | 'END {print NR}'
- In a file:
- Count the number of newlines
- Practice
awk
in real-time using anawk
REPL (sandbox) online editor
- Reference
grep
: Stands for Global Regular Expression Print and is used to search for specific terms in a file. Different fromawk
andsed
,grep
cannot add/modify/remove the text in a specific file. But it’s useful when you just want to search and filter out matches.- Reference
- One-liners
- Count the number of newlines
- In a file:
grep -c "" file.txt
- From a pipe:
ls | grep -c ""
- In a file:
- Count the number of newlines
tr
: A command line utility for translating or deleting characters. Great for newline substitutions sincesed
is not designed for this and thesed
syntax for translation involving the\n
character is convoluted because it has a harder ro read escape sequence for the newline character. For example, if you wanted to output all the windows paths, each other their own line by replacing all instances of a semicolon with a\n
, insed
it would look like much less readable:path | sed -e $'s/,/\\\n/g'
than usingtr
to do the same thing:path | tr ; '\n'
.
- General
- Powershell (check the version in Cmder by typing:
powershell $PSVersionTable
)- Tricks
- In Cmder, to run powershell in utf8 mode with a custom colorized prompt showing the powershell version number and current directory, just add the following one-liner (alias) to your
user_aliases.cmd
file:ps=powershell -NoExit -Command "function prompt {$ps = """"Powershell UTF8 v$((Get-Host).Version.Major).$((Get-Host).Version.Minor) $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1))""""; Write-Host $ps -NoNewline -ForegroundColor Cyan; return """" """"}; $OutputEncoding = [Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8;"
- Open any control panel item from this list
control appwiz.cpl
will open the add/remove programs dialog.
- In Cmder, to run powershell in utf8 mode with a custom colorized prompt showing the powershell version number and current directory, just add the following one-liner (alias) to your
- IDE
- Encoding
- Start a Powershell childprocess instantly as UTF8 (including pipes)
Powershell.exe -NoExit -Command "$OutputEncoding = [Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8"
- A good post on utf 8
- More on the Powershell default encoding
- Adding and removing keyboard languages with powershell
- Start a Powershell childprocess instantly as UTF8 (including pipes)
- Error Handling
- Run a program with elevated permissions from a Powershell script. This assumes that the user running the script has administrator privileges. A new cmd terminal window will be opened. We use cmd /k to keep the new process window open. Pass all the arguments at once in a quoted string after the
/k
. The following example shows the currently installed language packs on the Windows system:Start-Process -FilePath cmd -ArgumentList '/k DISM.exe /Online /Get-Intl /English' -Verb RunAs
- Tricks