summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorskanehira <sho19921005@gmail.com>2019-10-23 20:24:23 +0900
committerskanehira <sho19921005@gmail.com>2019-10-23 20:24:49 +0900
commit343fa7fe5a06e696d08382a476405676a6a2c364 (patch)
tree5b83821a7a744911875eae56be0781d3e269930e
parent8e9c18f327611e3e25ad229e17db1ed2a975d430 (diff)
add PS_ARGS to change display process info.1.2.1
-rw-r--r--README.md17
-rw-r--r--gui/env.go11
-rw-r--r--gui/processManager.go5
3 files changed, 29 insertions, 4 deletions
diff --git a/README.md b/README.md
index b13aa17..001d49b 100644
--- a/README.md
+++ b/README.md
@@ -7,6 +7,10 @@ This is TUI process monitor written in Go.
- Monitor process's list, info, tree
- Kill process
+## Support OS
+- Mac
+- Linux
+
## Installation
```sh
$ git clone https://github.com/skanehira/pst
@@ -14,9 +18,16 @@ $ cd pst
$ go install
```
-## Support OS
-- Mac
-- Linux
+## Options
+You can change the process info to be displayed with environment `PS_ARGS`.
+
+Default `PS_ARGS` value is `pid,ppid,%cpu,%mem,lstart,user,command`.
+
+e.g make alias and use it.
+
+```sh
+alias pst="env PS_ARGS=%cpu,%mem,lstart pst"
+```
## Usage
```sh
diff --git a/gui/env.go b/gui/env.go
new file mode 100644
index 0000000..337b6b0
--- /dev/null
+++ b/gui/env.go
@@ -0,0 +1,11 @@
+package gui
+
+import "os"
+
+func GetEnv(key string, defaultValue string) string {
+ if v := os.Getenv(key); v != "" {
+ return v
+ }
+
+ return defaultValue
+}
diff --git a/gui/processManager.go b/gui/processManager.go
index 3bc3f74..1bd6926 100644
--- a/gui/processManager.go
+++ b/gui/processManager.go
@@ -2,6 +2,7 @@ package gui
import (
"bytes"
+ "errors"
"fmt"
"log"
"os"
@@ -16,6 +17,8 @@ import (
"github.com/rivo/tview"
)
+var psArgs = GetEnv("PS_ARGS", "pid,ppid,%cpu,%mem,lstart,user,command")
+
type ProcessManager struct {
*tview.Table
processes []Process
@@ -171,7 +174,7 @@ func (p *ProcessManager) Info(pid int) (string, error) {
}
buf := bytes.Buffer{}
- cmd := exec.Command("ps", "-o", "pid,ppid,%cpu,%mem,lstart,user,command", "-p", strconv.Itoa(pid))
+ cmd := exec.Command("ps", "-o", psArgs, "-p", strconv.Itoa(pid))
cmd.Stdout = &buf
cmd.Stderr = &buf
if err := cmd.Run(); err != nil {