aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--dot_config/mpv/scripts/webtorrent-hook.lua212
-rw-r--r--dot_config/nvim/lua/config/options.lua1
-rw-r--r--dot_config/nvim/lua/plugins/git.lua12
-rw-r--r--dot_config/nvim/lua/plugins/init.lua28
-rw-r--r--dot_config/nvim/lua/plugins/lsp.lua21
-rw-r--r--dot_config/nvim/lua/plugins/treesitter.lua74
6 files changed, 212 insertions, 136 deletions
diff --git a/dot_config/mpv/scripts/webtorrent-hook.lua b/dot_config/mpv/scripts/webtorrent-hook.lua
index 80d991f..536d3da 100644
--- a/dot_config/mpv/scripts/webtorrent-hook.lua
+++ b/dot_config/mpv/scripts/webtorrent-hook.lua
@@ -5,132 +5,152 @@
-- for any item in playlist to see if it matches stored entry
local settings = {
- close_webtorrent = true,
- remove_files = true,
- download_directory = "/tmp/webtorrent",
- webtorrent_flags = "",
- webtorrent_verbosity = "speed"
+ close_webtorrent = true,
+ remove_files = true,
+ download_directory = "/tmp/webtorrent",
+ webtorrent_flags = "",
+ webtorrent_verbosity = "speed",
}
-(require "mp.options").read_options(settings, "webtorrent-hook")
+(require("mp.options")).read_options(settings, "webtorrent-hook")
local open_videos = {}
-- http://lua-users.org/wiki/StringRecipes
local function ends_with(str, ending)
- return ending == "" or str:sub(-#ending) == ending
+ return ending == "" or str:sub(-#ending) == ending
end
-- https://stackoverflow.com/questions/132397/get-back-the-output-of-os-execute-in-lua
function os.capture(cmd, decolorize, raw)
- if decolorize then
- -- https://github.com/webtorrent/webtorrent-cli/issues/132
- -- TODO webtorrent should have a way to just print json information with
- -- no colors
- -- https://stackoverflow.com/questions/19296667/remove-ansi-color-codes-from-a-text-file-using-bash/30938702#30938702
- cmd = cmd .. " | sed -r 's/\\x1B\\[(([0-9]{1,2})?(;)?([0-9]{1,2})?)?[m,K,H,f,J]//g'"
- end
- local f = assert(io.popen(cmd, 'r'))
- local s = assert(f:read('*a'))
- f:close()
- if raw then return s end
- s = string.gsub(s, '^%s+', '')
- s = string.gsub(s, '%s+$', '')
- -- s = string.gsub(s, '[\n\r]+', ' ')
- return s
+ if decolorize then
+ -- https://github.com/webtorrent/webtorrent-cli/issues/132
+ -- TODO webtorrent should have a way to just print json information with
+ -- no colors
+ -- https://stackoverflow.com/questions/19296667/remove-ansi-color-codes-from-a-text-file-using-bash/30938702#30938702
+ cmd = cmd
+ .. " | sed -r 's/\\x1B\\[(([0-9]{1,2})?(;)?([0-9]{1,2})?)?[m,K,H,f,J]//g'"
+ end
+ local f = assert(io.popen(cmd, "r"))
+ local s = assert(f:read("*a"))
+ f:close()
+ if raw then
+ return s
+ end
+ s = string.gsub(s, "^%s+", "")
+ s = string.gsub(s, "%s+$", "")
+ -- s = string.gsub(s, '[\n\r]+', ' ')
+ return s
end
function read_file(file)
- local fh = assert(io.open(file, "rb"))
- local contents = fh:read("*all")
- fh:close()
- return contents
+ local fh = assert(io.open(file, "rb"))
+ local contents = fh:read("*all")
+ fh:close()
+ return contents
end
function play_torrent()
- local url = mp.get_property("stream-open-filename")
- if (url:find("magnet:") == 1 or url:find("peerflix://") == 1
- or url:find("webtorrent://") == 1 or ends_with(url, "torrent")) then
- if url:find("webtorrent://") == 1 then
- url = url:sub(14)
- end
- if url:find("peerflix://") == 1 then
- url = url:sub(12)
- end
+ local url = mp.get_property("stream-open-filename")
+ if
+ url:find("magnet:") == 1
+ or url:find("peerflix://") == 1
+ or url:find("webtorrent://") == 1
+ or ends_with(url, "torrent")
+ then
+ if url:find("webtorrent://") == 1 then
+ url = url:sub(14)
+ end
+ if url:find("peerflix://") == 1 then
+ url = url:sub(12)
+ end
- os.execute("mkdir -p " .. settings.download_directory)
- -- don't reuse files (so multiple mpvs works)
- local output_file = settings.download_directory
- .. "/webtorrent-output-" .. mp.get_time() .. ".log"
- -- --keep-seeding is to prevent webtorrent from quitting once the download
- -- is done
- local webtorrent_command = "webtorrent "
- .. settings.webtorrent_flags
- .. " --out '" .. settings.download_directory .. "' --keep-seeding \""
- .. url .. "\" > " .. output_file .. " 2>&1 & echo $!"
- mp.msg.info("Starting webtorrent server")
- mp.msg.info(webtorrent_command)
- local pid = os.capture(webtorrent_command)
- mp.msg.info("Waiting for webtorrent server")
+ os.execute("mkdir -p " .. settings.download_directory)
+ -- don't reuse files (so multiple mpvs works)
+ local output_file = settings.download_directory
+ .. "/webtorrent-output-"
+ .. mp.get_time()
+ .. ".log"
+ -- --keep-seeding is to prevent webtorrent from quitting once the download
+ -- is done
+ local webtorrent_command = "webtorrent "
+ .. settings.webtorrent_flags
+ .. " --out '"
+ .. settings.download_directory
+ .. "' --keep-seeding \""
+ .. url
+ .. '" > '
+ .. output_file
+ .. " 2>&1 & echo $!"
+ mp.msg.info("Starting webtorrent server")
+ mp.msg.info(webtorrent_command)
+ local pid = os.capture(webtorrent_command)
+ mp.msg.info("Waiting for webtorrent server")
- local url_command = "tail -f " .. output_file
- .. " | awk '/Server running at:/ {print $4; exit}'"
- local url = os.capture(url_command, true)
- mp.msg.info("Webtorrent server is up")
+ local url_command = "tail -f "
+ .. output_file
+ .. " | awk '/Server running at:/ {print $4; exit}'"
+ local url = os.capture(url_command, true)
+ mp.msg.info("Webtorrent server is up")
- local title_command = "awk '/(Seeding|Downloading): / "
- .. "{gsub(/(Seeding|Downloading): /, \"\"); print; exit}' "
- .. output_file
- local title = os.capture(title_command, true)
- mp.msg.info("Setting media title to: " .. title)
- mp.set_property("force-media-title", title)
+ local title_command = "awk '/(Seeding|Downloading): / "
+ .. '{gsub(/(Seeding|Downloading): /, ""); print; exit}\' '
+ .. output_file
+ local title = os.capture(title_command, true)
+ mp.msg.info("Setting media title to: " .. title)
+ mp.set_property("force-media-title", title)
- local path
- if title then
- path = settings.download_directory .. "/\"" .. title .. "\""
- end
- open_videos[url] = {title=title,path=path,pid=pid}
+ local path
+ if title then
+ path = settings.download_directory .. '/"' .. title .. '"'
+ end
+ open_videos[url] = { title = title, path = path, pid = pid }
- mp.set_property("stream-open-filename", url)
+ mp.set_property("stream-open-filename", url)
- if settings.webtorrent_verbosity == "speed" then
- local printer_pid
- local printer_pid_file = settings.download_directory
- .. "/webtorrent-printer-" .. mp.get_time() .. ".pid"
- os.execute("tail -f " .. output_file
- .. " | awk '/Speed:/' ORS='\r' & echo -n $! > "
- .. printer_pid_file)
- printer_pid = read_file(printer_pid_file)
- mp.register_event("file-loaded",
- function()
- os.execute("kill " .. printer_pid)
- end
- )
- end
- end
+ if settings.webtorrent_verbosity == "speed" then
+ local printer_pid
+ local printer_pid_file = settings.download_directory
+ .. "/webtorrent-printer-"
+ .. mp.get_time()
+ .. ".pid"
+ os.execute(
+ "tail -f "
+ .. output_file
+ .. " | awk '/Speed:/' ORS='\r' & echo -n $! > "
+ .. printer_pid_file
+ )
+ printer_pid = read_file(printer_pid_file)
+ mp.register_event("file-loaded", function()
+ os.execute("kill " .. printer_pid)
+ end)
+ end
+ end
end
function webtorrent_cleanup()
- local url = mp.get_property("stream-open-filename")
- if settings.close_webtorrent and open_videos[url] then
- local title = open_videos[url].title
- local path = open_videos[url].path
- local pid = open_videos[url].pid
+ local url = mp.get_property("stream-open-filename")
+ if settings.close_webtorrent and open_videos[url] then
+ local title = open_videos[url].title
+ local path = open_videos[url].path
+ local pid = open_videos[url].pid
- if pid then
- mp.msg.info("Closing webtorrent for " .. title .. " with pid " .. pid)
- os.execute("kill " .. pid)
- end
+ if pid then
+ mp.msg.info("Closing webtorrent for " .. title .. " with pid " .. pid)
+ os.execute("kill " .. pid)
+ end
- if settings.remove_files then
- if path then
- mp.msg.info("Removing media file for " .. title .. " with path " .. path)
- os.execute("rm -r " .. path)
- end
+ if settings.remove_files then
+ if path then
+ mp.msg.info(
+ "Removing media file for " .. title .. " with path " .. path
+ )
+ os.execute("rm -r " .. path)
end
+ end
- open_videos[url] = {}
- end
+ open_videos[url] = {}
+ end
end
mp.add_hook("on_load", 50, play_torrent)
diff --git a/dot_config/nvim/lua/config/options.lua b/dot_config/nvim/lua/config/options.lua
index b2409b5..86529f6 100644
--- a/dot_config/nvim/lua/config/options.lua
+++ b/dot_config/nvim/lua/config/options.lua
@@ -111,4 +111,3 @@ opt.sessionoptions =
"blank,buffers,curdir,help,tabpages,winsize,winpos,terminal,localoptions"
opt.exrc = true -- source project-local .nvim.lua files
-
diff --git a/dot_config/nvim/lua/plugins/git.lua b/dot_config/nvim/lua/plugins/git.lua
index b052c33..8f4e571 100644
--- a/dot_config/nvim/lua/plugins/git.lua
+++ b/dot_config/nvim/lua/plugins/git.lua
@@ -101,17 +101,9 @@ require("gitsigns").setup({
nmap("<leader>hC", function()
gs.change_base("~")
end, "git [C]hange base to HEAD")
- nmap(
- "<leader>tgd",
- gs.preview_hunk_inline,
- "[T]oggle [G]it show [D]eleted"
- )
+ nmap("<leader>tgd", gs.preview_hunk_inline, "[T]oggle [G]it show [D]eleted")
nmap("<leader>tgw", gs.toggle_word_diff, "[T]oggle [G]it [W]ord diff")
- nmap(
- "<leader>tgl",
- gs.toggle_linehl,
- "[T]oggle [G]it [L]ine highlighting"
- )
+ nmap("<leader>tgl", gs.toggle_linehl, "[T]oggle [G]it [L]ine highlighting")
-- Text object
map(
{ "o", "x" },
diff --git a/dot_config/nvim/lua/plugins/init.lua b/dot_config/nvim/lua/plugins/init.lua
index b106b6e..24eb70d 100644
--- a/dot_config/nvim/lua/plugins/init.lua
+++ b/dot_config/nvim/lua/plugins/init.lua
@@ -1,9 +1,29 @@
-- Seamless navigation between neovim splits and zellij panes
require("smart-splits").setup({})
-vim.keymap.set("n", "<C-h>", require("smart-splits").move_cursor_left, { desc = "Move to left split/pane" })
-vim.keymap.set("n", "<C-j>", require("smart-splits").move_cursor_down, { desc = "Move to below split/pane" })
-vim.keymap.set("n", "<C-k>", require("smart-splits").move_cursor_up, { desc = "Move to above split/pane" })
-vim.keymap.set("n", "<C-l>", require("smart-splits").move_cursor_right, { desc = "Move to right split/pane" })
+vim.keymap.set(
+ "n",
+ "<C-h>",
+ require("smart-splits").move_cursor_left,
+ { desc = "Move to left split/pane" }
+)
+vim.keymap.set(
+ "n",
+ "<C-j>",
+ require("smart-splits").move_cursor_down,
+ { desc = "Move to below split/pane" }
+)
+vim.keymap.set(
+ "n",
+ "<C-k>",
+ require("smart-splits").move_cursor_up,
+ { desc = "Move to above split/pane" }
+)
+vim.keymap.set(
+ "n",
+ "<C-l>",
+ require("smart-splits").move_cursor_right,
+ { desc = "Move to right split/pane" }
+)
require("which-key").setup({
spec = {
diff --git a/dot_config/nvim/lua/plugins/lsp.lua b/dot_config/nvim/lua/plugins/lsp.lua
index ddd5bea..e9b7e84 100644
--- a/dot_config/nvim/lua/plugins/lsp.lua
+++ b/dot_config/nvim/lua/plugins/lsp.lua
@@ -120,16 +120,8 @@ vim.api.nvim_create_autocmd("LspAttach", {
nmap("<leader>ci", fzf.lsp_incoming_calls, "[C]ode [I]ncoming calls")
nmap("<leader>co", fzf.lsp_outgoing_calls, "[C]ode [O]utgoing calls")
nmap("gO", fzf.lsp_document_symbols, "d[O]ocument symbols")
- nmap(
- "<leader>ws",
- fzf.lsp_live_workspace_symbols,
- "[W]orkspace [S]ymbols"
- )
- nmap(
- "<leader>wd",
- fzf.diagnostics_workspace,
- "[W]orkspace [D]iagnostics"
- )
+ nmap("<leader>ws", fzf.lsp_live_workspace_symbols, "[W]orkspace [S]ymbols")
+ nmap("<leader>wd", fzf.diagnostics_workspace, "[W]orkspace [D]iagnostics")
local client = vim.lsp.get_client_by_id(event.data.client_id)
if
@@ -154,10 +146,7 @@ vim.api.nvim_create_autocmd("LspAttach", {
})
vim.api.nvim_create_autocmd("LspDetach", {
- group = vim.api.nvim_create_augroup(
- "lsp-detach",
- { clear = true }
- ),
+ group = vim.api.nvim_create_augroup("lsp-detach", { clear = true }),
callback = function(event2)
vim.lsp.buf.clear_references()
vim.api.nvim_clear_autocmds({
@@ -186,9 +175,7 @@ vim.api.nvim_create_autocmd("LspAttach", {
)
then
nmap("<leader>th", function()
- vim.lsp.inlay_hint.enable(
- not vim.lsp.inlay_hint.is_enabled(event.buf)
- )
+ vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled(event.buf))
end, "[T]oggle Inlay [H]ints")
end
end,
diff --git a/dot_config/nvim/lua/plugins/treesitter.lua b/dot_config/nvim/lua/plugins/treesitter.lua
index a4a488c..69902c6 100644
--- a/dot_config/nvim/lua/plugins/treesitter.lua
+++ b/dot_config/nvim/lua/plugins/treesitter.lua
@@ -1,13 +1,71 @@
require("treewalker").setup({})
-vim.keymap.set({ "n", "v" }, "<a-k>", "<cmd>Treewalker Up<cr>", { silent = true, desc = "Moves up to the previous neighbor node" })
-vim.keymap.set({ "n", "v" }, "<a-j>", "<cmd>Treewalker Down<cr>", { silent = true, desc = "Moves up to the next neighbor node" })
-vim.keymap.set({ "n", "v" }, "<a-h>", "<cmd>Treewalker Left<cr>", { silent = true, desc = "Moves to the first ancestor node that's on a different line from the current node" })
-vim.keymap.set({ "n", "v" }, "<a-l>", "<cmd>Treewalker Right<cr>", { silent = true, desc = "Moves to the next node down that's indented further than the current node" })
-vim.keymap.set("n", "<s-a-k>", "<cmd>Treewalker SwapUp<cr>", { silent = true, desc = "Swaps the highest node on the line upwards in the document" })
-vim.keymap.set("n", "<s-a-j>", "<cmd>Treewalker SwapDown<cr>", { silent = true, desc = "Swaps the biggest node on the line downward in the document" })
-vim.keymap.set("n", "<s-a-h>", "<cmd>Treewalker SwapLeft<cr>", { silent = true, desc = "Swap the node under the cursor with its previous neighbor" })
-vim.keymap.set("n", "<s-a-l>", "<cmd>Treewalker SwapRight<cr>", { silent = true, desc = "Swap the node under the cursor with its next neighbor" })
+vim.keymap.set(
+ { "n", "v" },
+ "<a-k>",
+ "<cmd>Treewalker Up<cr>",
+ { silent = true, desc = "Moves up to the previous neighbor node" }
+)
+vim.keymap.set(
+ { "n", "v" },
+ "<a-j>",
+ "<cmd>Treewalker Down<cr>",
+ { silent = true, desc = "Moves up to the next neighbor node" }
+)
+vim.keymap.set(
+ { "n", "v" },
+ "<a-h>",
+ "<cmd>Treewalker Left<cr>",
+ {
+ silent = true,
+ desc = "Moves to the first ancestor node that's on a different line from the current node",
+ }
+)
+vim.keymap.set(
+ { "n", "v" },
+ "<a-l>",
+ "<cmd>Treewalker Right<cr>",
+ {
+ silent = true,
+ desc = "Moves to the next node down that's indented further than the current node",
+ }
+)
+vim.keymap.set(
+ "n",
+ "<s-a-k>",
+ "<cmd>Treewalker SwapUp<cr>",
+ {
+ silent = true,
+ desc = "Swaps the highest node on the line upwards in the document",
+ }
+)
+vim.keymap.set(
+ "n",
+ "<s-a-j>",
+ "<cmd>Treewalker SwapDown<cr>",
+ {
+ silent = true,
+ desc = "Swaps the biggest node on the line downward in the document",
+ }
+)
+vim.keymap.set(
+ "n",
+ "<s-a-h>",
+ "<cmd>Treewalker SwapLeft<cr>",
+ {
+ silent = true,
+ desc = "Swap the node under the cursor with its previous neighbor",
+ }
+)
+vim.keymap.set(
+ "n",
+ "<s-a-l>",
+ "<cmd>Treewalker SwapRight<cr>",
+ {
+ silent = true,
+ desc = "Swap the node under the cursor with its next neighbor",
+ }
+)
require("nvim-treesitter").install({
"awk",