Skip to content

Commit

Permalink
feat: add telescope grep_string support
Browse files Browse the repository at this point in the history
  • Loading branch information
prichrd committed Jun 4, 2024
1 parent 9c8fd6e commit 908379c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,21 @@ function still has to be called to configure the commands:

### Telescope

vwd.nvim extends Telescope's `find_files` and `live_grep` functionality by
setting the CWD to the VWD. Here is a sample Telescope configuration:
vwd.nvim extends Telescope's `find_files`, `live_grep` and `grep_string`
functionalities by setting the CWD to the VWD. Here is a sample Telescope
configuration:

```lua
local telescope = require('telescope')

-- Register the vwd extension.
telescope.load_extension('vwd')

-- Configures find_files and live_grep to use VWD. You can still provide
-- Configures find_files, live_grep and grep_string to use VWD. You can still provide
-- regular Telescope arguments to the finders.
vim.api.nvim_set_keymap('n', '<Leader>ff', '<cmd>lua require"telescope".extensions.vwd.find_files{}<CR>', opts)
vim.api.nvim_set_keymap('n', '<Leader>fg', '<cmd>lua require"telescope".extensions.vwd.live_grep{}<CR>', opts)
vim.api.nvim_set_keymap('n', '<Leader>ff', '<cmd>lua require"telescope".extensions.vwd.find_files({})<CR>', opts)
vim.api.nvim_set_keymap('n', '<Leader>fg', '<cmd>lua require"telescope".extensions.vwd.live_grep({})<CR>', opts)
vim.api.nvim_set_keymap('n', '<Leader>fs', '<cmd>lua require"telescope".extensions.vwd.grep_string({})<CR>', opts)
```

## Usage
Expand Down
12 changes: 7 additions & 5 deletions doc/vwd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,20 @@ function still has to be called to configure the commands:
<
*vwd-configure-telescope*

This plugin extends Telescope's `find_files` and `live_grep` functionality by
setting the CWD to the VWD. Here is a sample Telescope configuration:
This plugin extends Telescope's `find_files`, `live_grep` and `grep_string`
functionalities by setting the CWD to the VWD. Here is a sample Telescope
configuration:
>lua
local telescope = require('telescope')

-- Register the vwd extension.
telescope.load_extension('vwd')

-- Configures find_files and live_grep to use VWD. You can still provide
-- Configures find_files, live_grep and grep_string to use VWD. You can still provide
-- regular Telescope arguments to the finders.
vim.api.nvim_set_keymap('n', '<Leader>ff', '<cmd>lua require"telescope".extensions.vwd.find_files{}<CR>', opts)
vim.api.nvim_set_keymap('n', '<Leader>fg', '<cmd>lua require"telescope".extensions.vwd.live_grep{}<CR>', opts)
vim.api.nvim_set_keymap('n', '<Leader>ff', '<cmd>lua require"telescope".extensions.vwd.find_files({})<CR>', opts)
vim.api.nvim_set_keymap('n', '<Leader>fg', '<cmd>lua require"telescope".extensions.vwd.live_grep({})<CR>', opts)
vim.api.nvim_set_keymap('n', '<Leader>fs', '<cmd>lua require"telescope".extensions.vwd.grep_string({})<CR>', opts)
<
==============================================================================
COMMANDS
Expand Down
7 changes: 7 additions & 0 deletions lua/telescope/_extensions/vwd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ local live_grep = function(opts)
builtin.live_grep(opts)
end

local grep_string = function(opts)
opts = opts or {}
opts.cwd = vwd.get_vwd()
builtin.grep_string(opts)
end

local file_browser = function(opts)
opts = opts or {}
opts.cwd = vwd.get_vwd()
Expand All @@ -23,6 +29,7 @@ return require("telescope").register_extension({
exports = {
find_files = find_files,
live_grep = live_grep,
grep_string = grep_string,
file_browser = file_browser,
actions = require("telescope._extensions.vwd.actions"),
},
Expand Down

0 comments on commit 908379c

Please sign in to comment.