diff --git a/README.md b/README.md index 1c53916..61cb3a9 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ upto ==== -Bash function that allows to go up to a certain directory. +Bash function and PowerShell script that allows to go up to a certain directory. Stop counting how many levels you have to go up in a folder tree and just type where you want to go! No more `cd ../../../..`. @@ -17,4 +17,10 @@ upto will go to the highest folder matched, in the previous example, if you writ Configuration ------------- +Bash: Just add `upto.sh` to your `/etc/profile.d/` folder. + +PowerShell: +Create a `Up-To` directory in one of yoru PowerShell Module Paths (typically `~\WindowsPowerShell\Modules`, but it can be any path returned by `$env:PSModulePath`) and add `up-to.psm1` there. + + diff --git a/up-to.psm1 b/up-to.psm1 new file mode 100644 index 0000000..1018fb8 --- /dev/null +++ b/up-to.psm1 @@ -0,0 +1,30 @@ +<# + .Synopsis + Quickly navigate up the directory hierarchy to a matching directory + + .Description + Searches up the directory hierarchy for a matching directory and sets the path + to the highest matching location + + .Parameter target + The subpath to search for + + .Example + # In `C:\Users\MyUser\Documents\foo\bar\baz` go to the `foo` directory + Up-To foo + + .Example + # From any directory on the `C:\` drive, quickly go to the top level directory + Up-To c +#> +Function Up-To { + Param ( + [Parameter(Mandatory=$true)] + [string]$target + ) + + Set-Location -Path ( + [regex]::match((Get-Item -Path ".\").FullName, "(.*?" + $target + ".*?(\\|$))|(^.*$)").Value) +} +Set-Alias upto Up-To +Export-ModuleMember -Function Up-To -Alias upto \ No newline at end of file