mirror of
https://github.com/LazyVim/starter.git
synced 2026-07-25 14:01:03 +00:00
Personal changes
This commit is contained in:
parent
92b2689e6f
commit
15ac692c65
21 changed files with 646 additions and 3 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -6,3 +6,6 @@ debug
|
||||||
foo.*
|
foo.*
|
||||||
*.log
|
*.log
|
||||||
data
|
data
|
||||||
|
.luarc.json
|
||||||
|
lazy-lock.json
|
||||||
|
lazyvim.json
|
||||||
|
|
|
||||||
4
.gitmodules
vendored
Normal file
4
.gitmodules
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
[submodule "thirdparty/json"]
|
||||||
|
path = thirdparty/json
|
||||||
|
url = https://github.com/rxi/json.lua.git
|
||||||
|
branch = master
|
||||||
2
init.lua
2
init.lua
|
|
@ -1,2 +1,4 @@
|
||||||
-- bootstrap lazy.nvim, LazyVim and your plugins
|
-- bootstrap lazy.nvim, LazyVim and your plugins
|
||||||
require("config.lazy")
|
require("config.lazy")
|
||||||
|
require("user.toggleterm")
|
||||||
|
require("user.csearchpath")
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,9 @@ require("lazy").setup({
|
||||||
-- add LazyVim and import its plugins
|
-- add LazyVim and import its plugins
|
||||||
{ "LazyVim/LazyVim", import = "lazyvim.plugins" },
|
{ "LazyVim/LazyVim", import = "lazyvim.plugins" },
|
||||||
-- import any extras modules here
|
-- import any extras modules here
|
||||||
-- { import = "lazyvim.plugins.extras.lang.typescript" },
|
{ import = "lazyvim.plugins.extras.lang.typescript" },
|
||||||
-- { import = "lazyvim.plugins.extras.lang.json" },
|
{ import = "lazyvim.plugins.extras.lang.json" },
|
||||||
-- { import = "lazyvim.plugins.extras.ui.mini-animate" },
|
{ import = "lazyvim.plugins.extras.ui.mini-animate" },
|
||||||
-- import/override with your plugins
|
-- import/override with your plugins
|
||||||
{ import = "plugins" },
|
{ import = "plugins" },
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
-- Options are automatically loaded before lazy.nvim startup
|
-- Options are automatically loaded before lazy.nvim startup
|
||||||
-- Default options that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/options.lua
|
-- Default options that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/options.lua
|
||||||
-- Add any additional options here
|
-- Add any additional options here
|
||||||
|
|
||||||
|
vim.opt.winbar = "%=%m %f"
|
||||||
|
|
|
||||||
7
lua/plugins/gist.lua
Normal file
7
lua/plugins/gist.lua
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
return {
|
||||||
|
{
|
||||||
|
"mattn/vim-gist",
|
||||||
|
event = "BufRead",
|
||||||
|
dependencies = "mattn/webapi-vim",
|
||||||
|
},
|
||||||
|
}
|
||||||
29
lua/plugins/goto-preview.lua
Normal file
29
lua/plugins/goto-preview.lua
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
return {
|
||||||
|
{
|
||||||
|
"rmagatti/goto-preview",
|
||||||
|
config = function()
|
||||||
|
require("goto-preview").setup({
|
||||||
|
width = 120, -- Width of the floating windowconfig
|
||||||
|
height = 25, -- Height of the floating window
|
||||||
|
default_mappings = true, -- Bind default mappings
|
||||||
|
debug = false, -- Print debug information
|
||||||
|
opacity = nil, -- 0-100 opacity level of the floating window where 100 is fully transparent.
|
||||||
|
post_open_hook = nil, -- A function taking two arguments, a buffer and a window to be ran as a hook.
|
||||||
|
references = { -- Configure the telescope UI for slowing the references cycling window.
|
||||||
|
-- telescope = telescope.themes.get_dropdown({ hide_preview = false })
|
||||||
|
},
|
||||||
|
-- These two configs can also be passed down to the goto-preview definition and implementation calls for one off "peak" functionality.
|
||||||
|
focus_on_open = true, -- Focus the floating window when opening it.
|
||||||
|
dismiss_on_move = false, -- Dismiss the floating window when moving the cursor.
|
||||||
|
force_close = true, -- passed into vim.api.nvim_win_close's second argument. See :h nvim_win_close
|
||||||
|
bufhidden = "wipe", -- the bufhidden option to set on the floating window. See :h bufhidden
|
||||||
|
|
||||||
|
-- You can use "default_mappings = true" setup option
|
||||||
|
-- Or explicitly set keybindings
|
||||||
|
-- vim.cmd("nnoremap gpd <cmd>lua require('goto-preview').goto_preview_definition()<CR>")
|
||||||
|
-- vim.cmd("nnoremap gpi <cmd>lua require('goto-preview').goto_preview_implementation()<CR>")
|
||||||
|
-- vim.cmd("nnoremap gP <cmd>lua require('goto-preview').close_all_win()<CR>")
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
}
|
||||||
10
lua/plugins/lualine.lua
Normal file
10
lua/plugins/lualine.lua
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
return {
|
||||||
|
-- the opts function can also be used to change the default opts:
|
||||||
|
{
|
||||||
|
"nvim-lualine/lualine.nvim",
|
||||||
|
event = "VeryLazy",
|
||||||
|
opts = function(_, opts)
|
||||||
|
table.insert(opts.sections.lualine_x, "😄")
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
}
|
||||||
14
lua/plugins/octo.lua
Normal file
14
lua/plugins/octo.lua
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
return {
|
||||||
|
{
|
||||||
|
"pwntester/octo.nvim",
|
||||||
|
cmd = "Octo",
|
||||||
|
dependencies = {
|
||||||
|
"nvim-lua/plenary.nvim",
|
||||||
|
"nvim-telescope/telescope.nvim",
|
||||||
|
"nvim-tree/nvim-web-devicons",
|
||||||
|
},
|
||||||
|
config = function()
|
||||||
|
require("octo").setup()
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
}
|
||||||
54
lua/plugins/supertab.lua
Normal file
54
lua/plugins/supertab.lua
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
return {
|
||||||
|
-- Use <tab> for completion and snippets (supertab)
|
||||||
|
-- first: disable default <tab> and <s-tab> behavior in LuaSnip
|
||||||
|
{
|
||||||
|
"L3MON4D3/LuaSnip",
|
||||||
|
keys = function()
|
||||||
|
return {}
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
-- then: setup supertab in cmp
|
||||||
|
{
|
||||||
|
"hrsh7th/nvim-cmp",
|
||||||
|
dependencies = {
|
||||||
|
"hrsh7th/cmp-emoji",
|
||||||
|
},
|
||||||
|
---@param opts cmp.ConfigSchema
|
||||||
|
opts = function(_, opts)
|
||||||
|
local has_words_before = function()
|
||||||
|
table.insert(opts.sources, { name = "emoji" })
|
||||||
|
unpack = unpack or table.unpack
|
||||||
|
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||||
|
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local luasnip = require("luasnip")
|
||||||
|
local cmp = require("cmp")
|
||||||
|
|
||||||
|
opts.mapping = vim.tbl_extend("force", opts.mapping, {
|
||||||
|
["<Tab>"] = cmp.mapping(function(fallback)
|
||||||
|
if cmp.visible() then
|
||||||
|
cmp.select_next_item()
|
||||||
|
-- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
|
||||||
|
-- this way you will only jump inside the snippet region
|
||||||
|
elseif luasnip.expand_or_jumpable() then
|
||||||
|
luasnip.expand_or_jump()
|
||||||
|
elseif has_words_before() then
|
||||||
|
cmp.complete()
|
||||||
|
else
|
||||||
|
fallback()
|
||||||
|
end
|
||||||
|
end, { "i", "s" }),
|
||||||
|
["<S-Tab>"] = cmp.mapping(function(fallback)
|
||||||
|
if cmp.visible() then
|
||||||
|
cmp.select_prev_item()
|
||||||
|
elseif luasnip.jumpable(-1) then
|
||||||
|
luasnip.jump(-1)
|
||||||
|
else
|
||||||
|
fallback()
|
||||||
|
end
|
||||||
|
end, { "i", "s" }),
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
}
|
||||||
8
lua/plugins/symbols-outline.lua
Normal file
8
lua/plugins/symbols-outline.lua
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
return {
|
||||||
|
{
|
||||||
|
"simrat39/symbols-outline.nvim",
|
||||||
|
cmd = "SymbolsOutline",
|
||||||
|
keys = { { "<leader>cs", "<cmd>SymbolsOutline<cr>", desc = "Symbols Outline" } },
|
||||||
|
config = true,
|
||||||
|
},
|
||||||
|
}
|
||||||
12
lua/plugins/telescope-fzf-native.lua
Normal file
12
lua/plugins/telescope-fzf-native.lua
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
return {
|
||||||
|
{
|
||||||
|
"telescope.nvim",
|
||||||
|
dependencies = {
|
||||||
|
"nvim-telescope/telescope-fzf-native.nvim",
|
||||||
|
build = "make",
|
||||||
|
config = function()
|
||||||
|
require("telescope").load_extension("fzf")
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
41
lua/plugins/toggleterm.lua
Normal file
41
lua/plugins/toggleterm.lua
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
return {
|
||||||
|
{
|
||||||
|
"akinsho/toggleterm.nvim",
|
||||||
|
version = "*",
|
||||||
|
config = true,
|
||||||
|
keys = {
|
||||||
|
-- horizontal bash
|
||||||
|
{ "<leader>th", "<cmd>lua TermToggleBash('horizontal')<cr>", desc = "H-Bash" },
|
||||||
|
{
|
||||||
|
"<a-1>",
|
||||||
|
mode = { "n", "v", "t" },
|
||||||
|
"<cmd> lua TermToggleBash('horizontal')<cr>",
|
||||||
|
desc = "H-Bash",
|
||||||
|
},
|
||||||
|
-- float bash
|
||||||
|
{ "<leader>tf", "<cmd>lua TermToggleBash('float')<cr>", desc = "Bash" },
|
||||||
|
{
|
||||||
|
"<a-2>",
|
||||||
|
mode = { "n", "v", "t" },
|
||||||
|
"<cmd> lua TermToggleBash('float')<cr>",
|
||||||
|
desc = "Bash",
|
||||||
|
},
|
||||||
|
-- containers
|
||||||
|
{ "<leader>tc", "<cmd>lua TermToggleContainer('float')<cr>", desc = "Container" },
|
||||||
|
{ "<a-3>", mode = { "n", "x", "o", "t" }, "<cmd>lua TermToggleContainer('float')<cr>", desc = "Container" },
|
||||||
|
-- ssh
|
||||||
|
{ "<leader>ts", "<cmd>lua TermToggleSsh('float')<cr>", desc = "ssh" },
|
||||||
|
{ "<a-4>", mode = { "n", "x", "o", "t" }, "<cmd>lua TermToggleSsh('float')<cr>", desc = "ssh" },
|
||||||
|
-- python
|
||||||
|
{ "<leader>tp", "<cmd>lua TermTogglePython('float')<cr>", desc = "Python" },
|
||||||
|
{ "<a-5>", mode = { "n", "x", "o", "t" }, "<cmd>lua TermTogglePython('float')<cr>", desc = "Python" },
|
||||||
|
-- node
|
||||||
|
{ "<leader>tn", "<cmd>lua TermToggleNode('float')<cr>", desc = "Node" },
|
||||||
|
{ "<a-6>", mode = { "n", "x", "o", "t" }, "<cmd>lua TermToggleNode('float')<cr>", desc = "Node" },
|
||||||
|
-- lua
|
||||||
|
{ "<leader>tl", "<cmd>lua TermToggleLua('float')<cr>", desc = "Lua" },
|
||||||
|
{ "<a-7>", mode = { "n", "x", "o", "t" }, "<cmd>lua TermToggleLua('float')<cr>", desc = "Lua" },
|
||||||
|
--
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
12
lua/plugins/window-picker.lua
Normal file
12
lua/plugins/window-picker.lua
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
return {
|
||||||
|
|
||||||
|
{
|
||||||
|
"s1n7ax/nvim-window-picker",
|
||||||
|
name = "window-picker",
|
||||||
|
event = "VeryLazy",
|
||||||
|
version = "2.*",
|
||||||
|
config = function()
|
||||||
|
require("window-picker").setup()
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
}
|
||||||
56
lua/user/csearchpath.lua
Normal file
56
lua/user/csearchpath.lua
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
-- csearchpath.lua
|
||||||
|
local function script_path()
|
||||||
|
local str = debug.getinfo(2, "S").source:sub(2)
|
||||||
|
return str:match("(.*/)")
|
||||||
|
end
|
||||||
|
|
||||||
|
function CSearchPaths(args)
|
||||||
|
args = args or {}
|
||||||
|
args.cxx = args.cxx or os.getenv("CXX") or "/usr/bin/g++"
|
||||||
|
args.cppflags = args.cppflags or os.getenv("CPPFLAGS") or ""
|
||||||
|
args.paths = args.paths or {}
|
||||||
|
|
||||||
|
local cmd = "bash -c 'export CXX=\""
|
||||||
|
.. string.gsub(args.cxx, '"', '\\"')
|
||||||
|
.. '";'
|
||||||
|
.. 'export CPPFLAGS="'
|
||||||
|
.. string.gsub(args.cppflags, '"', '\\"')
|
||||||
|
.. '";'
|
||||||
|
.. ". "
|
||||||
|
.. script_path()
|
||||||
|
.. "csearchpath.sh"
|
||||||
|
.. ";"
|
||||||
|
.. "csearchpaths'"
|
||||||
|
|
||||||
|
local proc = io.popen(cmd)
|
||||||
|
if proc == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local s = proc:read("*all")
|
||||||
|
proc:close()
|
||||||
|
|
||||||
|
if s == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Add Current working directory
|
||||||
|
vim.opt.path = vim.fn.getcwd() .. "/**"
|
||||||
|
|
||||||
|
-- Add user search paths
|
||||||
|
for _, path in pairs(args.paths) do
|
||||||
|
vim.opt.path = vim.opt.path + path
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Add toolchain search path
|
||||||
|
for path in string.gmatch(s, "[^\r\n]+") do
|
||||||
|
if string.sub(path, 1, 1) ~= "#" then
|
||||||
|
vim.opt.path = vim.opt.path + path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Add system wide includes
|
||||||
|
vim.opt.path = vim.opt.path + ".,/usr/include,,"
|
||||||
|
end
|
||||||
|
|
||||||
|
CSearchPaths()
|
||||||
34
lua/user/csearchpath.sh
Normal file
34
lua/user/csearchpath.sh
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
#export CPPFLAGS=""
|
||||||
|
#export CFLAGS=-std=c99
|
||||||
|
#export CXXFLAGS=-Weffc++
|
||||||
|
|
||||||
|
function cdefines() {
|
||||||
|
local regexp="^#include\s+(<|\")\.\.\.(>|\")\s+search\s+starts\s+here:$"
|
||||||
|
|
||||||
|
while read -r line; do
|
||||||
|
echo "$line"
|
||||||
|
done <<<"$(${CXX} "${CPPFLAGS}" -xc++ -E -dM - </dev/null 2>&1)"
|
||||||
|
}
|
||||||
|
|
||||||
|
function csearchpaths() {
|
||||||
|
local do_print=0
|
||||||
|
local regexp="^#include\s+(<|\")\.\.\.(>|\")\s+search\s+starts\s+here:$"
|
||||||
|
|
||||||
|
while read -r line; do
|
||||||
|
if [[ "${line}" =~ $regexp ]]; then
|
||||||
|
echo "${line}"
|
||||||
|
do_print=1
|
||||||
|
continue
|
||||||
|
elif [ "End of search list." == "${line}" ]; then
|
||||||
|
do_print=0
|
||||||
|
else
|
||||||
|
:
|
||||||
|
fi
|
||||||
|
if [ "${do_print}" == "1" ]; then
|
||||||
|
echo "${line}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
done <<<"$(${CXX} "${CPPFLAGS}" -xc++ -E -v - </dev/null 2>&1)"
|
||||||
|
}
|
||||||
57
lua/user/docker.lua
Normal file
57
lua/user/docker.lua
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
json = require("thirdparty.json.json")
|
||||||
|
utils = require("lua.user.utils")
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
function M.container(args)
|
||||||
|
args = args or { cmd = "list" }
|
||||||
|
|
||||||
|
function list()
|
||||||
|
local proc = io.popen("docker ps -as --no-trunc --format json", "r")
|
||||||
|
if proc == nil then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
lst = {}
|
||||||
|
for line in proc:lines() do
|
||||||
|
t = json.decode(line)
|
||||||
|
lst[t.Image] = t
|
||||||
|
end
|
||||||
|
return true, lst
|
||||||
|
end
|
||||||
|
|
||||||
|
function start(cid)
|
||||||
|
local suc, _, _ = os.execute("docker start " .. cid .. " > /dev/null 2>&1")
|
||||||
|
return suc ~= nil and suc
|
||||||
|
end
|
||||||
|
|
||||||
|
function stop(cid)
|
||||||
|
local suc, _, _ = os.execute("docker stop " .. cid .. " > /dev/null 2>&1")
|
||||||
|
return suc ~= nil and suc
|
||||||
|
end
|
||||||
|
|
||||||
|
function restart(cid)
|
||||||
|
stop(cid)
|
||||||
|
return start(cid)
|
||||||
|
end
|
||||||
|
|
||||||
|
function attach(cid, callback)
|
||||||
|
return start(cid) and callback(cid)
|
||||||
|
end
|
||||||
|
|
||||||
|
if args.cmd == "list" then
|
||||||
|
return list()
|
||||||
|
elseif args.cmd == "start" then
|
||||||
|
return start(args.cid)
|
||||||
|
elseif args.cmd == "stop" then
|
||||||
|
return stop(args.cid)
|
||||||
|
elseif args.cmd == "restart" then
|
||||||
|
return restart(args.cid)
|
||||||
|
elseif args.cmd == "attach" then
|
||||||
|
return attach(args.cid, args.callback)
|
||||||
|
else
|
||||||
|
return list()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
6
lua/user/scratchpad.lua
Normal file
6
lua/user/scratchpad.lua
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
local utils = require("user.utils")
|
||||||
|
|
||||||
|
vim.ui.select({ "apple", "banana", "mango" }, {
|
||||||
|
prompt = "Title",
|
||||||
|
telescope = require("telescope.themes").get_cursor(),
|
||||||
|
}, function(selected) end)
|
||||||
236
lua/user/toggleterm.lua
Normal file
236
lua/user/toggleterm.lua
Normal file
|
|
@ -0,0 +1,236 @@
|
||||||
|
-- toggleterm-config.lua
|
||||||
|
local utils = require("user.utils")
|
||||||
|
local docker = require("user.docker")
|
||||||
|
|
||||||
|
local status_ok, toggleterm = pcall(require, "toggleterm")
|
||||||
|
if not status_ok then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
toggleterm.setup({
|
||||||
|
size = 20,
|
||||||
|
open_mapping = [[<c-\>]],
|
||||||
|
hide_numbers = true,
|
||||||
|
shade_filetypes = {},
|
||||||
|
shade_terminals = true,
|
||||||
|
shading_factor = 2,
|
||||||
|
start_in_insert = true,
|
||||||
|
insert_mappings = true,
|
||||||
|
persist_size = true,
|
||||||
|
direction = "float",
|
||||||
|
close_on_exit = true,
|
||||||
|
shell = vim.o.shell,
|
||||||
|
float_opts = {
|
||||||
|
border = "curved",
|
||||||
|
winblend = 0,
|
||||||
|
highlights = {
|
||||||
|
border = "Normal",
|
||||||
|
background = "Normal",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
---@diagnostic disable-next-line: duplicate-set-field
|
||||||
|
function _G.set_terminal_keymaps()
|
||||||
|
local opts = { noremap = true }
|
||||||
|
vim.api.nvim_buf_set_keymap(0, "t", "<esc>", [[<C-\><C-n>]], opts)
|
||||||
|
vim.api.nvim_buf_set_keymap(0, "t", "jk", [[<C-\><C-n>]], opts)
|
||||||
|
vim.api.nvim_buf_set_keymap(0, "t", "<C-h>", [[<C-\><C-n><C-W>h]], opts)
|
||||||
|
vim.api.nvim_buf_set_keymap(0, "t", "<C-j>", [[<C-\><C-n><C-W>j]], opts)
|
||||||
|
vim.api.nvim_buf_set_keymap(0, "t", "<C-k>", [[<C-\><C-n><C-W>k]], opts)
|
||||||
|
vim.api.nvim_buf_set_keymap(0, "t", "<C-l>", [[<C-\><C-n><C-W>l]], opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.cmd("autocmd! TermOpen term://* lua set_terminal_keymaps()")
|
||||||
|
|
||||||
|
local Terminal = require("toggleterm.terminal").Terminal
|
||||||
|
|
||||||
|
local ids = 0
|
||||||
|
local function next_id()
|
||||||
|
id = ids
|
||||||
|
ids = ids + 1
|
||||||
|
return id
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_ssh_hosts(path)
|
||||||
|
local hosts = {}
|
||||||
|
path = path or os.getenv("HOME") .. "/.ssh/config"
|
||||||
|
|
||||||
|
if type(path) ~= "string" then
|
||||||
|
print("expected arg path of type 'string' actual '" .. type(path))
|
||||||
|
return hosts
|
||||||
|
end
|
||||||
|
|
||||||
|
if not utils.file_exists(path) then
|
||||||
|
print("file '" .. path .. "' do not exist!")
|
||||||
|
return hosts
|
||||||
|
end
|
||||||
|
|
||||||
|
local file = io.open(path, "r")
|
||||||
|
if file == nil then
|
||||||
|
print("could not open file '" .. path .. "'!")
|
||||||
|
return hosts
|
||||||
|
end
|
||||||
|
|
||||||
|
local cur_host = ""
|
||||||
|
for line in file:lines() do
|
||||||
|
for key, value in string.gmatch(line, "%s*(%w+)%s+(.*)") do
|
||||||
|
if key == "Host" then
|
||||||
|
cur_host = string.lower(value)
|
||||||
|
hosts[cur_host] = {}
|
||||||
|
hosts[cur_host][string.lower(key)] = cur_host
|
||||||
|
else
|
||||||
|
hosts[cur_host][string.lower(key)] = value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for k, _ in pairs(hosts) do
|
||||||
|
hosts[k].port = hosts[k].port or 22
|
||||||
|
hosts[k].hostname = hosts[k].hostname or os.getenv("HOSTNAME")
|
||||||
|
hosts[k].user = hosts[k].user or os.getenv("USERNAME")
|
||||||
|
hosts[k].term = nil
|
||||||
|
end
|
||||||
|
hosts.current = nil
|
||||||
|
return hosts
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_containers()
|
||||||
|
local suc, hosts = docker.container({ cmd = "list" })
|
||||||
|
if not suc or hosts == nil then
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
|
||||||
|
for k, _ in pairs(hosts) do
|
||||||
|
hosts[k].term = nil
|
||||||
|
end
|
||||||
|
hosts.current = nil
|
||||||
|
return hosts
|
||||||
|
end
|
||||||
|
|
||||||
|
local bash = {
|
||||||
|
float = {
|
||||||
|
term = nil,
|
||||||
|
size = -1,
|
||||||
|
},
|
||||||
|
vertical = {
|
||||||
|
term = nil,
|
||||||
|
size = 80,
|
||||||
|
},
|
||||||
|
horizontal = {
|
||||||
|
term = nil,
|
||||||
|
size = 20,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function TermToggleBash(direction)
|
||||||
|
direction = direction or "float"
|
||||||
|
if bash[direction].term == nil then
|
||||||
|
bash[direction].term = Terminal:new({
|
||||||
|
id = next_id(),
|
||||||
|
display_name = "bash:" .. direction,
|
||||||
|
cmd = "bash",
|
||||||
|
direction = direction,
|
||||||
|
hidden = true,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
bash[direction].term:toggle(bash[direction].size, direction)
|
||||||
|
end
|
||||||
|
|
||||||
|
local lazygit = nil
|
||||||
|
function TermToggleLazyGit()
|
||||||
|
if lazygit == nil then
|
||||||
|
lazygit = Terminal:new({ id = next_id(), display_name = "lazygit", cmd = "lazygit", hidden = true })
|
||||||
|
end
|
||||||
|
lazygit:toggle()
|
||||||
|
end
|
||||||
|
|
||||||
|
local lua = nil
|
||||||
|
function TermToggleLua()
|
||||||
|
if lua == nil then
|
||||||
|
lua = Terminal:new({ id = next_id(), display_name = "Lua", cmd = "lua", hidden = true })
|
||||||
|
end
|
||||||
|
lua:toggle()
|
||||||
|
end
|
||||||
|
|
||||||
|
local node = nil
|
||||||
|
function TermToggleNode()
|
||||||
|
if node == nil then
|
||||||
|
node = Terminal:new({ id = next_id(), display_name = "Node", cmd = "node", hidden = true })
|
||||||
|
end
|
||||||
|
node:toggle()
|
||||||
|
end
|
||||||
|
|
||||||
|
local python = nil
|
||||||
|
function TermTogglePython()
|
||||||
|
if python == nil then
|
||||||
|
python = Terminal:new({ id = next_id(), display_name = "Python", cmd = "python3", hidden = true })
|
||||||
|
end
|
||||||
|
python:toggle()
|
||||||
|
end
|
||||||
|
|
||||||
|
local htop = nil
|
||||||
|
function _HTOP_TOGGLE()
|
||||||
|
if htop == nil then
|
||||||
|
htop = Terminal:new({ id = next_id(), display_name = "htop", cmd = "htop", hidden = true })
|
||||||
|
end
|
||||||
|
htop:toggle()
|
||||||
|
end
|
||||||
|
|
||||||
|
local ssh_hosts = { items = get_ssh_hosts(), selected = nil }
|
||||||
|
function TermSelectSsh()
|
||||||
|
vim.ui.select(utils.get_keys(ssh_hosts.items), {
|
||||||
|
prompt = "Select a host:",
|
||||||
|
}, function(choice)
|
||||||
|
host = ssh_hosts.items[choice]
|
||||||
|
if host ~= nil then
|
||||||
|
if host.term == nil then
|
||||||
|
host.term = Terminal:new({
|
||||||
|
id = next_id(),
|
||||||
|
display_name = "ssh://" .. host.user .. "@" .. host.hostname .. ":" .. host.port,
|
||||||
|
cmd = "ssh " .. host.user .. "@" .. host.hostname .. " -p" .. host.port,
|
||||||
|
hidden = true,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
host.term:open()
|
||||||
|
ssh_hosts.selected = host
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
function TermToggleSsh()
|
||||||
|
if ssh_hosts.selected ~= nil then
|
||||||
|
ssh_hosts.selected.term:toggle()
|
||||||
|
else
|
||||||
|
TermSelectSsh()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local containers = { items = get_containers(), selected = nil }
|
||||||
|
function TermSelectContainer()
|
||||||
|
vim.ui.select(utils.get_keys(containers.items), {
|
||||||
|
prompt = "Select a container:",
|
||||||
|
}, function(choice)
|
||||||
|
container = containers.items[choice]
|
||||||
|
if container ~= nil then
|
||||||
|
if container.term == nil then
|
||||||
|
container.term = Terminal:new({
|
||||||
|
id = next_id(),
|
||||||
|
display_name = "container://" .. container.Image,
|
||||||
|
cmd = "docker start " .. container.ID .. " && docker attach " .. container.ID,
|
||||||
|
hidden = true,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
container.term:open()
|
||||||
|
containers.selected = container
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
function TermToggleContainer()
|
||||||
|
if containers.selected ~= nil then
|
||||||
|
containers.selected.term:toggle()
|
||||||
|
else
|
||||||
|
TermSelectContainer()
|
||||||
|
end
|
||||||
|
end
|
||||||
55
lua/user/utils.lua
Normal file
55
lua/user/utils.lua
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
function M.debug(...)
|
||||||
|
print(...)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.dump(t)
|
||||||
|
if type(t) == "table" then
|
||||||
|
local str = "{ "
|
||||||
|
for key, value in pairs(t) do
|
||||||
|
if type(key) ~= "number" then
|
||||||
|
key = '"' .. key .. '"'
|
||||||
|
end
|
||||||
|
str = str .. "[" .. key .. "] = " .. M.dump(value) .. ","
|
||||||
|
end
|
||||||
|
return str .. "} "
|
||||||
|
else
|
||||||
|
return tostring(t)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.file_exists(path)
|
||||||
|
local file = io.open(path, "r")
|
||||||
|
if file ~= nil then
|
||||||
|
io.close(file)
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.script_path()
|
||||||
|
local str = debug.getinfo(2, "S").source:sub(2)
|
||||||
|
return str:match("(.*/)")
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.get_keys(t)
|
||||||
|
local keys = {}
|
||||||
|
for key, _ in pairs(t) do
|
||||||
|
table.insert(keys, key)
|
||||||
|
end
|
||||||
|
return keys
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.get_values(t, key)
|
||||||
|
local values = {}
|
||||||
|
for k, v in pairs(t) do
|
||||||
|
if key == k then
|
||||||
|
table.insert(values, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return values
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
1
thirdparty/json
vendored
Submodule
1
thirdparty/json
vendored
Submodule
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit dbf4b2dd2eb7c23be2773c89eb059dadd6436f94
|
||||||
Loading…
Add table
Reference in a new issue