Skip to content
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

Create til::env to help with refreshing environment variables #12516

Closed
wants to merge 5 commits into from

Conversation

miniksa
Copy link
Member

@miniksa miniksa commented Feb 17, 2022

Summary of the Pull Request

References

PR Checklist

  • Closes #xxx
  • CLA signed. If not, go over here and sign the CLA
  • Tests added/passed
  • Documentation updated. If checked, please file a pull request on our docs repo and link it here: #xxx
  • Schema updated.
  • I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

@github-actions

This comment has been minimized.

@miniksa
Copy link
Member Author

miniksa commented Mar 31, 2022

@lhecker this can be yours now if you want it.

@github-actions
Copy link

@check-spelling-bot Report

🔴 Please review

See the 📂 files view or the 📜action log for details.

Unrecognized words (8)

autoexec
COMPUTERNAME
HOMESHARE
libpath
oken
sid
USERDNSDOMAIN
wiltmp

Previously acknowledged words that are now absent CLA demoable everytime Hirots inthread reingest unmark :arrow_right:
To accept ✔️ these unrecognized words as correct and remove the previously acknowledged and now absent words, run the following commands

... in a clone of the git@github.com:microsoft/terminal.git repository
on the dev/miniksa/env branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.21/apply.pl' |
perl - 'https://github.com/microsoft/terminal/actions/runs/3996360350/attempts/1'
✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

⚠️ The command is written for posix shells. If it doesn't work for you, you can manually add (one word per line) / remove items to expect.txt and the excludes.txt files.

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spelling/allow/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spelling/allow/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spelling/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spelling/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

@ianjoneill
Copy link
Contributor

I've added a commit to this on my fork of the terminal that no longer extends from std::map - https://github.com/ianjoneill/terminal/tree/dev/miniksa/env. Should I open another MR or is there some way of linking my branch with this MR?


std::wstring expand_environment_strings(std::wstring input)
{
// TODO: this should be replacing from ourselves, not from the OS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it this method needs implementing as follows - or is this too naive?

Iterate through the string - append characters to a "return" buffer until you find a percent character. At this point start appending the characters to a "key" buffer instead. When you find a "closing" percent, look the key up in the map. If found, append the looked up value to the return buffer, otherwise append the key as was (including the percent characters), then reset the state. If at the end there's stuff left in the key buffer, append it to the return buffer (including a literal percent character at the beginning).

Test cases:

  1. "Foo%ENV%Baz" with an environment variable %ENV% defined as "Bar" would result in the string "FooBarBaz".
  2. "Foo%ENV%Baz" with no %ENV% variable would result in the string "Foo%ENV%Baz".
  3. "Foo%ENV" would result in the string "Foo%ENV".

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "Foo%Baz%ENV%" with an %ENV% variable but no %Baz% variable? CMD seems to expand %ENV% in that situation, but I don't know what ExpandEnvironmentStringsW does.

@zadjii-msft
Copy link
Member

I've added a commit to this on my fork of the terminal that no longer extends from std::map - ianjoneill/terminal@dev/miniksa/env. Should I open another MR or is there some way of linking my branch with this MR?

Honestly, I'd recommend just filing a new one, I think that'd be the easiest way to iterate and get this in. Thanks!

@DHowett
Copy link
Member

DHowett commented Feb 13, 2023

Superseded by @ianjoneill's (excellent) work. Thanks Michael!

@DHowett DHowett closed this Feb 13, 2023
DHowett pushed a commit that referenced this pull request Mar 13, 2023
Adds a helper that replicates how the `RegenerateUserEnvironment()`
method in `shell32.dll` behaves.

* Raises #12516 from the dead.
* Half of #1125

Co-authored-by: Michael Niksa <miniksa@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants