Adds CopyToPlayers command
This commit is contained in:
parent
132f9d0636
commit
6f74d3b3db
8 changed files with 66 additions and 18 deletions
|
|
@ -5,3 +5,4 @@ require("config.lazy")
|
|||
|
||||
require("commands.optolith")
|
||||
require("commands.open")
|
||||
require("commands.CopyToPlayers")
|
||||
|
|
|
|||
26
.config/nvim/lua/commands/CopyToPlayers.lua
Normal file
26
.config/nvim/lua/commands/CopyToPlayers.lua
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
local fs = require("functions.fs")
|
||||
local git = require("functions.git")
|
||||
|
||||
vim.api.nvim_create_user_command("CopyToPlayers", function()
|
||||
local CONFIGFILE = ".dsa-players-path"
|
||||
|
||||
local pathFile = vim.fs.joinpath(vim.fn.getcwd(), CONFIGFILE)
|
||||
local fileExists = vim.fn.empty(vim.fn.glob(pathFile)) == 0
|
||||
if not fileExists then
|
||||
vim.notify("Can't find target path. Missing file", "error", {
|
||||
title = "Copy to players",
|
||||
})
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
local targetPath = vim.fs.joinpath(vim.fn.getcwd(), table.concat(vim.fn.readfile(pathFile)))
|
||||
|
||||
os.execute(string.format("mkdir -p '%s'", targetPath))
|
||||
|
||||
local localPath = fs.getCurrentPath()
|
||||
local targetFilePath = vim.fs.joinpath(targetPath, vim.fn.fnamemodify(localPath, ":t"))
|
||||
os.execute(string.format("ln -s '%s' '%s'", localPath, targetFilePath))
|
||||
|
||||
git.commitFile(targetFilePath)
|
||||
end, {})
|
||||
|
|
@ -1,27 +1,12 @@
|
|||
local nio = require("nio")
|
||||
local git = require("functions.git")
|
||||
|
||||
local function startswith(string, start)
|
||||
return string:sub(1, #start) == start
|
||||
end
|
||||
|
||||
local function get_current_path()
|
||||
local currentBuffer = vim.fn.expand("%")
|
||||
|
||||
if not startswith(currentBuffer, "neo-tree") then
|
||||
return currentBuffer
|
||||
end
|
||||
|
||||
local filesystemState = require("neo-tree.sources.manager").get_state("filesystem")
|
||||
local currentLine = vim.fn.getpos(".")[2]
|
||||
return filesystemState.tree:get_node(currentLine).path
|
||||
end
|
||||
local fs = require("functions.fs")
|
||||
|
||||
vim.api.nvim_create_user_command("Optolith", function()
|
||||
local LAUNCH_COMMAND = vim.fs.normalize("~/.local/share/appimages/OptolithInsider.AppImage")
|
||||
local OPTOLITH_DIRECTORY = "~/.config/Optolith Insider"
|
||||
|
||||
local currentHeroFile = get_current_path()
|
||||
local currentHeroFile = fs.get_current_path()
|
||||
|
||||
if currentHeroFile:find(".opto$") == nil then
|
||||
vim.notify("Invalid hero", "error", {
|
||||
|
|
|
|||
19
.config/nvim/lua/functions/fs.lua
Normal file
19
.config/nvim/lua/functions/fs.lua
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
local fs = {}
|
||||
|
||||
local function startswith(string, start)
|
||||
return string:sub(1, #start) == start
|
||||
end
|
||||
|
||||
function fs.getCurrentPath()
|
||||
local currentBuffer = vim.fn.expand("%")
|
||||
|
||||
if not startswith(currentBuffer, "neo-tree") then
|
||||
return currentBuffer
|
||||
end
|
||||
|
||||
local filesystemState = require("neo-tree.sources.manager").get_state("filesystem")
|
||||
local currentLine = vim.fn.getpos(".")[2]
|
||||
return filesystemState.tree:get_node(currentLine).path
|
||||
end
|
||||
|
||||
return fs
|
||||
|
|
@ -21,4 +21,16 @@ return {
|
|||
},
|
||||
},
|
||||
},
|
||||
keys = {
|
||||
{
|
||||
"<leader>e",
|
||||
function()
|
||||
local filesystemState = require("neo-tree.sources.manager").get_state("filesystem")
|
||||
local fsPath = table.concat(filesystemState.default_expanded_nodes)
|
||||
|
||||
require("neo-tree.command").execute({ toggle = true, dir = fsPath })
|
||||
end,
|
||||
desc = "Explorer NeoTree (reopen)",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
if true then
|
||||
return {}
|
||||
end
|
||||
|
||||
return {
|
||||
"epwalsh/obsidian.nvim",
|
||||
version = "*",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue