Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
gorillamoe committed Aug 2, 2024
1 parent d78c93a commit 26d7603
Showing 13 changed files with 467 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @gorillamoe
17 changes: 17 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
changelog:
exclude:
labels:
- ignore-for-release
categories:
- title: Breaking Changes 💥
labels:
- breaking-change
- title: Documentation 📚
labels:
- documentation
- title: Exciting New Features ✨
labels:
- enhancement
- title: Bug Fixes 🐛
labels:
- bug
23 changes: 23 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Release

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
jobs:
create-release:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up env
run: |
VERSION=${GITHUB_REF_NAME#v}
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Create Release
run: ./scripts/release.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20 changes: 20 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
stds.nvim = {
read_globals = { "jit" },
}

std = "lua51+nvim"

read_globals = {
"vim",
}

globals = {
"vim.g",
"vim.b",
"vim.w",
"vim.o",
"vim.bo",
"vim.wo",
"vim.go",
"vim.env",
}
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version:
./scripts/set-version.sh $(VERSION)
58 changes: 57 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,58 @@
<div align="center">

![tafuta logo](logo.svg)

# tafuta.nvim
A tiny 🤏🏾, wrapper around ripgrep, for making search 🔍 blazingly fast ⚡ and easy to use 👌🏾 in your favorite editor 🥰.

![Lua](https://img.shields.io/badge/Made%20with%20Lua-blueviolet.svg?style=for-the-badge&logo=lua)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/mistweaverco/tafuta.nvim?style=for-the-badge)](https://github.com/mistweaverco/tafuta.nvim/releases/latest)

[Install](#install)[Usage](#usage)

<p></p>

A tiny 🤏 wrapper around ripgrep for
making search 🔍 blazingly fast ⚡ and
easy to use 👌 in your favorite editor 🥰.

Tafuta is swahili for "search".

It allows you to search for text in your project.

<p></p>

</div>

## Install

> [!WARNING]
> Requires Neovim 0.10.0+
Via [lazy.nvim](https://github.com/folke/lazy.nvim):

### Configuration

```lua
require('lazy').setup({
-- blazingly fast ⚡ search 🔍
{
'mistweaverco/tafuta.nvim',
cmd = { "Tf" },
config = function()
-- Setup is required, even if you don't pass any options
require('tafuta').setup({
-- The user command to run the search e.g. `:Tf <query>`
user_command = "Tf",
-- rg options, a lua table of options to pass to rg
rg_options = nil,
})
end,
},
})
```

## Usage

```
:Tf <search-term>
```
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
208 changes: 208 additions & 0 deletions logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions lua/tafuta/config/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
local M = {}

M.defaults = {
-- The user command to run the search e.g. `:Tf <query>`
user_command = "Tf",
}

M.options = {}

M.setup = function(config)
M.options = vim.tbl_deep_extend("force", M.defaults, config or {})
end

M.get = function()
return M.options
end

return M
5 changes: 5 additions & 0 deletions lua/tafuta/globals/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
local M = {}

M.VERSION = "1.0.0"

return M
76 changes: 76 additions & 0 deletions lua/tafuta/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
local GLOBALS = require("tafuta.globals")
local CONFIG = require("tafuta.config")
local M = {}

local rg_installed = vim.fn.executable("rg") == 1

local async_run = vim.schedule_wrap(function(res)
local code = res.code
if code == 0 then
local matches = vim.split(res.stdout, "\n", { trimempty = true })
if vim.tbl_isempty(matches) then
vim.notify("❌ no match", vim.log.levels.INFO, { title = "Tafuta" })
return
end
vim.fn.setqflist({}, "r", {
title = "Tafuta results (" .. #matches .. ")",
lines = matches,
})
vim.cmd("copen")
elseif code == 1 then
vim.notify("❌ no match", vim.log.levels.INFO, { title = "Tafuta" })
else
vim.notify("💀 error occurred", vim.log.levels.ERROR, { title = "Tafuta" })
end
end)

local search = function(search_query)
local search_command = { "rg", "--vimgrep" }
local rg_options = CONFIG.get().rg_options
if rg_options ~= nil then
for _, option in ipairs(rg_options) do
table.insert(search_command, option)
end
end
table.insert(search_command, search_query)
vim.system(search_command, { text = true }, async_run)
end

M.setup = function(config)
CONFIG.setup(config)
local user_command = CONFIG.get().user_command
if user_command ~= nil then
vim.api.nvim_create_user_command(user_command, function(a)
if a.args == "" then
vim.notify("❌ No search query provided", vim.log.levels.INFO, { title = "Tafuta" })
return
end
M.run(a.args)
end, {
nargs = "?",
desc = "Tf, blazingly fast ⚡ search 🔍 using ripgrep 🦀",
})
end
end

M.run = function(search_query)
if not rg_installed then
vim.notify("❌ ripgrep not found on the system", vim.log.levels.WARN, { title = "Tafuta" })
return
end
if search_query == nil then
search_query = vim.fn.input("Search: ")
end
search(search_query)
end

M.version = function()
local neovim_version = vim.fn.execute("version")
vim.notify(
"Tafuta version: " .. GLOBALS.VERSION .. "\n\n" .. "Neovim version: " .. neovim_version,
"info",
{ title = "Tafuta" }
)
end

return M
29 changes: 29 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

set -euo pipefail

GH_TAG="v$VERSION"

set_version() {
./scripts/set-version.sh
}

check_git_dirty() {
if [[ -n $(git status -s) ]]; then
echo "Working directory is dirty. Please commit or stash your changes before releasing."
exit 1
fi
}

do_gh_release() {
echo "Creating new release $GH_TAG"
gh release create --generate-notes "$GH_TAG"
}

boot() {
set_version
check_git_dirty
do_gh_release
}

boot
11 changes: 11 additions & 0 deletions scripts/set-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -euo pipefail

update_lua_globals_version() {
local tmp
tmp=$(mktemp)
sed -e "s/VERSION = \".*\"/VERSION = \"$VERSION\"/" ./lua/tafuta/globals/init.lua > "$tmp" && mv "$tmp" ./lua/tafuta/globals/init.lua
}

update_lua_globals_version

0 comments on commit 26d7603

Please sign in to comment.