mayerwin / vs-customize-window-title

Customize Visual Studio Window Title - Visual Studio Extension
https://marketplace.visualstudio.com/items?itemName=mayerwin.RenameVisualStudioWindowTitle
MIT License
108 stars 30 forks source link

Feature Request - Detecting a "root" location within the path #32

Closed mtm31415926 closed 4 years ago

mtm31415926 commented 5 years ago

There are many cases people work within some workspace that has a root path. There can be multiple workspaces and it could be useful to see it or its part in the title. MSBuild has an interesting function called GetDirectoryNameOfFileAbove(, that looks for the specified file name in the specified folder and up, and returns the path the file is found in.

It could be nice to have a similar feature in the tool; the required path to display could be found by referring particular "anchor" file.

mayerwin commented 5 years ago

Thanks for the suggestion. Is this a feature you would need yourself? It looks feasible but a bit complex to make it work with the current tag system, so I'd like to make sure there's sufficient demand for it (otherwise it'll have to wait until it is possible to create custom tags with C# code from VS).

dakotahawkins commented 5 years ago

It's useful. We use that MSBuild function all over our build. It would probably be used to get the repo worktree directory name, which may be shorter than the branch name you're using, e.g. [parentDirWithChild:.git] or something.

My branch names tend to be pretty descriptive (and also usually start with some boilerplate like feature/<initials>/<target version>/..., so it's probably a feature I would use.

ScottLangham commented 4 years ago

Great idea, I was just going to suggest something similar myself!

My real requirement is to be able to display the name of the folder that my git repo is cloned to.

Parent depths aren't a usable way to select that repo root folder because I have solutions at different depths within repos. But git does put a hidden folder called ".git" at the root of each repo, so a search up for that folder could be used to find the folder that is my local repo root.

mayerwin commented 4 years ago

If this is a one-off need, you can always add a XML configuration file to hardcode the pattern for the specific solution you're working on:

It is possible to allow solution-specific settings overrides in two different ways:

By enabling this option in the settings, and placing a 'MySolution.sln.rn.xml' file in the same directory as the MySolution.sln file to which it should refer to. The file should be in xml format containing a single CustomizeVSWindowTitle/SettingsSet element, which attributes can be the following: SolutionName, FarthestParentDepth, ClosestParentDepth, PatternIfDesignMode, PatternIfBreakMode, PatternIfRunningMode, AppendedString.

ScottLangham commented 4 years ago

Thanks for the suggestion. I don't think this is a one off need, there's 3 of us commenting here we'd like this.

Also, there are a lot of dev teams in my company and 100s or 1000s of repos. It's not really practical to add configuration files when I look at another teams repo, the team that own the repo probably wouldn't appreciate me adding xml files to it.

It would be really nice to have the repo name in the VS title bar because I often get lost when dealing with multiple repos, especially when I have repos that were forked from a "template repo" and they all contain solutions with the same name! Possibly our procedure around creating repos from that template needs to change so we rename sln files. But, it would be nice if some tooling such as this extension meant that wasn't an issue.

mayerwin commented 4 years ago

OK it shouldn't be too hard to implement something like: [parentDirWithChild:.git:X:Y], I'll look into it for the next release.

WimLeflere commented 4 years ago

git rev-parse --show-toplevel could be used to get the root path of a git repository, e.g. C:\src\HelloWorld. The base directory (HelloWorld) could be used as repository name.

Source: https://stackoverflow.com/questions/15715825/how-do-you-get-the-git-repositorys-name-in-some-git-repository

mayerwin commented 4 years ago

This is now supported in 4.7.0 with [gitRepositoryName].