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

Copy CWD action #13526

Closed
wants to merge 1 commit into from
Closed

Copy CWD action #13526

wants to merge 1 commit into from

Conversation

davidegiacometti
Copy link
Contributor

Summary of the Pull Request

Added action for copy CWD

References

Require configuration: https://docs.microsoft.com/en-us/windows/terminal/tutorials/new-tab-same-directory

PR Checklist

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

@ghost ghost added Area-Settings Issues related to settings and customizability, for console or terminal Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal. labels Jul 17, 2022
@github-actions
Copy link

github-actions bot commented Jul 17, 2022

@check-spelling-bot Report

Unrecognized words, please review:

  • CWDTo
Previously acknowledged words that are now absent ansicode appconsult askubuntu aspx azuredevopspodcast azurewebsites biblioscape bitsavers charlespetzold Checkin ckuehl cla cliutils codeproject colororacle condev Consolescreen CPPARM cppreference CPPx css cxcy DCompile debolden deconstructed DECRST DECRSTS decstandar devblogs devicefamily devops Dls dostips DWMWA dwriteglyphrundescriptionclustermap dxp easyrgb ecma edu errno fabricbot FARPROC fcb fdopen fixterms freedesktop GETKEYSTATE guardxfg halfwidth HMIDIOUT HOWTO HPAINTBUFFER HPROPSHEETPAGE htm icch iconify ietf intptr inwap ipa issuecomment iwch kayla kovidgoyal leonerd linkid LLVM locstudio lparen LPCHARSETINFO MAKEWORD manpage MAPVIRTUALKEY mscorlib MSDL mspartners myignite ned newcursor nlength notmatch NOWAIT ocf opensource openxmlformats osfhandle pdp PENDTASKMSG pgorepro pgort PGU php Poli ppci PPORT PSMALL QWERTYUIOP rapidtables RDONLY rdpartysource redistributable referencesource restrictedcapabilities Rexx rfc robertelder rosettacode rparen runasradio scm SOURCESDIRECTORY stackoverflow stdio stgm techcommunity technet testmddefinition Timeline timelines tldp toolbars Toolset ucdxml umd unintense universaltest UWA UWAs uwaterloo uwspace viewtopic VKKEYSCAN vstudio wddmconrenderer wdx webclient wfdopen wfstream wikia wikipedia windev windowsdeveloper winfx winsdk wline wlinestream workitem WResult WSpace xfg Xzn ycombinator
Some files were were automatically ignored

These sample patterns would exclude them:

^samples/ConPTY/EchoCon/EchoCon/EchoCon\.vcxproj\.filters$
^src/host/exe/Host\.EXE\.vcxproj\.filters$
^src/tools/closetest/CloseTest\.vcxproj\.filters$

You should consider adding them to:

.github/actions/spelling/excludes.txt

File matching is via Perl regular expressions.

To check these files, more of their words need to be in the dictionary than not. You can use patterns.txt to exclude portions, add items to the dictionary (e.g. by adding them to allow.txt), or fix typos.

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 [email protected]:davidegiacometti/terminal.git repository
on the issue-12860 branch:

update_files() {
perl -e '
my @expect_files=qw('".github/actions/spelling/expect/alphabet.txt
.github/actions/spelling/expect/expect.txt
.github/actions/spelling/expect/web.txt"');
@ARGV=@expect_files;
my @stale=qw('"$patch_remove"');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spelling/expect/67662e1a6ad51a256d0316724c2815d8c5227c93.txt";
use File::Path qw(make_path);
use File::Basename qw(dirname);
make_path (dirname($new_expect_file));
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"$patch_add"');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a)."-".$a cmp lc($b)."-".$b} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;
system("git", "add", $new_expect_file);
'
(cat '.github/actions/spelling/excludes.txt' - <<EOF
$should_exclude_patterns
EOF
) |grep .|
sort -f |
uniq > '.github/actions/spelling/excludes.txt.temp' &&
mv '.github/actions/spelling/excludes.txt.temp' '.github/actions/spelling/excludes.txt'
}

comment_json=$(mktemp)
curl -L -s -S \
  --header "Content-Type: application/json" \
  "https://api.github.com/repos/microsoft/terminal/issues/comments/1186604862" > "$comment_json"
comment_body=$(mktemp)
jq -r .body < "$comment_json" > $comment_body
rm $comment_json

patch_remove=$(perl -ne 'next unless s{^</summary>(.*)</details>$}{$1}; print' < "$comment_body")
  

patch_add=$(perl -e '$/=undef;
$_=<>;
s{<details>.*}{}s;
s{^#.*}{};
s{\n##.*}{};
s{(?:^|\n)\s*\*}{}g;
s{\s+}{ }g;
print' < "$comment_body")
  

should_exclude_patterns=$(perl -e '$/=undef;
$_=<>;
exit unless s{(?:You should consider excluding directory paths|You should consider adding them to).*}{}s;
s{.*These sample patterns would exclude them:}{}s;
s{.*\`\`\`([^`]*)\`\`\`.*}{$1}m;
print' < "$comment_body" | grep . || true)

update_files
rm $comment_body
git add -u
✏️ 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. You can copy the contents of each perl command excluding the outer ' marks and dropping any '"/"' quotation mark pairs into a file and then run perl file.pl from the root of the repository to run the code. Alternatively, you can manually insert the items...

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 you see a bunch of garbage

If it relates to a ...

well-formed pattern

See if there's a pattern that would match it.

If not, try writing one and adding it to a patterns/{file}.txt.

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.

binary-ish string

Please add a file path to the excludes.txt file instead of just accepting the garbage.

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).

@github-actions
Copy link

github-actions bot commented Jul 17, 2022

@check-spelling-bot Report

Unrecognized words, please review:

  • CWDTo
Previously acknowledged words that are now absent ansicode appconsult askubuntu aspx azuredevopspodcast azurewebsites biblioscape bitsavers charlespetzold Checkin ckuehl cla cliutils codeproject colororacle condev Consolescreen CPPARM cppreference CPPx css cxcy DCompile debolden deconstructed DECRST DECRSTS decstandar devblogs devicefamily devops Dls dostips DWMWA dwriteglyphrundescriptionclustermap dxp easyrgb ecma edu errno fabricbot FARPROC fcb fdopen fixterms freedesktop GETKEYSTATE guardxfg halfwidth HMIDIOUT HOWTO HPAINTBUFFER HPROPSHEETPAGE htm icch iconify ietf intptr inwap ipa issuecomment iwch kayla kovidgoyal leonerd linkid LLVM locstudio lparen LPCHARSETINFO MAKEWORD manpage MAPVIRTUALKEY mscorlib MSDL mspartners myignite ned newcursor nlength notmatch NOWAIT ocf opensource openxmlformats osfhandle pdp PENDTASKMSG pgorepro pgort PGU php Poli ppci PPORT PSMALL QWERTYUIOP rapidtables RDONLY rdpartysource redistributable referencesource restrictedcapabilities Rexx rfc robertelder rosettacode rparen runasradio scm SOURCESDIRECTORY stackoverflow stdio stgm techcommunity technet testmddefinition Timeline timelines tldp toolbars Toolset ucdxml umd unintense universaltest UWA UWAs uwaterloo uwspace viewtopic VKKEYSCAN vstudio wddmconrenderer wdx webclient wfdopen wfstream wikia wikipedia windev windowsdeveloper winfx winsdk wline wlinestream workitem WResult WSpace xfg Xzn ycombinator
Some files were were automatically ignored

These sample patterns would exclude them:

^samples/ConPTY/EchoCon/EchoCon/EchoCon\.vcxproj\.filters$
^src/host/exe/Host\.EXE\.vcxproj\.filters$
^src/tools/closetest/CloseTest\.vcxproj\.filters$

You should consider adding them to:

.github/actions/spelling/excludes.txt

File matching is via Perl regular expressions.

To check these files, more of their words need to be in the dictionary than not. You can use patterns.txt to exclude portions, add items to the dictionary (e.g. by adding them to allow.txt), or fix typos.

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 [email protected]:davidegiacometti/terminal.git repository
on the issue-12860 branch:

update_files() {
perl -e '
my @expect_files=qw('".github/actions/spelling/expect/alphabet.txt
.github/actions/spelling/expect/expect.txt
.github/actions/spelling/expect/web.txt"');
@ARGV=@expect_files;
my @stale=qw('"$patch_remove"');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spelling/expect/67662e1a6ad51a256d0316724c2815d8c5227c93.txt";
use File::Path qw(make_path);
use File::Basename qw(dirname);
make_path (dirname($new_expect_file));
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"$patch_add"');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a)."-".$a cmp lc($b)."-".$b} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;
system("git", "add", $new_expect_file);
'
(cat '.github/actions/spelling/excludes.txt' - <<EOF
$should_exclude_patterns
EOF
) |grep .|
sort -f |
uniq > '.github/actions/spelling/excludes.txt.temp' &&
mv '.github/actions/spelling/excludes.txt.temp' '.github/actions/spelling/excludes.txt'
}

comment_json=$(mktemp)
curl -L -s -S \
  --header "Content-Type: application/json" \
  "https://api.github.com/repos/microsoft/terminal/issues/comments/1186605110" > "$comment_json"
comment_body=$(mktemp)
jq -r .body < "$comment_json" > $comment_body
rm $comment_json

patch_remove=$(perl -ne 'next unless s{^</summary>(.*)</details>$}{$1}; print' < "$comment_body")
  

patch_add=$(perl -e '$/=undef;
$_=<>;
s{<details>.*}{}s;
s{^#.*}{};
s{\n##.*}{};
s{(?:^|\n)\s*\*}{}g;
s{\s+}{ }g;
print' < "$comment_body")
  

should_exclude_patterns=$(perl -e '$/=undef;
$_=<>;
exit unless s{(?:You should consider excluding directory paths|You should consider adding them to).*}{}s;
s{.*These sample patterns would exclude them:}{}s;
s{.*\`\`\`([^`]*)\`\`\`.*}{$1}m;
print' < "$comment_body" | grep . || true)

update_files
rm $comment_body
git add -u
✏️ 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. You can copy the contents of each perl command excluding the outer ' marks and dropping any '"/"' quotation mark pairs into a file and then run perl file.pl from the root of the repository to run the code. Alternatively, you can manually insert the items...

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 you see a bunch of garbage

If it relates to a ...

well-formed pattern

See if there's a pattern that would match it.

If not, try writing one and adding it to a patterns/{file}.txt.

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.

binary-ish string

Please add a file path to the excludes.txt file instead of just accepting the garbage.

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).

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

I don't know if I love the action being copyCWD, but honestly it's short sweet and to the point. Not like I have a better suggestion 😅 It seems good to me!

(just update that one string 😄)

@@ -567,4 +567,7 @@
<data name="SwitchSelectionEndpointCommandKey" xml:space="preserve">
<value>Switch selection endpoint</value>
</data>
</root>
<data name="CopyCWDCommandKey" xml:space="preserve">
<value>Copy CWD</value>
Copy link
Member

Choose a reason for hiding this comment

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

Probably my only nit:

Suggested change
<value>Copy CWD</value>
<value>Copy current working directory</value>

I think it's okay to be a little more verbose here, plus the fuzzy matching should probably immediately filter to this command when typing cwd ("Copy current working directory")

@davidegiacometti
Copy link
Contributor Author

It was copyCurrentWorkingDirectory at first but it's really long 😅

@carlos-zamora
Copy link
Member

Looks good to me! Just be sure to document it in our docs repo and fix the string zadji mentioned above and I'll approve. Thanks!

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

I'm blocking this for more discussion based on some Teams chatter. Thanks for the patience!

@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jul 18, 2022
@davidegiacometti
Copy link
Contributor Author

davidegiacometti commented Jul 18, 2022

No problem! Will update this PR and also create a PR for the documentation based on feedback.

@zadjii-msft I have also tested this on WSL and the returned CWD is \\wsl$\Ubuntu\home\davide\.ssh.
This is perfect for #12859, but a bit strange for this. What do you think?

@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jul 18, 2022
@zadjii-msft zadjii-msft added the Needs-Discussion Something that requires a team discussion before we can proceed label Jul 19, 2022
@zadjii-msft zadjii-msft self-assigned this Aug 1, 2022
@zadjii-msft zadjii-msft removed the Needs-Discussion Something that requires a team discussion before we can proceed label Aug 1, 2022
@davidegiacometti
Copy link
Contributor Author

Hi @zadjii-msft
Any news on this? Feel free to close the PR if this isn't the wanted solution.

@zadjii-msft
Copy link
Member

Alas, yea, I do have news. This is definitely on me for putting off the bad news here.

We talked about this a little while back. The team consensus was that this is a perfectly good and sensible PR. The implementation is totally as we'd expect. However, it's probably not time for this feature quite yet. It's kinda... awkward.

  • The action doesn't overall provide that much value at the moment? Originally, I really expected this to be used with the context menu from Request: Right-click menu inside TerminalControl (w/ Copy & Paste?) #3337. I just don't think I really expected anyone to do it before we got around to that one
  • Most people definitely don't have the path integration set up, so for most people, this action ends up just copying the startingDirectory.
  • We probably didn't give the original idea the right amount of triage diligence to parent it to the context menu task, or at least really think it through. It was more of a showerthought.

So right now the team consensus was to

  • close this out
  • take off "easy starter"
  • eventually (in the fullness of time), recreate this exact PR to bring the action in (and give you a co-authored by: credit in the commit).

Does that all sound reasonable? Sorry for putting this off for so long. I thought I'd be better at being the bearer of bad news, but just ended up dragging my feet. That's on me 😓

@zadjii-msft zadjii-msft closed this Sep 1, 2022
@davidegiacometti
Copy link
Contributor Author

Don't worry @zadjii-msft, I totally understand.
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Settings Issues related to settings and customizability, for console or terminal Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an action to copy CWD path to clipboard
3 participants