jesseduffield / lazygit

simple terminal UI for git commands
MIT License
53.62k stars 1.87k forks source link

CUSTOM KEY VALIDATION #3570

Open epsilon11101 opened 6 months ago

epsilon11101 commented 6 months ago

I've created a custom key, but it doesn't validate if there are staged changes. It executes even if there are no staged files. Any help would be appreciated.

Here's my custom command configuration:


gui:
  nerdFontsVersion: "3"
customCommands:
  - key: "<c-c>"
    context: "files"
    description: "Commit with Gitmoji ๐Ÿ‘ฝ"

    prompts:
      - type: "menu"
        title: "Choose a Gitmoji"
        key: "Gitmoji"
        suggestions:
          preset: "branches"

        options:
          - name: "โœจ feat"
            value: "โœจ"
          - name: "๐Ÿ› fix"
            value: "๐Ÿ›"
          - name: "๐Ÿ“ docs"
            value: "๐Ÿ“"
          - name: "๐Ÿ’„ style"
            value: "๐Ÿ’„"
          - name: "โ™ป๏ธ refactor"
            value: "โ™ป๏ธ"
          - name: "โšก perf"
            value: "โšก"
          - name: "โœ… test"
            value: "โœ…"
          - name: "๐Ÿ”จ build"
            value: "๐Ÿ”จ"
          - name: "๐Ÿ’š ci"
            value: "๐Ÿ’š"
          - name: "๐Ÿ”ง chore"
            value: "๐Ÿ”ง"
          - name: "โช revert"
            value: "โช"
          - name: "๐Ÿšง wip"
            value: "๐Ÿšง"
          - name: "๐Ÿ”€ merge"
            value: "๐Ÿ”€"
          - name: "โฌ†๏ธ dependencies"
            value: "โฌ†๏ธ"
          - name: "โฌ‡๏ธ compatibility"
            value: "โฌ‡๏ธ"
          - name: "๐Ÿ‘• lint"
            value: "๐Ÿ‘•"
          - name: "๐Ÿ”’ security"
            value: "๐Ÿ”’"
          - name: "โ™ฟ accessibility"
            value: "โ™ฟ"
          - name: "๐ŸŒ i18n"
            value: "๐ŸŒ"
          - name: "๐Ÿท๏ธ release"
            value: "๐Ÿท๏ธ"
          - name: "๐ŸŽ‰ init"
            value: "๐ŸŽ‰"
          - name: "โž• dep-add"
            value: "โž•"
          - name: "โž– dep-remove"
            value: "โž–"
          - name: "๐Ÿ“ˆ analytics"
            value: "๐Ÿ“ˆ"
          - name: "๐Ÿ“ฑ responsive"
            value: "๐Ÿ“ฑ"
          - name: "๐ŸŽจ ux/ui"
            value: "๐ŸŽจ"
          - name: "๐Ÿ” seo"
            value: "๐Ÿ”"
          - name: "๐Ÿ’€ dead code"
            value: "๐Ÿ’€"

      - type: "input"
        title: "Enter the commit title"
        key: "CommitSummary"
        initialValue: ""
      - type: "input"
        title: "Enter the commit description"
        key: "CommitDescription"
        initialValue: ""
    checkForConflicts: true
    command: |
      staged_files=$(git diff --cached --name-only)
      if [ -z "$staged_files" ]; then
        echo "No files staged for commit. Please stage your changes first."
        exit 1
      else
        git commit -m '{{.Form.Gitmoji}} {{.Form.CommitSummary}}' -m '{{.Form.CommitDescription}}'
      fi
    loadingText: "Committing..."
ยดยดยด
ricardoprato commented 5 months ago

Hello! @epsilon11101 Based on your command, you could use the gitmoji tool to insert emojis in your commits without having to map them one by one. Here is an example:

customCommands:
- key: "c"
  description: "commit with gitmoji"
  context: "files"
  loadingText: "opening gitmoji commit tool"
  subprocess: true       
  command: |
    staged_files=$(git diff --cached --name-only)
    if [ -z "$staged_files" ]; then
      echo "No files staged for commit. Please stage your changes first."
      exit 1
    else
      gitmoji -c
    fi