-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Custom Commands Compendium
NikolayHD edited this page Mar 21, 2022
·
48 revisions
If you have implemented a custom command(s) that you find useful, please add it here so others can find it too. If a particular command proves popular, we will merge it into the codebase for all to use.
If you want to know how to implement your own custom commands see here
Creating a review in Gerrit
customCommands:
- key: '<c-p>'
command: "git push origin HEAD:refs/for/{{.CheckedOutBranch.Name}}"
context: 'global'
loadingText: 'pushing'
customCommands:
- key: '<c-p>'
context: 'global'
loadingText: 'pushing'
prompts:
- type: 'input'
title: 'which branch do you want to push to?'
command: "git push origin {{index .PromptResponses 0}}"
- key : 'N'
description: 'create annotated tag'
command: "git tag -a {{index .PromptResponses 0}} -m \"{{index .PromptResponses 1}}\""
context: 'tags'
prompts:
- type: 'input'
title: 'Annotated tag name:'
- type: 'input'
title: 'Annotated tag message:'
customCommands:
- key: "<c-r>"
command: "gh pr create --fill --web"
context: "global"
loadingText: "Creating pull request on GitHub"
This can be customized to fit your needs. Run gh pr create --help
to see what flags are available.
customCommands:
- key: "v" # couldn't think of a better keybinding
prompts:
- type: 'input'
title: 'PR id:'
command: "hub pr checkout {{index .PromptResponses 0}}"
context: "localBranches"
loadingText: "checking out PR"
customCommands:
- key: "M"
command: "git mergetool {{ .SelectedFile.Name }}"
context: "files"
loadingText: "opening git mergetool"
subprocess: true
customCommands:
- key: "<c-p>"
command: "git remote prune {{.SelectedRemote.Name}}"
context: "remotes"
loadingText: "Pruning..."
description: "prune deleted remote branches"
customCommands:
- key: "C"
command: "git cz"
context: "files"
loadingText: "opening commitizen commit tool"
subprocess: true
You need to build lazygit from master branch for this to work!
customCommands:
- key : '<c-a>'
description: 'Search the whole history (From a ref and down) for an expression in a file'
command: "git checkout {{index .PromptResponses 3}}"
context: 'commits'
prompts:
- type: 'input'
title: 'Search word:'
- type: 'input'
title: 'File/Subtree:'
- type: 'input'
title: 'Ref:'
initialValue: "{{index .CheckedOutBranch.Name }}"
- type: 'menuFromCommand'
title: 'Commits:'
command: "git log --oneline {{index .PromptResponses 2}} -S'{{index .PromptResponses 0}}' --all -- {{index .PromptResponses 1}}"
filter: '(?P<commit_id>[0-9a-zA-Z]*) *(?P<commit_msg>.*)'
valueFormat: '{{ .commit_id }}'
labelFormat: '{{ .commit_id | green | bold }} - {{ .commit_msg | yellow }}'
Example Usage on lazygit repo:
- Search word:
lazygit
- Subtree/File:
**/commits.go
- Ref:
master
Note also that color functions are supported inlabelFormat
customCommands:
- key: '<c-f>'
description: 'fetch a remote branch as a new local branch'
command: "git fetch {{index .SelectedRemote.Name }} {{index .PromptResponses 0}}:{{index .PromptResponses 1}}"
context: 'remotes'
prompts:
- type: 'input'
title: 'Remote Branch Name'
initialValue: ''
- type: 'input'
title: 'New Local Branch Name'
initialValue: ''
loadingText: 'fetching branch'
customCommands:
- key: '<c-c>'
description: 'commit as non-default author'
command: 'git commit -m "{{index .PromptResponses 0}}" --author="{{index .PromptResponses 1}} <{{index .PromptResponses 2}}>"'
context: 'files'
prompts:
- type: 'input'
title: 'Commit Message'
initialValue: ''
- type: 'input'
title: 'Author Name'
initialValue: ''
- type: 'input'
title: 'Email Address'
initialValue: ''
loadingText: 'commiting'
customCommands:
- key: '<c-a>'
description: 'amend the author of last commit'
command: 'git commit --amend --author="{{index .PromptResponses 0}} <{{index .PromptResponses 1}}>"'
context: 'commits'
prompts:
- type: 'input'
title: 'Author Name'
initialValue: ''
- type: 'input'
title: 'Email Address'
subprocess: yes
initialValue: ''
subprocess: true
Blame via tig
customCommands:
- key: b
command: tig blame -- {{.SelectedFile.Name}}
context: files
description: blame file at tree
subprocess: yes
- key: b
command: tig blame {{.SelectedSubCommit.Sha}} -- {{.SelectedCommitFile.Name}}
context: commitFiles
description: blame file at revision
subprocess: yes
- key: B
command: tig blame -- {{.SelectedCommitFile.Name}}
context: commitFiles
description: blame file at tree
subprocess: yes
Browse files at revision via tig
customCommands:
- key: t
command: tig show {{.SelectedSubCommit.Sha}}
context: subCommits
description: tig commit (`t` again to browse files at revision)
subprocess: yes
- key: t
command: tig show {{.SelectedLocalBranch.Name}}
context: localBranches
description: tig branch (`t` again to browse files at revision)
subprocess: yes
- key: t
command: tig show {{.SelectedRemoteBranch.RemoteName}}/{{.SelectedRemoteBranch.Name}}
context: remoteBranches
description: tig branch (`t` again to browse files at revision)
subprocess: yes