From d219cd1479d4e8e1a8e5802e9bed3c78b0b5b5e7 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Fri, 13 Dec 2024 20:35:12 +0000 Subject: [PATCH] Replace default cd alias with cd function Define cd to work more like Unix/Linux: * No path argument changes to the users home directory * Passing "-" for the path argument changes to the previous directory --- alias.ps1 | 8 ++++---- profile.ps1 | 3 ++- utils.ps1 | 16 +++++++++++++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/alias.ps1 b/alias.ps1 index 7c3d5e6..63108ad 100644 --- a/alias.ps1 +++ b/alias.ps1 @@ -1,4 +1,4 @@ -# Remove these aliases to PowerShell builtins which clobber the actaul exes. -Remove-Item alias:curl -Remove-Item alias:wget -# TODO: Remove default abbriviation aliases +# Remove builtin aliases +Remove-Item Alias:curl +Remove-Item Alias:wget +Remove-Item Alias:cd diff --git a/profile.ps1 b/profile.ps1 index 1ef05f3..6d9604a 100644 --- a/profile.ps1 +++ b/profile.ps1 @@ -11,4 +11,5 @@ $OutputEncoding = New-Object -typename System.Text.UTF8Encoding . $PSScriptRoot\alias.ps1 . $PSScriptRoot\utils.ps1 . $PSScriptRoot\layout.ps1 -# TODO: $PSScriptRoot\build.ps1 +# TODO: . $PSScriptRoot\build.ps1 +# TODO: . $PSScriptRoot\autoenv.ps1 diff --git a/utils.ps1 b/utils.ps1 index b850a50..c4758d0 100644 --- a/utils.ps1 +++ b/utils.ps1 @@ -1,2 +1,16 @@ -# TODO: Define cd to work with zero args for home and - for last directory +# Define cd to work more like Unix/Linux: +# * No path argument changes to the users home directory +# * Passing "-" for the path argument changes to the previous directory +$Global:cdPreviousPath = Get-Location +function cd { + Param ([string]$Path) + if ($Path -eq "") { + $Path = "~" + } elseif ($Path -eq "-") { + $Path = $cdPreviousPath + } + $Global:cdPreviousPath = Get-Location + Set-Location -Path $Path +} + # TODO: Define rm to work with -rf and multiple entries