Updated zsh themes to support conda environments. Updated nvim init for extra bindings

This commit is contained in:
five-hundred-eleven
2024-04-14 14:03:02 -04:00
parent 0970855503
commit 4ebffe08d4
3 changed files with 160 additions and 83 deletions

View File

@@ -2,11 +2,17 @@
# Helper method for showing python virtual env info in the prompt. # Helper method for showing python virtual env info in the prompt.
venv_prompt_info() { venv_prompt_info() {
if [[ -z "$VIRTUAL_ENV" ]]
if [[ -z "$VIRTUAL_ENV" ]]; then then
return return
fi fi
echo -e "${ZSH_THEME_VENV_PROMPT_PREFIX}$(basename $VIRTUAL_ENV)${ZSH_THEME_VENV_PROMPT_SUFFIX}" echo -e "${ZSH_THEME_VENV_PROMPT_PREFIX}$(basename $VIRTUAL_ENV)${ZSH_THEME_VENV_PROMPT_SUFFIX}"
}
conda_prompt_info() {
if [[ -z "$CONDA_DEFAULT_ENV" ]]
then
return
fi
echo -e "${ZSH_THEME_CONDA_PROMPT_PREFIX}${CONDA_DEFAULT_ENV}${ZSH_THEME_CONDA_PROMPT_SUFFIX}"
} }

View File

@@ -6,6 +6,7 @@ VIRTUAL_ENV_DISABLE_PROMPT=true
PROMPT="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ ) %{$fg[cyan]%}%c%{$reset_color%} " PROMPT="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ ) %{$fg[cyan]%}%c%{$reset_color%} "
PROMPT+='$(git_prompt_info)' PROMPT+='$(git_prompt_info)'
PROMPT+='$(venv_prompt_info)' PROMPT+='$(venv_prompt_info)'
PROMPT+='$(conda_prompt_info)'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[yellow]%}(" ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[yellow]%}("
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} " ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
@@ -14,3 +15,6 @@ ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[yellow]%})"
ZSH_THEME_VENV_PROMPT_PREFIX="%{$fg_bold[blue]%}(" ZSH_THEME_VENV_PROMPT_PREFIX="%{$fg_bold[blue]%}("
ZSH_THEME_VENV_PROMPT_SUFFIX=")%{$reset_color%} " ZSH_THEME_VENV_PROMPT_SUFFIX=")%{$reset_color%} "
ZSH_THEME_CONDA_PROMPT_PREFIX="%{$fg_bold[blue]%}("
ZSH_THEME_CONDA_PROMPT_SUFFIX=")%{$reset_color%} "

219
init.lua
View File

@@ -40,7 +40,14 @@ require("lazy").setup({
"neovim/nvim-lspconfig", "neovim/nvim-lspconfig",
{ {
"nvim-telescope/telescope-file-browser.nvim", "nvim-telescope/telescope-file-browser.nvim",
dependencies = { "nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim" } dependencies = {
"nvim-telescope/telescope.nvim",
"nvim-lua/plenary.nvim",
{
"nvim-telescope/telescope-live-grep-args.nvim",
version = "^1.0.0",
},
}
}, },
"neovim/nvim-lspconfig", "neovim/nvim-lspconfig",
--"kien/ctrlp.vim", --"kien/ctrlp.vim",
@@ -78,7 +85,7 @@ require("lazy").setup({
}, },
--"averms/black-nvim", --"averms/black-nvim",
"tpope/vim-fugitive", "tpope/vim-fugitive",
"gsuuon/llm.nvim", --"gsuuon/llm.nvim",
}) })
-- color schemes -- color schemes
@@ -87,6 +94,42 @@ require("tokyonight")
vim.o.background = "dark" vim.o.background = "dark"
vim.cmd("colorscheme tokyonight-night") vim.cmd("colorscheme tokyonight-night")
-- https://github.com/nvim-telescope/telescope-live-grep-args.nvim/blob/master/lua/telescope-live-grep-args/shortcuts.lua
local get_visual = function()
local _, ls, cs = unpack(vim.fn.getpos("v"))
local _, le, ce = unpack(vim.fn.getpos("."))
ls, le = math.min(ls, le), math.max(ls, le)
cs, ce = math.min(cs, ce), math.max(cs, ce)
return vim.api.nvim_buf_get_text(0, ls - 1, cs - 1, le - 1, ce, {})
end
-- https://github.com/nvim-telescope/telescope-live-grep-args.nvim/blob/master/lua/telescope-live-grep-args/shortcuts.lua
local grep_under_default_opts = {
postfix = " -F ",
quote = true,
trim = true,
}
-- https://github.com/nvim-telescope/telescope-live-grep-args.nvim/blob/master/lua/telescope-live-grep-args/shortcuts.lua
local process_grep_under_text = function(value, opts)
opts = opts or {}
if opts.trim then
value = vim.trim(value)
end
if opts.quote then
value = helpers.quote(value, opts)
end
if opts.postfix then
value = value .. opts.postfix
end
return value
end
require("telescope").setup { require("telescope").setup {
extensions = { extensions = {
@@ -122,23 +165,47 @@ require("telescope").setup {
local telescope_builtin = require('telescope.builtin') local telescope_builtin = require('telescope.builtin')
local prompt = require('telescope.themes').get_dropdown({ shorten_path = true })
local myfindfiles = function()
return telescope_builtin.find_files(prompt)
end
local mylivegrep = function()
return require("telescope").extensions.live_grep_args.live_grep_args(prompt)
end
local mylivegrep_visual_selection = function()
local opts = {}
local visual = get_visual()
local text = visual[1] or ""
text = process_grep_under_text(text, opts)
opts.default_text = text
opts = vim.tbl_extend("force", opts, prompt)
return require("telescope").extensions.live_grep_args.live_grep_args(opts)
end
local mybuffers = function()
return telescope_builtin.buffers(prompt)
end
local mylspreferences = function()
return telescope_builtin.lsp_references(prompt)
end
local mytags = function() local mytags = function()
-- this should always exist because of gutentags -- this should always exist because of gutentags
local tagspath = vim.fn.getcwd() .. "/tags" local opts = { ctags_file = vim.fn.getcwd() .. "/tags" }
return telescope_builtin.tags({ ctags_file = tagspath }) opts = vim.tbl_extend("force", opts, prompt)
return telescope_builtin.tags(opts)
end end
local file_browser = require('telescope').extensions.file_browser.file_browser
local myfilebrowser = function() local myfilebrowser = function()
local opts = { path = "%:p:h", select_buffer = true } local opts = { path = "%:p:h", select_buffer = true }
return file_browser(opts) opts = vim.tbl_extend("force", opts, prompt)
return require('telescope').extensions.file_browser.file_browser(opts)
end end
vim.keymap.set('n', '<leader>f', telescope_builtin.find_files, {}) vim.keymap.set('n', '<leader>f', myfindfiles, {})
vim.keymap.set('n', '<leader>g', telescope_builtin.live_grep, {}) vim.keymap.set('n', '<leader>g', mylivegrep, {})
vim.keymap.set('n', '<leader>b', telescope_builtin.buffers, {}) vim.keymap.set('v', '<leader>g', mylivegrep_visual_selection, {})
vim.keymap.set('n', '<leader>b', mybuffers, {})
vim.keymap.set('n', '<leader>h', telescope_builtin.help_tags, {}) vim.keymap.set('n', '<leader>h', telescope_builtin.help_tags, {})
vim.keymap.set('n', '<leader>c', mytags, {}) vim.keymap.set('n', '<leader>c', mytags, {})
vim.keymap.set('n', '<leader>n', myfilebrowser, {}) vim.keymap.set('n', '<leader>n', myfilebrowser, {})
vim.keymap.set('n', '<leader>r', telescope_builtin.lsp_references, {}) vim.keymap.set('n', '<leader>r', mylspreferences, {})
--vim.keymap.set('n', '<leader>n', file_browser, {}) --vim.keymap.set('n', '<leader>n', file_browser, {})
--vim.keymap.set('n', '<leader>c', ":CtrlPTag<CR>", {}) --vim.keymap.set('n', '<leader>c', ":CtrlPTag<CR>", {})
--vim.keymap.set('n', 'gd', ":tag <C-r><C-w><CR>", {}) --vim.keymap.set('n', 'gd', ":tag <C-r><C-w><CR>", {})
@@ -256,7 +323,7 @@ set.scrolloff = 6
-- autoindent works weirdly sometimes -- autoindent works weirdly sometimes
-- set.autoindent = true -- set.autoindent = true
-- some terminal emulators mess up mouse integration- uncomment the following -- some terminal emulators mess up mouse integration- uncomment the following
-- set.mouse = nil set.mouse = nil
vim.keymap.set("n", "gtl", ":tabn<cr>") vim.keymap.set("n", "gtl", ":tabn<cr>")
vim.keymap.set("n", "gth", ":tabp<cr>") vim.keymap.set("n", "gth", ":tabp<cr>")
vim.keymap.set("n", "gt0", ":tabfirst<cr>") vim.keymap.set("n", "gt0", ":tabfirst<cr>")
@@ -386,72 +453,72 @@ local function display_string_in_buf(s)
vim.api.nvim_buf_set_lines(buf, 0, 0, true, lines) vim.api.nvim_buf_set_lines(buf, 0, 0, true, lines)
end end
local curl = require("llm.curl") --local curl = require("llm.curl")
function call_localai(model, prompt, temperature) --function call_localai(model, prompt, temperature)
display_string_in_buf(prompt) --display_string_in_buf(prompt)
local opts = { --local opts = {
url = "http://localhost:8515/chat/completions", --url = "http://localhost:8515/chat/completions",
method = "POST", --method = "POST",
headers = { [ "Content-Type" ] = "application/json" }, --headers = { [ "Content-Type" ] = "application/json" },
body = { --body = {
model = model, --model = model,
messages = { { role = "user", content = prompt }, }, --messages = { { role = "user", content = prompt }, },
temperature = temperature, --temperature = temperature,
}, --},
} --}
local function on_complete(stdout) --local function on_complete(stdout)
-- decode response ---- decode response
local out_json = vim.json.decode(stdout) --local out_json = vim.json.decode(stdout)
-- get content of response ---- get content of response
-- TODO make this more dynamic ---- TODO make this more dynamic
local response_str = out_json["choices"][1]["message"]["content"] --local response_str = out_json["choices"][1]["message"]["content"]
-- display content of response ---- display content of response
display_string_in_buf(response_str) --display_string_in_buf(response_str)
-- apply formatting ---- apply formatting
local line = vim.fn.line("$") --local line = vim.fn.line("$")
while line > 0 do --while line > 0 do
vim.cmd(tostring(line)) --vim.cmd(tostring(line))
vim.cmd.normal("gqq") --vim.cmd.normal("gqq")
line = line - 1 --line = line - 1
end --end
end --end
local function on_error(stderr) --local function on_error(stderr)
print("Error: " .. stderr) --print("Error: " .. stderr)
end --end
curl.request(opts, on_complete, on_error) --curl.request(opts, on_complete, on_error)
end --end
function localai_review(args) --function localai_review(args)
local visual_selection = get_visual_selection() --local visual_selection = get_visual_selection()
local prompt = "Please review the following code:\n```\n" .. visual_selection .. "```" --local prompt = "Please review the following code:\n```\n" .. visual_selection .. "```"
call_localai("WizardCoder-15B-1.0.ggmlv3.q4_1.bin", prompt, 0.1) --call_localai("WizardCoder-15B-1.0.ggmlv3.q4_1.bin", prompt, 0.1)
end --end
function localai_write_code(args) --function localai_write_code(args)
local visual_selection = get_visual_selection() --local visual_selection = get_visual_selection()
local language = "" --local language = ""
if vim.bo.filetype == "lua" then --if vim.bo.filetype == "lua" then
language = "lua" --language = "lua"
elseif vim.bo.filetype == "python" then --elseif vim.bo.filetype == "python" then
language = "python" --language = "python"
elseif vim.bo.filetype == "c" or vim.bo.filetype == "h" then --elseif vim.bo.filetype == "c" or vim.bo.filetype == "h" then
language = "c" --language = "c"
elseif vim.bo.filetype == "cpp" or vim.bo.filetype == "hpp" then --elseif vim.bo.filetype == "cpp" or vim.bo.filetype == "hpp" then
language = "c++" --language = "c++"
elseif vim.bo.filetype == "go" then --elseif vim.bo.filetype == "go" then
language = "golang" --language = "golang"
elseif vim.bo.filetype == "sh" then --elseif vim.bo.filetype == "sh" then
language = "bash" --language = "bash"
else --else
print("Could not determine language!") --print("Could not determine language!")
return --return
end --end
local prompt = "Please write code in " .. language .. " that does the following:\n" .. visual_selection --local prompt = "Please write code in " .. language .. " that does the following:\n" .. visual_selection
call_localai("WizardCoder-15B-1.0.ggmlv3.q4_1.bin", prompt, 0.2) --call_localai("WizardCoder-15B-1.0.ggmlv3.q4_1.bin", prompt, 0.2)
end --end
vim.keymap.set("n", "<leader>ar", localai_review, nil) --vim.keymap.set("n", "<leader>ar", localai_review, nil)
vim.keymap.set("v", "<leader>ar", localai_review, nil) --vim.keymap.set("v", "<leader>ar", localai_review, nil)
vim.keymap.set("n", "<leader>ac", localai_write_code, nil) --vim.keymap.set("n", "<leader>ac", localai_write_code, nil)
vim.keymap.set("v", "<leader>ac", localai_write_code, nil) --vim.keymap.set("v", "<leader>ac", localai_write_code, nil)