Setting up Windows Command-Line Working Env for Linux-like OS guys

Motivation

For developers who are accustomed to Linux-like OS systems, Windows 10 is not a productive working environment. This toolset will make their eyes shine. Because it is providing an equivalent experience to working in Mac OS with iTerms2+Oh-my-zsh equipped.

Final Result Screenshot

Xnip2022-05-09_14-52-38

Explanation:

  • cdcode and gst are my aliases for entering the EMS project folder and executing git status
  • ipconfig is a Windows built-in command-line tool used for showing information of network interfaces. Whereas grep is a Linux built-in command-line tool used for printing lines that match patterns which could not be used in Windows before, no matter how desperately a Linux-like OS developer wanted to use it. However, with WSL installed, it has become a reality to execute Linux commands directly in Windows now. dig is another similar example of executing Linux commands in Windows.

Features at a glance

  • define command aliases
  • use Linux built-in command-line tools directly
  • mixed use Windows PowerShell and Linux command line directives
  • selection as a copy
  • git status support
  • tabs
  • split panes
    ...

Installation

1. Install PowerShell

PowerShell is shipped with most Windows 10 distributions. If you already have it, don't bother to install it again, unless you want to use PowerShell 7.x which is not installed by default.

2. Install WSL

WSL is short for "Windows subsystems for Linux". It will enable you to use Linux tools in Windows. To install it is quite easy, just execute wsl --install in PowerShell. Go to here for more details.

3. Install Windows Terminal

Microsoft’s new Windows Terminal is finally stable. Windows finally has a more modern terminal environment including features like tabs, split panes, multiple session types, and settings that let you configure everything from keyboard shortcuts to animated GIF backgrounds. This is an alternative tool to iTerm2 in Mac. It is a console enhancement tool, so it must run based on one of your existing command-line shell instances, such as PowerShell.
You can get it from Microsoft Store
Please google its configuration details. It's up to you how deeply custom configuration you like to do.

4. Install Oh-My-Posh

With the previous 3 steps, you are now having a modern terminal in Windows. Now it's time that we customize the command line prompt to make the terminal working environment more powerful. Oh-My-Posh is a custom prompt engine for any shell that has the ability to adjust the prompt string with a function or variable.
Get Oh-My-Posh and its documentation from its official website
Now, you can use the full-colour set of your terminal, adjust existing themes or create your own, and keep track of git status automatically.
To switch between the pre-defined themes, execute the following command and replace theme_name with your favourite theme.

oh-my-posh init pwsh --config C:\Users\wharvey\AppData\Local\Programs\oh-my-posh\themes\{theme_name}.omp.json | Invoke-Expression

Conclusion

With the power of WSL, we can now use Linux tools in Windows directly.
Windows Terminal is a modern terminal tool enabling developers to use tabs, multiple panes, background images and much other advanced functionality. Windows Terminal is based on command-line shell instances, such as PowerShell.
Oh-My-Posh is an extension to the command-line shell. It enables developers to make good use of the command line prompt.
Enjoy this toolset!