Compare commits
6 commits
ce5e3e7b5e
...
d0a039c17b
Author | SHA1 | Date | |
---|---|---|---|
d0a039c17b | |||
8ae5a415f6 | |||
e668e19ba0 | |||
67062f7555 | |||
7032eb3a33 | |||
b3d33d5558 |
4 changed files with 34 additions and 12 deletions
13
Makefile
13
Makefile
|
@ -8,8 +8,8 @@ HOST_GOOS=$(shell go env GOOS)
|
||||||
HOST_GOARCH=$(shell go env GOARCH)
|
HOST_GOARCH=$(shell go env GOARCH)
|
||||||
# GOOS=windows GOARCH=386
|
# GOOS=windows GOARCH=386
|
||||||
|
|
||||||
NAME=vedecom-ukko
|
NAME=randomedit
|
||||||
REPO_PATH=bitbucket.com/glenux-corp/vedecom-ukko
|
REPO_PATH=bitbucket.com/glenux-corp/randomedit
|
||||||
BUILD_DIR=$(shell pwd)/_build
|
BUILD_DIR=$(shell pwd)/_build
|
||||||
INSTALL_DIR=$(PREFIX)/bin
|
INSTALL_DIR=$(PREFIX)/bin
|
||||||
SHARE_DIR=$(PREFIX)/share/$(NAME)
|
SHARE_DIR=$(PREFIX)/share/$(NAME)
|
||||||
|
@ -20,14 +20,9 @@ build: vendor ## build executable
|
||||||
@mkdir -p "$(BUILD_DIR)"
|
@mkdir -p "$(BUILD_DIR)"
|
||||||
# go build -i ./...
|
# go build -i ./...
|
||||||
# GOBIN="$(BUILD_DIR)" go install ./...
|
# GOBIN="$(BUILD_DIR)" go install ./...
|
||||||
for binary in "./cmd"/* ; do \
|
for binary in $$(cd cmd ; ls) ; do \
|
||||||
name="$$(basename "$$binary")" ; \
|
name="$$(basename "$$binary")" ; \
|
||||||
go build -i "$$binary" || exit 1 ; \
|
go build -o "_build/$$binary" ./cmd/$$binary/... || exit 1 ; \
|
||||||
if [ -f "$$name.exe" ]; then \
|
|
||||||
mv "$$name.exe" "$(BUILD_DIR)/$$name.exe" || exit 1 ; \
|
|
||||||
else \
|
|
||||||
mv "$$name" "$(BUILD_DIR)/$$name" || exit 1 ; \
|
|
||||||
fi ; \
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,15 @@
|
||||||
|
|
||||||
For when you can't decide what you want to start with.
|
For when you can't decide what you want to start with.
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
Make sure you have a recent version of Golang installed.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
:warning: FIXME
|
Type the following command:
|
||||||
|
|
||||||
|
make build
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|
|
@ -36,21 +36,30 @@ func findFiles(dir string, patterns []string) []string {
|
||||||
func main() {
|
func main() {
|
||||||
var directories []string
|
var directories []string
|
||||||
var patterns []string
|
var patterns []string
|
||||||
|
var verbose bool
|
||||||
|
var editor string
|
||||||
flag.StringArrayVarP(&directories, "dir", "d", []string{"."}, "Look in given directory")
|
flag.StringArrayVarP(&directories, "dir", "d", []string{"."}, "Look in given directory")
|
||||||
flag.StringArrayVarP(&patterns, "pattern", "p", []string{}, "Match given globbing pattern")
|
flag.StringArrayVarP(&patterns, "pattern", "p", []string{}, "Match given globbing pattern")
|
||||||
|
flag.StringVarP(&editor, "editor", "e", "", "Use given editor command")
|
||||||
|
flag.BoolVarP(&verbose, "verbose", "v", false, "Match given globbing pattern")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if len(patterns) < 1 {
|
if len(patterns) < 1 {
|
||||||
patterns = []string{"*.txt", "*.md"}
|
patterns = []string{"*.txt", "*.md"}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fmt.Printf("%#v\n", directories)
|
// fmt.Printf("%#v\n", directories)
|
||||||
editor := os.Getenv("EDITOR")
|
|
||||||
|
if len(editor) < 1 {
|
||||||
|
editor = os.Getenv("EDITOR")
|
||||||
|
}
|
||||||
|
|
||||||
// walk dirs & merge result
|
// walk dirs & merge result
|
||||||
filesSet := map[string]int{}
|
filesSet := map[string]int{}
|
||||||
for _, dir := range directories {
|
for _, dir := range directories {
|
||||||
for _, file := range findFiles(dir, patterns) {
|
for _, file := range findFiles(dir, patterns) {
|
||||||
|
if verbose {
|
||||||
|
fmt.Printf("d: Found %s\n", file)
|
||||||
|
}
|
||||||
if _, ok := filesSet[file]; !ok {
|
if _, ok := filesSet[file]; !ok {
|
||||||
filesSet[file] = 0
|
filesSet[file] = 0
|
||||||
}
|
}
|
||||||
|
@ -60,9 +69,17 @@ func main() {
|
||||||
// extract keys
|
// extract keys
|
||||||
files := []string{}
|
files := []string{}
|
||||||
for k := range filesSet {
|
for k := range filesSet {
|
||||||
|
if verbose {
|
||||||
|
fmt.Printf("d: #%d. %s\n", len(files), k)
|
||||||
|
}
|
||||||
files = append(files, k)
|
files = append(files, k)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if verbose {
|
||||||
|
// fmt.Printf("d: List %+v\n", files)
|
||||||
|
fmt.Printf("d: List has %d entries\n", len(files))
|
||||||
|
}
|
||||||
|
|
||||||
if len(files) < 1 {
|
if len(files) < 1 {
|
||||||
fmt.Println("No file found")
|
fmt.Println("No file found")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -70,6 +87,9 @@ func main() {
|
||||||
|
|
||||||
rand.Seed(time.Now().UTC().UnixNano())
|
rand.Seed(time.Now().UTC().UnixNano())
|
||||||
choice := rand.Intn(len(files))
|
choice := rand.Intn(len(files))
|
||||||
|
if verbose {
|
||||||
|
fmt.Printf("d: Chosen entry n°%d\n", choice)
|
||||||
|
}
|
||||||
fmt.Printf("%s %s\n", editor, files[choice])
|
fmt.Printf("%s %s\n", editor, files[choice])
|
||||||
|
|
||||||
// Run editor
|
// Run editor
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -1,3 +1,5 @@
|
||||||
module github.com/glenux/randomedit
|
module github.com/glenux/randomedit
|
||||||
|
|
||||||
|
go 1.15
|
||||||
|
|
||||||
require github.com/spf13/pflag v1.0.2
|
require github.com/spf13/pflag v1.0.2
|
||||||
|
|
Loading…
Add table
Reference in a new issue