mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 04:45:47 +02:00
Add "Absolute path" item to the file view's copy menu (#4410)
- **PR Description** Make it possible to copy the absolute path of a file to the clipboard. Addresses #4409.
This commit is contained in:
commit
77651cac35
5 changed files with 74 additions and 11 deletions
|
@ -2,6 +2,7 @@ package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
|
@ -228,8 +229,8 @@ func (self *CommitFilesController) openCopyMenu() error {
|
||||||
DisabledReason: self.require(self.singleItemSelected())(),
|
DisabledReason: self.require(self.singleItemSelected())(),
|
||||||
Key: 'n',
|
Key: 'n',
|
||||||
}
|
}
|
||||||
copyPathItem := &types.MenuItem{
|
copyRelativePathItem := &types.MenuItem{
|
||||||
Label: self.c.Tr.CopyFilePath,
|
Label: self.c.Tr.CopyRelativeFilePath,
|
||||||
OnPress: func() error {
|
OnPress: func() error {
|
||||||
if err := self.c.OS().CopyToClipboard(node.GetPath()); err != nil {
|
if err := self.c.OS().CopyToClipboard(node.GetPath()); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -240,6 +241,18 @@ func (self *CommitFilesController) openCopyMenu() error {
|
||||||
DisabledReason: self.require(self.singleItemSelected())(),
|
DisabledReason: self.require(self.singleItemSelected())(),
|
||||||
Key: 'p',
|
Key: 'p',
|
||||||
}
|
}
|
||||||
|
copyAbsolutePathItem := &types.MenuItem{
|
||||||
|
Label: self.c.Tr.CopyAbsoluteFilePath,
|
||||||
|
OnPress: func() error {
|
||||||
|
if err := self.c.OS().CopyToClipboard(filepath.Join(self.c.Git().RepoPaths.RepoPath(), node.GetPath())); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
self.c.Toast(self.c.Tr.FilePathCopiedToast)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
DisabledReason: self.require(self.singleItemSelected())(),
|
||||||
|
Key: 'P',
|
||||||
|
}
|
||||||
copyFileDiffItem := &types.MenuItem{
|
copyFileDiffItem := &types.MenuItem{
|
||||||
Label: self.c.Tr.CopySelectedDiff,
|
Label: self.c.Tr.CopySelectedDiff,
|
||||||
OnPress: func() error {
|
OnPress: func() error {
|
||||||
|
@ -282,7 +295,8 @@ func (self *CommitFilesController) openCopyMenu() error {
|
||||||
Title: self.c.Tr.CopyToClipboardMenu,
|
Title: self.c.Tr.CopyToClipboardMenu,
|
||||||
Items: []*types.MenuItem{
|
Items: []*types.MenuItem{
|
||||||
copyNameItem,
|
copyNameItem,
|
||||||
copyPathItem,
|
copyRelativePathItem,
|
||||||
|
copyAbsolutePathItem,
|
||||||
copyFileDiffItem,
|
copyFileDiffItem,
|
||||||
copyAllDiff,
|
copyAllDiff,
|
||||||
copyFileContentItem,
|
copyFileContentItem,
|
||||||
|
|
|
@ -3,6 +3,7 @@ package controllers
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
|
@ -976,8 +977,8 @@ func (self *FilesController) openCopyMenu() error {
|
||||||
DisabledReason: self.require(self.singleItemSelected())(),
|
DisabledReason: self.require(self.singleItemSelected())(),
|
||||||
Key: 'n',
|
Key: 'n',
|
||||||
}
|
}
|
||||||
copyPathItem := &types.MenuItem{
|
copyRelativePathItem := &types.MenuItem{
|
||||||
Label: self.c.Tr.CopyFilePath,
|
Label: self.c.Tr.CopyRelativeFilePath,
|
||||||
OnPress: func() error {
|
OnPress: func() error {
|
||||||
if err := self.c.OS().CopyToClipboard(node.GetPath()); err != nil {
|
if err := self.c.OS().CopyToClipboard(node.GetPath()); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -988,6 +989,18 @@ func (self *FilesController) openCopyMenu() error {
|
||||||
DisabledReason: self.require(self.singleItemSelected())(),
|
DisabledReason: self.require(self.singleItemSelected())(),
|
||||||
Key: 'p',
|
Key: 'p',
|
||||||
}
|
}
|
||||||
|
copyAbsolutePathItem := &types.MenuItem{
|
||||||
|
Label: self.c.Tr.CopyAbsoluteFilePath,
|
||||||
|
OnPress: func() error {
|
||||||
|
if err := self.c.OS().CopyToClipboard(filepath.Join(self.c.Git().RepoPaths.RepoPath(), node.GetPath())); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
self.c.Toast(self.c.Tr.FilePathCopiedToast)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
DisabledReason: self.require(self.singleItemSelected())(),
|
||||||
|
Key: 'P',
|
||||||
|
}
|
||||||
copyFileDiffItem := &types.MenuItem{
|
copyFileDiffItem := &types.MenuItem{
|
||||||
Label: self.c.Tr.CopySelectedDiff,
|
Label: self.c.Tr.CopySelectedDiff,
|
||||||
Tooltip: self.c.Tr.CopyFileDiffTooltip,
|
Tooltip: self.c.Tr.CopyFileDiffTooltip,
|
||||||
|
@ -1044,7 +1057,8 @@ func (self *FilesController) openCopyMenu() error {
|
||||||
Title: self.c.Tr.CopyToClipboardMenu,
|
Title: self.c.Tr.CopyToClipboardMenu,
|
||||||
Items: []*types.MenuItem{
|
Items: []*types.MenuItem{
|
||||||
copyNameItem,
|
copyNameItem,
|
||||||
copyPathItem,
|
copyRelativePathItem,
|
||||||
|
copyAbsolutePathItem,
|
||||||
copyFileDiffItem,
|
copyFileDiffItem,
|
||||||
copyAllDiff,
|
copyAllDiff,
|
||||||
},
|
},
|
||||||
|
|
|
@ -76,7 +76,8 @@ type TranslationSet struct {
|
||||||
FileFilter string
|
FileFilter string
|
||||||
CopyToClipboardMenu string
|
CopyToClipboardMenu string
|
||||||
CopyFileName string
|
CopyFileName string
|
||||||
CopyFilePath string
|
CopyRelativeFilePath string
|
||||||
|
CopyAbsoluteFilePath string
|
||||||
CopyFileDiffTooltip string
|
CopyFileDiffTooltip string
|
||||||
CopySelectedDiff string
|
CopySelectedDiff string
|
||||||
CopyAllFilesDiff string
|
CopyAllFilesDiff string
|
||||||
|
@ -1120,7 +1121,8 @@ func EnglishTranslationSet() *TranslationSet {
|
||||||
FileFilter: "Filter files by status",
|
FileFilter: "Filter files by status",
|
||||||
CopyToClipboardMenu: "Copy to clipboard",
|
CopyToClipboardMenu: "Copy to clipboard",
|
||||||
CopyFileName: "File name",
|
CopyFileName: "File name",
|
||||||
CopyFilePath: "Path",
|
CopyRelativeFilePath: "Relative path",
|
||||||
|
CopyAbsoluteFilePath: "Absolute path",
|
||||||
CopyFileDiffTooltip: "If there are staged items, this command considers only them. Otherwise, it considers all the unstaged ones.",
|
CopyFileDiffTooltip: "If there are staged items, this command considers only them. Otherwise, it considers all the unstaged ones.",
|
||||||
CopySelectedDiff: "Diff of selected file",
|
CopySelectedDiff: "Diff of selected file",
|
||||||
CopyAllFilesDiff: "Diff of all files",
|
CopyAllFilesDiff: "Diff of all files",
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package diff
|
package diff
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||||
)
|
)
|
||||||
|
@ -63,7 +65,7 @@ var CopyToClipboard = NewIntegrationTest(NewIntegrationTestArgs{
|
||||||
Tap(func() {
|
Tap(func() {
|
||||||
t.ExpectPopup().Menu().
|
t.ExpectPopup().Menu().
|
||||||
Title(Equals("Copy to clipboard")).
|
Title(Equals("Copy to clipboard")).
|
||||||
Select(Contains("Path")).
|
Select(Contains("Relative path")).
|
||||||
Confirm().
|
Confirm().
|
||||||
Tap(func() {
|
Tap(func() {
|
||||||
t.ExpectToast(Equals("File path copied to clipboard"))
|
t.ExpectToast(Equals("File path copied to clipboard"))
|
||||||
|
@ -71,6 +73,19 @@ var CopyToClipboard = NewIntegrationTest(NewIntegrationTestArgs{
|
||||||
})
|
})
|
||||||
}).
|
}).
|
||||||
Press(keys.Files.CopyFileInfoToClipboard).
|
Press(keys.Files.CopyFileInfoToClipboard).
|
||||||
|
Tap(func() {
|
||||||
|
t.ExpectPopup().Menu().
|
||||||
|
Title(Equals("Copy to clipboard")).
|
||||||
|
Select(Contains("Absolute path")).
|
||||||
|
Confirm().
|
||||||
|
Tap(func() {
|
||||||
|
t.ExpectToast(Equals("File path copied to clipboard"))
|
||||||
|
repoDir, _ := os.Getwd()
|
||||||
|
// On windows the following path would have backslashes, but we don't run integration tests on windows yet.
|
||||||
|
expectClipboard(t, Equals(repoDir+"/dir/file1"))
|
||||||
|
})
|
||||||
|
}).
|
||||||
|
Press(keys.Files.CopyFileInfoToClipboard).
|
||||||
Tap(func() {
|
Tap(func() {
|
||||||
t.ExpectPopup().Menu().
|
t.ExpectPopup().Menu().
|
||||||
Title(Equals("Copy to clipboard")).
|
Title(Equals("Copy to clipboard")).
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package file
|
package file
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||||
)
|
)
|
||||||
|
@ -103,13 +105,13 @@ var CopyMenu = NewIntegrationTest(NewIntegrationTestArgs{
|
||||||
expectClipboard(t, Equals("1-unstaged_file"))
|
expectClipboard(t, Equals("1-unstaged_file"))
|
||||||
})
|
})
|
||||||
|
|
||||||
// Copy file path
|
// Copy relative file path
|
||||||
t.Views().Files().
|
t.Views().Files().
|
||||||
Press(keys.Files.CopyFileInfoToClipboard).
|
Press(keys.Files.CopyFileInfoToClipboard).
|
||||||
Tap(func() {
|
Tap(func() {
|
||||||
t.ExpectPopup().Menu().
|
t.ExpectPopup().Menu().
|
||||||
Title(Equals("Copy to clipboard")).
|
Title(Equals("Copy to clipboard")).
|
||||||
Select(Contains("Path")).
|
Select(Contains("Relative path")).
|
||||||
Confirm()
|
Confirm()
|
||||||
|
|
||||||
t.ExpectToast(Equals("File path copied to clipboard"))
|
t.ExpectToast(Equals("File path copied to clipboard"))
|
||||||
|
@ -117,6 +119,22 @@ var CopyMenu = NewIntegrationTest(NewIntegrationTestArgs{
|
||||||
expectClipboard(t, Equals("dir/1-unstaged_file"))
|
expectClipboard(t, Equals("dir/1-unstaged_file"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Copy absolute file path
|
||||||
|
t.Views().Files().
|
||||||
|
Press(keys.Files.CopyFileInfoToClipboard).
|
||||||
|
Tap(func() {
|
||||||
|
t.ExpectPopup().Menu().
|
||||||
|
Title(Equals("Copy to clipboard")).
|
||||||
|
Select(Contains("Absolute path")).
|
||||||
|
Confirm()
|
||||||
|
|
||||||
|
t.ExpectToast(Equals("File path copied to clipboard"))
|
||||||
|
|
||||||
|
repoDir, _ := os.Getwd()
|
||||||
|
// On windows the following path would have backslashes, but we don't run integration tests on windows yet.
|
||||||
|
expectClipboard(t, Equals(repoDir+"/dir/1-unstaged_file"))
|
||||||
|
})
|
||||||
|
|
||||||
// Selected path diff on a single (unstaged) file
|
// Selected path diff on a single (unstaged) file
|
||||||
t.Views().Files().
|
t.Views().Files().
|
||||||
Press(keys.Files.CopyFileInfoToClipboard).
|
Press(keys.Files.CopyFileInfoToClipboard).
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue