Skip to content

Instantly share code, notes, and snippets.

@mikefrobbins
Forked from SteveL-MSFT/profile.ps1
Created September 20, 2022 20:51
Show Gist options
  • Save mikefrobbins/7f20932de3c1b941d03c8d7352452c1d to your computer and use it in GitHub Desktop.
Save mikefrobbins/7f20932de3c1b941d03c8d7352452c1d to your computer and use it in GitHub Desktop.

Revisions

  1. @SteveL-MSFT SteveL-MSFT revised this gist Sep 13, 2022. 1 changed file with 6 additions and 5 deletions.
    11 changes: 6 additions & 5 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 7

    # Version 1.2.10
    # Version 1.2.12

    # check if newer version
    $gistUrl = "https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e"
    @@ -79,10 +79,11 @@ function prompt {
    }
    }

    Set-PSReadLineOption -Colors @{ Selection = "`e[92;7m"; InLinePrediction = "`e[36;7;238m" } -PredictionSource History
    Set-PSReadLineOption -Colors @{ Selection = "`e[92;7m"; InLinePrediction = "`e[36;7;238m" } -PredictionSource HistoryAndPlugin
    Set-PSReadLineKeyHandler -Chord Shift+Tab -Function MenuComplete
    Set-PSReadLineKeyHandler -Chord Ctrl+b -Function BackwardWord
    Set-PSReadLineKeyHandler -Chord Ctrl+f -Function ForwardWord
    Set-PSReadLineKeyHandler -Chord F2 -Function SwitchPredictionView

    if ($IsWindows) {
    Set-PSReadLineOption -EditMode Emacs -ShowToolTips
    @@ -91,12 +92,12 @@ function prompt {
    }
    else {
    try {
    Import-UnixCompleters
    Import-PSUnixTabCompletion
    }
    catch [System.Management.Automation.CommandNotFoundException]
    {
    Install-Module Microsoft.PowerShell.UnixCompleters -Repository PSGallery -AcceptLicense -Force
    Import-UnixCompleters
    Install-Module Microsoft.PowerShell.UnixTabCompletion -Repository PSGallery -AcceptLicense -Force
    Import-PSUnixTabCompletion
    }
    }

  2. @SteveL-MSFT SteveL-MSFT revised this gist Jun 18, 2021. 1 changed file with 4 additions and 5 deletions.
    9 changes: 4 additions & 5 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 7

    # Version 1.2.9
    # Version 1.2.10

    # check if newer version
    $gistUrl = "https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e"
    @@ -36,7 +36,7 @@ if ([System.IO.File]::Exists($latestVersionFile)) {
    }
    }

    $profile_initialized = $false
    $global:profile_initialized = $false

    function prompt {

    @@ -110,11 +110,10 @@ function prompt {
    $env:PATH += [System.IO.Path]::PathSeparator+ [System.IO.Path]::Combine("$HOME",'.dotnet')
    }
    }

    $profile_initialized = $true
    }

    if (!$profile_initialized) {
    if ($global:profile_initialized -ne $true) {
    $global:profile_initialized = $true
    Initialize-Profile
    }

  3. @SteveL-MSFT SteveL-MSFT revised this gist Apr 14, 2021. 1 changed file with 12 additions and 12 deletions.
    24 changes: 12 additions & 12 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 7

    # Version 1.2.8
    # Version 1.2.9

    # check if newer version
    $gistUrl = "https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e"
    @@ -15,7 +15,7 @@ if ([System.IO.File]::Exists($latestVersionFile)) {
    $currentVersion = $matches.Version
    }

    if ($latestVersion -gt $currentVersion) {
    if ([version]$latestVersion -gt $currentVersion) {
    Write-Verbose "Your version: $currentVersion" -Verbose
    Write-Verbose "New version: $latestVersion" -Verbose
    $choice = Read-Host -Prompt "Found newer profile, install? (Y)"
    @@ -44,10 +44,10 @@ function prompt {

    $null = Start-ThreadJob -Name "Get version of `$profile from gist" -ArgumentList $gistUrl, $latestVersionFile, $versionRegEx -ScriptBlock {
    param ($gistUrl, $latestVersionFile, $versionRegEx)

    try {
    $gist = Invoke-RestMethod $gistUrl -ErrorAction Stop

    $gistProfile = $gist.Files."profile.ps1".Content
    [version]$gistVersion = "0.0.0"
    if ($gistProfile -match $versionRegEx) {
    @@ -60,16 +60,16 @@ function prompt {
    Write-Verbose -Verbose "Was not able to access gist to check for newer version"
    }
    }

    if ((Get-Module PSReadLine).Version -lt 2.2) {
    throw "Profile requires PSReadLine 2.2+"
    }

    # setup psdrives
    if ([System.IO.File]::Exists([System.IO.Path]::Combine("$HOME",'test'))) {
    New-PSDrive -Root ~/test -Name Test -PSProvider FileSystem -ErrorAction Ignore > $Null
    }

    if (!(Test-Path repos:)) {
    if (Test-Path ([System.IO.Path]::Combine("$HOME",'git'))) {
    New-PSDrive -Root ~/repos -Name git -PSProvider FileSystem > $Null
    @@ -78,12 +78,12 @@ function prompt {
    New-PSDrive -Root D:\ -Name git -PSProvider FileSystem > $Null
    }
    }

    Set-PSReadLineOption -Colors @{ Selection = "`e[92;7m"; InLinePrediction = "`e[36;7;238m" } -PredictionSource History
    Set-PSReadLineKeyHandler -Chord Shift+Tab -Function MenuComplete
    Set-PSReadLineKeyHandler -Chord Ctrl+b -Function BackwardWord
    Set-PSReadLineKeyHandler -Chord Ctrl+f -Function ForwardWord

    if ($IsWindows) {
    Set-PSReadLineOption -EditMode Emacs -ShowToolTips
    Set-PSReadLineKeyHandler -Chord Ctrl+Shift+c -Function Copy
    @@ -99,18 +99,18 @@ function prompt {
    Import-UnixCompleters
    }
    }

    # add path to dotnet global tools
    $env:PATH += [System.IO.Path]::PathSeparator + [System.IO.Path]::Combine("$HOME",'.dotnet','tools')

    # ensure dotnet cli is in path
    $dotnet = Get-Command dotnet -CommandType Application -ErrorAction Ignore
    if ($null -eq $dotnet) {
    if ([System.IO.File]::Exists("$HOME/.dotnet/dotnet")){
    $env:PATH += [System.IO.Path]::PathSeparator+ [System.IO.Path]::Combine("$HOME",'.dotnet')
    }
    }

    $profile_initialized = $true
    }

  4. @SteveL-MSFT SteveL-MSFT revised this gist Apr 3, 2021. 1 changed file with 79 additions and 65 deletions.
    144 changes: 79 additions & 65 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,15 @@
    #Requires -Version 7

    # Version 1.2.7
    # Version 1.2.8

    # check if newer version
    $gistUrl = "https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e"
    $latestVersionFile = [System.IO.Path]::Combine("$HOME",'.latest_profile_version')
    $versionRegEx = "# Version (?<version>\d+\.\d+\.\d+)"

    if (Test-Path $latestVersionFile) {
    $latestVersion = Get-Content $latestVersionFile -ReadCount 0
    $currentProfile = (Get-Content $profile -Raw -ReadCount 0)[0]
    if ([System.IO.File]::Exists($latestVersionFile)) {
    $latestVersion = [System.IO.File]::ReadAllText($latestVersionFile)
    $currentProfile = [System.IO.File]::ReadAllText($profile)
    [version]$currentVersion = "0.0.0"
    if ($currentProfile -match $versionRegEx) {
    $currentVersion = $matches.Version
    @@ -36,73 +36,87 @@ if (Test-Path $latestVersionFile) {
    }
    }

    $null = Start-ThreadJob -Name "Get version of `$profile from gist" -ArgumentList $gistUrl, $latestVersionFile, $versionRegEx -ScriptBlock {
    param ($gistUrl, $latestVersionFile, $versionRegEx)
    $profile_initialized = $false

    try {
    $gist = Invoke-RestMethod $gistUrl -ErrorAction Stop

    $gistProfile = $gist.Files."profile.ps1".Content
    [version]$gistVersion = "0.0.0"
    if ($gistProfile -match $versionRegEx) {
    $gistVersion = $matches.Version
    Set-Content -Path $latestVersionFile -Value $gistVersion
    }
    }
    catch {
    # we can hit rate limit issue with GitHub since we're using anonymous
    Write-Verbose -Verbose "Was not able to access gist to check for newer version"
    }
    }

    # add path to dotnet global tools
    $env:PATH += [System.IO.Path]::PathSeparator + [System.IO.Path]::Combine("$HOME",'.dotnet','tools')

    if ($IsWindows) {
    Set-PSReadLineOption -EditMode Emacs -ShowToolTips
    Set-PSReadLineKeyHandler -Chord Ctrl+Shift+c -Function Copy
    Set-PSReadLineKeyHandler -Chord Ctrl+Shift+v -Function Paste
    }
    else {
    if ($null -eq (Get-Module Microsoft.PowerShell.UnixCompleters -listavailable)) {
    Install-Module Microsoft.PowerShell.UnixCompleters -Repository PSGallery -AcceptLicense -Force
    }

    Import-Module Microsoft.PowerShell.UnixCompleters
    }

    if ((Get-Module PSReadLine).Version -lt 2.2) {
    throw "Profile requires PSReadLine 2.2+"
    }
    function prompt {

    Set-PSReadLineOption -Colors @{ Selection = "`e[92;7m"; InLinePrediction = "`e[36;7;238m" } -PredictionSource History
    Set-PSReadLineKeyHandler -Chord Shift+Tab -Function MenuComplete
    Set-PSReadLineKeyHandler -Chord Ctrl+b -Function BackwardWord
    Set-PSReadLineKeyHandler -Chord Ctrl+f -Function ForwardWord
    function Initialize-Profile {

    # ensure dotnet cli is in path
    $dotnet = Get-Command dotnet -CommandType Application -ErrorAction Ignore
    if ($null -eq $dotnet) {
    if (Test-Path ~/.dotnet/dotnet) {
    $env:PATH += [System.IO.Path]::PathSeparator+ [System.IO.Path]::Combine("$HOME",'.dotnet')
    $null = Start-ThreadJob -Name "Get version of `$profile from gist" -ArgumentList $gistUrl, $latestVersionFile, $versionRegEx -ScriptBlock {
    param ($gistUrl, $latestVersionFile, $versionRegEx)

    try {
    $gist = Invoke-RestMethod $gistUrl -ErrorAction Stop

    $gistProfile = $gist.Files."profile.ps1".Content
    [version]$gistVersion = "0.0.0"
    if ($gistProfile -match $versionRegEx) {
    $gistVersion = $matches.Version
    Set-Content -Path $latestVersionFile -Value $gistVersion
    }
    }
    catch {
    # we can hit rate limit issue with GitHub since we're using anonymous
    Write-Verbose -Verbose "Was not able to access gist to check for newer version"
    }
    }

    if ((Get-Module PSReadLine).Version -lt 2.2) {
    throw "Profile requires PSReadLine 2.2+"
    }

    # setup psdrives
    if ([System.IO.File]::Exists([System.IO.Path]::Combine("$HOME",'test'))) {
    New-PSDrive -Root ~/test -Name Test -PSProvider FileSystem -ErrorAction Ignore > $Null
    }

    if (!(Test-Path repos:)) {
    if (Test-Path ([System.IO.Path]::Combine("$HOME",'git'))) {
    New-PSDrive -Root ~/repos -Name git -PSProvider FileSystem > $Null
    }
    elseif (Test-Path "d:\PowerShell") {
    New-PSDrive -Root D:\ -Name git -PSProvider FileSystem > $Null
    }
    }

    Set-PSReadLineOption -Colors @{ Selection = "`e[92;7m"; InLinePrediction = "`e[36;7;238m" } -PredictionSource History
    Set-PSReadLineKeyHandler -Chord Shift+Tab -Function MenuComplete
    Set-PSReadLineKeyHandler -Chord Ctrl+b -Function BackwardWord
    Set-PSReadLineKeyHandler -Chord Ctrl+f -Function ForwardWord

    if ($IsWindows) {
    Set-PSReadLineOption -EditMode Emacs -ShowToolTips
    Set-PSReadLineKeyHandler -Chord Ctrl+Shift+c -Function Copy
    Set-PSReadLineKeyHandler -Chord Ctrl+Shift+v -Function Paste
    }
    else {
    try {
    Import-UnixCompleters
    }
    catch [System.Management.Automation.CommandNotFoundException]
    {
    Install-Module Microsoft.PowerShell.UnixCompleters -Repository PSGallery -AcceptLicense -Force
    Import-UnixCompleters
    }
    }

    # add path to dotnet global tools
    $env:PATH += [System.IO.Path]::PathSeparator + [System.IO.Path]::Combine("$HOME",'.dotnet','tools')

    # ensure dotnet cli is in path
    $dotnet = Get-Command dotnet -CommandType Application -ErrorAction Ignore
    if ($null -eq $dotnet) {
    if ([System.IO.File]::Exists("$HOME/.dotnet/dotnet")){
    $env:PATH += [System.IO.Path]::PathSeparator+ [System.IO.Path]::Combine("$HOME",'.dotnet')
    }
    }

    $profile_initialized = $true
    }
    }

    # setup psdrives
    if ((Test-Path ([System.IO.Path]::Combine("$HOME",'test'))) -and (!(Test-Path test:))) {
    New-PSDrive -Root ~/test -Name Test -PSProvider FileSystem > $Null
    }

    if (!(Test-Path repos:)) {
    if (Test-Path ([System.IO.Path]::Combine("$HOME",'git'))) {
    New-PSDrive -Root ~/repos -Name git -PSProvider FileSystem > $Null
    }
    elseif (Test-Path "d:\PowerShell") {
    New-PSDrive -Root D:\ -Name git -PSProvider FileSystem > $Null
    if (!$profile_initialized) {
    Initialize-Profile
    }
    }

    function prompt {

    $currentLastExitCode = $LASTEXITCODE
    $lastSuccess = $?
  5. @SteveL-MSFT SteveL-MSFT revised this gist Apr 2, 2021. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,15 @@
    #Requires -Version 7

    # Version 1.2.6
    # Version 1.2.7

    # check if newer version
    $gistUrl = "https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e"
    $latestVersionFile = Join-Path -Path ~ -ChildPath ".latest_profile_version"
    $latestVersionFile = [System.IO.Path]::Combine("$HOME",'.latest_profile_version')
    $versionRegEx = "# Version (?<version>\d+\.\d+\.\d+)"

    if (Test-Path $latestVersionFile) {
    $latestVersion = Get-Content $latestVersionFile
    $currentProfile = Get-Content $profile -Raw
    $latestVersion = Get-Content $latestVersionFile -ReadCount 0
    $currentProfile = (Get-Content $profile -Raw -ReadCount 0)[0]
    [version]$currentVersion = "0.0.0"
    if ($currentProfile -match $versionRegEx) {
    $currentVersion = $matches.Version
    @@ -56,7 +56,7 @@ $null = Start-ThreadJob -Name "Get version of `$profile from gist" -ArgumentList
    }

    # add path to dotnet global tools
    $env:PATH += [System.IO.Path]::PathSeparator + (Join-Path (Resolve-Path ~) ".dotnet" "tools")
    $env:PATH += [System.IO.Path]::PathSeparator + [System.IO.Path]::Combine("$HOME",'.dotnet','tools')

    if ($IsWindows) {
    Set-PSReadLineOption -EditMode Emacs -ShowToolTips
    @@ -84,17 +84,17 @@ Set-PSReadLineKeyHandler -Chord Ctrl+f -Function ForwardWord
    $dotnet = Get-Command dotnet -CommandType Application -ErrorAction Ignore
    if ($null -eq $dotnet) {
    if (Test-Path ~/.dotnet/dotnet) {
    $env:PATH += [System.IO.Path]::PathSeparator + (Join-Path (Resolve-Path ~) ".dotnet")
    $env:PATH += [System.IO.Path]::PathSeparator+ [System.IO.Path]::Combine("$HOME",'.dotnet')
    }
    }

    # setup psdrives
    if ((Test-Path (Join-Path -Path ~ -ChildPath 'test')) -and (!(Test-Path test:))) {
    if ((Test-Path ([System.IO.Path]::Combine("$HOME",'test'))) -and (!(Test-Path test:))) {
    New-PSDrive -Root ~/test -Name Test -PSProvider FileSystem > $Null
    }

    if (!(Test-Path repos:)) {
    if (Test-Path (Join-Path -Path ~ -ChildPath 'git')) {
    if (Test-Path ([System.IO.Path]::Combine("$HOME",'git'))) {
    New-PSDrive -Root ~/repos -Name git -PSProvider FileSystem > $Null
    }
    elseif (Test-Path "d:\PowerShell") {
    @@ -152,7 +152,7 @@ function prompt {
    $gitBranch = ""
    $path = Get-Location
    while ($path -ne "") {
    if (Test-Path (Join-Path $path .git)) {
    if (Test-Path ([System.IO.Path]::Combine($path,'.git'))) {
    # need to do this so the stderr doesn't show up in $error
    $ErrorActionPreferenceOld = $ErrorActionPreference
    $ErrorActionPreference = 'Ignore'
  6. @SteveL-MSFT SteveL-MSFT revised this gist Feb 17, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 7

    # Version 1.2.5
    # Version 1.2.6

    # check if newer version
    $gistUrl = "https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e"
    @@ -75,7 +75,7 @@ if ((Get-Module PSReadLine).Version -lt 2.2) {
    throw "Profile requires PSReadLine 2.2+"
    }

    Set-PSReadLineOption -Colors @{ Selection = "`e[92;7m"; InLinePrediction = "`e[36;7;238m" } -PredictionSource HistoryAndPlugin -PredictionViewStyle ListView
    Set-PSReadLineOption -Colors @{ Selection = "`e[92;7m"; InLinePrediction = "`e[36;7;238m" } -PredictionSource History
    Set-PSReadLineKeyHandler -Chord Shift+Tab -Function MenuComplete
    Set-PSReadLineKeyHandler -Chord Ctrl+b -Function BackwardWord
    Set-PSReadLineKeyHandler -Chord Ctrl+f -Function ForwardWord
  7. @SteveL-MSFT SteveL-MSFT revised this gist Nov 5, 2020. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 6
    #Requires -Version 7

    # Version 1.2.4
    # Version 1.2.5

    # check if newer version
    $gistUrl = "https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e"
    @@ -71,12 +71,14 @@ else {
    Import-Module Microsoft.PowerShell.UnixCompleters
    }

    Set-PSReadLineOption -Colors @{ Selection = "`e[92;7m" }
    Set-PSReadLineOption -Colors @{ InLinePrediction = "`e[36;7;238m" }
    if ((Get-Module PSReadLine).Version -lt 2.2) {
    throw "Profile requires PSReadLine 2.2+"
    }

    Set-PSReadLineOption -Colors @{ Selection = "`e[92;7m"; InLinePrediction = "`e[36;7;238m" } -PredictionSource HistoryAndPlugin -PredictionViewStyle ListView
    Set-PSReadLineKeyHandler -Chord Shift+Tab -Function MenuComplete
    Set-PSReadLineKeyHandler -Chord Ctrl+b -Function BackwardWord
    Set-PSReadLineKeyHandler -Chord Ctrl+f -Function ForwardWord
    Set-PSReadLineOption -PredictionSource History

    # ensure dotnet cli is in path
    $dotnet = Get-Command dotnet -CommandType Application -ErrorAction Ignore
  8. @SteveL-MSFT SteveL-MSFT revised this gist Oct 20, 2020. 1 changed file with 11 additions and 8 deletions.
    19 changes: 11 additions & 8 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 6

    # Version 1.2.3
    # Version 1.2.4

    # check if newer version
    $gistUrl = "https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e"
    @@ -71,7 +71,8 @@ else {
    Import-Module Microsoft.PowerShell.UnixCompleters
    }

    Set-PSReadLineOption -Colors @{Selection = "`e[92;7m"}
    Set-PSReadLineOption -Colors @{ Selection = "`e[92;7m" }
    Set-PSReadLineOption -Colors @{ InLinePrediction = "`e[36;7;238m" }
    Set-PSReadLineKeyHandler -Chord Shift+Tab -Function MenuComplete
    Set-PSReadLineKeyHandler -Chord Ctrl+b -Function BackwardWord
    Set-PSReadLineKeyHandler -Chord Ctrl+f -Function ForwardWord
    @@ -86,15 +87,17 @@ if ($null -eq $dotnet) {
    }

    # setup psdrives
    if (Test-Path (Join-Path -Path ~ -ChildPath 'test')) {
    if ((Test-Path (Join-Path -Path ~ -ChildPath 'test')) -and (!(Test-Path test:))) {
    New-PSDrive -Root ~/test -Name Test -PSProvider FileSystem > $Null
    }

    if (Test-Path (Join-Path -Path ~ -ChildPath 'repos')) {
    New-PSDrive -Root ~/repos -Name git -PSProvider FileSystem > $Null
    }
    elseif (Test-Path "d:\PowerShell") {
    New-PSDrive -Root D:\ -Name git -PSProvider FileSystem > $Null
    if (!(Test-Path repos:)) {
    if (Test-Path (Join-Path -Path ~ -ChildPath 'git')) {
    New-PSDrive -Root ~/repos -Name git -PSProvider FileSystem > $Null
    }
    elseif (Test-Path "d:\PowerShell") {
    New-PSDrive -Root D:\ -Name git -PSProvider FileSystem > $Null
    }
    }

    function prompt {
  9. @SteveL-MSFT SteveL-MSFT revised this gist Jun 6, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 6

    # Version 1.2.2
    # Version 1.2.3

    # check if newer version
    $gistUrl = "https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e"
    @@ -75,6 +75,7 @@ Set-PSReadLineOption -Colors @{Selection = "`e[92;7m"}
    Set-PSReadLineKeyHandler -Chord Shift+Tab -Function MenuComplete
    Set-PSReadLineKeyHandler -Chord Ctrl+b -Function BackwardWord
    Set-PSReadLineKeyHandler -Chord Ctrl+f -Function ForwardWord
    Set-PSReadLineOption -PredictionSource History

    # ensure dotnet cli is in path
    $dotnet = Get-Command dotnet -CommandType Application -ErrorAction Ignore
  10. @SteveL-MSFT SteveL-MSFT revised this gist Apr 27, 2020. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 6

    # Version 1.2.1
    # Version 1.2.2

    # check if newer version
    $gistUrl = "https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e"
    @@ -84,6 +84,18 @@ if ($null -eq $dotnet) {
    }
    }

    # setup psdrives
    if (Test-Path (Join-Path -Path ~ -ChildPath 'test')) {
    New-PSDrive -Root ~/test -Name Test -PSProvider FileSystem > $Null
    }

    if (Test-Path (Join-Path -Path ~ -ChildPath 'repos')) {
    New-PSDrive -Root ~/repos -Name git -PSProvider FileSystem > $Null
    }
    elseif (Test-Path "d:\PowerShell") {
    New-PSDrive -Root D:\ -Name git -PSProvider FileSystem > $Null
    }

    function prompt {

    $currentLastExitCode = $LASTEXITCODE
  11. @SteveL-MSFT SteveL-MSFT revised this gist Apr 18, 2020. 1 changed file with 7 additions and 4 deletions.
    11 changes: 7 additions & 4 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 6

    # Version 1.1.9
    # Version 1.2.1

    # check if newer version
    $gistUrl = "https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e"
    @@ -55,17 +55,20 @@ $null = Start-ThreadJob -Name "Get version of `$profile from gist" -ArgumentList
    }
    }

    # add path to dotnet global tools
    $env:PATH += [System.IO.Path]::PathSeparator + (Join-Path (Resolve-Path ~) ".dotnet" "tools")

    if ($IsWindows) {
    Set-PSReadLineOption -EditMode Emacs -ShowToolTips
    Set-PSReadLineKeyHandler -Chord Ctrl+Shift+c -Function Copy
    Set-PSReadLineKeyHandler -Chord Ctrl+Shift+v -Function Paste
    }
    else {
    if ($null -eq (Get-Module PSUnixUtilCompleters -listavailable)) {
    Install-Module PSUnixUtilCompleters -Repository PSGallery -AcceptLicense -Force
    if ($null -eq (Get-Module Microsoft.PowerShell.UnixCompleters -listavailable)) {
    Install-Module Microsoft.PowerShell.UnixCompleters -Repository PSGallery -AcceptLicense -Force
    }

    Import-Module PSUnixUtilCompleters
    Import-Module Microsoft.PowerShell.UnixCompleters
    }

    Set-PSReadLineOption -Colors @{Selection = "`e[92;7m"}
  12. @SteveL-MSFT SteveL-MSFT revised this gist Jan 24, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 6

    # Version 1.1.8
    # Version 1.1.9

    # check if newer version
    $gistUrl = "https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e"
    @@ -71,6 +71,7 @@ else {
    Set-PSReadLineOption -Colors @{Selection = "`e[92;7m"}
    Set-PSReadLineKeyHandler -Chord Shift+Tab -Function MenuComplete
    Set-PSReadLineKeyHandler -Chord Ctrl+b -Function BackwardWord
    Set-PSReadLineKeyHandler -Chord Ctrl+f -Function ForwardWord

    # ensure dotnet cli is in path
    $dotnet = Get-Command dotnet -CommandType Application -ErrorAction Ignore
  13. @SteveL-MSFT SteveL-MSFT revised this gist Dec 17, 2019. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 6

    # Version 1.1.7
    # Version 1.1.8

    # check if newer version
    $gistUrl = "https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e"
    @@ -91,6 +91,7 @@ function prompt {
    Green = "`e[32;1m"
    Yellow = "`e[33;1m"
    Grey = "`e[37;0m"
    White = "`e[37;1m"
    Invert = "`e[7m"
    RedBackground = "`e[41m"
    }
  14. @SteveL-MSFT SteveL-MSFT revised this gist Nov 4, 2019. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 6

    # Version 1.1.6
    # Version 1.1.7

    # check if newer version
    $gistUrl = "https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e"
    @@ -55,8 +55,6 @@ $null = Start-ThreadJob -Name "Get version of `$profile from gist" -ArgumentList
    }
    }

    Set-PSReadLineKeyHandler -Chord Ctrl+b -Function BackwardWord

    if ($IsWindows) {
    Set-PSReadLineOption -EditMode Emacs -ShowToolTips
    Set-PSReadLineKeyHandler -Chord Ctrl+Shift+c -Function Copy
    @@ -70,6 +68,10 @@ else {
    Import-Module PSUnixUtilCompleters
    }

    Set-PSReadLineOption -Colors @{Selection = "`e[92;7m"}
    Set-PSReadLineKeyHandler -Chord Shift+Tab -Function MenuComplete
    Set-PSReadLineKeyHandler -Chord Ctrl+b -Function BackwardWord

    # ensure dotnet cli is in path
    $dotnet = Get-Command dotnet -CommandType Application -ErrorAction Ignore
    if ($null -eq $dotnet) {
  15. @SteveL-MSFT SteveL-MSFT revised this gist Oct 28, 2019. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 6

    # Version 1.1.5
    # Version 1.1.6

    # check if newer version
    $gistUrl = "https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e"
    @@ -80,6 +80,7 @@ if ($null -eq $dotnet) {

    function prompt {

    $currentLastExitCode = $LASTEXITCODE
    $lastSuccess = $?

    $color = @{
    @@ -181,4 +182,6 @@ function prompt {
    } catch {
    # do nothing if can't be set
    }

    $global:LASTEXITCODE = $currentLastExitCode
    }
  16. @SteveL-MSFT SteveL-MSFT revised this gist Oct 26, 2019. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 6

    # Version 1.1.4
    # Version 1.1.5

    # check if newer version
    $gistUrl = "https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e"
    @@ -89,6 +89,7 @@ function prompt {
    Yellow = "`e[33;1m"
    Grey = "`e[37;0m"
    Invert = "`e[7m"
    RedBackground = "`e[41m"
    }

    # set color of PS based on success of last execution
    @@ -160,7 +161,7 @@ function prompt {
    # check if running dev built pwsh
    $devBuild = ''
    if ($PSHOME.Contains("publish")) {
    $devBuild = " $($color.Red)$($color.Invert)DevPwsh$($color.Reset)"
    $devBuild = " $($color.White)$($color.RedBackground)DevPwsh$($color.Reset)"
    }

    "${lastCmdTime}${currentDirectory}${gitBranch}${devBuild}`n${lastExit}PS$($color.Reset)$('>' * ($nestedPromptLevel + 1)) "
  17. @SteveL-MSFT SteveL-MSFT revised this gist Oct 20, 2019. 1 changed file with 9 additions and 2 deletions.
    11 changes: 9 additions & 2 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 6

    # Version 1.1.3
    # Version 1.1.4

    # check if newer version
    $gistUrl = "https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e"
    @@ -88,6 +88,7 @@ function prompt {
    Green = "`e[32;1m"
    Yellow = "`e[33;1m"
    Grey = "`e[37;0m"
    Invert = "`e[7m"
    }

    # set color of PS based on success of last execution
    @@ -156,7 +157,13 @@ function prompt {
    $currentDirectory = "`u{2026}" + $currentDirectory.SubString($currentDirectory.Length - $maxPath)
    }

    "$lastCmdTime$currentDirectory$gitBranch`n$($lastExit)PS$($color.Reset)$('>' * ($nestedPromptLevel + 1)) "
    # check if running dev built pwsh
    $devBuild = ''
    if ($PSHOME.Contains("publish")) {
    $devBuild = " $($color.Red)$($color.Invert)DevPwsh$($color.Reset)"
    }

    "${lastCmdTime}${currentDirectory}${gitBranch}${devBuild}`n${lastExit}PS$($color.Reset)$('>' * ($nestedPromptLevel + 1)) "

    # set window title
    try {
  18. @SteveL-MSFT SteveL-MSFT revised this gist Oct 13, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 6

    # Version 1.1.2
    # Version 1.1.3

    # check if newer version
    $gistUrl = "https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e"
    @@ -64,7 +64,7 @@ if ($IsWindows) {
    }
    else {
    if ($null -eq (Get-Module PSUnixUtilCompleters -listavailable)) {
    Install-Module PSUnixUtilCompleters -Repository PSGallery -Force
    Install-Module PSUnixUtilCompleters -Repository PSGallery -AcceptLicense -Force
    }

    Import-Module PSUnixUtilCompleters
  19. @SteveL-MSFT SteveL-MSFT revised this gist Oct 13, 2019. 1 changed file with 10 additions and 2 deletions.
    12 changes: 10 additions & 2 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 6

    # Version 1.1.0
    # Version 1.1.2

    # check if newer version
    $gistUrl = "https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e"
    @@ -55,13 +55,20 @@ $null = Start-ThreadJob -Name "Get version of `$profile from gist" -ArgumentList
    }
    }

    Set-PSReadLineKeyHandler -Chord Ctrl+b -Function BackwardWord

    if ($IsWindows) {
    Set-PSReadLineOption -EditMode Emacs -ShowToolTips
    Set-PSReadLineKeyHandler -Chord Ctrl+Shift+c -Function Copy
    Set-PSReadLineKeyHandler -Chord Ctrl+Shift+v -Function Paste
    }
    else {
    if ($null -eq (Get-Module PSUnixUtilCompleters -listavailable)) {
    Install-Module PSUnixUtilCompleters -Repository PSGallery -Force
    }

    Set-PSReadLineKeyHandler -Chord Ctrl+b -Function BackwardWord
    Import-Module PSUnixUtilCompleters
    }

    # ensure dotnet cli is in path
    $dotnet = Get-Command dotnet -CommandType Application -ErrorAction Ignore
    @@ -153,6 +160,7 @@ function prompt {

    # set window title
    try {
    $prefix = ''
    if ($isWindows) {
    $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
    $windowsPrincipal = [Security.Principal.WindowsPrincipal]::new($identity)
  20. @SteveL-MSFT SteveL-MSFT revised this gist Sep 30, 2019. 1 changed file with 42 additions and 23 deletions.
    65 changes: 42 additions & 23 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,41 +1,58 @@
    #Requires -Version 6

    # Version 1.0.9
    # Version 1.1.0

    # check if newer version
    try {
    $gist = Invoke-RestMethod https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e -ErrorAction Stop
    $gistUrl = "https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e"
    $latestVersionFile = Join-Path -Path ~ -ChildPath ".latest_profile_version"
    $versionRegEx = "# Version (?<version>\d+\.\d+\.\d+)"

    $gistProfile = $gist.Files."profile.ps1".Content
    if (Test-Path $latestVersionFile) {
    $latestVersion = Get-Content $latestVersionFile
    $currentProfile = Get-Content $profile -Raw
    if ($gistProfile.GetHashCode() -ne $currentProfile.GetHashCode()) {
    [version]$currentVersion = "0.0.0"
    $versionRegEx = "# Version (?<version>\d+\.\d+\.\d+)"
    if ($currentProfile -match $versionRegEx) {
    $currentVersion = $matches.Version
    }

    [version]$gistVersion = "0.0.0"
    if ($gistProfile -match $versionRegEx) {
    $gistVersion = $matches.Version
    }
    [version]$currentVersion = "0.0.0"
    if ($currentProfile -match $versionRegEx) {
    $currentVersion = $matches.Version
    }

    if ($gistVersion -gt $currentVersion) {
    Write-Verbose "Your version: $currentVersion" -Verbose
    Write-Verbose "New version: $gistVersion" -Verbose
    $choice = Read-Host -Prompt "Found newer profile, install? (Y)"
    if ($choice -eq "Y" -or $choice -eq "") {
    if ($latestVersion -gt $currentVersion) {
    Write-Verbose "Your version: $currentVersion" -Verbose
    Write-Verbose "New version: $latestVersion" -Verbose
    $choice = Read-Host -Prompt "Found newer profile, install? (Y)"
    if ($choice -eq "Y" -or $choice -eq "") {
    try {
    $gist = Invoke-RestMethod $gistUrl -ErrorAction Stop
    $gistProfile = $gist.Files."profile.ps1".Content
    Set-Content -Path $profile -Value $gistProfile
    Write-Verbose "Installed newer version of profile" -Verbose
    . $profile
    return
    }
    catch {
    # we can hit rate limit issue with GitHub since we're using anonymous
    Write-Verbose -Verbose "Was not able to access gist, try again next time"
    }
    }
    }
    }
    catch [WebCmdletWebResponseException] {
    # we can hit rate limit issue with GitHub since we're using anonymous
    Write-Verbose -Verbose "Was not able to access gist to check for newer version"

    $null = Start-ThreadJob -Name "Get version of `$profile from gist" -ArgumentList $gistUrl, $latestVersionFile, $versionRegEx -ScriptBlock {
    param ($gistUrl, $latestVersionFile, $versionRegEx)

    try {
    $gist = Invoke-RestMethod $gistUrl -ErrorAction Stop

    $gistProfile = $gist.Files."profile.ps1".Content
    [version]$gistVersion = "0.0.0"
    if ($gistProfile -match $versionRegEx) {
    $gistVersion = $matches.Version
    Set-Content -Path $latestVersionFile -Value $gistVersion
    }
    }
    catch {
    # we can hit rate limit issue with GitHub since we're using anonymous
    Write-Verbose -Verbose "Was not able to access gist to check for newer version"
    }
    }

    if ($IsWindows) {
    @@ -44,6 +61,8 @@ if ($IsWindows) {
    Set-PSReadLineKeyHandler -Chord Ctrl+Shift+v -Function Paste
    }

    Set-PSReadLineKeyHandler -Chord Ctrl+b -Function BackwardWord

    # ensure dotnet cli is in path
    $dotnet = Get-Command dotnet -CommandType Application -ErrorAction Ignore
    if ($null -eq $dotnet) {
  21. @SteveL-MSFT SteveL-MSFT revised this gist Jun 1, 2019. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 6

    # Version 1.0.8
    # Version 1.0.9

    # check if newer version
    try {
    @@ -99,10 +99,14 @@ function prompt {
    $path = Get-Location
    while ($path -ne "") {
    if (Test-Path (Join-Path $path .git)) {
    $branch = git rev-parse --abbrev-ref --symbolic-full-name --% @{u}
    # need to do this so the stderr doesn't show up in $error
    $ErrorActionPreferenceOld = $ErrorActionPreference
    $ErrorActionPreference = 'Ignore'
    $branch = git rev-parse --abbrev-ref --symbolic-full-name '@{u}'
    $ErrorActionPreference = $ErrorActionPreferenceOld

    # handle case where branch is local
    if ($lastexitcode -ne 0) {
    if ($lastexitcode -ne 0 -or $null -eq $branch) {
    $branch = git rev-parse --abbrev-ref HEAD
    }

  22. @SteveL-MSFT SteveL-MSFT revised this gist Apr 27, 2019. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 6

    # Version 1.0.7
    # Version 1.0.8

    # check if newer version
    try {
    @@ -61,7 +61,7 @@ function prompt {
    Red = "`e[31;1m"
    Green = "`e[32;1m"
    Yellow = "`e[33;1m"
    Grey = "`e[37m"
    Grey = "`e[37;0m"
    }

    # set color of PS based on success of last execution
    @@ -120,12 +120,13 @@ function prompt {

    # truncate the current location if too long
    $currentDirectory = $executionContext.SessionState.Path.CurrentLocation.Path
    $maxPath = 24
    $consoleWidth = [Console]::WindowWidth
    $maxPath = [int]($consoleWidth / 2)
    if ($currentDirectory.Length -gt $maxPath) {
    $currentDirectory = "`u{2026}" + $currentDirectory.SubString($currentDirectory.Length - $maxPath)
    }

    "$($lastExit)PS$($color.Reset) $lastCmdTime$currentDirectory$gitBranch$('>' * ($nestedPromptLevel + 1)) "
    "$lastCmdTime$currentDirectory$gitBranch`n$($lastExit)PS$($color.Reset)$('>' * ($nestedPromptLevel + 1)) "

    # set window title
    try {
  23. @SteveL-MSFT SteveL-MSFT revised this gist Apr 20, 2019. 1 changed file with 30 additions and 23 deletions.
    53 changes: 30 additions & 23 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,35 +1,42 @@
    #Requires -Version 6

    # Version 1.0.6
    # Version 1.0.7

    # check if newer version
    $gist = Invoke-RestMethod https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e
    $gistProfile = $gist.Files."profile.ps1".Content
    $currentProfile = Get-Content $profile -Raw
    if ($gistProfile.GetHashCode() -ne $currentProfile.GetHashCode()) {
    [version]$currentVersion = "0.0.0"
    $versionRegEx = "# Version (?<version>\d+\.\d+\.\d+)"
    if ($currentProfile -match $versionRegEx) {
    $currentVersion = $matches.Version
    }
    try {
    $gist = Invoke-RestMethod https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e -ErrorAction Stop

    $gistProfile = $gist.Files."profile.ps1".Content
    $currentProfile = Get-Content $profile -Raw
    if ($gistProfile.GetHashCode() -ne $currentProfile.GetHashCode()) {
    [version]$currentVersion = "0.0.0"
    $versionRegEx = "# Version (?<version>\d+\.\d+\.\d+)"
    if ($currentProfile -match $versionRegEx) {
    $currentVersion = $matches.Version
    }

    [version]$gistVersion = "0.0.0"
    if ($gistProfile -match $versionRegEx) {
    $gistVersion = $matches.Version
    }
    [version]$gistVersion = "0.0.0"
    if ($gistProfile -match $versionRegEx) {
    $gistVersion = $matches.Version
    }

    if ($gistVersion -gt $currentVersion) {
    Write-Verbose "Your version: $currentVersion" -Verbose
    Write-Verbose "New version: $gistVersion" -Verbose
    $choice = Read-Host -Prompt "Found newer profile, install? (Y)"
    if ($choice -eq "Y" -or $choice -eq "") {
    Set-Content -Path $profile -Value $gistProfile
    Write-Verbose "Installed newer version of profile" -Verbose
    . $profile
    return
    if ($gistVersion -gt $currentVersion) {
    Write-Verbose "Your version: $currentVersion" -Verbose
    Write-Verbose "New version: $gistVersion" -Verbose
    $choice = Read-Host -Prompt "Found newer profile, install? (Y)"
    if ($choice -eq "Y" -or $choice -eq "") {
    Set-Content -Path $profile -Value $gistProfile
    Write-Verbose "Installed newer version of profile" -Verbose
    . $profile
    return
    }
    }
    }
    }
    catch [WebCmdletWebResponseException] {
    # we can hit rate limit issue with GitHub since we're using anonymous
    Write-Verbose -Verbose "Was not able to access gist to check for newer version"
    }

    if ($IsWindows) {
    Set-PSReadLineOption -EditMode Emacs -ShowToolTips
  24. @SteveL-MSFT SteveL-MSFT revised this gist Apr 5, 2019. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 6

    # Version 1.0.5
    # Version 1.0.6

    # check if newer version
    $gist = Invoke-RestMethod https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e
    @@ -31,7 +31,11 @@ if ($gistProfile.GetHashCode() -ne $currentProfile.GetHashCode()) {
    }
    }

    Set-PSReadLineOption -EditMode Emacs -ShowToolTips
    if ($IsWindows) {
    Set-PSReadLineOption -EditMode Emacs -ShowToolTips
    Set-PSReadLineKeyHandler -Chord Ctrl+Shift+c -Function Copy
    Set-PSReadLineKeyHandler -Chord Ctrl+Shift+v -Function Paste
    }

    # ensure dotnet cli is in path
    $dotnet = Get-Command dotnet -CommandType Application -ErrorAction Ignore
  25. @SteveL-MSFT SteveL-MSFT revised this gist Apr 3, 2019. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 6

    # Version 1.0.4
    # Version 1.0.5

    # check if newer version
    $gist = Invoke-RestMethod https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e
    @@ -31,6 +31,8 @@ if ($gistProfile.GetHashCode() -ne $currentProfile.GetHashCode()) {
    }
    }

    Set-PSReadLineOption -EditMode Emacs -ShowToolTips

    # ensure dotnet cli is in path
    $dotnet = Get-Command dotnet -CommandType Application -ErrorAction Ignore
    if ($null -eq $dotnet) {
  26. @SteveL-MSFT SteveL-MSFT revised this gist Mar 20, 2019. 1 changed file with 10 additions and 2 deletions.
    12 changes: 10 additions & 2 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 6

    # Version 1.0.3
    # Version 1.0.4

    # check if newer version
    $gist = Invoke-RestMethod https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e
    @@ -116,7 +116,15 @@ function prompt {

    # set window title
    try {
    $Host.ui.RawUI.WindowTitle = $PWD
    if ($isWindows) {
    $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
    $windowsPrincipal = [Security.Principal.WindowsPrincipal]::new($identity)
    if ($windowsPrincipal.IsInRole("Administrators") -eq 1) {
    $prefix = "Admin:"
    }
    }

    $Host.ui.RawUI.WindowTitle = "$prefix$PWD"
    } catch {
    # do nothing if can't be set
    }
  27. @SteveL-MSFT SteveL-MSFT revised this gist Feb 21, 2019. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,14 @@
    #Requires -Version 6

    # Version 1.0.2
    # Version 1.0.3

    # check if newer version
    $gist = Invoke-RestMethod https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e
    $gistProfile = $gist.Files."profile.ps1".Content
    $currentProfile = Get-Content $profile -Raw
    if ($gistProfile.GetHashCode() -ne $currentProfile.GetHashCode()) {
    [version]$currentVersion = "0.0.0"
    $versionRegEx = "# Version (version:.*?)\n"
    $versionRegEx = "# Version (?<version>\d+\.\d+\.\d+)"
    if ($currentProfile -match $versionRegEx) {
    $currentVersion = $matches.Version
    }
    @@ -19,10 +19,12 @@ if ($gistProfile.GetHashCode() -ne $currentProfile.GetHashCode()) {
    }

    if ($gistVersion -gt $currentVersion) {
    Write-Verbose "Your version: $currentVersion" -Verbose
    Write-Verbose "New version: $gistVersion" -Verbose
    $choice = Read-Host -Prompt "Found newer profile, install? (Y)"
    if ($choice -eq "Y" -or $choice -eq "") {
    Set-Content -Path $profile -Value $gistProfile
    Write-Verbose "Installed newer version of profile"
    Write-Verbose "Installed newer version of profile" -Verbose
    . $profile
    return
    }
  28. @SteveL-MSFT SteveL-MSFT revised this gist Feb 21, 2019. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 6

    # Version 1.0.1
    # Version 1.0.2

    # check if newer version
    $gist = Invoke-RestMethod https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e
    @@ -111,4 +111,11 @@ function prompt {
    }

    "$($lastExit)PS$($color.Reset) $lastCmdTime$currentDirectory$gitBranch$('>' * ($nestedPromptLevel + 1)) "

    # set window title
    try {
    $Host.ui.RawUI.WindowTitle = $PWD
    } catch {
    # do nothing if can't be set
    }
    }
  29. @SteveL-MSFT SteveL-MSFT revised this gist Feb 9, 2019. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Requires -Version 6

    # Version 1.0.0
    # Version 1.0.1

    # check if newer version
    $gist = Invoke-RestMethod https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e
    @@ -29,6 +29,14 @@ if ($gistProfile.GetHashCode() -ne $currentProfile.GetHashCode()) {
    }
    }

    # ensure dotnet cli is in path
    $dotnet = Get-Command dotnet -CommandType Application -ErrorAction Ignore
    if ($null -eq $dotnet) {
    if (Test-Path ~/.dotnet/dotnet) {
    $env:PATH += [System.IO.Path]::PathSeparator + (Join-Path (Resolve-Path ~) ".dotnet")
    }
    }

    function prompt {

    $lastSuccess = $?
  30. @SteveL-MSFT SteveL-MSFT revised this gist Feb 1, 2019. 1 changed file with 25 additions and 8 deletions.
    33 changes: 25 additions & 8 deletions profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,31 @@
    #Requires -Version 6

    # Version 1.0.0

    # check if newer version
    $promptScript = Invoke-RestMethod https://gist.github.com/SteveL-MSFT/a208d2bd924691bae7ec7904cab0bd8e/raw/64e1e1330b8dcf1fe7ad17a12b4ff520034a225d/profile.ps1
    if ($promptScript.GetHashCode() -ne (Get-Content $profile -Raw).GetHashCode()) {
    $choice = Read-Host -Prompt "Found newer profile, install? (Y)"
    if ($choice -eq "Y" -or $choice -eq "") {
    Set-Content -Path $profile -Value $promptScript
    Write-Verbose "Installed newer version of profile"
    . $profile
    return
    $gist = Invoke-RestMethod https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e
    $gistProfile = $gist.Files."profile.ps1".Content
    $currentProfile = Get-Content $profile -Raw
    if ($gistProfile.GetHashCode() -ne $currentProfile.GetHashCode()) {
    [version]$currentVersion = "0.0.0"
    $versionRegEx = "# Version (version:.*?)\n"
    if ($currentProfile -match $versionRegEx) {
    $currentVersion = $matches.Version
    }

    [version]$gistVersion = "0.0.0"
    if ($gistProfile -match $versionRegEx) {
    $gistVersion = $matches.Version
    }

    if ($gistVersion -gt $currentVersion) {
    $choice = Read-Host -Prompt "Found newer profile, install? (Y)"
    if ($choice -eq "Y" -or $choice -eq "") {
    Set-Content -Path $profile -Value $gistProfile
    Write-Verbose "Installed newer version of profile"
    . $profile
    return
    }
    }
    }