You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Victorique/vtqe/tools/cd.go

39 lines
716 B
Go

5 years ago
// +build windows
package tools
import (
"bufio"
"os"
"os/exec"
"path/filepath"
"github.com/spf13/cobra"
)
var cdcmd = &cobra.Command{
Use: "cd",
Short: "便捷进入文件夹",
Long: "使用stdin便捷进入文件夹",
Run: func(this *cobra.Command, args []string) {
fileInfo, _ := os.Stdin.Stat()
if (fileInfo.Mode() & os.ModeNamedPipe) != os.ModeNamedPipe {
if len(args) != 1 {
os.Exit(1)
} else {
exec.Command("cmd.exe", "/c", "explorer "+filepath.Dir(args[0])).Run()
return
}
}
s := bufio.NewScanner(os.Stdin)
for s.Scan() {
exec.Command("cmd.exe", "/c", "explorer "+filepath.Dir(s.Text())).Run()
return
}
},
}
func init() {
Maincmd.AddCommand(cdcmd)
}