-
Notifications
You must be signed in to change notification settings - Fork 587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[rush] Feature idea: "rushcd" change directory to project folder #3771
Comments
Definitely seems useful. Would we want to build this into Rush directly? Seems like that might be slower than people would want. BTW, I wrote and have been using a $RUSH_LIST_OUTPUT_CACHE = @{}
$RUSH_LIST_OUTPUT_CACHE_HASHES = @{}
function Goto-RushProject {
param(
[Parameter(Position=0,mandatory=$true)]
[string]$projectName
)
function getRushJsonPath {
$rushJsonFolder = Get-Location
while ($true) {
$rushJsonPath = Join-Path $rushJsonFolder "rush.json"
if (Test-Path $rushJsonPath) {
return $rushJsonPath
} else {
$rushJsonFolder = Split-Path -Path $rushJsonFolder -Parent
if ($rushJsonFolder -eq "") {
return $null
}
}
}
}
$rushJsonPath = getRushJsonPath
if ($null -eq $rushJsonPath) {
throw "Not in a Rush repo."
}
$rushJsonHash = (Get-FileHash $rushJsonPath).Hash
$rushListData = $RUSH_LIST_OUTPUT_CACHE[$rushJsonPath]
if (($null -eq $rushListData) -or ($RUSH_LIST_OUTPUT_CACHE_HASHES[$rushJsonPath] -ne $rushJsonHash)) {
$rushListData = rush list --json | ConvertFrom-Json
$RUSH_LIST_OUTPUT_CACHE[$rushJsonPath] = $rushListData
$RUSH_LIST_OUTPUT_CACHE_HASHES[$rushJsonPath] = $rushJsonHash
}
$projectEntry = $rushListData.projects | Where-Object { $_.name -eq $projectName}
if ($projectEntry.length -eq 0) {
throw "No project found $projectName"
} else {
Set-Location $projectEntry.fullPath
}
}
New-Alias -Name "rcd" Goto-RushProject |
Ah, thanks for that! The hashing idea is a good one, get most of the speed improvement while still relying on rush itself to produce the structured data. @iclanton for a powershell user, what do you "do" with that snippet to make it part of your overall shell? is there a magic file you add it to, like bashrc? |
Yes, there is a file whose path is defined in the |
Here's my revamped proposal for this feature based on my prototype and @iclanton 's powershell script:
I think this is the full feature, let me know your thoughts! |
Summary
@octogonz mentioned once in a conversation that it would be cool/useful if you could
rush cd @acme/dynamite
to change directory into the folder of the named project.This issue is a design/brainstorm ticket to see if such a feature could be included in Rush.
Details
Rush bash/zsh alias
If you were to implement this for yourself, on your own machine, you'd need an alias or function (since an executable cannot alter the current working directory of the shell).
Here's a simple example:
Now, the real beauty of a
rush cd
command would be the auto-completion. Again, here's a simple version of what that could look like (for bash and zsh):Add the above scripts to your bashrc/zshrc to get a working
rushcd
command with auto-completion (albeit without a whole lot of error checking or correction).Faster and uglier
In my local monorepo, the
rushcd
command above and the corresponding completion have to call rush and it's unfortunately quite slow... a double-TAB on a partial project name is a sluggish 1.89s.If we're willing to get really hacky, we can do better (showing just the zsh version this time):
A double-TAB on a partial project now clocks in at 0.18s, which feels much more responsive. (Again, not much error correction.)
Windows support?
No idea -- does command and/or pwsh offer similar features? (If the user is running a subshell or bash on windows then they can use the bash version.)
What's next?
We could:
CI Support
Today, the de facto "cd into project folder" in a CI environment probably looks something like this:
User-facing features, like bash completions, don't apply here. But, if part of the cleanup / robustifying process above involves converting to nodejs, perhaps there's room for a new
common/scripts/rushcd.js
-- it takes as input the partial project name and returns (very quickly) the available completions. If this existed then CI could use it too!Standard questions
Please answer these questions to help us investigate your issue more quickly:
@microsoft/rush
globally installed version?rushVersion
from rush.json?useWorkspaces
from rush.json?node -v
)?The text was updated successfully, but these errors were encountered: