Updates nvim setup
This commit is contained in:
parent
1c38c7b171
commit
6f069d32e1
13 changed files with 285 additions and 4 deletions
5
.config/nvim/lua/commands/open.lua
Normal file
5
.config/nvim/lua/commands/open.lua
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
vim.api.nvim_create_user_command("Open", function()
|
||||
local buffername = vim.fn.expand("%")
|
||||
|
||||
os.execute(string.format('xdg-open "%s" &> /dev/null &', buffername))
|
||||
end, {})
|
||||
101
.config/nvim/lua/commands/optolith.lua
Normal file
101
.config/nvim/lua/commands/optolith.lua
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
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
|
||||
|
||||
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()
|
||||
|
||||
if currentHeroFile:find(".opto$") == nil then
|
||||
vim.notify("Invalid hero", "error", {
|
||||
title = "Optolith",
|
||||
})
|
||||
return
|
||||
end
|
||||
|
||||
local absOptolithDirectory = vim.fs.normalize(OPTOLITH_DIRECTORY)
|
||||
if vim.fn.isdirectory(absOptolithDirectory) == 0 then
|
||||
vim.notify("Can't find folder. Please start the application once.\nFolder: " .. OPTOLITH_DIRECTORY, "error", {
|
||||
title = "Optolith",
|
||||
})
|
||||
return
|
||||
end
|
||||
|
||||
local heroesPath = vim.fs.joinpath(absOptolithDirectory, "heroes.json")
|
||||
local heroesGlob = vim.fn.glob(heroesPath)
|
||||
local heroesFileExists = vim.fn.empty(heroesGlob) == 0
|
||||
if heroesFileExists and vim.fn.filewritable(heroesPath) == 0 then
|
||||
vim.notify("Can't modify heroes file... Can't inject hero.", "error", {
|
||||
title = "Optolith",
|
||||
})
|
||||
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",
|
||||
})
|
||||
return
|
||||
end
|
||||
if heroesFileExists then
|
||||
local mvCommand = os.execute(string.format('mv "%s" "%s.swp"', heroesPath, heroesPath))
|
||||
if mvCommand ~= 0 then
|
||||
vim.notify("Can not move heroes file.", "error", {
|
||||
title = "Optolith",
|
||||
})
|
||||
return
|
||||
end
|
||||
swapFileExists = true
|
||||
end
|
||||
|
||||
local linkCommand = os.execute(string.format('ln -s "%s" "%s"', currentHeroFile, heroesPath))
|
||||
if linkCommand ~= 0 then
|
||||
vim.notify("Can't create link...", "error", {
|
||||
title = "Optolith",
|
||||
})
|
||||
return
|
||||
end
|
||||
|
||||
-- If the file is just one character, its not a valid heroes.json file.
|
||||
-- So we need to create a valid file.
|
||||
local file = table.concat(vim.fn.readfile(currentHeroFile))
|
||||
local fileData = vim.fn.json_decode(file)
|
||||
if fileData["id"] ~= nil then
|
||||
local newData = {}
|
||||
newData[fileData["id"]] = fileData
|
||||
vim.fn.writefile({ vim.fn.json_encode(newData) }, currentHeroFile)
|
||||
end
|
||||
|
||||
local task = nio.run(function()
|
||||
local process = nio.process.run({
|
||||
cmd = LAUNCH_COMMAND,
|
||||
})
|
||||
|
||||
process.result()
|
||||
end, function()
|
||||
os.remove(heroesPath)
|
||||
if swapFileExists then
|
||||
os.execute(string.format('mv "%s.swp" "%s"', heroesPath, heroesPath))
|
||||
end
|
||||
|
||||
git.commitFile(currentHeroFile)
|
||||
end)
|
||||
end, {})
|
||||
|
|
@ -4,21 +4,35 @@ local git = require("functions.git")
|
|||
-- Default autocmds that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/autocmds.lua
|
||||
-- Add any additional autocmds here
|
||||
|
||||
local enabledGit = os.getenv("ENABLE_GIT_SETUP") or false
|
||||
|
||||
vim.api.nvim_create_autocmd("BufWritePost", {
|
||||
pattern = { "*.md" },
|
||||
callback = function(args)
|
||||
if not enabledGit then
|
||||
return
|
||||
end
|
||||
|
||||
git.commitFile(args.file)
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("VimLeavePre", {
|
||||
callback = function()
|
||||
if not enabledGit then
|
||||
return
|
||||
end
|
||||
|
||||
git.push()
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("VimEnter", {
|
||||
callback = function()
|
||||
if not enabledGit then
|
||||
return
|
||||
end
|
||||
|
||||
git.pull()
|
||||
end,
|
||||
})
|
||||
|
|
|
|||
60
.config/nvim/lua/functions/git.lua
Normal file
60
.config/nvim/lua/functions/git.lua
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
local nio = require("nio")
|
||||
local git = {}
|
||||
|
||||
function git.commitFile(filepath)
|
||||
local function get_file_name(file)
|
||||
return vim.fn.fnamemodify(file, ":t:r")
|
||||
end
|
||||
|
||||
local commitMessage = get_file_name(filepath) .. "-" .. os.date("%m_%B_%Y")
|
||||
|
||||
os.execute('git add "' .. filepath .. '"')
|
||||
local commitCommand = 'git commit -m "' .. commitMessage .. '" &> /dev/null'
|
||||
local commitResult = os.execute(commitCommand)
|
||||
|
||||
print("Commiting... " .. commitMessage)
|
||||
if commitResult == 256 then
|
||||
print("Nothing to commit")
|
||||
return
|
||||
elseif commitResult == 0 then
|
||||
print("Commit complete")
|
||||
else
|
||||
print("Unknown Error " .. commitResult)
|
||||
print(commitCommand)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
function git.push()
|
||||
print("Pushing changes...")
|
||||
-- Push twice, in case the credentials expired. Ugly hack, but it works
|
||||
local pushSuccess = os.execute("git push &> /dev/null")
|
||||
if pushSuccess > 0 then
|
||||
os.execute("git push &> /dev/null")
|
||||
end
|
||||
|
||||
print("Done")
|
||||
end
|
||||
|
||||
function git.pull()
|
||||
nio.run(function()
|
||||
local pullProcess = nio.process.run({
|
||||
cmd = "git",
|
||||
args = { "pull", "--rebase", "--quiet", "--no-edit" },
|
||||
})
|
||||
|
||||
local pullSuccess = pullProcess.result(true)
|
||||
if pullSuccess == 256 then
|
||||
vim.notify("Conflicts found. Please resolve and continue rebase", "error", {
|
||||
title = "Updating...",
|
||||
})
|
||||
return
|
||||
end
|
||||
|
||||
vim.notify("Pull success", "info", {
|
||||
title = "Updating...",
|
||||
})
|
||||
end)
|
||||
end
|
||||
|
||||
return git
|
||||
6
.config/nvim/lua/plugins/buffer-closer.lua
Normal file
6
.config/nvim/lua/plugins/buffer-closer.lua
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
return {
|
||||
"psjay/buffer-closer.nvim",
|
||||
config = function()
|
||||
require("buffer-closer").setup()
|
||||
end,
|
||||
}
|
||||
4
.config/nvim/lua/plugins/bullets.lua
Normal file
4
.config/nvim/lua/plugins/bullets.lua
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
return {
|
||||
"bullets-vim/bullets.vim",
|
||||
version = "*"
|
||||
}
|
||||
5
.config/nvim/lua/plugins/git-conflict.lua
Normal file
5
.config/nvim/lua/plugins/git-conflict.lua
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
return {
|
||||
"akinsho/git-conflict.nvim",
|
||||
version = "*",
|
||||
config = true,
|
||||
}
|
||||
24
.config/nvim/lua/plugins/neotree.lua
Normal file
24
.config/nvim/lua/plugins/neotree.lua
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
return {
|
||||
"nvim-neo-tree/neo-tree.nvim",
|
||||
opts = {
|
||||
window = {
|
||||
width = 40,
|
||||
},
|
||||
filesystem = {
|
||||
window = {
|
||||
mappings = {
|
||||
["<C-l>"] = function(state)
|
||||
local node = state.tree:get_node()
|
||||
|
||||
if vim.fn.fnamemodify(node.path, ":e") == "opto" then
|
||||
vim.cmd.Optolith()
|
||||
return
|
||||
end
|
||||
|
||||
os.execute(string.format('xdg-open "%s" &> /dev/null &', node.path))
|
||||
end,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
3
.config/nvim/lua/plugins/nio.lua
Normal file
3
.config/nvim/lua/plugins/nio.lua
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
return {
|
||||
"nvim-neotest/nvim-nio",
|
||||
}
|
||||
21
.config/nvim/lua/plugins/obsidian.lua
Normal file
21
.config/nvim/lua/plugins/obsidian.lua
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
return {
|
||||
"epwalsh/obsidian.nvim",
|
||||
version = "*",
|
||||
lazy = true,
|
||||
ft = "markdown",
|
||||
dependencies = {
|
||||
-- Required.
|
||||
"nvim-lua/plenary.nvim",
|
||||
},
|
||||
opts = {
|
||||
ui = {
|
||||
enable = true,
|
||||
},
|
||||
workspaces = {
|
||||
{
|
||||
name = "notes",
|
||||
path = ".",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
17
.config/nvim/lua/plugins/render-markdown.lua
Normal file
17
.config/nvim/lua/plugins/render-markdown.lua
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
return {
|
||||
"MeanderingProgrammer/render-markdown.nvim",
|
||||
dependencies = { "nvim-treesitter/nvim-treesitter", "echasnovski/mini.nvim" }, -- if you use the mini.nvim suite
|
||||
opts = {},
|
||||
config = function()
|
||||
require("render-markdown").setup({
|
||||
bullet = {},
|
||||
anti_conceal = {
|
||||
enabled = false,
|
||||
},
|
||||
preset = "obsidian",
|
||||
heading = {
|
||||
position = "inline",
|
||||
},
|
||||
})
|
||||
end,
|
||||
}
|
||||
22
.config/nvim/lua/plugins/style.lua
Normal file
22
.config/nvim/lua/plugins/style.lua
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
-- since this is just an example spec, don't actually load anything here and return an empty spec
|
||||
-- stylua: ignore
|
||||
if false then return {} end
|
||||
|
||||
-- every spec file under the "plugins" directory will be loaded automatically by lazy.nvim
|
||||
--
|
||||
-- In your plugin files, you can:
|
||||
-- * add extra plugins
|
||||
-- * disable/enabled LazyVim plugins
|
||||
-- * override the configuration of LazyVim plugins
|
||||
return {
|
||||
-- add gruvbox
|
||||
{ "ellisonleao/gruvbox.nvim" },
|
||||
|
||||
-- Configure LazyVim to load gruvbox
|
||||
{
|
||||
"LazyVim/LazyVim",
|
||||
opts = {
|
||||
colorscheme = "gruvbox",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -7,9 +7,8 @@ export EDITOR="$VISUAL"
|
|||
alias ls='ls --color=auto'
|
||||
alias grep='grep --color=auto'
|
||||
alias vim='nvim'
|
||||
alias note='(cd ~/Notes/ && nvim ~/Notes/)'
|
||||
alias note-diary='(cd ~/Notes/ && nvim ~/Notes/Diary.md)'
|
||||
alias note-dsa='(cd ~/DSA/ && nvim ~/DSA/)'
|
||||
alias doch='sudo "$BASH" -c "$(history -p !!)"'
|
||||
alias note='(cd ~/Notes/ && ENABLE_GIT_SETUP=true nvim ~/Notes/)'
|
||||
alias note-diary='(cd ~/Notes/ && ENABLE_GIT_SETUP=true nvim ~/Notes/Diary.md)'
|
||||
alias note-dsa='(cd ~/DSA/ && ENABLE_GIT_SETUP=true nvim ~/DSA/)'
|
||||
|
||||
eval "$(zoxide init bash --cmd cd)"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue