Skip to content

Instantly share code, notes, and snippets.

@UnitedWithCode
Forked from MarcHeiden/terminal-setup.md
Created September 27, 2022 07:34
Show Gist options
  • Select an option

  • Save UnitedWithCode/1cc70f9d32e0d3695302647e16762005 to your computer and use it in GitHub Desktop.

Select an option

Save UnitedWithCode/1cc70f9d32e0d3695302647e16762005 to your computer and use it in GitHub Desktop.

Revisions

  1. @MarcHeiden MarcHeiden revised this gist Sep 11, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions terminal-setup.md
    Original file line number Diff line number Diff line change
    @@ -109,6 +109,7 @@ Set-PSReadLineOption -Colors @{
    #### Windows Terminal Settings

    Add the following json snippets to the Windows Terminal settings to mimic my settings. Of course you can change everything to your needs.

    **Hint:** Do not copy the comments, cause json don't support them. I just added them for explanation purposes 🙃

    ```javascript
  2. @MarcHeiden MarcHeiden created this gist Sep 11, 2022.
    294 changes: 294 additions & 0 deletions terminal-setup.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,294 @@
    # Setting up a decent looking Windows Terminal with Oh-my-Posh that works with WSL and integrate it in VSCode and IntelliJ

    This is a briefly summary of what I did to set up my Windows Terminal for Powershell on the Windows side and Zsh on the WSL(Ubuntu) side and integrate it in VSCode and IntelliJ.

    <p align="center">
    <img alt="powershell" src="https://user-images.githubusercontent.com/74560465/189548999-576d6835-0675-4db6-ae6e-2ebe157a20fc.png" width="45%">
    &nbsp &nbsp &nbsp &nbsp
    <img alt="zsh" src="https://user-images.githubusercontent.com/74560465/189549010-d38aeffe-d560-45ef-af24-3951909421b7.png" width="45%">
    </p>

    ## Powershell and Windows Terminal

    Let's begin by setting up powershell and the Windows Terminal.

    ### Installation of required packages

    #### Optional: Upgrading PowerShellGet and PackageManagement

    Fell free to skip this part. I just wanted to make sure everything is up to date.

    1. Run Powershell as administrator
    2. Install the newest **NuGet** version

    ```powershell
    > Install-PackageProvider Nuget -Force
    ```
    3. Install the newest version of **PowerShellGet** and **PackageManagement**
    ```powershell
    > Install-Module -Name PowerShellGet -Force
    > Install-Module -Name PackageManagement -Force
    ```
    4. Remove the previous versions by deleting the respective folders in the installation path. The following command will show all available powershell packages with their version and their installation path:
    ```powershell
    > Get-Module -ListAvailable
    ```
    #### Install Terminal-Icons
    Install **Terminal-Icons** via PowerShellGet to get some nice looking icons for the `ls` output:
    ```powershell
    > Install-Module -Name Terminal-Icons
    ```

    #### Install posh-git

    Install **posh-git** via PowerShellGet for git command autocompletion:

    ```powershell
    > Install-Module -Name posh-git
    ```

    #### Install Oh-my-Posh

    You can easily install **Oh-my-Posh** via winget:

    ```powershell
    > winget install JanDeDobbeleer.OhMyPosh
    ```

    For other installation methods check out the [docs](https://ohmyposh.dev/docs/windows#install).

    #### Install a Powerline Font

    Install a powerline font, so that glyphs used in oh-my-posh themes are rendered correctly. [Nerdfonts](https://www.nerdfonts.com/font-downloads) has a decent selection of fonts. I am using the [Caskaydia Cove Nerd Font](https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/CascadiaCode.zip) and [Meslo Font](https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/Meslo.zip) but feel free to choose what suits your needs.

    ### Setup

    Now that we have installed all required packages we can start with the setup.

    #### Oh-my-Posh Theme

    You can use one of the [default themes](https://ohmyposh.dev/docs/themes) that you can install with

    ```powershell
    > Get-PoshThemes
    ```

    create your own theme (take a look in the [documentation](https://ohmyposh.dev/docs/config-overview)) or use my [theme](https://gist.github.com/p4ceman/a892cc9260ad2be30e909dbcb4e77a7e). Make sure to provide the path to your theme in your powershell profile:

    #### Powershell Profile

    Open the Powershell Profile for the current user or create one under `~\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1` if it does not exist and add the following:

    ```powershell
    # Importing Powershell Packages to the current session
    Import-Module PackageManagement
    Import-Module PowerShellGet
    Import-Module Terminal-Icons
    Import-Module posh-git
    # Oh-my-posh Setup
    oh-my-posh --init --shell pwsh --config "path to oh-my-posh theme" | Invoke-Expression
    # Tweaked PSReadLine Colors to fit my color scheme
    # Feel free to change it :)
    Set-PSReadLineOption -Colors @{
    Command = 'Green'
    Comment = 'DarkGray'
    Variable = 'Magenta'
    Keyword = 'Magenta'
    }
    ```

    #### Windows Terminal Settings

    Add the following json snippets to the Windows Terminal settings to mimic my settings. Of course you can change everything to your needs.
    **Hint:** Do not copy the comments, cause json don't support them. I just added them for explanation purposes 🙃

    ```javascript
    // Set powershell as default shell
    {
    "defaultProfile": "Enter guid of Windows Powershell to set Powershell as default shell"
    }
    ```

    ```javascript
    // Set default appereance
    {
    "profiles": {
    "defaults": {
    "acrylicOpacity": 0.90000000000000002,
    "colorScheme": "ColorOne",
    "font": {
    "face": "CaskaydiaCove NF",
    "size": 12,
    "weight": "normal"
    },
    "useAcrylic": false
    }
    }
    }
    ```

    ```javascript
    // Add color scheme
    {
    "schemes": [
    {
    "background": "#282C34",
    "black": "#282C34",
    "blue": "#0078FF",
    "brightBlack": "#5A6374",
    "brightBlue": "#0078FF",
    "brightCyan": "#4FB2FF",
    "brightGreen": "#39FA73",
    "brightPurple": "#A140FC",
    "brightRed": "#ED3E4E",
    "brightWhite": "#F2F2F2",
    "brightYellow": "#F1F139",
    "cursorColor": "#FFFFFF",
    "cyan": "#4FB2FF",
    "foreground": "#F2F2F2",
    "green": "#39FA73",
    "name": "ColorOne",
    "purple": "#A140FC",
    "red": "#ED3E4E",
    "selectionBackground": "#FFFFFF",
    "white": "#F2F2F2",
    "yellow": "#F1F139"
    }
    ]
    }
    ```

    ## WSL

    Now that we have set up powershell and the Windows Terminal we can set up zsh and oh-my-posh for WSL.
    <sup>PS: I am using Ubuntu, but the steps should be replicatible when using other distros.<sup>

    ### Installation of required packages

    #### Install Zsh

    ```shell
    > sudo apt install zsh
    ```

    #### Install Zsh Syntax Highlighting

    ```shell
    > git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.zsh/zsh-syntax-highlighting
    ```

    #### Install Oh-my-Posh

    Download **Oh-my-Posh** from github:

    ```shell
    > wget https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-linux-amd64 -O /usr/local/bin/oh-my-posh
    ```

    and make it executable:

    ```shell
    > chmod +x /usr/local/bin/oh-my-posh
    ```

    ### Setup

    #### Zsh Config

    Create a `.zshrc` file in your homediretory and add or append the following lines in order to clone my settings. Again fell free to change everything.

    ```.zshrc
    # Enable colors for available commands
    alias ls='ls --color=auto'
    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
    alias diff='diff --color=auto'
    alias ip='ip --color=auto'
    # Oh-my-posh Setup
    eval "$(oh-my-posh init zsh --config "path to oh-my-posh theme")"
    # Import Zsh Syntax Highlighting
    source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
    # Adjusted Zsh syntax highlighting colors
    ZSH_HIGHLIGHT_STYLES[unknown-token]=fg=007
    ZSH_HIGHLIGHT_STYLES[single-quoted-argument]=fg=006
    ZSH_HIGHLIGHT_STYLES[double-quoted-argument]=fg=006
    ZSH_HIGHLIGHT_STYLES[single-hyphen-option]=fg=008
    ZSH_HIGHLIGHT_STYLES[double-hyphen-option]=fg=008
    ZSH_HIGHLIGHT_STYLES[comment]=fg=008
    ZSH_HIGHLIGHT_STYLES[function]=fg=006
    ZSH_HIGHLIGHT_STYLES[reserved-word]=fg=005
    ZSH_HIGHLIGHT_STYLES[commandseparator]=fg=005
    ZSH_HIGHLIGHT_STYLES[redirection]=fg=005
    ```

    #### Set Zsh as the default shell

    Use the following command to set Zsh as the default shell:

    ```shell
    sudo chsh -s $(which zsh)
    ```

    ## VSCode Integration

    These are the json snippets I added to my VSCode settings, so that the integrated VSCode Terminal matches with the Windows Terminal:

    ```javascript
    // Set font
    {
    "terminal.integrated.fontFamily": "MesloLGM NF",
    "terminal.integrated.fontSize": 14
    }
    ```

    ```javascript
    // Add Color Scheme
    {
    "workbench.colorCustomizations": {
    "terminal.foreground": "#F2F2F2",
    "terminal.ansiBlack": "#282C34",
    "terminal.ansiBlue": "#0078FF",
    "terminal.ansiCyan": "#4FB2FF",
    "terminal.ansiGreen": "#39FA73",
    "terminal.ansiMagenta": "#A140FC",
    "terminal.ansiRed": "#ED3E4E",
    "terminal.ansiWhite": "#F2F2F2",
    "terminal.ansiYellow": "#F1F139",
    "terminal.ansiBrightBlack": "#5A6374",
    "terminal.ansiBrightBlue": "#0078FF",
    "terminal.ansiBrightCyan": "#4FB2FF",
    "terminal.ansiBrightGreen": "#39FA73",
    "terminal.ansiBrightMagenta": "#A140FC",
    "terminal.ansiBrightRed": "#ED3E4E",
    "terminal.ansiBrightWhite": "#F2F2F2",
    "terminal.ansiBrightYellow": "#F1F139",
    "terminal.selectionBackground": "#FFFFFF",
    "terminalCursor.foreground": "#F2F2F2"
    }
    }
    ```

    ## IntelliJ Integration

    Got to `Settings > Editor > Color Scheme > Console Font` to tweak the Console Font. My settings look like this:

    <img alt="IntelliJ Console font settings" src="https://user-images.githubusercontent.com/74560465/152699611-ca0d4eef-c38a-48b8-bd27-0f9b593ba5b5.png">

    Now go to `Settings > Editor > Color Scheme > Console Colors` and change the colors, so that they match with your color scheme.

    ### Ready

    That's it. You should now have a decent looking Windows Terminal that matches with the integrated VSCode and IntelliJ terminal :smiley: