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

feat: add os.copyToClipboardCmd to allow for a custom command #1055 #2784

Merged
merged 1 commit into from
Jul 29, 2023

Conversation

redstreet
Copy link
Contributor

  • feat: add os.copyToClipboardCmd to allow for a custom command

  • Please check if the PR fulfills these requirements

  • Cheatsheets are up-to-date (run go run scripts/cheatsheet/main.go generate)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • Docs (specifically docs/Config.md) have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

Copy link
Owner

@jesseduffield jesseduffield left a comment

Choose a reason for hiding this comment

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

Looks good!

There's an existing integration test, pkg/integration/tests/patch_building/copy_patch_to_clipboard.go which we've disabled due to a lack of clipboard on CI. Would you be able to unskip that test and tweak it so that we define in SetupConfig for copyToClipboardCmd to be echo "{{text}}" > clipboard" and then we assert that a file shows up called clipboard in the files panel with the expected contents? Lemme know if that makes sense

@@ -267,6 +267,13 @@ func (c *OSCommand) CopyToClipboard(str string) error {
escaped := strings.Replace(str, "\n", "\\n", -1)
truncated := utils.TruncateWithEllipsis(escaped, 40)
c.LogCommand(fmt.Sprintf("Copying '%s' to clipboard", truncated), false)
if c.UserConfig.OS.CopyToClipboardCmd != "" {
cmdStr := utils.ResolvePlaceholderString(c.UserConfig.OS.CopyToClipboardCmd, map[string]string{
"text": c.Cmd.Quote(str),
Copy link
Owner

Choose a reason for hiding this comment

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

I see that text is quoted here but that we're also quoting it in the example command above. Does that still work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. The example worked fine because there are another pair of outer enclosing quotes, but was confusing. Simplified.

@redstreet
Copy link
Contributor Author

redstreet commented Jul 17, 2023

Makes sense. I did what you said, and ran
go run cmd/integration_test/main.go cli --sandbox patch_building/copy_patch_to_clipboard. Manually doing a copy executes the configured command correctly, evidenced by:

bash -c "echo "0553aecdb695ed0e5d70100b1b2af769176786c4" > clipboard"

in the Command log. However, I can't figure out where the clipboard file is created. If I give it an absolute path (eg /tmp/clipboard), that works. I can see the directory with pwd. But if I write to a file (date > date.txt), no new file appears in the repo as I'd expect. What am I missing?

Second issue: quoting in the command above doesn't look right. That wouldn't work if {{text}} contained a space. What would you recommend?

@jesseduffield
Copy link
Owner

@redstreet hmm, I'm surprised that the file isn't showing up in the repo. Could you commit your test so I can take a closer look?

As for the quoting, the command log may be adding quotes for the sake of reading, but the resulting command may work fine.

@redstreet
Copy link
Contributor Author

Sure, committed the test. I've been testing it manually using --sandbox, so please ignore the rest of the test, which is not ready yet.

@jesseduffield
Copy link
Owner

Ah, so the reason for the file not showing up is that we don't refresh the files view upon copying to clipboard (nor do we have any file watching functionality in place). So you'll need to focus the files panel and press 'r' to refresh it. Then you'll see the clipboard file :)

@redstreet
Copy link
Contributor Author

Ah, that was silly of me to miss that! Will submit the full test soon. Thank you.

@redstreet redstreet force-pushed the copytoclipboard branch 2 times, most recently from 6eca785 to 1d57f60 Compare July 20, 2023 07:44
@redstreet
Copy link
Contributor Author

Ready for review. Caveats:

  • the test checks for the presence of a new file named clipboard, but does not check its contents (the SHA). The SHA can probably be obtained from the commit log, but I don't know how
  • it would be nice to check for "Copied to clipboard" which appears on the screen on copy. I don't know how to do this either. t.ExpectToast(Contains("Copied to clipboard")) errors out

@redstreet redstreet force-pushed the copytoclipboard branch 2 times, most recently from f004cb3 to e2ac6cd Compare July 20, 2023 07:59
@redstreet
Copy link
Contributor Author

Quick ping 🙂

@jesseduffield
Copy link
Owner

That toast erroring out is interesting: we recently made it so that we don't progress the test until lazygit is idle again, which would mean waiting until after the toast is no longer shown before asserting on it. So that would explain why it's failing. I'm happy to just leave that out of the test.

I've pushed some fixes. We're good to go!

@jesseduffield jesseduffield added the enhancement New feature or request label Jul 29, 2023
Issue jesseduffield#1055

test: CopyPatchToClipboard (temporary commit for review)
@jesseduffield jesseduffield merged commit f174172 into jesseduffield:master Jul 29, 2023
@redstreet
Copy link
Contributor Author

Great, and thanks for the excellent guidance on this PR!

@jesseduffield
Copy link
Owner

No worries @redstreet, thanks for making it

renovate bot referenced this pull request in scottames/dots Aug 5, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
|
[GoogleContainerTools/skaffold](https://github.com/GoogleContainerTools/skaffold)
| patch | `v2.6.2` -> `v2.6.3` |
| [ajeetdsouza/zoxide](https://github.com/ajeetdsouza/zoxide) | patch
| `v0.9.1` -> `v0.9.2` |
| [aquaproj/aqua-registry](https://github.com/aquaproj/aqua-registry)
| patch | `v4.32.0` -> `v4.32.2` |
| [jesseduffield/lazygit](https://github.com/jesseduffield/lazygit) |
minor | `v0.39.4` -> `v0.40.0` |
| [weaveworks/eksctl](https://github.com/weaveworks/eksctl) | minor |
`v0.150.0` -> `v0.151.0` |

---

### Release Notes

<details>
<summary>GoogleContainerTools/skaffold
(GoogleContainerTools/skaffold)</summary>

###
[`v2.6.3`](https://github.com/GoogleContainerTools/skaffold/releases/tag/v2.6.3):
Release

[Compare
Source](https://github.com/GoogleContainerTools/skaffold/compare/v2.6.2...v2.6.3)

##### v2.6.3 Release - 2023-08-04

**Linux amd64**
`curl -Lo skaffold
https://storage.googleapis.com/skaffold/releases/v2.6.3/skaffold-linux-amd64
&& chmod +x skaffold && sudo mv skaffold /usr/local/bin`

**Linux arm64**
`curl -Lo skaffold
https://storage.googleapis.com/skaffold/releases/v2.6.3/skaffold-linux-arm64
&& chmod +x skaffold && sudo mv skaffold /usr/local/bin`

**macOS amd64**
`curl -Lo skaffold
https://storage.googleapis.com/skaffold/releases/v2.6.3/skaffold-darwin-amd64
&& chmod +x skaffold && sudo mv skaffold /usr/local/bin`

**macOS arm64**
`curl -Lo skaffold
https://storage.googleapis.com/skaffold/releases/v2.6.3/skaffold-darwin-arm64
&& chmod +x skaffold && sudo mv skaffold /usr/local/bin`

**Windows**

https://storage.googleapis.com/skaffold/releases/v2.6.3/skaffold-windows-amd64.exe

**Docker image**
`gcr.io/k8s-skaffold/skaffold:v2.6.3`

**Full Changelog**:
GoogleContainerTools/skaffold@v2.6.2...v2.6.3

</details>

<details>
<summary>ajeetdsouza/zoxide (ajeetdsouza/zoxide)</summary>

###
[`v0.9.2`](https://github.com/ajeetdsouza/zoxide/releases/tag/v0.9.2):
0.9.2

[Compare
Source](https://github.com/ajeetdsouza/zoxide/compare/v0.9.1...v0.9.2)

##### Added

-   Short option `-a` for `zoxide query --all`.

##### Fixed

-   PowerShell: use `global` scope for variables / functions.

</details>

<details>
<summary>aquaproj/aqua-registry (aquaproj/aqua-registry)</summary>

###
[`v4.32.2`](https://github.com/aquaproj/aqua-registry/releases/tag/v4.32.2)

[Compare
Source](https://github.com/aquaproj/aqua-registry/compare/v4.32.1...v4.32.2)


[Issues](https://github.com/aquaproj/aqua-registry/issues?q=is%3Aissue+milestone%3Av4.32.2)
| [Pull
Requests](https://github.com/aquaproj/aqua-registry/pulls?q=is%3Apr+milestone%3Av4.32.2)
| aquaproj/aqua-registry@v4.32.1...v4.32.2

##### Fixes


[#&#8203;14327](https://github.com/aquaproj/aqua-registry/issues/14327)
Rename kyleconroy/sqlc to sqlc-dev/sqlc as of repository migration
[@&#8203;ichizero](https://github.com/ichizero)

[#&#8203;14339](https://github.com/aquaproj/aqua-registry/issues/14339)
sqlc-dev/sqlc: Support old versions

###
[`v4.32.1`](https://github.com/aquaproj/aqua-registry/releases/tag/v4.32.1)

[Compare
Source](https://github.com/aquaproj/aqua-registry/compare/v4.32.0...v4.32.1)


[Issues](https://github.com/aquaproj/aqua-registry/issues?q=is%3Aissue+milestone%3Av4.32.1)
| [Pull
Requests](https://github.com/aquaproj/aqua-registry/pulls?q=is%3Apr+milestone%3Av4.32.1)
| aquaproj/aqua-registry@v4.32.0...v4.32.1

#### Fixes


[#&#8203;14275](https://github.com/aquaproj/aqua-registry/issues/14275)
[#&#8203;14276](https://github.com/aquaproj/aqua-registry/issues/14276)
[#&#8203;14277](https://github.com/aquaproj/aqua-registry/issues/14277)
[#&#8203;14278](https://github.com/aquaproj/aqua-registry/issues/14278)
[domoritz/arrow-tools/{csv2arrow,csv2parquet,json2arrow,json2parquet}](https://github.com/domoritz/arrow-tools):
Follow up changes of asset names

</details>

<details>
<summary>jesseduffield/lazygit (jesseduffield/lazygit)</summary>

###
[`v0.40.0`](https://github.com/jesseduffield/lazygit/releases/tag/v0.40.0)

[Compare
Source](https://github.com/jesseduffield/lazygit/compare/v0.39.4...v0.40.0)

<!-- Release notes generated using configuration in .github/release.yml
at v0.40.0 -->

### 🎉  LAZYGIT FIVE YEAR ANNIVERSARY EDITION 🎉

Holy moly, has it really been 5 years since Lazygit's birth? Time flies
when you're having fun.

I've written a post celebrating the anniversary
[here](https://jesseduffield.com/Lazygit-5-Years-On).

As for this release, we've got some great features here.

##### Worktrees

We now have a worktrees view so you can easily create worktrees and
switch to them and so on. I'm not a big worktrees user myself so please
raise an issue if you can think of places to improve the UX.


![worktree_create_from_branches-compressed](https://github.com/jesseduffield/lazygit/assets/8456633/3ef0b085-e9d0-42de-af58-16cbae581d34)

##### Rebase --onto

Rebasing onto a marked base commit is a very useful feature that we've
been sorely lacking for a while
(demo coming soon)

##### Auto-refresh on window focus

Auto-refresh on window activation is a complete game-changer. No more
having to manually press shift+R when you come back from your editor.

##### Nuking the worktree

We also have a fun enhancement in this release: showing an explosion
animation when you nuke the working tree.


![nuke-gif](https://github.com/jesseduffield/lazygit/assets/8456633/32b3f91c-fea3-474d-8997-1de2f5e4f5d4)

You'll also notice in the readme we've got some updated demo gifs to
showoff Lazygit's features. More of those to come.

#### What's Changed

##### Features ✨

- Add worktrees view by
[@&#8203;jesseduffield](https://github.com/jesseduffield) (with help
from [@&#8203;kadaan](https://github.com/kadaan)) in
[https://github.com/jesseduffield/lazygit/pull/2147](https://github.com/jesseduffield/lazygit/pull/2147)
- Rebase onto branch from a marked base commit by
[@&#8203;stefanhaller](https://github.com/stefanhaller) in
[https://github.com/jesseduffield/lazygit/pull/2835](https://github.com/jesseduffield/lazygit/pull/2835)
- Auto-refresh on window activation by
[@&#8203;stefanhaller](https://github.com/stefanhaller) in
[https://github.com/jesseduffield/lazygit/pull/2854](https://github.com/jesseduffield/lazygit/pull/2854)

##### Enhancements 🔥

- Faster refresh by
[@&#8203;jesseduffield](https://github.com/jesseduffield) in
[https://github.com/jesseduffield/lazygit/pull/2841](https://github.com/jesseduffield/lazygit/pull/2841)
- feat: add os.copyToClipboardCmd to allow for a custom command
[#&#8203;1055](https://github.com/jesseduffield/lazygit/issues/1055)
by [@&#8203;redstreet](https://github.com/redstreet) in
[https://github.com/jesseduffield/lazygit/pull/2784](https://github.com/jesseduffield/lazygit/pull/2784)
- Add bisect menu entry that lets you choose bisect terms by
[@&#8203;stefanhaller](https://github.com/stefanhaller) in
[https://github.com/jesseduffield/lazygit/pull/2838](https://github.com/jesseduffield/lazygit/pull/2838)
- When bisecting, always mark the current commit as good/bad, not the
selected by [@&#8203;stefanhaller](https://github.com/stefanhaller) in
[https://github.com/jesseduffield/lazygit/pull/2837](https://github.com/jesseduffield/lazygit/pull/2837)
- Visualize local branch heads in commits panel, 2nd approach by
[@&#8203;stefanhaller](https://github.com/stefanhaller) in
[https://github.com/jesseduffield/lazygit/pull/2775](https://github.com/jesseduffield/lazygit/pull/2775)
- Allow force-tagging if tag exists by
[@&#8203;stefanhaller](https://github.com/stefanhaller) in
[https://github.com/jesseduffield/lazygit/pull/2827](https://github.com/jesseduffield/lazygit/pull/2827)
- Save IgnoreWhitespaceInDiffView in state.yml by
[@&#8203;stefanhaller](https://github.com/stefanhaller) in
[https://github.com/jesseduffield/lazygit/pull/2830](https://github.com/jesseduffield/lazygit/pull/2830)
- Show loader when rebasing by
[@&#8203;KarlHeitmann](https://github.com/KarlHeitmann) in
[https://github.com/jesseduffield/lazygit/pull/2851](https://github.com/jesseduffield/lazygit/pull/2851)
- Internationalise logging of commands by
[@&#8203;KarlHeitmann](https://github.com/KarlHeitmann) in
[https://github.com/jesseduffield/lazygit/pull/2852](https://github.com/jesseduffield/lazygit/pull/2852)
- Show visual explosion effect when nuking worktree by
[@&#8203;jesseduffield](https://github.com/jesseduffield) in
[https://github.com/jesseduffield/lazygit/pull/2861](https://github.com/jesseduffield/lazygit/pull/2861)

##### Fixes 🔧

- Fix issue where using `null` to un-map a keybinding was ignored by
[@&#8203;hatredholder](https://github.com/hatredholder) in
[https://github.com/jesseduffield/lazygit/pull/2832](https://github.com/jesseduffield/lazygit/pull/2832)
- Show error when trying to open patch menu with an empty patch by
[@&#8203;stefanhaller](https://github.com/stefanhaller) in
[https://github.com/jesseduffield/lazygit/pull/2829](https://github.com/jesseduffield/lazygit/pull/2829)
- Fix merge status for update-ref command by
[@&#8203;stefanhaller](https://github.com/stefanhaller) in
[https://github.com/jesseduffield/lazygit/pull/2845](https://github.com/jesseduffield/lazygit/pull/2845)
- Stop worktrees view from stealing the window by
[@&#8203;jesseduffield](https://github.com/jesseduffield) in
[https://github.com/jesseduffield/lazygit/pull/2863](https://github.com/jesseduffield/lazygit/pull/2863)
- Fix confirmation view sizing by
[@&#8203;jesseduffield](https://github.com/jesseduffield) in
[https://github.com/jesseduffield/lazygit/pull/2879](https://github.com/jesseduffield/lazygit/pull/2879)

##### Maintenance ⚙️

- Standardise on using lo for slice functions by
[@&#8203;jesseduffield](https://github.com/jesseduffield) in
[https://github.com/jesseduffield/lazygit/pull/2846](https://github.com/jesseduffield/lazygit/pull/2846)
- Remove redundant secureexec package by
[@&#8203;jesseduffield](https://github.com/jesseduffield) in
[https://github.com/jesseduffield/lazygit/pull/2847](https://github.com/jesseduffield/lazygit/pull/2847)
- Add automated demo recordings by
[@&#8203;jesseduffield](https://github.com/jesseduffield) in
[https://github.com/jesseduffield/lazygit/pull/2853](https://github.com/jesseduffield/lazygit/pull/2853)
- Remove file watcher code by
[@&#8203;jesseduffield](https://github.com/jesseduffield) in
[https://github.com/jesseduffield/lazygit/pull/2865](https://github.com/jesseduffield/lazygit/pull/2865)
- Add more demos to the README by
[@&#8203;jesseduffield](https://github.com/jesseduffield) in
[https://github.com/jesseduffield/lazygit/pull/2866](https://github.com/jesseduffield/lazygit/pull/2866)
- Move features to top of readme by
[@&#8203;jesseduffield](https://github.com/jesseduffield) in
[https://github.com/jesseduffield/lazygit/pull/2867](https://github.com/jesseduffield/lazygit/pull/2867)
- Add more demos by
[@&#8203;jesseduffield](https://github.com/jesseduffield) in
[https://github.com/jesseduffield/lazygit/pull/2874](https://github.com/jesseduffield/lazygit/pull/2874)

##### Other Changes

- Create demo output dir if it doesn't already exist by
[@&#8203;jesseduffield](https://github.com/jesseduffield) in
[https://github.com/jesseduffield/lazygit/pull/2857](https://github.com/jesseduffield/lazygit/pull/2857)

#### New Contributors

- [@&#8203;hatredholder](https://github.com/hatredholder) made their
first contribution in
[https://github.com/jesseduffield/lazygit/pull/2832](https://github.com/jesseduffield/lazygit/pull/2832)
- [@&#8203;redstreet](https://github.com/redstreet) made their first
contribution in
[https://github.com/jesseduffield/lazygit/pull/2784](https://github.com/jesseduffield/lazygit/pull/2784)
- [@&#8203;kadaan](https://github.com/kadaan) made their first
contribution in
[https://github.com/jesseduffield/lazygit/pull/2147](https://github.com/jesseduffield/lazygit/pull/2147)
- [@&#8203;KarlHeitmann](https://github.com/KarlHeitmann) made their
first contribution in
[https://github.com/jesseduffield/lazygit/pull/2851](https://github.com/jesseduffield/lazygit/pull/2851)

**Full Changelog**:
jesseduffield/lazygit@v0.39.4...v0.40.0

</details>

<details>
<summary>weaveworks/eksctl (weaveworks/eksctl)</summary>

###
[`v0.151.0`](https://github.com/eksctl-io/eksctl/releases/tag/v0.151.0):
eksctl 0.151.0 (permalink)

[Compare
Source](https://github.com/weaveworks/eksctl/compare/0.150.0...0.151.0)

### Release v0.151.0

#### 🚀 Features

- Support custom AMIs for self-managed Windows nodegroups
([#&#8203;6804](https://github.com/weaveworks/eksctl/issues/6804))
- Support custom Ubuntu AMIs for EKS-managed nodegroups
([#&#8203;6850](https://github.com/weaveworks/eksctl/issues/6850))

#### 🎯 Improvements

- Remove support for EKS 1.22
([#&#8203;6704](https://github.com/weaveworks/eksctl/issues/6704))

#### 🐛 Bug Fixes

- Fix error with tar in `Post Cache go-build and mod` step
([#&#8203;6840](https://github.com/weaveworks/eksctl/issues/6840))
- Fix setting link-time variables for release version
([#&#8203;6841](https://github.com/weaveworks/eksctl/issues/6841))
- Select one subnet for AZs where multiple are present and no VPC config
provided
([#&#8203;6814](https://github.com/weaveworks/eksctl/issues/6814))
- Paginate instance type offerings response
([#&#8203;6832](https://github.com/weaveworks/eksctl/issues/6832))

#### 🧰 Maintenance

- Bump dependencies
([#&#8203;6852](https://github.com/weaveworks/eksctl/issues/6852),
[#&#8203;6859](https://github.com/weaveworks/eksctl/issues/6859))
- Cleanup Flux Integration
([#&#8203;6836](https://github.com/weaveworks/eksctl/issues/6836))

#### Acknowledgments

Weaveworks would like to sincerely thank:
[@&#8203;watany-dev](https://github.com/watany-dev)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 4pm on thursday" (UTC),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://github.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/scottames/dots).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4yNy4xIiwidXBkYXRlZEluVmVyIjoiMzYuMjcuMSIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants