Skip to content
Myr

proxy_windows.go

This file

Path

src/proxy_windows.go

85 lines · 1.5 KiB · Go

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than 76efddd point at it.

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

lines 1–85why, one step back
1//go:build windows
23package fzf45import (6 "fmt"7 "io"8 "os/exec"9 "strconv"10 "strings"11 "sync/atomic"12)1314var shPath atomic.Value1516func sh(bash bool) (string, error) {17 if cached := shPath.Load(); cached != nil {18 return cached.(string), nil19 }2021 name := "sh"22 if bash {23 name = "bash"24 }25 cmd := exec.Command("cygpath", "-w", "/usr/bin/"+name)26 bytes, err := cmd.Output()27 if err != nil {28 return "", err29 }3031 sh := strings.TrimSpace(string(bytes))32 shPath.Store(sh)33 return sh, nil34}3536func mkfifo(path string, mode uint32) (string, error) {37 m := strconv.FormatUint(uint64(mode), 8)38 sh, err := sh(false)39 if err != nil {40 return path, err41 }42 cmd := exec.Command(sh, "-c", fmt.Sprintf(`command mkfifo -m %s %q`, m, path))43 if err := cmd.Run(); err != nil {44 return path, err45 }46 return path + ".lnk", nil47}4849func withOutputPipe(output string, task func(io.ReadCloser)) error {50 sh, err := sh(false)51 if err != nil {52 return err53 }54 cmd := exec.Command(sh, "-c", fmt.Sprintf(`command cat %q`, output))55 outputFile, err := cmd.StdoutPipe()56 if err != nil {57 return err58 }59 if err := cmd.Start(); err != nil {60 return err61 }6263 task(outputFile)64 cmd.Wait()65 return nil66}6768func withInputPipe(input string, task func(io.WriteCloser)) error {69 sh, err := sh(false)70 if err != nil {71 return err72 }73 cmd := exec.Command(sh, "-c", fmt.Sprintf(`command cat - > %q`, input))74 inputFile, err := cmd.StdinPipe()75 if err != nil {76 return err77 }78 if err := cmd.Start(); err != nil {79 return err80 }81 task(inputFile)82 inputFile.Close()83 cmd.Wait()84 return nil85}