summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-01-17 01:02:10 +0100
committerHampusM <hampus@hampusmat.com>2024-01-17 01:02:10 +0100
commitcd6efe97c41be6ec5ccda57b53a835968acfdd79 (patch)
tree03896977c42b3d86c58134c4fe57195b3d133944 /lua
parent635b69ac3f88cacc30a862809d138d072d55ad3b (diff)
octoocto
Diffstat (limited to 'lua')
-rw-r--r--lua/autocommands/buffer.lua4
-rw-r--r--lua/functions.lua72
-rw-r--r--lua/plugins.lua18
3 files changed, 93 insertions, 1 deletions
diff --git a/lua/autocommands/buffer.lua b/lua/autocommands/buffer.lua
index da330c8..798baa6 100644
--- a/lua/autocommands/buffer.lua
+++ b/lua/autocommands/buffer.lua
@@ -2,3 +2,7 @@ require("utility.autocmd")
-- autocmd("BufEnter", "*", "lua remove_hidden_windowless_buffers()")
+autocmd("BufEnter", "octo://*/*/review*", "lua prepare_pr_review_curr_buf()")
+
+autocmd("BufLeave", "octo://*/*/review*", "lua unprepare_pr_review_curr_buf()")
+
diff --git a/lua/functions.lua b/lua/functions.lua
index 12eca3a..8278ff0 100644
--- a/lua/functions.lua
+++ b/lua/functions.lua
@@ -12,6 +12,23 @@ function table.filter(list, predicate)
return filtered_list
end
+local function split(inputstr, sep)
+ if sep == nil then
+ sep = "%s"
+ end
+ local t={}
+ for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
+ table.insert(t, str)
+ end
+ return t
+end
+
+local function file_exists(name)
+ local f=io.open(name,"r")
+
+ if f~=nil then io.close(f) return true else return false end
+end
+
function _G.check_back_space()
local col = vim.api.nvim_win_get_cursor(0)[2]
@@ -122,3 +139,58 @@ function _G.close_current_buffer()
end
end
+num = vim.fn.system("od -A n -t d -N 3 /dev/random")
+
+num = num:gsub("%s+", "")
+num = num:gsub("%s+", "")
+
+function _G.prepare_pr_review_curr_buf()
+ local buf_name = vim.fn.bufname()
+
+ local buf_name_parts = split(buf_name, "/")
+
+ local buf_file = buf_name_parts[#buf_name_parts]
+ local side = buf_name_parts[#buf_name_parts - 1]
+
+ local tmp_file = "/tmp/nvim-pr-review-" .. num .. "-"
+ .. side .. "-" .. buf_file
+
+ if file_exists(tmp_file) then
+ return
+ end
+
+ local lines = vim.api.nvim_buf_get_lines(0, 0, -1, true)
+
+ local file = io.open(tmp_file, "a")
+
+ if file == nil then
+ error("Temporary file not created")
+ return
+ end
+
+ for _, line in next, lines, nil do
+ file:write(line)
+ end
+
+ file:close()
+
+ vim.api.nvim_buf_set_name(0, tmp_file)
+end
+
+function _G.unprepare_pr_review_curr_buf()
+ local buf_name = vim.fn.bufname()
+
+ local buf_name_parts = split(buf_name, "/")
+
+ local buf_file = buf_name_parts[#buf_name_parts]
+ local side = buf_name_parts[#buf_name_parts - 1]
+
+ local tmp_file = "/tmp/nvim-pr-review-" .. num .. "-"
+ .. side .. "-" .. buf_file
+
+ if file_exists(tmp_file) == false then
+ return
+ end
+
+ os.remove(tmp_file)
+end
diff --git a/lua/plugins.lua b/lua/plugins.lua
index 481bc87..e0a4122 100644
--- a/lua/plugins.lua
+++ b/lua/plugins.lua
@@ -14,7 +14,8 @@ return require("packer").startup(function(use)
use "lukas-reineke/indent-blankline.nvim"
-- Coc
- use {"neoclide/coc.nvim", branch = "release"}
+ -- use {"neoclide/coc.nvim", branch = "release"}
+ use { "/home/hampus/Projects/coc.nvim", run = "yarn install --frozen-lockfile" }
-- Syntax
use "tikhomirov/vim-glsl"
@@ -35,4 +36,19 @@ return require("packer").startup(function(use)
-- Formatting
use "alx741/vim-rustfmt"
+
+ use {
+ "pwntester/octo.nvim",
+ commit = "c6b008434d684e746a40e443876b646b521cebbf",
+ requires = {
+ "nvim-lua/plenary.nvim",
+ "nvim-telescope/telescope.nvim",
+ "nvim-tree/nvim-web-devicons",
+ },
+ config = function ()
+ require "octo".setup()
+ end
+ }
+
+ use "PhilRunninger/nerdtree-visual-selection"
end)