Skip to content

Commit

Permalink
Update nvim configs, add kubectl zsh plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
A committed Jun 10, 2023
1 parent 59983e7 commit 5486c37
Show file tree
Hide file tree
Showing 19 changed files with 192 additions and 53 deletions.
40 changes: 29 additions & 11 deletions bin/analyze-tracks
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import os
import re
import keyfinder
import unidecode
import threading

# cwd = os.path.dirname(os.path.realpath(__file__))
cwd = os.getcwd()
files = os.listdir(cwd)

Expand All @@ -22,22 +23,39 @@ def get_key(file):
key = keyfinder.key(file)
return f'{key.camelot()} {key}'

def rename(file):
key = get_key(file)

name = remove_numeration(file)
name = remove_original_mix(name)

next_file = f'{key} - {name}'

print(f'[RENAME] {next_file}')

os.rename(os.path.join(cwd, file), os.path.join(cwd, next_file))

def is_processed(file):
return re.match(r'^\d+[A-G]\s+', file)

for file in files:
_, ext = os.path.splitext(file)

if ext not in EXTS:
continue

key = get_key(file)
name = remove_numeration(file)
name = remove_original_mix(name)
if is_processed(file):
print(f'[SKIP] {file}')
continue

next_file = f'{key} - {name}'
# next_file = name
print(f'[ANALYZING] {file}')

print(file)
print(next_file)
print()
unaccented_file = unidecode.unidecode(file)
if file != unaccented_file:
os.rename(os.path.join(cwd, file), os.path.join(cwd, unaccented_file))
file = unaccented_file

thread = threading.Thread(target=rename, args=(file,))
thread.start()
thread.join()

# breakpoint()
os.rename(os.path.join(cwd, file), os.path.join(cwd, next_file))
5 changes: 4 additions & 1 deletion configs/nvim/lua/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ local enabled_packages = {
'packages/tmux-navigation',
'packages/nvim-session',
'packages/quickfix-to-bottom',
'packages/neo-tree',
-- 'packages/neo-tree',
'packages/nerdtree',
'packages/treesitter',
'packages/null-ls',
'packages/trouble',
Expand All @@ -22,6 +23,8 @@ local enabled_packages = {
'packages/extended-syntax',
'packages/close-buffers',
'packages/import-cost',
'packages/todo-txt',
'packages/glow'
}

local enabled_treesitter_configs = {
Expand Down
11 changes: 11 additions & 0 deletions configs/nvim/lua/lib/utils/table_slice.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local function table_slice(tbl, first, last, step)
local sliced = {}

for i = first or 1, last or #tbl, step or 1 do
sliced[#sliced+1] = tbl[i]
end

return sliced
end

return { table_slice = table_slice }
4 changes: 3 additions & 1 deletion configs/nvim/lua/opts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ g.markdown_fenced_languages = {
'ts=typescript',
'typescript',
'vim',
'dbml',
'sass',
}

opt.verbose = 2
-- opt.verbose = 2
opt.verbosefile = "/Users/anton/.logs/nvim.log"
opt.backup = false
opt.clipboard = 'unnamedplus'
Expand Down
2 changes: 1 addition & 1 deletion configs/nvim/lua/packages/cmp-completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ local function install(use)
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
-- ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}),

experimental = {native_menu = false, ghost_text = false},
Expand Down
3 changes: 2 additions & 1 deletion configs/nvim/lua/packages/extended-syntax.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function install(use)
local function install(use)
use 'nono/vim-handlebars'
use 'jidn/vim-dbml'
end

return {
Expand Down
10 changes: 5 additions & 5 deletions configs/nvim/lua/packages/git.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
local keys = {
g = {
name = 'git',
b = { '<cmd>:git blame<cr>', 'blame'},
d = { '<cmd>:git diff<cr>', 'diff'},
l = { '<cmd>:git log<cr>', 'log'},
s = { '<cmd>:git<cr>', 'status'},
o = { '<cmd>:git browse', 'open url to this file' },
b = { '<cmd>:G blame<cr>', 'blame'},
d = { '<cmd>:G diff<cr>', 'diff'},
l = { '<cmd>:G log<cr>', 'log'},
s = { '<cmd>:G<cr>', 'status'},
o = { '<cmd>:G browse', 'open url to this file' },
},
}

Expand Down
27 changes: 27 additions & 0 deletions configs/nvim/lua/packages/glow.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
local keys = {
m = {
name = "markdown",
p = { "<cmd>Glow keep<CR>", "Preview" },
h = { "<cmd>Glow preview<CR>", "Hover Preview" },
s = { "<cmd>Glow split<CR>", "Split Preview" },
}
}

local function install(use)
-- use {"ellisonleao/glow.nvim"}
use {"lnc3l0t/glow.nvim", branch = "advanced_window"}
end

local function setup()
require("glow").setup({
in_place = true,
-- pager = true,
})
end


return {
install = install,
setup = setup,
keys = keys,
}
8 changes: 8 additions & 0 deletions configs/nvim/lua/packages/import-cost.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
local api = vim.api

local function install(use)
use({ "yardnsm/vim-import-cost", run = "npm install" })
end

local function post_setup()
api.nvim_command(':highlight link ImportCostVirtualText Comment')
api.nvim_command('au FileType typescript,typescriptreact,javascript,javascriptreact :silent! ImportCost')
end

return {
install = install,
post_setup = post_setup,
}
20 changes: 10 additions & 10 deletions configs/nvim/lua/packages/lsp/format.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ local pylint = {
}

return {
css = { prettier },
html = { prettier },
javascript = { prettier, eslint },
javascriptreact = { prettier, eslint },
json = { prettier },
-- css = { prettier },
-- html = { prettier },
-- javascript = { prettier, eslint },
-- javascriptreact = { prettier, eslint },
-- json = { prettier },
lua = { stylua },
markdown = { prettier },
-- markdown = { prettier },
python = { blue },
scss = { prettier },
typescript = { prettier, eslint },
typescriptreact = { prettier, eslint },
yaml = { prettier },
-- scss = { prettier },
-- typescript = { prettier, eslint },
-- typescriptreact = { prettier, eslint },
-- yaml = { prettier },
}
4 changes: 2 additions & 2 deletions configs/nvim/lua/packages/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ local function setup()
require('nvim-lsp-installer').setup({})
end


local function post_setup()
local lsp_installer_servers = require('nvim-lsp-installer.servers')

Expand All @@ -35,7 +34,8 @@ local function post_setup()

config.on_attach = function(client)
if client.name ~= 'null_ls' then
client.resolved_capabilities.document_formatting = false
-- client.resolved_capabilities.document_formatting = false
client.server_capabilities.documentFormattingProvider = false
end
end

Expand Down
7 changes: 5 additions & 2 deletions configs/nvim/lua/packages/lsp/keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ local keys = {
a = { '<cmd>lua vim.lsp.buf.code_action()<CR>', 'Select a code action' },
d = {
name = 'Diagnostic actions..',
d = { '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', 'Open diagnostics window for current line' },
d = {'<cmd>lua vim.diagnostic.open_float()<CR>', 'Open diagnostics window for current line' },
e = {'<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', 'Go to previous diagnostic'},
n = {'<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', 'Go to next diagnostic'},
O = {'<cmd>lua vim.diagnostic.config({virtual_text = true})<CR>', 'enable virtual text'},
o = {'<cmd>lua vim.diagnostic.config({virtual_text = false})<CR>', 'disable virtual text'},
},
E = {'<Cmd>lua vim.lsp.buf.declaration()<CR>', 'Jump to symbol declaration'},
e = {'<Cmd>lua vim.lsp.buf.definition()<CR>', 'Jump to symbol definition'},
f = {"<cmd>lua vim.lsp.buf.formatting()<CR>", 'Format the current buffer'},
-- f = {"<cmd>lua vim.lsp.buf.formatting()<CR>", 'Format the current buffer'},
f = {"<cmd>lua vim.lsp.buf.format({ async = true })<CR>", "Format the current buffer"},
h = {'<Cmd>lua vim.lsp.buf.hover()<CR>', 'Display hover information for symbol'},
H = {'<Cmd>lua vim.lsp.buf.hover();vim.lsp.buf.hover()<CR>', 'Jump into hover information for symbol'},
i = {'<cmd>lua vim.lsp.buf.implementation()<CR>', 'List implementations for symbol'},
Expand Down
7 changes: 5 additions & 2 deletions configs/nvim/lua/packages/lsp/lsp_python.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ local fn = vim.fn
-- https://github.com/neovim/nvim-lspconfig/issues/500#issuecomment-876700701
-- https://github.com/neovim/nvim-lspconfig/issues/500#issuecomment-877293306
local function get_python_path(workspace)
print("get python path")

-- Use activated virtualenv.
if env.VIRTUAL_ENV then
return path.join(env.VIRTUAL_ENV, 'bin', 'python')
Expand All @@ -17,7 +19,8 @@ local function get_python_path(workspace)
local match = fn.glob(path.join(workspace, 'poetry.lock'))
if match ~= '' then
local venv = fn.trim(fn.system('poetry env info -p'))
return path.join(venv, 'bin', 'python')
local p = path.join(venv, 'bin', 'python')
return p
end

-- Fallback to system Python.
Expand All @@ -26,7 +29,7 @@ end


local function on_init(client)
client.config.settings.python.pythonPath = get_python_path(client.config.root_dir)
client.config.settings.python.pythonPath = get_python_path(client.config.root_dir)
end


Expand Down
5 changes: 4 additions & 1 deletion configs/nvim/lua/packages/null-ls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ end

local function setup()
local null_ls = require('null-ls')
local lspconfig = require('lspconfig')

null_ls.setup({
root_dir = lspconfig.util.root_pattern(".null-ls-root", "Makefile", "tsconfig.json", "go.mod", "poetry.toml", ".git"),
sources = {
-- null_ls.builtins.completion.spell,
null_ls.builtins.code_actions.eslint_d,
Expand All @@ -26,7 +29,7 @@ local function setup()
null_ls.builtins.formatting.fixjson,
null_ls.builtins.formatting.lua_format,
null_ls.builtins.formatting.markdownlint,
null_ls.builtins.formatting.prettier,
null_ls.builtins.formatting.prettierd,

null_ls.builtins.hover.dictionary,
},
Expand Down
13 changes: 5 additions & 8 deletions configs/nvim/lua/packages/nvim-obsidian/init.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
local keys = {
o = {
name = 'Obsidian',
r = { "<cmd>lua require('packages/nvim-obsidian/lib').rename()<CR>", "Rename Note" },
b = { "<cmd>lua require('packages/nvim-obsidian/lib').show_backlinks()<CR>", "Show Backlinks" },
r = { "<cmd>lua require('packages/nvim-obsidian/lib').rename()<CR>", "Rename a note" },
b = { "<cmd>lua require('packages/nvim-obsidian/lib').show_backlinks()<CR>", "Show backlinks" },
h = { "<cmd>lua require('packages/nvim-obsidian/lib').hover_link()<CR>", "Preview a link under cursor" },
x = { "<cmd>lua require('packages/nvim-obsidian/lib').open_link()<CR>", "Open a link under cursor" },
}
}

local function install(use)
use({
'andrewferrier/vim-wrapping-softhard',
config = function()
require('wrapping').setup(opts)
end,
})
use 'cdutboy928/vim_markdown_shortcuts.vim'
end

local function setup_cmp()
Expand Down
55 changes: 54 additions & 1 deletion configs/nvim/lua/packages/nvim-obsidian/lib.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
local table_slice = require('lib/utils/table_slice').table_slice
local cmd = vim.cmd
local api = vim.api
local ui = vim.ui
-- local fs = vim.fs
local fn = vim.fn
local lsp = vim.lsp

local function get_file_under_cursor()
local filename = fn.expand("<cfile>") .. '.md'
local path = fn.system('find . -name "' .. filename .. '"')
return path:gsub('\n', '')
end

local function read_file_content(path)
local content = fn.system('cat "' .. path .. '"')
local raw_lines = lsp.util.convert_input_to_markdown_lines(content)
local lines = raw_lines
if (raw_lines[1] == '---') then
local content_start
local pointer = 1
for i, l in pairs(raw_lines) do
if (pointer ~= 1 and l == '---') then
content_start = pointer + 1
end
pointer = pointer + 1
end
lines = table_slice(raw_lines, content_start, pointer)
end

if not next(lines) then
lines = nil
end

return lines
end

local function get_basename(file)
for k in string.gmatch(file, ".*/(.*)%.md$") do
Expand Down Expand Up @@ -44,7 +75,29 @@ local function show_backlinks()
cmd('TroubleToggle quickfix')
end

local function hover_link()
local file = get_file_under_cursor()
local lines = read_file_content(file)

if (lines == nil) then
return
end

local ok = pcall(lsp.util.open_floating_preview, lines, 'markdown')

if (not ok) then
print('Nothing to preview...')
end
end

local function open_link()
local file = get_file_under_cursor()
fn.system('cat "' .. file .. '" | rg "link: (.*)" -r \'$1\' | xargs open')
end

return {
rename = rename,
show_backlinks = show_backlinks,
hover_link = hover_link,
open_link = open_link,
}
Loading

0 comments on commit 5486c37

Please sign in to comment.