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

Add executeCommand Prompt #4183

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

marakalwa
Copy link

@marakalwa marakalwa commented Jan 18, 2025

  • PR Description

  • Please check if the PR fulfills these requirements

  • Cheatsheets are up-to-date (run 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)
  • If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

@jesseduffield
Copy link
Owner

@marakalwa could you explain the use-case behind this PR?

@jwickers
Copy link

Hmm I was looking at a way to get the result of a command into an input initialValue, would this somehow allow that since initialValue could be "{{.Form.field}}" where field is the output of executeCommand ?

@marakalwa
Copy link
Author

marakalwa commented Feb 25, 2025

@marakalwa could you explain the use-case behind this PR?

Oh my, I did not want to create a pull request for this PR yet. Must have done that very sleepy, either very early or very late 😅

Hmm I was looking at a way to get the result of a command into an input initialValue, would this somehow allow that since initialValue could be "{{.Form.field}}" where field is the output of executeCommand ?

This is exactly the use case for this PR. Running a command without user interaction and saving the result for use in further inputs is imo absolutely vital for building powerful custom commands.

I will just use the relevant part of the customCommand that led me to create this change:

- key: 'i'
    context: 'commits'
    description: 'Change the commit date of this and all subsequent commits'
    prompts:
      - type: 'executeCommand'
        command: |
          date -r {{.SelectedLocalCommit.UnixTimestamp}} +"%a %b %d %H:%M:%S %Y %z" | tr -d "\n"
        key: 'CurrentTimeStamp'
      - type: 'input'
        title: 'What is the new timestamp? Old: {{.Form.CurrentTimeStamp}}'
        initialValue: '{{.Form.CurrentTimeStamp}}'
        key: 'TimeStamp'

As you can see I used an excecuteCommand prompt here to format the UnixTimeStamp of the SelectedLocalCommit in such a way that it is human readable/editable (and can later be read by git in the 'command' part). Without executeCommand this would (afaik) be impossible in this form and require at least two custom commands and the use of the clipboard to get anything close to this.

I have been running lazygit with this change for over a month with various customCommands using multiple executeCommand prompts without issue.

I will try to now finish this PR asap. Lmk if you think I did something wrong here :) and thank you for this awesome tool @jesseduffield

@jesseduffield
Copy link
Owner

Okay that makes sense, sounds reasonable. I'll review the code once you've completed the PR

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.

3 participants