summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmd/gdu/app/app.go9
-rw-r--r--cmd/gdu/main.go10
-rw-r--r--internal/common/ignore.go1
-rw-r--r--internal/common/ignore_test.go2
-rw-r--r--internal/testdir/test_dir.go4
-rw-r--r--pkg/analyze/dir_linux_test.go4
-rw-r--r--pkg/analyze/dir_test.go6
-rw-r--r--pkg/analyze/memory.go12
-rw-r--r--pkg/analyze/sequential_test.go6
-rw-r--r--pkg/analyze/stored_test.go19
-rw-r--r--pkg/remove/parallel_linux_test.go4
-rw-r--r--pkg/remove/remove_linux_test.go2
-rw-r--r--report/export_test.go4
-rw-r--r--stdout/stdout_test.go8
-rw-r--r--tui/actions.go6
-rw-r--r--tui/actions_test.go4
-rw-r--r--tui/exec_other.go76
-rw-r--r--tui/exec_windows.go66
-rw-r--r--tui/export_test.go2
-rw-r--r--tui/keys_test.go8
20 files changed, 137 insertions, 116 deletions
diff --git a/cmd/gdu/app/app.go b/cmd/gdu/app/app.go
index f6def74..4169077 100644
--- a/cmd/gdu/app/app.go
+++ b/cmd/gdu/app/app.go
@@ -4,14 +4,13 @@ import (
"fmt"
"io"
"io/fs"
+ "net/http"
+ "net/http/pprof"
"os"
"path/filepath"
"runtime"
"strings"
- "net/http"
- "net/http/pprof"
-
log "github.com/sirupsen/logrus"
"github.com/dundee/gdu/v5/build"
@@ -215,7 +214,7 @@ func (a *App) createUI() (UI, error) {
if a.Flags.OutputFile == "-" {
output = os.Stdout
} else {
- output, err = os.OpenFile(a.Flags.OutputFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
+ output, err = os.OpenFile(a.Flags.OutputFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)
if err != nil {
return nil, fmt.Errorf("opening output file: %w", err)
}
@@ -357,7 +356,7 @@ func (a *App) runAction(ui UI, path string) error {
if a.Flags.InputFile == "-" {
input = os.Stdin
} else {
- input, err = os.OpenFile(a.Flags.InputFile, os.O_RDONLY, 0600)
+ input, err = os.OpenFile(a.Flags.InputFile, os.O_RDONLY, 0o600)
if err != nil {
return fmt.Errorf("opening input file: %w", err)
}
diff --git a/cmd/gdu/main.go b/cmd/gdu/main.go
index f35e641..a842f10 100644
--- a/cmd/gdu/main.go
+++ b/cmd/gdu/main.go
@@ -19,8 +19,10 @@ import (
"github.com/dundee/gdu/v5/pkg/device"
)
-var af *app.Flags
-var configErr error
+var (
+ af *app.Flags
+ configErr error
+)
var rootCmd = &cobra.Command{
Use: "gdu [directory_to_scan]",
@@ -136,7 +138,7 @@ func runE(command *cobra.Command, args []string) error {
if af.CfgFile == "" {
setDefaultConfigFilePath()
}
- err = os.WriteFile(af.CfgFile, data, 0600)
+ err = os.WriteFile(af.CfgFile, data, 0o600)
if err != nil {
return fmt.Errorf("Error writing config file %s: %w", af.CfgFile, err)
}
@@ -150,7 +152,7 @@ func runE(command *cobra.Command, args []string) error {
if af.LogFile == "-" {
f = os.Stdout
} else {
- f, err = os.OpenFile(af.LogFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
+ f, err = os.OpenFile(af.LogFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)
if err != nil {
return fmt.Errorf("opening log file: %w", err)
}
diff --git a/internal/common/ignore.go b/internal/common/ignore.go
index 2ae1458..366b059 100644
--- a/internal/common/ignore.go
+++ b/internal/common/ignore.go
@@ -48,7 +48,6 @@ func (ui *UI) SetIgnoreFromFile(ignoreFile string) error {
log.Printf("Reading ignoring dir patterns from file '%s'", ignoreFile)
file, err := os.Open(ignoreFile)
-
if err != nil {
return err
}
diff --git a/internal/common/ignore_test.go b/internal/common/ignore_test.go
index 6638644..8ac5c6d 100644
--- a/internal/common/ignore_test.go
+++ b/internal/common/ignore_test.go
@@ -57,7 +57,7 @@ func TestIgnoreByPattern(t *testing.T) {
}
func TestIgnoreFromFile(t *testing.T) {
- file, err := os.OpenFile("ignore", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
+ file, err := os.OpenFile("ignore", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)
if err != nil {
panic(err)
}
diff --git a/internal/testdir/test_dir.go b/internal/testdir/test_dir.go
index d6e3de6..0793921 100644
--- a/internal/testdir/test_dir.go
+++ b/internal/testdir/test_dir.go
@@ -10,10 +10,10 @@ func CreateTestDir() func() {
if err := os.MkdirAll("test_dir/nested/subnested", os.ModePerm); err != nil {
panic(err)
}
- if err := os.WriteFile("test_dir/nested/subnested/file", []byte("hello"), 0600); err != nil {
+ if err := os.WriteFile("test_dir/nested/subnested/file", []byte("hello"), 0o600); err != nil {
panic(err)
}
- if err := os.WriteFile("test_dir/nested/file2", []byte("go"), 0600); err != nil {
+ if err := os.WriteFile("test_dir/nested/file2", []byte("go"), 0o600); err != nil {
panic(err)
}
return func() {
diff --git a/pkg/analyze/dir_linux_test.go b/pkg/analyze/dir_linux_test.go
index 3fd2615..0ea7d23 100644
--- a/pkg/analyze/dir_linux_test.go
+++ b/pkg/analyze/dir_linux_test.go
@@ -19,7 +19,7 @@ func TestErr(t *testing.T) {
err := os.Chmod("test_dir/nested", 0)
assert.Nil(t, err)
defer func() {
- err = os.Chmod("test_dir/nested", 0755)
+ err = os.Chmod("test_dir/nested", 0o755)
assert.Nil(t, err)
}()
@@ -45,7 +45,7 @@ func TestSeqErr(t *testing.T) {
err := os.Chmod("test_dir/nested", 0)
assert.Nil(t, err)
defer func() {
- err = os.Chmod("test_dir/nested", 0755)
+ err = os.Chmod("test_dir/nested", 0o755)
assert.Nil(t, err)
}()
diff --git a/pkg/analyze/dir_test.go b/pkg/analyze/dir_test.go
index 89f6f86..f4de591 100644
--- a/pkg/analyze/dir_test.go
+++ b/pkg/analyze/dir_test.go
@@ -83,7 +83,7 @@ func TestFlags(t *testing.T) {
fin := testdir.CreateTestDir()
defer fin()
- err := os.Mkdir("test_dir/empty", 0644)
+ err := os.Mkdir("test_dir/empty", 0o644)
assert.Nil(t, err)
err = os.Symlink("test_dir/nested/file2", "test_dir/nested/file3")
@@ -137,7 +137,7 @@ func TestFollowSymlink(t *testing.T) {
fin := testdir.CreateTestDir()
defer fin()
- err := os.Mkdir("test_dir/empty", 0644)
+ err := os.Mkdir("test_dir/empty", 0o644)
assert.Nil(t, err)
err = os.Symlink("./file2", "test_dir/nested/file3")
@@ -169,7 +169,7 @@ func TestBrokenSymlinkSkipped(t *testing.T) {
fin := testdir.CreateTestDir()
defer fin()
- err := os.Mkdir("test_dir/empty", 0644)
+ err := os.Mkdir("test_dir/empty", 0o644)
assert.Nil(t, err)
err = os.Symlink("xxx", "test_dir/nested/file3")
diff --git a/pkg/analyze/memory.go b/pkg/analyze/memory.go
index 1bbda0b..fdb1c57 100644
--- a/pkg/analyze/memory.go
+++ b/pkg/analyze/memory.go
@@ -27,14 +27,14 @@ func manageMemoryUsage(c <-chan struct{}) {
}
/*
- Try to balance performance and memory consumption.
+Try to balance performance and memory consumption.
- When less memory is used by gdu than the total free memory of the host,
- Garbage Collection is disabled during the analysis phase at all.
+When less memory is used by gdu than the total free memory of the host,
+Garbage Collection is disabled during the analysis phase at all.
- Otherwise GC is enabled.
- The more memory is used and the less memory is free,
- the more often will the GC happen.
+Otherwise GC is enabled.
+The more memory is used and the less memory is free,
+the more often will the GC happen.
*/
func rebalanceGC(disabledGC *bool) {
memStats := runtime.MemStats{}
diff --git a/pkg/analyze/sequential_test.go b/pkg/analyze/sequential_test.go
index a791e4a..b3e9592 100644
--- a/pkg/analyze/sequential_test.go
+++ b/pkg/analyze/sequential_test.go
@@ -83,7 +83,7 @@ func TestFlagsSeq(t *testing.T) {
fin := testdir.CreateTestDir()
defer fin()
- err := os.Mkdir("test_dir/empty", 0644)
+ err := os.Mkdir("test_dir/empty", 0o644)
assert.Nil(t, err)
err = os.Symlink("test_dir/nested/file2", "test_dir/nested/file3")
@@ -137,7 +137,7 @@ func TestFollowSymlinkSeq(t *testing.T) {
fin := testdir.CreateTestDir()
defer fin()
- err := os.Mkdir("test_dir/empty", 0644)
+ err := os.Mkdir("test_dir/empty", 0o644)
assert.Nil(t, err)
err = os.Symlink("./file2", "test_dir/nested/file3")
@@ -169,7 +169,7 @@ func TestBrokenSymlinkSkippedSeq(t *testing.T) {
fin := testdir.CreateTestDir()
defer fin()
- err := os.Mkdir("test_dir/empty", 0644)
+ err := os.Mkdir("test_dir/empty", 0o644)
assert.Nil(t, err)
err = os.Symlink("xxx", "test_dir/nested/file3")
diff --git a/pkg/analyze/stored_test.go b/pkg/analyze/stored_test.go
index 1082942..fd69f5a 100644
--- a/pkg/analyze/stored_test.go
+++ b/pkg/analyze/stored_test.go
@@ -117,6 +117,7 @@ func TestParentDirGetNamePanics(t *testing.T) {
dir := &ParentDir{}
dir.GetName()
}
+
func TestParentDirGetFlagPanics(t *testing.T) {
defer func() {
if r := recover(); r != nil {
@@ -126,6 +127,7 @@ func TestParentDirGetFlagPanics(t *testing.T) {
dir := &ParentDir{}
dir.GetFlag()
}
+
func TestParentDirIsDirPanics(t *testing.T) {
defer func() {
if r := recover(); r != nil {
@@ -135,6 +137,7 @@ func TestParentDirIsDirPanics(t *testing.T) {
dir := &ParentDir{}
dir.IsDir()
}
+
func TestParentDirGetSizePanics(t *testing.T) {
defer func() {
if r := recover(); r != nil {
@@ -144,6 +147,7 @@ func TestParentDirGetSizePanics(t *testing.T) {
dir := &ParentDir{}
dir.GetSize()
}
+
func TestParentDirGetTypePanics(t *testing.T) {
defer func() {
if r := recover(); r != nil {
@@ -153,6 +157,7 @@ func TestParentDirGetTypePanics(t *testing.T) {
dir := &ParentDir{}
dir.GetType()
}
+
func TestParentDirGetUsagePanics(t *testing.T) {
defer func() {
if r := recover(); r != nil {
@@ -162,6 +167,7 @@ func TestParentDirGetUsagePanics(t *testing.T) {
dir := &ParentDir{}
dir.GetUsage()
}
+
func TestParentDirGetMtimePanics(t *testing.T) {
defer func() {
if r := recover(); r != nil {
@@ -171,6 +177,7 @@ func TestParentDirGetMtimePanics(t *testing.T) {
dir := &ParentDir{}
dir.GetMtime()
}
+
func TestParentDirGetItemCountPanics(t *testing.T) {
defer func() {
if r := recover(); r != nil {
@@ -180,6 +187,7 @@ func TestParentDirGetItemCountPanics(t *testing.T) {
dir := &ParentDir{}
dir.GetItemCount()
}
+
func TestParentDirGetParentPanics(t *testing.T) {
defer func() {
if r := recover(); r != nil {
@@ -189,6 +197,7 @@ func TestParentDirGetParentPanics(t *testing.T) {
dir := &ParentDir{}
dir.GetParent()
}
+
func TestParentDirSetParentPanics(t *testing.T) {
defer func() {
if r := recover(); r != nil {
@@ -198,6 +207,7 @@ func TestParentDirSetParentPanics(t *testing.T) {
dir := &ParentDir{}
dir.SetParent(nil)
}
+
func TestParentDirGetMultiLinkedInodePanics(t *testing.T) {
defer func() {
if r := recover(); r != nil {
@@ -207,6 +217,7 @@ func TestParentDirGetMultiLinkedInodePanics(t *testing.T) {
dir := &ParentDir{}
dir.GetMultiLinkedInode()
}
+
func TestParentDirEncodeJSONPanics(t *testing.T) {
defer func() {
if r := recover(); r != nil {
@@ -217,6 +228,7 @@ func TestParentDirEncodeJSONPanics(t *testing.T) {
err := dir.EncodeJSON(nil, false)
assert.NoError(t, err)
}
+
func TestParentDirUpdateStatsPanics(t *testing.T) {
defer func() {
if r := recover(); r != nil {
@@ -226,6 +238,7 @@ func TestParentDirUpdateStatsPanics(t *testing.T) {
dir := &ParentDir{}
dir.UpdateStats(nil)
}
+
func TestParentDirAddFilePanics(t *testing.T) {
defer func() {
if r := recover(); r != nil {
@@ -235,6 +248,7 @@ func TestParentDirAddFilePanics(t *testing.T) {
dir := &ParentDir{}
dir.AddFile(nil)
}
+
func TestParentDirGetFilesPanics(t *testing.T) {
defer func() {
if r := recover(); r != nil {
@@ -244,6 +258,7 @@ func TestParentDirGetFilesPanics(t *testing.T) {
dir := &ParentDir{}
dir.GetFiles()
}
+
func TestParentDirGetFilesLockedPanics(t *testing.T) {
defer func() {
if r := recover(); r != nil {
@@ -253,6 +268,7 @@ func TestParentDirGetFilesLockedPanics(t *testing.T) {
dir := &ParentDir{}
dir.GetFilesLocked()
}
+
func TestParentDirRLockPanics(t *testing.T) {
defer func() {
if r := recover(); r != nil {
@@ -262,6 +278,7 @@ func TestParentDirRLockPanics(t *testing.T) {
dir := &ParentDir{}
dir.RLock()
}
+
func TestParentDirSetFilesPanics(t *testing.T) {
defer func() {
if r := recover(); r != nil {
@@ -271,6 +288,7 @@ func TestParentDirSetFilesPanics(t *testing.T) {
dir := &ParentDir{}
dir.SetFiles(nil)
}
+
func TestParentDirRemoveFilePanics(t *testing.T) {
defer func() {
if r := recover(); r != nil {
@@ -280,6 +298,7 @@ func TestParentDirRemoveFilePanics(t *testing.T) {
dir := &ParentDir{}
dir.RemoveFile(nil)
}
+
func TestParentDirGetItemStatsPanics(t *testing.T) {
defer func() {
if r := recover(); r != nil {
diff --git a/pkg/remove/parallel_linux_test.go b/pkg/remove/parallel_linux_test.go
index 0f6e61f..fca34ef 100644
--- a/pkg/remove/parallel_linux_test.go
+++ b/pkg/remove/parallel_linux_test.go
@@ -20,7 +20,7 @@ func TestRemoveItemFromDirParallelWithErr(t *testing.T) {
err := os.Chmod("test_dir/nested", 0)
assert.Nil(t, err)
defer func() {
- err = os.Chmod("test_dir/nested", 0755)
+ err = os.Chmod("test_dir/nested", 0o755)
assert.Nil(t, err)
}()
@@ -49,7 +49,7 @@ func TestRemoveItemFromDirParallelWithErr2(t *testing.T) {
err := os.Chmod("test_dir/nested/subnested", 0)
assert.Nil(t, err)
defer func() {
- err = os.Chmod("test_dir/nested/subnested", 0755)
+ err = os.Chmod("test_dir/nested/subnested", 0o755)
assert.Nil(t, err)
}()
diff --git a/pkg/remove/remove_linux_test.go b/pkg/remove/remove_linux_test.go
index c09d85d..19fc503 100644
--- a/pkg/remove/remove_linux_test.go
+++ b/pkg/remove/remove_linux_test.go
@@ -19,7 +19,7 @@ func TestRemoveFileWithErr(t *testing.T) {
err := os.Chmod("test_dir/nested", 0)
assert.Nil(t, err)
defer func() {
- err = os.Chmod("test_dir/nested", 0755)
+ err = os.Chmod("test_dir/nested", 0o755)
assert.Nil(t, err)
}()
diff --git a/report/export_test.go b/report/export_test.go
index f35778a..c1931cd 100644
--- a/report/export_test.go
+++ b/report/export_test.go
@@ -74,7 +74,7 @@ func TestExportToFile(t *testing.T) {
fin := testdir.CreateTestDir()
defer fin()
- reportOutput, err := os.OpenFile("output.json", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
+ reportOutput, err := os.OpenFile("output.json", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
assert.Nil(t, err)
defer func() {
os.Remove("output.json")
@@ -89,7 +89,7 @@ func TestExportToFile(t *testing.T) {
err = ui.StartUILoop()
assert.Nil(t, err)
- reportOutput, err = os.OpenFile("output.json", os.O_RDONLY, 0644)
+ reportOutput, err = os.OpenFile("output.json", os.O_RDONLY, 0o644)
assert.Nil(t, err)
_, err = reportOutput.Seek(0, 0)
assert.Nil(t, err)
diff --git a/stdout/stdout_test.go b/stdout/stdout_test.go
index 2146367..240ed13 100644
--- a/stdout/stdout_test.go
+++ b/stdout/stdout_test.go
@@ -149,7 +149,7 @@ func TestShowDevicesWithColor(t *testing.T) {
}
func TestReadAnalysisWithColor(t *testing.T) {
- input, err := os.OpenFile("../internal/testdata/test.json", os.O_RDONLY, 0644)
+ input, err := os.OpenFile("../internal/testdata/test.json", os.O_RDONLY, 0o644)
assert.Nil(t, err)
output := bytes.NewBuffer(make([]byte, 10))
@@ -162,7 +162,7 @@ func TestReadAnalysisWithColor(t *testing.T) {
}
func TestReadAnalysisBw(t *testing.T) {
- input, err := os.OpenFile("../internal/testdata/test.json", os.O_RDONLY, 0644)
+ input, err := os.OpenFile("../internal/testdata/test.json", os.O_RDONLY, 0o644)
assert.Nil(t, err)
output := bytes.NewBuffer(make([]byte, 10))
@@ -175,7 +175,7 @@ func TestReadAnalysisBw(t *testing.T) {
}
func TestReadAnalysisWithWrongFile(t *testing.T) {
- input, err := os.OpenFile("../internal/testdata/wrong.json", os.O_RDONLY, 0644)
+ input, err := os.OpenFile("../internal/testdata/wrong.json", os.O_RDONLY, 0o644)
assert.Nil(t, err)
output := bytes.NewBuffer(make([]byte, 10))
@@ -187,7 +187,7 @@ func TestReadAnalysisWithWrongFile(t *testing.T) {
}
func TestReadAnalysisWithSummarize(t *testing.T) {
- input, err := os.OpenFile("../internal/testdata/test.json", os.O_RDONLY, 0644)
+ input, err := os.OpenFile("../internal/testdata/test.json", os.O_RDONLY, 0o644)
assert.Nil(t, err)
output := bytes.NewBuffer(make([]byte, 10))
diff --git a/tui/actions.go b/tui/actions.go
index 5ca16ee..92347e7 100644
--- a/tui/actions.go
+++ b/tui/actions.go
@@ -22,8 +22,10 @@ import (
"github.com/rivo/tview"
)
-const defaultLinesCount = 500
-const linesTreshold = 20
+const (
+ defaultLinesCount = 500
+ linesTreshold = 20
+)
// ListDevices lists mounted devices and shows their disk usage
func (ui *UI) ListDevices(getter device.DevicesInfoGetter) error {
diff --git a/tui/actions_test.go b/tui/actions_test.go
index b4d2af0..8c5e266 100644
--- a/tui/actions_test.go
+++ b/tui/actions_test.go
@@ -152,7 +152,7 @@ func TestReadAnalysis(t *testing.T) {
simScreen := testapp.CreateSimScreen()
defer simScreen.Fini()
- input, err := os.OpenFile("../internal/testdata/test.json", os.O_RDONLY, 0644)
+ input, err := os.OpenFile("../internal/testdata/test.json", os.O_RDONLY, 0o644)
assert.Nil(t, err)
app := testapp.CreateMockedApp(true)
@@ -175,7 +175,7 @@ func TestReadAnalysisWithWrongFile(t *testing.T) {
simScreen := testapp.CreateSimScreen()
defer simScreen.Fini()
- input, err := os.OpenFile("../internal/testdata/wrong.json", os.O_RDONLY, 0644)
+ input, err := os.OpenFile("../internal/testdata/wrong.json", os.O_RDONLY, 0o644)
assert.Nil(t, err)
app := testapp.CreateMockedApp(true)
diff --git a/tui/exec_other.go b/tui/exec_other.go
index 6fd0b91..e05e4e5 100644
--- a/tui/exec_other.go
+++ b/tui/exec_other.go
@@ -1,38 +1,38 @@
-//go:build !windows
-// +build !windows
-
-package tui
-
-import (
- "os"
- "syscall"
-)
-
-func getShellBin() string {
- shellbin, ok := os.LookupEnv("SHELL")
- if !ok {
- shellbin = "/bin/bash"
- }
- return shellbin
-}
-
-func (ui *UI) spawnShell() {
- if ui.currentDir == nil {
- return
- }
-
- ui.app.Suspend(func() {
- if err := os.Chdir(ui.currentDirPath); err != nil {
- ui.showErr("Error changing directory", err)
- return
- }
-
- if err := ui.exec(getShellBin(), nil, os.Environ()); err != nil {
- ui.showErr("Error executing shell", err)
- }
- })
-}
-
-func stopProcess() error {
- return syscall.Kill(syscall.Getpid(), syscall.SIGTSTP)
-}
+//go:build !windows
+// +build !windows
+
+package tui
+
+import (
+ "os"
+ "syscall"
+)
+
+func getShellBin() string {
+ shellbin, ok := os.LookupEnv("SHELL")
+ if !ok {
+ shellbin = "/bin/bash"
+ }
+ return shellbin
+}
+
+func (ui *UI) spawnShell() {
+ if ui.currentDir == nil {
+ return
+ }
+
+ ui.app.Suspend(func() {
+ if err := os.Chdir(ui.currentDirPath); err != nil {
+ ui.showErr("Error changing directory", err)
+ return
+ }
+
+ if err := ui.exec(getShellBin(), nil, os.Environ()); err != nil {
+ ui.showErr("Error executing shell", err)
+ }
+ })
+}
+
+func stopProcess() error {
+ return syscall.Kill(syscall.Getpid(), syscall.SIGTSTP)
+}
diff --git a/tui/exec_windows.go b/tui/exec_windows.go
index def10f0..93eb31b 100644
--- a/tui/exec_windows.go
+++ b/tui/exec_windows.go
@@ -1,33 +1,33 @@
-package tui
-
-import (
- "os"
-)
-
-func getShellBin() string {
- shellbin, ok := os.LookupEnv("COMSPEC")
- if !ok {
- shellbin = "C:\\WINDOWS\\System32\\cmd.exe"
- }
- return shellbin
-}
-
-func (ui *UI) spawnShell() {
- if ui.currentDir == nil {
- return
- }
-
- ui.app.Stop()
-
- if err := os.Chdir(ui.currentDirPath); err != nil {
- ui.showErr("Error changing directory", err)
- return
- }
- if err := ui.exec(getShellBin(), nil, os.Environ()); err != nil {
- ui.showErr("Error executing shell", err)
- }
-}
-
-func stopProcess() error {
- return nil
-}
+package tui
+
+import (
+ "os"
+)
+
+func getShellBin() string {
+ shellbin, ok := os.LookupEnv("COMSPEC")
+ if !ok {
+ shellbin = "C:\\WINDOWS\\System32\\cmd.exe"
+ }
+ return shellbin
+}
+
+func (ui *UI) spawnShell() {
+ if ui.currentDir == nil {
+ return
+ }
+
+ ui.app.Stop()
+
+ if err := os.Chdir(ui.currentDirPath); err != nil {
+ ui.showErr("Error changing directory", err)
+ return
+ }
+ if err := ui.exec(getShellBin(), nil, os.Environ()); err != nil {
+ ui.showErr("Error executing shell", err)
+ }
+}
+
+func stopProcess() error {
+ return nil
+}
diff --git a/tui/export_test.go b/tui/export_test.go
index 52fd22c..b7fae0b 100644
--- a/tui/export_test.go
+++ b/tui/export_test.go
@@ -175,7 +175,7 @@ func TestExportAnalysisWithoutRights(t *testing.T) {
err = os.Chmod("export.json", 0)
assert.NoError(t, err)
defer func() {
- err = os.Chmod("export.json", 0755)
+ err = os.Chmod("export.json", 0o755)
assert.Nil(t, err)
err = os.Remove("export.json")
assert.NoError(t, err)
diff --git a/tui/keys_test.go b/tui/keys_test.go
index cb7baa8..7b352c4 100644
--- a/tui/keys_test.go
+++ b/tui/keys_test.go
@@ -217,7 +217,7 @@ func TestSpawnShell(t *testing.T) {
app := testapp.CreateMockedApp(false)
buff := &bytes.Buffer{}
ui := CreateUI(app, simScreen, buff, true, true, false, false, false)
- var called = false
+ called := false
ui.exec = func(argv0 string, argv, envv []string) error {
called = true
return nil
@@ -247,7 +247,7 @@ func TestSpawnShellWithoutDir(t *testing.T) {
app := testapp.CreateMockedApp(false)
buff := &bytes.Buffer{}
ui := CreateUI(app, simScreen, buff, true, true, false, false, false)
- var called = false
+ called := false
ui.exec = func(argv0 string, argv, envv []string) error {
called = true
return nil
@@ -269,7 +269,7 @@ func TestSpawnShellWithWrongDir(t *testing.T) {
app := testapp.CreateMockedApp(false)
buff := &bytes.Buffer{}
ui := CreateUI(app, simScreen, buff, true, true, false, false, false)
- var called = false
+ called := false
ui.exec = func(argv0 string, argv, envv []string) error {
called = true
return nil
@@ -294,7 +294,7 @@ func TestSpawnShellWithError(t *testing.T) {
app := testapp.CreateMockedApp(false)
buff := &bytes.Buffer{}
ui := CreateUI(app, simScreen, buff, true, true, false, false, false)
- var called = false
+ called := false
ui.exec = func(argv0 string, argv, envv []string) error {
called = true
return errors.New("wrong shell")