Last active
June 24, 2018 20:07
-
-
Save reckenrode/4f786094f56694461c55153e29ee8520 to your computer and use it in GitHub Desktop.
PowerShell config file for macOS, which correctly updates the Terminal’s cwd and also understands /etc/paths.d.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$env:PATH = { | |
# Powershell doesn’t understand paths.d, nor does it put sbin in the path. | |
# Fix-up the paths to have the same ones as bash. | |
$pathPrefixes = "/usr/local/bin" | |
$pathSuffixes = "/usr/sbin", "/sbin", ` | |
[System.String]::Join(":", (Get-ChildItem -Path "/etc/paths.d" | Get-Content)) | |
"$([System.String]::Join(':', $pathPrefixes)):$($env:PATH):$([System.String]::Join(':', $pathSuffixes))" | |
}.Invoke() | |
function Format-Path { | |
param ( | |
[String]$path | |
) | |
if ($env:HOME -eq $path) { | |
"~" | |
} elseif ("/" -eq $path) { | |
"/" | |
} else { | |
[System.IO.Path]::GetFileName($path) | |
} | |
} | |
function Update-TerminalPath { | |
param ( | |
[String]$path | |
) | |
$uri = New-Object System.Uri $path | |
$uribuilder = New-Object System.UriBuilder $uri | |
$uribuilder.Host = [System.Net.Dns]::GetHostName() | |
Write-Host -NoNewline "$([char]0x1B)]7;$($uribuilder.Uri.AbsoluteUri)`a" | |
} | |
function prompt { | |
Update-TerminalPath $PWD | |
"$([System.Environment]::MachineName):$(Format-Path $PWD) $([System.Environment]::UserName)$ " | |
} | |
function ls-GF { | |
& /bin/ls -GF $args | |
} | |
Set-Alias ls ls-GF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment