Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: search by the arbitrary regex instead of rules #54

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading