Category Archives: Technical

Custom PowerShell prompt

My custom PowerShell prompt without the use of oh-my-posh. Create or open file with name Microsoft.PowerShell_profile.ps1 at location C:\Users\<your user name>\Documents\PowerShell\ and paste this code inside that. Then open a PowerShell window to check the prompt.

function prompt
{
    [string] $currentFolderName = GetCurrentFolderName
    [string] $gitStatus = (git status)
    if ([string]::IsNullOrEmpty($gitStatus))
    {
        Write-Host "→ $currentFolderName" -NoNewLine -ForegroundColor DarkCyan
    }
    else
    {
        Write-Host "→ $currentFolderName (" -NoNewLine -ForegroundColor DarkCyan
        Write-Host "$(git branch --show-current)" -NoNewLine -ForegroundColor DarkRed
        Write-Host ")" -NoNewLine -ForegroundColor DarkCyan
    }
    return " "
}

function GetCurrentFolderName
{
    [string] $location = Get-Location
    [string] $currentFolderName = [string]::Empty
    if ($location.EndsWith("\"))
    {
        $currentFolderName = $location
    }
    else
    {
        [int] $lastIndexOfSlash = $location.LastIndexOf("\")
        $currentFolderName = $location.SubString($lastIndexOfSlash + 1)
    }
    return $currentFolderName
}

Global using in C# 10

In any C# application one common problem I noticed is, declare large number of using for namespaces in every .cs files. This has been taken care now by introducing global using in C# 10. Now you can declare common namespace using statements in single file and every file in that project can refer them. No need to declare large number of common using statements in every file.

Read more about global using here. Also there is a good YouTube tutorial on this.

I think this is a very nice feature.

.NET terminal support

Doing daily tasks on terminal is not a very common thing for .NET Framework developers for many years because they used to use rich tools support of Visual Studio. But in .NET Core the things has been changed. All the tasks can be done now from terminal. Now developers has the option to choose between terminal and rich tools support of Visual Studio.

If you are coming from .NET Framework background and working with .NET Core then you can continue to use Visual Studio. But you are coming from a different background where you used to use terminal and working with .NET Core then no need to use Visual Studio, you can use terminal and a light weight editor like Visual Studio Code for that. Now .NET is much more flexible in terms of developer choice of tools for work.

Note: When I say .NET Core in this blog, I actually means .NET Core, .NET 5 and newer.