Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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 ../../../..`.

Expand All @@ -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.


30 changes: 30 additions & 0 deletions up-to.psm1
Original file line number Diff line number Diff line change
@@ -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