Skip to content

Commit

Permalink
feat: search by the arbitrary regex instead of rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanilves committed Mar 2, 2024
1 parent 29fac21 commit fbcd54b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
APP_NAME := travelgrunt
API_VERSION := 0.4
API_VERSION := 0.5
BUILD_PATH := ./cmd/${APP_NAME}

CURRENT_PATCH = $(shell (git fetch --tags && git tag --sort=creatordate | grep -F "v${API_VERSION}." || echo -1) | tail -n1 | sed -r "s/^v([0-9]+\.){2}//")
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ rules:

:bulb: Even while developing `travelgrunt` itself we use it to navigate [package directories](https://github.com/ivanilves/travelgrunt/blob/main/.travelgrunt.yml) of the application :tophat:

## Override configured rules with arbitrary expression

You can search by the arbitrary expression instead of configured rules:

```
tg -x <EXPRESSION> [<match> <match2> ... <matchN>]
```

## Shell aliases and functions

It is **absolutely required** to use `zsh` aliases or `bash` functions. Start from something like this:
Expand All @@ -52,8 +60,8 @@ alias tt='_tt(){ travelgrunt -top -out-file ~/.tg-path && cd "$(cat ~/.tg-path)"
```
#### BASH
```
function tg() {
travelgrunt -out-file ~/.tg-path ${@} && cd "$(cat ~/.tg-path)"
function tg() {
travelgrunt -out-file ~/.tg-path ${@} && cd "$(cat ~/.tg-path)"
}
function tt() {
Expand Down
9 changes: 9 additions & 0 deletions cmd/travelgrunt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"

"github.com/ivanilves/travelgrunt/pkg/config"
"github.com/ivanilves/travelgrunt/pkg/config/rule"
"github.com/ivanilves/travelgrunt/pkg/directory"
"github.com/ivanilves/travelgrunt/pkg/directory/tree"
"github.com/ivanilves/travelgrunt/pkg/file"
Expand All @@ -18,11 +19,13 @@ import (
var appVersion = "default"

var outFile string
var expression string
var top bool
var version bool

func init() {
flag.StringVar(&outFile, "out-file", "", "output selected path into the file specified")
flag.StringVar(&expression, "x", "", "use arbitrary expression passed instead of configured rules")
flag.BoolVar(&top, "top", false, "get to the repository top level (root) path")
flag.BoolVar(&version, "version", false, "print application version and exit")
}
Expand Down Expand Up @@ -113,6 +116,12 @@ func main() {
log.Fatalf("failed to load travelgrunt config: %s", err.Error())
}

if expression != "" {
rules := []rule.Rule{{NameEx: expression}}

cfg.Rules = rules
}

entries, paths, err := directory.Collect(rootPath, cfg)

if err != nil {
Expand Down

0 comments on commit fbcd54b

Please sign in to comment.