-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfirst-file.lua
More file actions
58 lines (42 loc) · 1.22 KB
/
Copy pathfirst-file.lua
File metadata and controls
58 lines (42 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
--- @since 26.5.6
-- The module to handle the first file command
-- Import the utilities module
local utils = require(".utils")
-- The module table
local M = {}
-- Function to execute the first file command
---@type fun(): nil
local exec = ya.sync(function()
-- Get the current working directory
local current = cx.active.current
-- Get the files in the current working directory
local files = current.files
-- Initialise the index of the first file
local first_file_index = nil
-- Iterate over the files
for index, file in ipairs(files) do
-- If the file isn't a directory,
if not file.cha.is_dir then
-- Set the first file index
first_file_index = index
-- Break out of the loop
break
end
end
-- Get the amount to move the cursor by.
--
-- The cursor index needs to be increased by 1
-- because the cursor index is 0-indexed
-- while Lua tables are 1-indexed.
local move_by = first_file_index - (current.cursor + 1)
-- Emit the augmented arrow command
utils.emit_augmented_command("arrow", { move_by })
end)
-- Function to handle the first file command
---@type YaziPluginEntry
function M:entry()
-- Call the function to execute the first file command
exec()
end
-- Return the module table
return M