Compare commits

..

6 Commits

10 changed files with 154 additions and 114 deletions
+6
View File
@@ -19,3 +19,9 @@
[submodule "zsh/custom/plugins/zsh-vi-mode"]
path = zsh/custom/plugins/zsh-vi-mode
url = https://github.com/jeffreytse/zsh-vi-mode
[submodule "zsh/custom/plugins/evalcache"]
path = zsh/custom/plugins/evalcache
url = https://github.com/mroth/evalcache/
[submodule "zsh/custom/plugins/zsh-defer"]
path = zsh/custom/plugins/zsh-defer
url = https://github.com/romkatv/zsh-defer
@@ -7,13 +7,10 @@ return {
lazy = false,
branch = "main",
build = ":TSUpdate",
-- main = "nvim-treesitter.configs",
init = function()
vim.wo.foldmethod = "expr"
vim.wo.foldexpr = "v:lua.vim.treesitter.foldexpr()"
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
require("nvim-treesitter").install({
-- Taken from kickstart.nvim
config = function()
-- ensure basic parser are installed
local parsers = {
"c",
"cpp",
"go",
@@ -32,6 +29,56 @@ return {
"cmake",
"json",
"yaml",
}
require("nvim-treesitter").install(parsers)
---@param buf integer
---@param language string
local function treesitter_try_attach(buf, language)
-- Check if the parser exists
if not vim.treesitter.language.add(language) then
return
end
vim.treesitter.start(buf, language)
-- TODO: Does this work properly?
local has_fold_query = vim.treesitter.query.get(language, "folds") ~= nil
if has_fold_query then
vim.wo.foldmethod = "expr"
vim.wo.foldexpr = "v:lua.vim.treesitter.foldexpr()"
end
local has_indent_query = vim.treesitter.query.get(language, "indents") ~= nil
if has_indent_query then
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
end
end
local available_parsers = require("nvim-treesitter").get_available()
vim.api.nvim_create_autocmd("FileType", {
callback = function(args)
local buf, filetype = args.buf, args.match
local language = vim.treesitter.language.get_lang(filetype)
if not language then
return
end
local installed_parsers = require("nvim-treesitter").get_installed("parsers")
if vim.tbl_contains(installed_parsers, language) then
-- enable the parser if it is installed
treesitter_try_attach(buf, language)
elseif vim.tbl_contains(available_parsers, language) then
-- if a parser is available in `nvim-treesitter` auto install it, and enable it after the installation is done
require("nvim-treesitter").install(language):await(function()
treesitter_try_attach(buf, language)
end)
else
-- try to enable treesitter features in case the parser exists but is not available from `nvim-treesitter`
treesitter_try_attach(buf, language)
end
end,
})
end,
},
+32
View File
@@ -0,0 +1,32 @@
# mise
Adds integration with [mise](https://github.com/jdx/mise) (formerly `rtx`), a runtime executor compatible with
npm, nodenv, pyenv, etc. mise is written in rust and is very fast. 20x-200x faster than asdf. With that being
said, mise is compatible with asdf plugins and .tool-versions files. It can be used as a drop-in replacement.
## Installation
1. [Download & install mise](https://github.com/jdx/mise#installation) by running the following:
```bash
curl https://mise.jdx.dev/install.sh | sh
```
2. [Enable mise](https://github.com/jdx/mise#quickstart) by adding it to your `plugins` definition in
`~/.zshrc`.
```bash
plugins=(mise)
```
## Usage
See the [mise readme](https://github.com/jdx/mise#table-of-contents) for information on how to use mise. Here
are a few examples:
```bash
mise install node Install the current version specified in .tool-versions/.mise.toml
mise use -g node@system Use system node as global default
mise install node@20.0.0 Install a specific version number
mise use -g node@20 Use node-20.x as global default
```
+17
View File
@@ -0,0 +1,17 @@
if (( ! $+commands[mise] )); then
return
fi
# Load mise hooks
zsh-defer -a _evalcache mise activate zsh
# If the completion file doesn't exist yet, we need to autoload it and
# bind it to `mise`. Otherwise, compinit will have already done that.
if [[ ! -f "$ZSH_CACHE_DIR/completions/_mise" ]]; then
typeset -g -A _comps
autoload -Uz _mise
_comps[mise]=_mise
fi
# Generate and load mise completion
mise completion zsh >| "$ZSH_CACHE_DIR/completions/_mise" &|
+19 -97
View File
@@ -156,72 +156,32 @@ prompt_git() {
fi
}
prompt_bzr() {
(( $+commands[bzr] )) || return
# Test if bzr repository in directory hierarchy
local dir="$PWD"
while [[ ! -d "$dir/.bzr" ]]; do
[[ "$dir" = "/" ]] && return
dir="${dir:h}"
done
local bzr_status status_mod status_all revision
if bzr_status=$(bzr status 2>&1); then
status_mod=$(echo -n "$bzr_status" | head -n1 | grep "modified" | wc -m)
status_all=$(echo -n "$bzr_status" | head -n1 | wc -m)
revision=${$(bzr log -r-1 --log-format line | cut -d: -f1):gs/%/%%}
if [[ $status_mod -gt 0 ]] ; then
prompt_segment yellow black "bzr@$revision ✚"
else
if [[ $status_all -gt 0 ]] ; then
prompt_segment yellow black "bzr@$revision"
else
prompt_segment 10 black "bzr@$revision"
fi
fi
fi
}
prompt_hg() {
(( $+commands[hg] )) || return
local rev st branch
if $(hg id >/dev/null 2>&1); then
if $(hg prompt >/dev/null 2>&1); then
if [[ $(hg prompt "{status|unknown}") = "?" ]]; then
# if files are not added
prompt_segment red white
st='±'
elif [[ -n $(hg prompt "{status|modified}") ]]; then
# if any modification
prompt_segment yellow black
st='±'
else
# if working copy is clean
prompt_segment 10 $CURRENT_FG
fi
echo -n ${$(hg prompt "☿ {rev}@{branch}"):gs/%/%%} $st
else
st=""
rev=$(hg id -n 2>/dev/null | sed 's/[^-0-9]//g')
branch=$(hg id -b 2>/dev/null)
if `hg st | grep -q "^\?"`; then
prompt_segment red black
st='±'
elif `hg st | grep -q "^[MA]"`; then
prompt_segment yellow black
st='±'
else
prompt_segment 10 $CURRENT_FG
fi
echo -n "☿ ${rev:gs/%/%%}@${branch:gs/%/%%}" $st
git_toplevel() {
local repo_root=$(git rev-parse --show-toplevel)
if [[ $repo_root = '' ]]; then
# We are in a bare repo. Use git dir as root
repo_root=$(git rev-parse --git-dir)
if [[ $repo_root = '.' ]]; then
repo_root=$PWD
fi
fi
echo -n $repo_root
}
# Dir: current working directory
prompt_dir() {
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
# Git repo and inline path enabled, hence only show the git root
local repo_root=$(git_toplevel)
local path_in_repo=$(pwd | sed "s/^$(echo "$repo_root" | sed 's:/:\\/:g;s/\$/\\$/g')//;s:^/::;s:/$::;")
if [[ -z "$path_in_repo" ]]; then
prompt_segment 12 $CURRENT_FG "$(git_toplevel | sed "s:^$HOME:~:")"
else
prompt_segment 12 $CURRENT_FG "$(git_toplevel | sed "s:^$HOME:~:")/%B$path_in_repo%b"
fi
else
prompt_segment 12 $CURRENT_FG '%~'
fi
}
# Virtualenv: current working virtualenv
@@ -232,27 +192,6 @@ prompt_virtualenv() {
fi
}
# nix-shell: currently running nix-shell
prompt_nix_shell() {
if [[ -n "$IN_NIX_SHELL" ]]; then
if [[ -n $NIX_SHELL_PACKAGES ]]; then
local package_names=""
local packages=($NIX_SHELL_PACKAGES)
for package in $packages; do
package_names+=" ${package##*.}"
done
prompt_segment magenta black "$package_names"
elif [[ -n $name ]]; then
local cleanName=${name#interactive-}
cleanName=${cleanName#lorri-keep-env-hack-}
cleanName=${cleanName%-environment}
prompt_segment magenta black "$cleanName"
else # This case is only reached if the nix-shell plugin isn't installed or failed in some way
prompt_segment magenta black "nix-shell"
fi
fi
}
# Status:
# - was there an error
# - am I root
@@ -264,31 +203,14 @@ prompt_status() {
[[ $UID -eq 0 ]] && prompt_segment 11 black "󱐋"
}
#AWS Profile:
# - display current AWS_PROFILE name
# - displays yellow on red if profile name contains 'production' or
# ends in '-prod'
# - displays black on green otherwise
prompt_aws() {
[[ -z "$AWS_PROFILE" || "$SHOW_AWS_PROMPT" = false ]] && return
case "$AWS_PROFILE" in
*-prod|*production*) prompt_segment red 11 "AWS: ${AWS_PROFILE:gs/%/%%}" ;;
*) prompt_segment cyan black "AWS: ${AWS_PROFILE:gs/%/%%}" ;;
esac
}
## Main prompt
build_prompt() {
RETVAL=$?
prompt_status
prompt_context
prompt_virtualenv
prompt_nix_shell
prompt_aws
prompt_dir
prompt_git
prompt_bzr
prompt_hg
prompt_end
}
+19 -5
View File
@@ -1,3 +1,4 @@
# vim: set ft=zsh:
# Path to your oh-my-zsh installation.
export DOTFILES=${DOTFILES:-"$HOME/.dotfiles"}
export ZSH="$DOTFILES/zsh/ohmyzsh"
@@ -5,8 +6,18 @@ export ZSH_CUSTOM="$DOTFILES/zsh/custom"
ZSH_THEME="agnoster_dx"
zstyle ':omz:update' mode reminder # just remind me to update when it's time
# zstyle ':omz:update' frequency 13
zstyle -s ':omz:update' mode "disabled"
# Fix slow pasting due to zsh-autosuggestions
pasteinit() {
OLD_SELF_INSERT=${${(s.:.)widgets[self-insert]}[2,3]}
zle -N self-insert url-quote-magic # I wonder if you'd need `.url-quote-magic`?
}
pastefinish() {
zle -N self-insert $OLD_SELF_INSERT
}
zstyle :bracketed-paste-magic paste-init pasteinit
zstyle :bracketed-paste-magic paste-finish pastefinish
# CASE_SENSITIVE="true"
# HYPHEN_INSENSITIVE="true"
@@ -18,6 +29,8 @@ ZSH_DISABLE_COMPFIX="true"
ZOXIDE_CMD_OVERRIDE="cd"
plugins=(
evalcache
zsh-defer
git
zsh-autosuggestions
# Disabled because the highlighting conflicts with autosuggestions
@@ -30,6 +43,7 @@ plugins=(
zoxide
mise
gpg-agent
vagrant
)
bindkey -M vicmd "k" up-line-or-beginning-search
@@ -63,7 +77,6 @@ KEYTIMEOUT=1
fpath+=${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/completions
fpath+=${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions/src
autoload -Uz compinit && compinit
source "$ZSH/oh-my-zsh.sh"
less_termcap[so]="${fg_bold[black]}${bg[white]}"
@@ -117,7 +130,8 @@ else
unset PNPM_HOME
fi
if (( $+commands[pnpm] )); then
source <(pnpm completion zsh)
# Without evalcache it more than doubles startup time
_evalcache pnpm completion zsh
fi
export FZF_DEFAULT_OPTS='--tmux'
@@ -138,7 +152,7 @@ fi
if (( $+commands[fzf] )); then
# Fix fzf keybind after zsh-vi-mode has loaded
zvm_after_init_commands+=('source <(fzf --zsh)')
zvm_after_init_commands+=('_evalcache fzf --zsh')
if (( $+commands[paru] )); then
function pi {