all repos

viye @ 9f9e365d9f5437ceeb417be7809b0c3c43e42601

my shot at reimplementing xiki
4 files changed, 42 insertions(+), 14 deletions(-)
show files content
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-07-23 12:27:11 +0300
Authored at: 2026-07-22 18:17:44 +0300
Change ID: mwsnomopyzskzzzmzuvnuytvpnrtmply
Parent: 2ee545d
M internal/plumbing/files/files.go
···
        1
        1
         package files

      
        2
        2
         

      
        3
        3
         import (

      
        
        4
        +	"bufio"

      
        
        5
        +	"fmt"

      
        4
        6
         	"os"

      
        5
        7
         	"path/filepath"

      
        6
        8
         	"strings"

      
        7
        9
         

      
        8
        
        -	"github.com/olexsmir/viye/internal/osutil"

      
        9
        10
         	"github.com/olexsmir/viye/internal/viye"

      
        10
        11
         )

      
        11
        12
         

      ···
        33
        34
         	switch {

      
        34
        35
         	case info.IsDir():

      
        35
        36
         		if len(ctx.Path) == 1 {

      
        36
        
        -			return listDir(path)

      
        
        37
        +			ls, err := listDir(path)

      
        
        38
        +			if err != nil {

      
        
        39
        +				return "", err

      
        
        40
        +			}

      
        
        41
        +			return viye.FormatBulltlist(ls), nil

      
        37
        42
         		}

      
        38
        43
         		ctx.Dir = path

      
        39
        44
         		ctx.Path = ctx.Path[1:]

      ···
        43
        48
         	// 	return runExec(path)

      
        44
        49
         

      
        45
        50
         	default:

      
        46
        
        -		return "", osutil.Open(path)

      
        
        51
        +		s, err := head(path, 10)

      
        
        52
        +		if err != nil {

      
        
        53
        +			return "", err

      
        
        54
        +		}

      
        
        55
        +		return s, nil

      
        47
        56
         	}

      
        48
        57
         }

      
        49
        58
         

      ···
        79
        88
         	return b.String(), nil

      
        80
        89
         }

      
        81
        90
         

      
        82
        
        -// func runExec(path string) (string, error) {

      
        83
        
        -// 	cmd := exec.Command(path)

      
        84
        
        -// 	out, err := cmd.Output()

      
        85
        
        -// 	if err != nil {

      
        86
        
        -// 		return "", err

      
        87
        
        -// 	}

      
        88
        
        -// 	return string(out), nil

      
        89
        
        -// }

      
        
        91
        +func head(path string, n int) (string, error) {

      
        
        92
        +	f, err := os.Open(path)

      
        
        93
        +	if err != nil {

      
        
        94
        +		return "", err

      
        
        95
        +	}

      
        
        96
        +	defer f.Close()

      
        
        97
        +

      
        
        98
        +	sc := bufio.NewScanner(f)

      
        
        99
        +	var b strings.Builder

      
        
        100
        +	for i := 0; i < n && sc.Scan(); i++ {

      
        
        101
        +		fmt.Fprintf(&b, "| %s\n", sc.Text())

      
        
        102
        +	}

      
        
        103
        +	if sc.Scan() {

      
        
        104
        +		b.WriteString("| ...\n")

      
        
        105
        +	}

      
        
        106
        +	return b.String(), sc.Err()

      
        
        107
        +}

      
M internal/plumbing/gobin/gobin.go
···
        68
        68
         	cmd := exec.Command("go", append([]string{subcmd}, args...)...)

      
        69
        69
         	cmd.Dir = dir

      
        70
        70
         	out, _ := cmd.CombinedOutput()

      
        71
        
        -	return viye.Indent(string(out)), nil

      
        
        71
        +	return viye.FormatOutput(string(out)), nil

      
        72
        72
         }

      
M internal/plumbing/shell/shell.go
···
        35
        35
         				return "", fmt.Errorf("timeout: command exceeded 5s")

      
        36
        36
         			}

      
        37
        37
         		}

      
        38
        
        -		return viye.Indent(string(out)), nil

      
        
        38
        +		return viye.FormatOutput(string(out)), nil

      
        39
        39
         

      
        40
        40
         	case isBGCmd(ctx):

      
        41
        41
         		cmd := exec.Command("sh", "-c", strings.Join(ctx.Args, " "))

      
M internal/viye/format.go
···
        2
        2
         

      
        3
        3
         import "strings"

      
        4
        4
         

      
        5
        
        -func Indent(s string) string {

      
        
        5
        +func FormatOutput(s string) string {

      
        6
        6
         	s = strings.TrimSuffix(s, "\n")

      
        7
        7
         	if s == "" {

      
        8
        8
         		return ""

      ···
        17
        17
         	}

      
        18
        18
         	return strings.Join(lines, "\n") + "\n"

      
        19
        19
         }

      
        
        20
        +

      
        
        21
        +func FormatBulltlist(s string) string {

      
        
        22
        +	lines := strings.Split(s, "\n")

      
        
        23
        +	for i, line := range lines {

      
        
        24
        +		if line != "" {

      
        
        25
        +			lines[i] = "- " + line

      
        
        26
        +		}

      
        
        27
        +	}

      
        
        28
        +	return strings.Join(lines, "\n") + "\n"

      
        
        29
        +}