Skip to content

Commit c3edf79

Browse files
committed
Provide download tool and updated README
1 parent 5f7e200 commit c3edf79

File tree

3 files changed

+183
-4
lines changed

3 files changed

+183
-4
lines changed

README.md

+56-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# telescope-fzf-native.nvim
1+
``# telescope-fzf-native.nvim
22

33
**fzf-native** is a `c` port of **[fzf][fzf]**. It only covers the algorithm and
44
implements few functions to support calculating the score.
@@ -29,14 +29,65 @@ available for telescope (as native component or as lua component).
2929

3030
## Installation
3131

32-
To get **fzf-native** working, you need to build it with either `cmake` or `make`. As of now, we do not ship binaries.
33-
Both install methods will be supported going forward.
32+
`telescope-fzf-native` is mostly a native binary. We do not commit this to the
33+
repo, so you'll need to include a post install step to get it downloaded from
34+
our github releases.
35+
36+
```lua
37+
use {
38+
'nvim-telescope/telescope-fzf-native.nvim',
39+
run = function() require('telescope-fzf-native').download_library() end
40+
}
41+
```
42+
43+
Normally this tries to detect your operating system and defaults to downloading
44+
the latest version.
45+
46+
For other package managers, you'll want to look at the postinstall step:
47+
48+
- [`packer.nvim`](https://github.com/wbthomason/packer.nvim) wants `run`
49+
- [`lazy.nvim`](https://github.com/folke/lazy.nvim) will want you to use `build`
50+
- [`vimplug`](https://github.com/junegunn/vim-plug) will probably want some kind `do` involving `:lua` :shrug:
51+
52+
53+
```vim
54+
Plug 'nvim-telescope/telescope-fzf-native.nvim', {
55+
'do': ':lua require("telescope-fzf-native").download_library()'
56+
}
57+
```
58+
59+
### download options
60+
61+
```lua
62+
use {
63+
'nvim-telescope/telescope-fzf-native.nvim',
64+
run = function()
65+
require('telescope-fzf-native').download_library({
66+
platform = 'windows' -- windows | ubuntu | macos
67+
compiler = 'cc', -- windows: cc, unix: gcc | clang
68+
version = 'latest' -- any release name found on our github releases page
69+
})
70+
end
71+
}
72+
```
73+
74+
> 🤚 Note
75+
>
76+
> You'll need to have both `curl` and `sh` shell installed.
77+
>
78+
> On windows, this is done by installing git, and on linux and mac this should already be solved.
79+
80+
81+
82+
## Building yourself
83+
84+
If you want to build **fzf-native** yourself, you will need either `cmake` or `make`.
3485

3586
### CMake (Windows, Linux, MacOS)
3687

3788
This requires:
3889

39-
- CMake, and the Microsoft C++ Build Tools on Windows
90+
- CMake, and the Microsoft C++ Build Tools (vcc) on Windows
4091
- CMake, make, and GCC or Clang on Linux and MacOS
4192

4293
#### vim-plug
@@ -47,6 +98,7 @@ Plug 'nvim-telescope/telescope-fzf-native.nvim', { 'do': 'cmake -S. -Bbuild -DCM
4798

4899
#### packer.nvim
49100

101+
50102
```lua
51103
use {'nvim-telescope/telescope-fzf-native.nvim', run = 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build' }
52104
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
local uv = vim.loop
2+
local plugin_path = string.sub(debug.getinfo(1).source, 2, #"/lua/telescope-fzf-native/download_library.lua" * -1)
3+
local releases_url = "https://github.com/nvim-telescope/telescope-fzf-native.nvim/releases/download"
4+
5+
local get_platform = function()
6+
if vim.fn.has("win32") == 1 then
7+
return 'windows'
8+
end
9+
10+
if vim.fn.has("mac") then
11+
return 'macos'
12+
end
13+
14+
return "ubuntu"
15+
end
16+
17+
local get_valid_compiler = function(platform)
18+
if platform == 'windows' then
19+
return 'cc'
20+
elseif platform == 'macos' then
21+
return 'gcc'
22+
elseif platform == 'linux' then
23+
return 'gcc'
24+
end
25+
end
26+
27+
local path_join = function(strings)
28+
local path_separator = (platform == "windows") and '\\' or '/'
29+
30+
return table.concat(strings, path_separator)
31+
end
32+
33+
local write_async = function(path, txt, flag)
34+
uv.fs_open(path, flag, 438, function(open_err, fd)
35+
assert(not open_err, open_err)
36+
uv.fs_write(fd, txt, -1, function(write_err)
37+
assert(not write_err, write_err)
38+
uv.fs_close(fd, function(close_err)
39+
assert(not close_err, close_err)
40+
end)
41+
end)
42+
end)
43+
end
44+
45+
local spawn = function(cmd, on_exit)
46+
local stdout = uv.new_pipe()
47+
48+
local buffer = ""
49+
50+
local real_cmd = table.remove(cmd, 1)
51+
52+
uv.spawn(real_cmd, {
53+
args = cmd,
54+
stdio = { nil, stdout },
55+
verbatim = true
56+
}, function()
57+
stdout:read_stop()
58+
if (type(on_exit) == "function") then
59+
on_exit(buffer)
60+
end
61+
end)
62+
63+
uv.read_start(stdout, function(err, data)
64+
assert(not err, err)
65+
if data then
66+
buffer = buffer .. data
67+
end
68+
end)
69+
70+
end
71+
72+
local download = function(options)
73+
options = options or {}
74+
local platform = options.platform or get_platform()
75+
local compiler = options.compiler or get_valid_compiler(platform)
76+
local version = options.version or "latest"
77+
78+
local command = nil
79+
80+
if platform == 'windows' then
81+
command = {
82+
'curl', '-L',
83+
string.format("%s/%s/windows-2019-%s-libfzf.dll", releases_url, version, compiler),
84+
'-o', path_join({ plugin_path, 'build', 'libfzf.dll' })
85+
}
86+
end
87+
88+
if platform == 'ubuntu' then
89+
command = {
90+
"curl", "-L",
91+
string.format("%s/%s/ubuntu-%s-libfzf.so", releases_url, version, compiler),
92+
"-o", path_join({ plugin_path, 'build', 'libfzf.so' })
93+
}
94+
end
95+
96+
if platform == 'macos' then
97+
command = {
98+
"curl", "-L",
99+
string.format("%s/%s/macos-%s-libfzf.so", releases_url, version, compiler),
100+
"-o", path_join({ plugin_path, 'build', 'libfzf.so' })
101+
}
102+
end
103+
104+
--
105+
-- Ensure the Build directory exists
106+
--
107+
-- using format, becase we need to run the command in a subshell on windows.
108+
--
109+
spawn({
110+
'sh',
111+
'-c',
112+
string.format("' mkdir %s'", path_join({ plugin_path, 'build' }))
113+
})
114+
115+
--
116+
-- Curl the download
117+
--
118+
spawn(command)
119+
120+
end
121+
122+
return download

lua/telescope-fzf-native/init.lua

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
local download_library = require('telescope-fzf-native.download_library')
2+
3+
return {
4+
download_library = download_library
5+
}

0 commit comments

Comments
 (0)