Adds neotree support for optolith setup
This commit is contained in:
parent
d858ee8e8e
commit
2ea0877394
2 changed files with 26 additions and 8 deletions
|
|
@ -1,13 +1,25 @@
|
|||
local nio = require("nio")
|
||||
|
||||
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
|
||||
|
||||
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 absOptolithDirectory = vim.fs.normalize(OPTOLITH_DIRECTORY)
|
||||
local directoryExists = vim.fn.isdirectory(absOptolithDirectory)
|
||||
|
||||
local currentHeroFile = vim.fn.expand("%")
|
||||
local currentHeroFile = get_current_path()
|
||||
|
||||
if currentHeroFile:find(".json$") == nil then
|
||||
vim.notify("Invalid hero", "error", {
|
||||
|
|
@ -16,6 +28,8 @@ vim.api.nvim_create_user_command("Optolith", function()
|
|||
return
|
||||
end
|
||||
|
||||
local absOptolithDirectory = vim.fs.normalize(OPTOLITH_DIRECTORY)
|
||||
local directoryExists = vim.fn.isdirectory(absOptolithDirectory)
|
||||
if directoryExists == 0 then
|
||||
vim.notify("Can't find folder. Please start the application once.\nFolder: " .. OPTOLITH_DIRECTORY, "error", {
|
||||
title = "Optolith",
|
||||
|
|
@ -33,6 +47,12 @@ vim.api.nvim_create_user_command("Optolith", function()
|
|||
return
|
||||
end
|
||||
|
||||
local swapFileExists = vim.fn.empty(vim.fn.glob(heroesPath .. ".swp")) == 0
|
||||
if swapFileExists then
|
||||
vim.notify("Swap file already exists. To prevent data loss, please restore the swap file.", "error", {
|
||||
title = "Optolith",
|
||||
})
|
||||
end
|
||||
if heroesFileExists then
|
||||
local mvCommand = os.execute(string.format('mv "%s" "%s.swp"', heroesPath, heroesPath))
|
||||
if mvCommand ~= 0 then
|
||||
|
|
@ -41,6 +61,7 @@ vim.api.nvim_create_user_command("Optolith", function()
|
|||
})
|
||||
return
|
||||
end
|
||||
swapFileExists = true
|
||||
end
|
||||
|
||||
local linkCommand = os.execute(string.format('ln -s "%s" "%s"', currentHeroFile, heroesPath))
|
||||
|
|
@ -59,8 +80,6 @@ vim.api.nvim_create_user_command("Optolith", function()
|
|||
vim.fn.writefile({ vim.fn.json_encode(newData) }, currentHeroFile)
|
||||
end
|
||||
|
||||
local swapFileExists = vim.fn.empty(vim.fn.glob(heroesPath .. ".swp")) == 0
|
||||
|
||||
local task = nio.run(function()
|
||||
local process = nio.process.run({
|
||||
cmd = LAUNCH_COMMAND,
|
||||
|
|
@ -68,7 +87,6 @@ vim.api.nvim_create_user_command("Optolith", function()
|
|||
|
||||
process.result()
|
||||
end, function()
|
||||
print("Execute")
|
||||
os.remove(heroesPath)
|
||||
if swapFileExists then
|
||||
os.execute(string.format('mv "%s.swp" "%s"', heroesPath, heroesPath))
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
<property name="last-side-pane" type="string" value="ThunarShortcutsPane"/>
|
||||
<property name="last-location-bar" type="string" value="ThunarLocationEntry"/>
|
||||
<property name="last-details-view-zoom-level" type="string" value="THUNAR_ZOOM_LEVEL_50_PERCENT"/>
|
||||
<property name="last-details-view-column-widths" type="string" value="118,50,124,117,86,87,50,50,2769,50,50,67,50,78"/>
|
||||
<property name="last-details-view-column-widths" type="string" value="118,50,124,117,86,87,50,50,1775,50,50,71,50,188"/>
|
||||
<property name="last-sort-column" type="string" value="THUNAR_COLUMN_DATE_CREATED"/>
|
||||
<property name="last-sort-order" type="string" value="GTK_SORT_DESCENDING"/>
|
||||
<property name="last-details-view-visible-columns" type="string" value="THUNAR_COLUMN_DATE_CREATED,THUNAR_COLUMN_DATE_MODIFIED,THUNAR_COLUMN_NAME,THUNAR_COLUMN_SIZE,THUNAR_COLUMN_TYPE"/>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue