Skip to content

Commit

Permalink
fix: active bug report (#7) (#8)
Browse files Browse the repository at this point in the history
* wrap example in quotes

* fix: arrow disappears on search #6

* rewrite / update docs

* bump version
  • Loading branch information
hay-kot committed Aug 3, 2022
1 parent 369d2b9 commit 65e92f7
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 28 deletions.
93 changes: 66 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,80 @@
# Gofind
<!-- PROJECT LOGO -->
<br />
<div align="center">
<h1 align="center">GoFind</h1>
<p align="center"><i>An fzf knockoff</i></p>
</div>

- [About](#about)
- [Installation](#installation)
- [Config](#config)
- [Commands](#commands)
- [Configuration Example](#configuration-example)
- [Help](#help)
- [Examples](#examples)

## About

GoFind is a small cli program for quickly finding and searching directories using the producer/consumer pattern. It uses the `filepath.Match` function to look for matching children in root directories, and if the child is found, it will stop return the parent directory and stop recursively looking into that parents children.

**Why though?** The primary use case for this library is to tie into other scripts to quickly and easily navigate (or other action) to a file path. For example you can use an alias to quickly search through all your git repositories and quickly search, find, and navigate in your terminal. See the [examples](#examples) for more details
The primary use case for this library is to tie into other scripts to quickly and easily navigate (or other action) to a file path. For example you can use an alias to quickly search through all your git repositories and quickly search, find, and navigate in your terminal. See the [examples](#examples) for more details

https://user-images.githubusercontent.com/64056131/182485271-0c906802-c44e-4059-8079-37d6ea86e005.mp4

## Installation

You can install GoFind by running `go install github.com/hay-kot/gofind` or download the latest release from [GitHub](https://github.com/hay-kot/gofind/releases)

After installing you must run `gofind setup` to initialize the configuration file and setup the cache

## Config
GoFind uses a json file in `~/.config/gofind.json` to store the configuration for the search entries and the default search. It also uses this file to cache results so that the search is faster on subsequent runs. The config file example here has two jobs,

**repos:** which will recursively search the ~/Code directory for any directory that matches `.git`
**compose:** which will recursively search the ~/Docker directory for any directory that matches `docker-compose*`
GoFind uses a json file in `~/.config/gofind.json` to store the configuration for the search entries and the default search. It also has a cache file that's used to store the results of a search so they aren't computed every time. You can set this path in the configuration file. If you ever need to re-cache the results, you can run `gofind cache` to recompute all caches, however they expire after 24 hours.


| Key | Type | Description |
| --------------- | ----------- | ------------------------------------------------------------- |
| `default` | string | The default command to run when calling `gofind find` |
| `commands` | object | An object containing all of the registered commands available |
| `cache` | string/path | Path to the cache directory |
| `max_recursion` | number | Max level of recursion from the root directory |


### Commands

The commands key is an object where the `key` is the name of the command and the value is an object with the following keys:

I use these to either quickly find a repository I forgot the name of or where it exists, or quickly find a docker stack location and navigate to it.
| Key | Type | Description |
| ------- | ------------ | ------------------------------------------------------ |
| `roots` | string array | The root directories to search inside of for the match |
| `match` | string | The file match pattern used to find matches |

In the example configuration there are two commands registered

- **docker:** will search the ~/docker directory of and present you with a list of all subdirectories that contain a docker-compose* file match. This is useful for quickly navigating to a docker-compose file directory to manage a container stack
- **repos:** will search the "~Code/OtherRepos" and "~/Code/Repos" directories for a match of the `.git` directory (or file). This is useful for quickly navigating to a git repository

### Configuration Example

```json
{
"default": "repos",
"commands": {
"compose": {
"root": ["~/Docker"],
"match": "docker-compose*"
},
"repos": {
"root": ["~/Code"],
"match": ".git"
}
"default": "repos",
"commands": {
"docker": {
"roots": [
"~/docker"
],
"match": "docker-compose*"
},
"cache": {}
"repos": {
"roots": [
"~/Code/OtherRepos",
"~/Code/Repos"
],
"match": ".git"
}
},
"cache": "~/.cache/gofind/"
}
```

Expand All @@ -41,7 +88,7 @@ USAGE:
gofind [global options] command [command options] [arguments...]

VERSION:
0.1.0
0.1.3

COMMANDS:
cache, c cache all config entries
Expand All @@ -57,22 +104,14 @@ GLOBAL OPTIONS:

## Examples


**Open VSCode**

```shell
alias fcode="code \`gofind find repos\`"
```

**Change into Directory**

```shell
repos() {
# Navigate to repos director and open target directory is specified
if [ -z "$1" ]; then
cd `gofind find repos`
cd "`gofind find repos`"
return
fi
cd ~/code/repos/$1
}
```
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

func main() {
app := &cli.App{
Version: "0.1.2",
Version: "0.1.3",
Name: "gofind",
Usage: "an interactive search for directories using the filepath.Match function",
Commands: []*cli.Command{
Expand Down
4 changes: 4 additions & 0 deletions tui/fuzzyfinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ func (m fuzzyFinderView) View() string {
m.search.View(),
)

if m.ctrl.selected > m.ctrl.limit {
m.ctrl.selected = 0
}

str.WriteString(ui.Subtle(fmt.Sprintf("\n %d/%d", len(results), len(m.ctrl.matches))) + "\n")
str.WriteString(m.fmtMatches(results[:determinedMax]))

Expand Down

0 comments on commit 65e92f7

Please sign in to comment.