Skip to content

Instantly share code, notes, and snippets.

@RoadToDream
Last active June 8, 2024 18:45
Show Gist options
  • Select an option

  • Save RoadToDream/d799fb837596210174829b48c4c9a71f to your computer and use it in GitHub Desktop.

Select an option

Save RoadToDream/d799fb837596210174829b48c4c9a71f to your computer and use it in GitHub Desktop.

Revisions

  1. RoadToDream revised this gist Jun 8, 2024. 1 changed file with 10 additions and 4 deletions.
    14 changes: 10 additions & 4 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -6,15 +6,21 @@ Set-PSReadLineOption -HistorySearchCursorMovesToEnd
    Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
    Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward

    # This will not load oh-my-posh and posh-git module on start up, but will load after the first command
    # Reason for that is because oh-my-posh or posh-git takes a lot of time to load, especially for the
    # first time after the boot(3-5 seconds). With that we can get PowerShell ready to use instantly.

    $global:globalPromptInvokedCount = 0

    Function prompt() {
    if ($global:globalPromptInvokedCount -eq 0) {
    $global:globalPromptInvokedCount++
    $currentLocation = $executionContext.SessionState.Path.CurrentLocation.ToString()
    $userHome = [Environment]::GetFolderPath("UserProfile")
    if ($currentLocation -eq $userHome) {
    $currentLocation = "~"
    } else {
    $currentLocation = Split-Path -Path $currentLocation -Leaf
    }
    $ESC = [char]27
    "$ESC[38;2;227;100;100m@jduan $ESC[0m$ESC[38;2;98;237;139m➜ $ESC[0m$ESC[38;2;86;182;194m$currentLocation$ESC[0m "

    } elseif ($global:globalPromptInvokedCount -eq 1) {
    oh-my-posh init pwsh --config "C:\Users\jduan\AppData\Local\Programs\oh-my-posh\themes\zash_custom.omp.json" | Invoke-Expression
    Import-Module posh-git
  2. RoadToDream revised this gist Jun 3, 2024. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,10 @@ Set-PSReadLineOption -HistorySearchCursorMovesToEnd
    Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
    Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward

    # This will not load oh-my-posh and posh-git module on start up, but will load after the first command
    # Reason for that is because oh-my-posh or posh-git takes a lot of time to load, especially for the
    # first time after the boot(3-5 seconds). With that we can get PowerShell ready to use instantly.

    $global:globalPromptInvokedCount = 0

    Function prompt() {
  3. RoadToDream created this gist Jun 3, 2024.
    20 changes: 20 additions & 0 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    Set-PSReadLineOption -EditMode Emacs
    Set-PSReadLineKeyHandler -Chord Ctrl+LeftArrow BackwardWord
    Set-PSReadLineKeyHandler -Chord Ctrl+RightArrow ForwardWord
    Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
    Set-PSReadLineOption -HistorySearchCursorMovesToEnd
    Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
    Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward

    $global:globalPromptInvokedCount = 0

    Function prompt() {
    if ($global:globalPromptInvokedCount -eq 0) {
    $global:globalPromptInvokedCount++
    } elseif ($global:globalPromptInvokedCount -eq 1) {
    oh-my-posh init pwsh --config "C:\Users\jduan\AppData\Local\Programs\oh-my-posh\themes\zash_custom.omp.json" | Invoke-Expression
    Import-Module posh-git
    $global:globalPromptInvokedCount++
    prompt
    }
    }