mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 20:36:03 +02:00
rename OSCommand field to os
This commit is contained in:
parent
d82f175e79
commit
cd31a762b9
13 changed files with 32 additions and 22 deletions
|
@ -72,9 +72,14 @@ func FileType(path string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *OSCommand) OpenFile(filename string) error {
|
func (c *OSCommand) OpenFile(filename string) error {
|
||||||
|
return c.OpenFileAtLine(filename, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *OSCommand) OpenFileAtLine(filename string, lineNumber int) error {
|
||||||
commandTemplate := c.UserConfig.OS.OpenCommand
|
commandTemplate := c.UserConfig.OS.OpenCommand
|
||||||
templateValues := map[string]string{
|
templateValues := map[string]string{
|
||||||
"filename": c.Quote(filename),
|
"filename": c.Quote(filename),
|
||||||
|
"line": fmt.Sprintf("%d", lineNumber),
|
||||||
}
|
}
|
||||||
command := utils.ResolvePlaceholderString(commandTemplate, templateValues)
|
command := utils.ResolvePlaceholderString(commandTemplate, templateValues)
|
||||||
return c.Cmd.NewShell(command).Run()
|
return c.Cmd.NewShell(command).Run()
|
||||||
|
|
|
@ -79,7 +79,7 @@ func (gui *Gui) handleCopyPullRequestURLPress() error {
|
||||||
return gui.c.Error(err)
|
return gui.c.Error(err)
|
||||||
}
|
}
|
||||||
gui.c.LogAction(gui.c.Tr.Actions.CopyPullRequestURL)
|
gui.c.LogAction(gui.c.Tr.Actions.CopyPullRequestURL)
|
||||||
if err := gui.OSCommand.CopyToClipboard(url); err != nil {
|
if err := gui.os.CopyToClipboard(url); err != nil {
|
||||||
return gui.c.Error(err)
|
return gui.c.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ type IFilesHelper interface {
|
||||||
EditFile(filename string) error
|
EditFile(filename string) error
|
||||||
EditFileAtLine(filename string, lineNumber int) error
|
EditFileAtLine(filename string, lineNumber int) error
|
||||||
OpenFile(filename string) error
|
OpenFile(filename string) error
|
||||||
|
OpenFileAtLine(filename string, lineNumber int) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type FilesHelper struct {
|
type FilesHelper struct {
|
||||||
|
@ -49,8 +50,12 @@ func (self *FilesHelper) EditFileAtLine(filename string, lineNumber int) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *FilesHelper) OpenFile(filename string) error {
|
func (self *FilesHelper) OpenFile(filename string) error {
|
||||||
|
return self.OpenFileAtLine(filename, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *FilesHelper) OpenFileAtLine(filename string, lineNumber int) error {
|
||||||
self.c.LogAction(self.c.Tr.Actions.OpenFile)
|
self.c.LogAction(self.c.Tr.Actions.OpenFile)
|
||||||
if err := self.os.OpenFile(filename); err != nil {
|
if err := self.os.OpenFileAtLine(filename, lineNumber); err != nil {
|
||||||
return self.c.Error(err)
|
return self.c.Error(err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -247,7 +247,7 @@ func (gui *Gui) handleCustomCommandKeybinding(customCommand config.CustomCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
if customCommand.Subprocess {
|
if customCommand.Subprocess {
|
||||||
return gui.runSubprocessWithSuspenseAndRefresh(gui.OSCommand.Cmd.NewShell(cmdStr))
|
return gui.runSubprocessWithSuspenseAndRefresh(gui.os.Cmd.NewShell(cmdStr))
|
||||||
}
|
}
|
||||||
|
|
||||||
loadingText := customCommand.LoadingText
|
loadingText := customCommand.LoadingText
|
||||||
|
@ -256,7 +256,7 @@ func (gui *Gui) handleCustomCommandKeybinding(customCommand config.CustomCommand
|
||||||
}
|
}
|
||||||
return gui.c.WithWaitingStatus(loadingText, func() error {
|
return gui.c.WithWaitingStatus(loadingText, func() error {
|
||||||
gui.c.LogAction(gui.c.Tr.Actions.CustomCommand)
|
gui.c.LogAction(gui.c.Tr.Actions.CustomCommand)
|
||||||
cmdObj := gui.OSCommand.Cmd.NewShell(cmdStr)
|
cmdObj := gui.os.Cmd.NewShell(cmdStr)
|
||||||
if customCommand.Stream {
|
if customCommand.Stream {
|
||||||
cmdObj.StreamOutput()
|
cmdObj.StreamOutput()
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ func (gui *Gui) exitDiffMode() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) renderDiff() error {
|
func (gui *Gui) renderDiff() error {
|
||||||
cmdObj := gui.OSCommand.Cmd.New(
|
cmdObj := gui.os.Cmd.New(
|
||||||
fmt.Sprintf("git diff --submodule --no-ext-diff --color %s", gui.diffStr()),
|
fmt.Sprintf("git diff --submodule --no-ext-diff --color %s", gui.diffStr()),
|
||||||
)
|
)
|
||||||
task := NewRunPtyTask(cmdObj.GetCmd())
|
task := NewRunPtyTask(cmdObj.GetCmd())
|
||||||
|
|
|
@ -219,7 +219,7 @@ func (gui *Gui) handleCopySelectedSideContextItemToClipboard() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.c.LogAction(gui.c.Tr.Actions.CopyToClipboard)
|
gui.c.LogAction(gui.c.Tr.Actions.CopyToClipboard)
|
||||||
if err := gui.OSCommand.CopyToClipboard(itemId); err != nil {
|
if err := gui.os.CopyToClipboard(itemId); err != nil {
|
||||||
return gui.c.Error(err)
|
return gui.c.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ func (gui *Gui) withGpgHandling(cmdObj oscommands.ICmdObj, waitingStatus string,
|
||||||
|
|
||||||
useSubprocess := gui.git.Config.UsingGpg()
|
useSubprocess := gui.git.Config.UsingGpg()
|
||||||
if useSubprocess {
|
if useSubprocess {
|
||||||
success, err := gui.runSubprocessWithSuspense(gui.OSCommand.Cmd.NewShell(cmdObj.ToString()))
|
success, err := gui.runSubprocessWithSuspense(gui.os.Cmd.NewShell(cmdObj.ToString()))
|
||||||
if success && onSuccess != nil {
|
if success && onSuccess != nil {
|
||||||
if err := onSuccess(); err != nil {
|
if err := onSuccess(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -36,7 +36,7 @@ func (gui *Gui) withGpgHandling(cmdObj oscommands.ICmdObj, waitingStatus string,
|
||||||
|
|
||||||
func (gui *Gui) RunAndStream(cmdObj oscommands.ICmdObj, waitingStatus string, onSuccess func() error) error {
|
func (gui *Gui) RunAndStream(cmdObj oscommands.ICmdObj, waitingStatus string, onSuccess func() error) error {
|
||||||
return gui.c.WithWaitingStatus(waitingStatus, func() error {
|
return gui.c.WithWaitingStatus(waitingStatus, func() error {
|
||||||
cmdObj := gui.OSCommand.Cmd.NewShell(cmdObj.ToString())
|
cmdObj := gui.os.Cmd.NewShell(cmdObj.ToString())
|
||||||
cmdObj.AddEnvVars("TERM=dumb")
|
cmdObj.AddEnvVars("TERM=dumb")
|
||||||
cmdWriter := gui.getCmdWriter()
|
cmdWriter := gui.getCmdWriter()
|
||||||
cmd := cmdObj.GetCmd()
|
cmd := cmdObj.GetCmd()
|
||||||
|
|
|
@ -83,9 +83,9 @@ type Repo string
|
||||||
// Gui wraps the gocui Gui object which handles rendering and events
|
// Gui wraps the gocui Gui object which handles rendering and events
|
||||||
type Gui struct {
|
type Gui struct {
|
||||||
*common.Common
|
*common.Common
|
||||||
g *gocui.Gui
|
g *gocui.Gui
|
||||||
git *commands.GitCommand
|
git *commands.GitCommand
|
||||||
OSCommand *oscommands.OSCommand
|
os *oscommands.OSCommand
|
||||||
|
|
||||||
// this is the state of the GUI for the current repo
|
// this is the state of the GUI for the current repo
|
||||||
State *GuiRepoState
|
State *GuiRepoState
|
||||||
|
@ -318,7 +318,7 @@ func (gui *Gui) onNewRepo(filterPath string, reuseState bool) error {
|
||||||
var err error
|
var err error
|
||||||
gui.git, err = commands.NewGitCommand(
|
gui.git, err = commands.NewGitCommand(
|
||||||
gui.Common,
|
gui.Common,
|
||||||
gui.OSCommand,
|
gui.os,
|
||||||
git_config.NewStdCachedGitConfig(gui.Log),
|
git_config.NewStdCachedGitConfig(gui.Log),
|
||||||
gui.Mutexes.SyncMutex,
|
gui.Mutexes.SyncMutex,
|
||||||
)
|
)
|
||||||
|
@ -479,7 +479,7 @@ func NewGui(
|
||||||
|
|
||||||
osCommand := oscommands.NewOSCommand(cmn, oscommands.GetPlatform(), guiIO)
|
osCommand := oscommands.NewOSCommand(cmn, oscommands.GetPlatform(), guiIO)
|
||||||
|
|
||||||
gui.OSCommand = osCommand
|
gui.os = osCommand
|
||||||
|
|
||||||
gui.watchFilesForChanges()
|
gui.watchFilesForChanges()
|
||||||
|
|
||||||
|
@ -509,7 +509,7 @@ func NewGui(
|
||||||
|
|
||||||
func (gui *Gui) resetControllers() {
|
func (gui *Gui) resetControllers() {
|
||||||
controllerCommon := gui.c
|
controllerCommon := gui.c
|
||||||
osCommand := gui.OSCommand
|
osCommand := gui.os
|
||||||
rebaseHelper := controllers.NewRebaseHelper(controllerCommon, gui.State.Contexts, gui.git, gui.takeOverMergeConflictScrolling)
|
rebaseHelper := controllers.NewRebaseHelper(controllerCommon, gui.State.Contexts, gui.git, gui.takeOverMergeConflictScrolling)
|
||||||
model := gui.State.Model
|
model := gui.State.Model
|
||||||
gui.helpers = &Helpers{
|
gui.helpers = &Helpers{
|
||||||
|
@ -977,7 +977,7 @@ func (gui *Gui) loadNewRepo() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gui.OSCommand.UpdateWindowTitle(); err != nil {
|
if err := gui.os.UpdateWindowTitle(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,9 +44,9 @@ func (gui *Gui) handleInfoClick() error {
|
||||||
|
|
||||||
// if we're not in an active mode we show the donate button
|
// if we're not in an active mode we show the donate button
|
||||||
if cx <= len(gui.c.Tr.Donate) {
|
if cx <= len(gui.c.Tr.Donate) {
|
||||||
return gui.OSCommand.OpenLink(constants.Links.Donate)
|
return gui.os.OpenLink(constants.Links.Donate)
|
||||||
} else if cx <= len(gui.c.Tr.Donate)+1+len(gui.c.Tr.AskQuestion) {
|
} else if cx <= len(gui.c.Tr.Donate)+1+len(gui.c.Tr.AskQuestion) {
|
||||||
return gui.OSCommand.OpenLink(constants.Links.Discussions)
|
return gui.os.OpenLink(constants.Links.Discussions)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ func (gui *Gui) copySelectedToClipboard() error {
|
||||||
selected := state.PlainRenderSelected()
|
selected := state.PlainRenderSelected()
|
||||||
|
|
||||||
gui.c.LogAction(gui.c.Tr.Actions.CopySelectedTextToClipboard)
|
gui.c.LogAction(gui.c.Tr.Actions.CopySelectedTextToClipboard)
|
||||||
if err := gui.OSCommand.CopyToClipboard(selected); err != nil {
|
if err := gui.os.CopyToClipboard(selected); err != nil {
|
||||||
return gui.c.Error(err)
|
return gui.c.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ func (gui *Gui) handleOpenFileAtLine() error {
|
||||||
|
|
||||||
// need to look at current index, then work out what my hunk's header information is, and see how far my line is away from the hunk header
|
// need to look at current index, then work out what my hunk's header information is, and see how far my line is away from the hunk header
|
||||||
lineNumber := state.CurrentLineNumber()
|
lineNumber := state.CurrentLineNumber()
|
||||||
if err := gui.editFileAtLine(filename, lineNumber); err != nil {
|
if err := gui.os.OpenFileAtLine(filename, lineNumber); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ func (gui *Gui) createPullRequest(from string, to string) error {
|
||||||
|
|
||||||
gui.c.LogAction(gui.c.Tr.Actions.OpenPullRequest)
|
gui.c.LogAction(gui.c.Tr.Actions.OpenPullRequest)
|
||||||
|
|
||||||
if err := gui.OSCommand.OpenLink(url); err != nil {
|
if err := gui.os.OpenLink(url); err != nil {
|
||||||
return gui.c.Error(err)
|
return gui.c.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ func (gui *Gui) recordDirectory(dirName string) error {
|
||||||
if newDirFilePath == "" {
|
if newDirFilePath == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return gui.OSCommand.CreateFileWithContent(newDirFilePath, dirName)
|
return gui.os.CreateFileWithContent(newDirFilePath, dirName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleQuitWithoutChangingDirectory() error {
|
func (gui *Gui) handleQuitWithoutChangingDirectory() error {
|
||||||
|
|
|
@ -62,7 +62,7 @@ func (gui *Gui) dispatchSwitchToRepo(path string, reuse bool) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := commands.VerifyInGitRepo(gui.OSCommand); err != nil {
|
if err := commands.VerifyInGitRepo(gui.os); err != nil {
|
||||||
if err := os.Chdir(originalPath); err != nil {
|
if err := os.Chdir(originalPath); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue