summaryrefslogtreecommitdiff
path: root/scratch
diff options
context:
space:
mode:
authorTJ DeVries <devries.timothyj@gmail.com>2020-07-17 00:03:20 -0400
committerTJ DeVries <devries.timothyj@gmail.com>2020-07-17 00:03:20 -0400
commitababfbfd88334ca6d94d5d0a8b6324dd6600d602 (patch)
tree99dd820cca2d906175b9a645694cb778add58499 /scratch
parentc6f0142fc651dcbd2431630956d034c046293e7e (diff)
Another stream
Diffstat (limited to 'scratch')
-rw-r--r--scratch/file_finder.lua84
-rw-r--r--scratch/simple_rg.lua32
-rwxr-xr-xscratch/slow_proc.sh4
-rw-r--r--scratch/string_distance_stuff.lua7
4 files changed, 102 insertions, 25 deletions
diff --git a/scratch/file_finder.lua b/scratch/file_finder.lua
new file mode 100644
index 0000000..8b5bb7b
--- /dev/null
+++ b/scratch/file_finder.lua
@@ -0,0 +1,84 @@
+local telescope = require('telescope')
+
+-- Goals:
+-- 1. You pick a directory
+-- 2. We `git ls-files` in that directory ONCE and ONLY ONCE to get the results.
+-- 3. You can fuzzy find those results w/ fzf
+-- 4. Select one and go to file.
+
+
+--[[
+ls_files_job.start()
+fzf_job.stdin = ls_files_job.stdout
+
+ self.stdin = vim.loop.new_pipe(false)
+ -> self.stdin = finder.stdout
+
+
+ -- Finder:
+ intermediary_pipe = self.stdout
+
+ -- repeat send this pipe when we want to get new filtering
+ self.stdin = intermediary_pipe
+
+
+ -- Filter + Sort
+ ok, we could do scoring + cutoff and have that always be the case.
+
+ OR
+
+ filter takes a function, signature (prompt: str, line: str): number
+
+ => echo $line | fzf --filter "prompt"
+ return stdout != ""
+
+ => lua_fuzzy_finder(prompt, line) return true if good enough
+
+ TODO: Rename everything to be more clear like the name below.
+ IFilterSorterAbstractFactoryGeneratorv1ProtoBeta
+
+--]]
+
+local string_distance = require('telescope.algos.string_distance')
+
+local file_finder = telescope.finders.new {
+ fn_command = function(self, prompt)
+ -- todo figure out how to cache this later
+ if false then
+ if self[prompt] == nil then
+ self[prompt] = nil
+ end
+
+ return self[prompt]
+ else
+ return 'git ls-files'
+ end
+ end,
+}
+
+local file_sorter = telescope.sorters.new {
+ scoring_function = function(self, prompt, line)
+ if prompt == '' then return 0 end
+ if not line then return -1 end
+
+ local dist = string_distance(prompt, line)
+ -- if dist > (0.75 * #line) and #prompt > 3 then
+ -- return -1
+ -- end
+
+ return dist
+ end
+}
+
+local file_previewer = telescope.previewers.vim_buffer
+
+local file_picker = telescope.pickers.new {
+ previewer = file_previewer
+}
+
+file_picker:find {
+ prompt = 'Find File',
+ finder = file_finder,
+ sorter = file_sorter,
+}
+
diff --git a/scratch/simple_rg.lua b/scratch/simple_rg.lua
index c6a8481..5102611 100644
--- a/scratch/simple_rg.lua
+++ b/scratch/simple_rg.lua
@@ -5,37 +5,19 @@ local telescope = require('telescope')
-- When updating the table, we should call filter on those items
-- and then only display ones that pass the filter
local rg_finder = telescope.finders.new {
- fn_command = function(prompt)
+ fn_command = function(self, prompt)
return string.format('rg --vimgrep %s', prompt)
end,
responsive = false
}
-
local p = telescope.pickers.new {
- previewer = telescope.previewers.new(function(preview_win, preview_bufnr, results_bufnr, row)
- assert(preview_bufnr)
-
- local line = vim.api.nvim_buf_get_lines(results_bufnr, row, row + 1, false)[1]
- local file_name = vim.split(line, ":")[1]
-
- -- print(file_name)
- -- vim.fn.termopen(
- -- string.format("bat --color=always --style=grid %s"),
- -- vim.fn.fnamemodify(file_name, ":p")
- local bufnr = vim.fn.bufadd(file_name)
- vim.fn.bufload(bufnr)
-
- -- TODO: We should probably call something like this because we're not always getting highlight and all that stuff.
- -- api.nvim_command('doautocmd filetypedetect BufRead ' .. vim.fn.fnameescape(filename))
- vim.api.nvim_win_set_buf(preview_win, bufnr)
- vim.api.nvim_win_set_option(preview_win, 'wrap', false)
- vim.api.nvim_win_set_option(preview_win, 'winhl', 'Normal:Normal')
- vim.api.nvim_win_set_option(preview_win, 'winblend', 20)
- vim.api.nvim_win_set_option(preview_win, 'signcolumn', 'no')
- vim.api.nvim_win_set_option(preview_win, 'foldlevel', 100)
- end)
+ previewer = telescope.previewers.vim_buffer
+}
+p:find {
+ prompt = 'grep',
+ finder = rg_finder
}
-p:find(rg_finder)
+
diff --git a/scratch/slow_proc.sh b/scratch/slow_proc.sh
index 6326991..bbcf8bf 100755
--- a/scratch/slow_proc.sh
+++ b/scratch/slow_proc.sh
@@ -4,3 +4,7 @@ sleep 1
echo "cool"
sleep 1
echo "world"
+sleep 1
+echo "x"
+sleep 1
+echo "y"
diff --git a/scratch/string_distance_stuff.lua b/scratch/string_distance_stuff.lua
new file mode 100644
index 0000000..283f00f
--- /dev/null
+++ b/scratch/string_distance_stuff.lua
@@ -0,0 +1,7 @@
+
+local string_distance = require('telescope.algos.string_distance')
+
+print(string_distance("hello", "help"))
+print(string_distance("hello", "hello"))
+print(string_distance("hello", "asdf"))
+