mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
feat: faster command time
This commit is contained in:
parent
0250e8d5d1
commit
408b94fcd4
|
@ -1,7 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
@ -138,17 +139,34 @@ func (env *environment) getPlatform() string {
|
|||
}
|
||||
|
||||
func (env *environment) runCommand(command string, args ...string) (string, error) {
|
||||
out, err := exec.Command(command, args...).Output()
|
||||
|
||||
var exerr *exec.ExitError
|
||||
if errors.As(err, &exerr) {
|
||||
return "", &commandError{exitCode: exerr.ExitCode()}
|
||||
cmd := exec.Command(command, args...)
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return strings.TrimSpace(string(out)), nil
|
||||
defer func() {
|
||||
_ = cmd.Process.Kill()
|
||||
}()
|
||||
output := new(bytes.Buffer)
|
||||
defer output.Reset()
|
||||
buf := bufio.NewReader(stdout)
|
||||
multiline := false
|
||||
for {
|
||||
line, _, _ := buf.ReadLine()
|
||||
if line == nil {
|
||||
break
|
||||
}
|
||||
if multiline {
|
||||
output.WriteString("\n")
|
||||
}
|
||||
output.Write(line)
|
||||
multiline = true
|
||||
}
|
||||
return output.String(), nil
|
||||
}
|
||||
|
||||
func (env *environment) runShellCommand(shell, command string) string {
|
||||
|
|
Loading…
Reference in a new issue