summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/Config.md1
-rw-r--r--pkg/config/user_config.go24
-rw-r--r--pkg/gui/global_handlers.go13
-rw-r--r--pkg/gui/keybindings.go4
-rw-r--r--schema/config.json5
5 files changed, 35 insertions, 12 deletions
diff --git a/docs/Config.md b/docs/Config.md
index 4e2486784..243c807c4 100644
--- a/docs/Config.md
+++ b/docs/Config.md
@@ -126,6 +126,7 @@ git:
overrideGpg: false # prevents lazygit from spawning a separate process when using GPG
disableForcePushing: false
parseEmoji: false
+ truncateCopiedCommitHashesTo: 12 # When copying commit hashes to the clipboard, truncate them to this length. Set to 40 to disable truncation.
os:
copyToClipboardCmd: '' # See 'Custom Command for Copying to Clipboard' section
editPreset: '' # see 'Configuring File Editing' section
diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go
index 588fe2638..e93fbb06c 100644
--- a/pkg/config/user_config.go
+++ b/pkg/config/user_config.go
@@ -214,6 +214,9 @@ type GitConfig struct {
ParseEmoji bool `yaml:"parseEmoji"`
// Config for showing the log in the commits view
Log LogConfig `yaml:"log"`
+ // When copying commit hashes to the clipboard, truncate them to this
+ // length. Set to 40 to disable truncation.
+ TruncateCopiedCommitHashesTo int `yaml:"truncateCopiedCommitHashesTo"`
}
type PagerType string
@@ -690,16 +693,17 @@ func GetDefaultConfig() *UserConfig {
ShowGraph: "always",
ShowWholeGraph: false,
},
- SkipHookPrefix: "WIP",
- MainBranches: []string{"master", "main"},
- AutoFetch: true,
- AutoRefresh: true,
- FetchAll: true,
- BranchLogCmd: "git log --graph --color=always --abbrev-commit --decorate --date=relative --pretty=medium {{branchName}} --",
- AllBranchesLogCmd: "git log --graph --all --color=always --abbrev-commit --decorate --date=relative --pretty=medium",
- DisableForcePushing: false,
- CommitPrefixes: map[string]CommitPrefixConfig(nil),
- ParseEmoji: false,
+ SkipHookPrefix: "WIP",
+ MainBranches: []string{"master", "main"},
+ AutoFetch: true,
+ AutoRefresh: true,
+ FetchAll: true,
+ BranchLogCmd: "git log --graph --color=always --abbrev-commit --decorate --date=relative --pretty=medium {{branchName}} --",
+ AllBranchesLogCmd: "git log --graph --all --color=always --abbrev-commit --decorate --date=relative --pretty=medium",
+ DisableForcePushing: false,
+ CommitPrefixes: map[string]CommitPrefixConfig(nil),
+ ParseEmoji: false,
+ TruncateCopiedCommitHashesTo: 12,
},
Refresher: RefresherConfig{
RefreshInterval: 10,
diff --git a/pkg/gui/global_handlers.go b/pkg/gui/global_handlers.go
index 9513fff61..c20b10ad7 100644
--- a/pkg/gui/global_handlers.go
+++ b/pkg/gui/global_handlers.go
@@ -110,6 +110,15 @@ func (gui *Gui) scrollDownConfirmationPanel() error {
}
func (gui *Gui) handleCopySelectedSideContextItemToClipboard() error {
+ return gui.handleCopySelectedSideContextItemToClipboardWithTruncation(-1)
+}
+
+func (gui *Gui) handleCopySelectedSideContextItemCommitHashToClipboard() error {
+ return gui.handleCopySelectedSideContextItemToClipboardWithTruncation(
+ gui.UserConfig.Git.TruncateCopiedCommitHashesTo)
+}
+
+func (gui *Gui) handleCopySelectedSideContextItemToClipboardWithTruncation(maxWidth int) error {
// important to note that this assumes we've selected an item in a side context
currentSideContext := gui.c.CurrentSideContext()
if currentSideContext == nil {
@@ -127,6 +136,10 @@ func (gui *Gui) handleCopySelectedSideContextItemToClipboard() error {
return nil
}
+ if maxWidth > 0 {
+ itemId = itemId[:utils.Min(len(itemId), maxWidth)]
+ }
+
gui.c.LogAction(gui.c.Tr.Actions.CopyToClipboard)
if err := gui.os.CopyToClipboard(itemId); err != nil {
return gui.c.Error(err)
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index 6275d5189..02405b9b6 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -146,7 +146,7 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi
{
ViewName: "commits",
Key: opts.GetKey(opts.Config.Universal.CopyToClipboard),
- Handler: self.handleCopySelectedSideContextItemToClipboard,
+ Handler: self.handleCopySelectedSideContextItemCommitHashToClipboard,
GetDisabledReason: self.getCopySelectedSideContextItemToClipboardDisabledReason,
Description: self.c.Tr.CopyCommitShaToClipboard,
},
@@ -166,7 +166,7 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi
{
ViewName: "subCommits",
Key: opts.GetKey(opts.Config.Universal.CopyToClipboard),
- Handler: self.handleCopySelectedSideContextItemToClipboard,
+ Handler: self.handleCopySelectedSideContextItemCommitHashToClipboard,
GetDisabledReason: self.getCopySelectedSideContextItemToClipboardDisabledReason,
Description: self.c.Tr.CopyCommitShaToClipboard,
},
diff --git a/schema/config.json b/schema/config.json
index 65383cd9f..3a2cad060 100644
--- a/schema/config.json
+++ b/schema/config.json
@@ -559,6 +559,11 @@
"additionalProperties": false,
"type": "object",
"description": "Config for showing the log in the commits view"
+ },
+ "truncateCopiedCommitHashesTo": {
+ "type": "integer",
+ "description": "When copying commit hashes to the clipboard, truncate them to this\nlength. Set to 40 to disable truncation.",
+ "default": 12
}
},
"additionalProperties": false,