First commit

This commit is contained in:
James Dugan 2025-02-04 21:06:01 -07:00
commit 847c9e64c0
51 changed files with 4058 additions and 0 deletions

View file

@ -0,0 +1,13 @@
# local-config
evaluate-commands %sh{
cwd=$(pwd)
while [ $cwd != "/" ]; do
path="$cwd/.local.kak"
if [ -f $path ]; then
printf "%s\n" "source $path"
break
fi
cd ..
cwd=$(pwd)
done
}

View file

@ -0,0 +1,8 @@
map global normal <F2> :toggle-whitespace<ret>
map global normal <F4> :buffer-switcher<ret>
map global normal <F5> :xplr<ret>
map global normal <F6> :lazygit<ret>
map global user 'p' '<a-!>pbpaste<ret>' -docstring 'Paste from clipboard'
map global user 'P' '!pbpaste<ret>' -docstring 'Paste from clipboard'
map global user 'y' '<a-|>pbcopy<ret>' -docstring 'Yank to clipboard'

View file

@ -0,0 +1,17 @@
colorscheme everforest-dark-soft
set-option global ui_options terminal_set_title=no terminal_assistant=cat # The cat is critically important.
set-option global tabstop 4
set-option global indentwidth 4
add-highlighter global/ show-matching
declare-option str windowing_placement horizontal
# With the way that Kakoune's windowing detection is currently set up, the wezterm module will never be loaded.
# So, we need to fix the order in which windowing modules are declared.
declare-option str-list windowing_modules 'tmux' 'screen' 'zellij' 'kitty' 'wezterm' 'iterm' 'appleterminal' 'sway' 'wayland' 'x11'
hook global WinCreate .* %{
add-highlighter window/number-lines number-lines -hlcursor
}

View file

@ -0,0 +1,122 @@
source "%val{config}/bundle/kak-bundle/rc/kak-bundle.kak"
bundle-noload kak-bundle "ln -sf ~/workspace/kak-bundle/"
bundle kakoune-lsp "https://github.com/kakoune-lsp/kakoune-lsp" %{
set-option global lsp_diagnostic_line_error_sign 
set-option global lsp_diagnostic_line_hint_sign ?
set-option global lsp_diagnostic_line_info_sign
set-option global lsp_diagnostic_line_warning_sign 
# kakoune-lsp doesn't have a command to enable auto-hover per buffer,
# only supporting enabling auto-hover globally,
# which causes issues in filetypes that don't have lsp set up.
# So, we need to define one ourselves.
define-command lsp-auto-hover-enable-buffer %{
remove-hooks buffer lsp-auto-hover
hook -group lsp-auto-hover buffer NormalIdle .* %{ lsp-check-auto-hover lsp-hover }
}
# Convenience commands for enabling lsp features
define-command lsp-semantic-tokens-enable %{
hook window -group semantic-tokens BufReload .* lsp-semantic-tokens
hook window -group semantic-tokens NormalIdle .* lsp-semantic-tokens
hook window -group semantic-tokens InsertIdle .* lsp-semantic-tokens
hook -once -always window WinSetOption filetype=.* %{
remove-hooks window semantic-tokens
}
}
define-command lsp-enable-buffer %{
lsp-enable-window
lsp-auto-hover-enable-buffer
lsp-inlay-diagnostics-enable buffer
lsp-inlay-hints-enable buffer
}
# We want to be explicit about lsp server settings per filetype
# So, we are disabling the default lsp server hooks
remove-hooks global lsp-filetype-.*
}
bundle-install-hook kakoune-lsp %{
cargo install --locked --force --path .
}
bundle-noload everforest.kak "ln -sf ~/workspace/everforest.kak/"
bundle-install-hook everforest.kak %{
mkdir -p "${kak_config}/colors"
ln -sf "${kak_opt_bundle_path}/everforest.kak" "${kak_config}/colors/"
}
bundle-cleaner everforest.kak %{
rm "${kak_config}/colors/everforest.kak"
}
bundle luar "https://github.com/gustavo-hms/luar" %@
require-module luar
# Luar's highlighters are very subtly broken so we need to replace them
# TODO: submit a PR to luar with these fixes.
remove-highlighter shared/kakrc/lua1
remove-highlighter shared/kakrc/lua2
remove-highlighter shared/kakrc/lua3
remove-highlighter shared/kakrc/lua4
add-highlighter shared/kakrc/lua1 region -recurse '\{' '(^|\h)lua\s(([\s{}\w%/$-|''"])* )?%\{\K' '\}' ref lua
add-highlighter shared/kakrc/lua2 region -recurse '\(' '(^|\h)lua\s(([\s{}\w%/$-|''"])* )?%\(\K' '\)' ref lua
add-highlighter shared/kakrc/lua3 region -recurse '\[' '(^|\h)lua\s(([\s{}\w%/$-|''"])* )?%\[\K' '\]' ref lua
add-highlighter shared/kakrc/lua4 region -recurse '<' '(^|\h)lua\s(([\s{}\w%/$-|''"])* )?%<\K' '>' ref lua
@
bundle kakoune-buffer-switcher "https://github.com/occivink/kakoune-buffer-switcher" %{
# Make the current buffer more visible
set-face global BufferSwitcherCurrent value
}
bundle kakoune-focus "https://github.com/caksoylar/kakoune-focus" %{
map global user <space> ':focus-toggle<ret>' -docstring "toggle selections focus"
}
bundle kakship https://github.com/eburghar/kakship %{
kakship-enable
}
bundle-install-hook kakship %{
cargo install --force --path . --root ~/.local
[ ! -e $kak_config/starship.toml ] && cp starship.toml $kak_config/
}
bundle-cleaner kakship %{
rm ~/.local/bin/kakship
}
bundle popup.kak https://github.com/enricozb/popup.kak
bundle-install-hook popup.kak %{
cargo install --force --path .
}
bundle-cleaner popup.kak %{
cargo uninstall kak-popup
}
bundle-customload kak-tree-sitter https://git.sr.ht/~hadronized/kak-tree-sitter %{
evaluate-commands %sh{ kak-tree-sitter -dks --init $kak_session }
}
bundle-install-hook kak-tree-sitter %{
cargo install --force --path ./kak-tree-sitter
cargo install --force --path ./ktsctl
}
bundle-cleaner kak-tree-sitter %{
cargo uninstall kak-tree-sitter
cargo uninstall ktsctl
}
bundle-noload kakeidoscope "git clone --recurse-submodules https://git.sr.ht/~orchid/kakeidoscope"
bundle-install-hook kakeidoscope %{
cd src
make
mv kakeidoscope ~/.local/bin/
}
bundle-cleaner kakeidoscope %{
rm ~/.local/bin/kakeidoscope
}
bundle-updater kakeidoscope %{
git pull --recurse-submodules
}
bundle peneira https://github.com/gustavo-hms/peneira %{
require-module peneira
}

View file

@ -0,0 +1,22 @@
hook global WinSetOption filetype=go %{
set-option buffer lsp_servers %{
[gopls]
root_globs = ["go.mod", ".git", ".hg"]
command = "gopls"
[gopls.settings.gopls]
# See https://github.com/golang/tools/blob/master/gopls/doc/settings.md
# "build.buildFlags" = []
gofumpt = true
hints.assignVariableTypes = true
hints.compositeLiteralFields = true
hints.compositeLiteralTypes = true
hints.constantValues = true
hints.functionTypeParameters = true
hints.parameterNames = true
hints.rangeVariableTypes = true
usePlaceholders = true
semanticTokens = true
}
lsp-enable-buffer
lsp-semantic-tokens-enable
}

View file

@ -0,0 +1,13 @@
hook global WinSetOption filetype=kak %{
softtab-enable
}
hook global ModuleLoaded kak %@
# toml highlighting for lsp_servers
require-module toml
try %~
add-highlighter shared/kakrc/lsp_servers region -recurse '\{' '\blsp_servers\s+%\{' '\}' ref toml
~ catch %$
echo -debug "Error: kakrc: can't declare additional kakrc highlighters: %val{error}"
$
@

View file

@ -0,0 +1,10 @@
hook global WinSetOption filetype=lua %{
set-option buffer lsp_servers %{
[lua-language-server]
root_globs = [".luarc.json", ".git", ".hg"]
command = "lua-language-server"
}
lsp-semantic-tokens-enable
softtab-enable
lsp-enable-buffer
}

View file

@ -0,0 +1,22 @@
hook global WinSetOption filetype=python %{
set-option buffer lsp_servers %{
[basedpyright] # pretty much a strict upgrade over vanilla pyright
root_globs = ["requirements.txt", "setup.py", "pyrightconfig.json", ".git", ".hg"]
command = "basedpyright-langserver"
args = ["--stdio"]
[ruff]
root_globs = ["requirements.txt", "setup.py", "pyrightconfig.json", ".git", ".hg"]
command = "ruff"
args = ["server", "--preview"]
}
lsp-enable-buffer
lsp-semantic-tokens-enable
softtab-enable
}
hook global ModuleLoaded python %{
# By default, Kakoune highlights the "import" and "from" keywords in the "meta" face.
# This is incorrect - they should be highlighted as keywords.
# So, we override the builtin highlighter with our own.
add-highlighter shared/python/code/ regex '\b(import|from)\b' 0:keyword
}

View file

@ -0,0 +1,3 @@
hook global BufSetOption tree_sitter_lang=sh %{
set-option buffer tree_sitter_lang bash
}

View file

@ -0,0 +1,5 @@
hook global WinSetOption filetype=yaml %{
set-option global tabstop 2
set-option global indentwidth 2
softtab
}

47
.config/kak/kakrc Normal file
View file

@ -0,0 +1,47 @@
# Command for loading config files
# This helps to keep the config neat and tidy
define-command load -params 2 %{
source "%val{config}/%arg{1}/%arg{2}.kak"
}
# Plugins
load config plugins
# Additional syntaxes
load syntaxes capnp
load syntaxes kdl
load syntaxes rainbow_csv
load syntaxes sshconfig
# Utility commands
load utils beacon
load utils whitespace
# Tool integration
load tools lazygit
load tools xplr
# Colorscheme/options
load config options
# Mappings
load config mappings
# Filetype-specific configs
load filetypes go
load filetypes kak
load filetypes lua
load filetypes python
load filetypes sh
load filetypes yaml
# Local config (needs to come after everything else)
load config local_config

175
.config/kak/starship.toml Normal file
View file

@ -0,0 +1,175 @@
add_newline = false
format = """\
${custom.kaklsp_progress}\
${custom.kaklsp_err}\
${custom.kaklsp_warn}\
${custom.kaklsp_hint}\
${custom.kakcursor}\
${custom.kakposition}\
${custom.kakmode}\
${custom.kakcontext}\
$directory\
${custom.kakfile}\
${custom.kakfiletype}\
${custom.kaklsp_code_actions}\
$package\
$git_branch\
$git_commit\
$git_state\
$git_status\
${custom.kaksession}"""
[git_branch]
format = '[  $branch]($style)'
style = 'fg:bright-blue italic'
only_attached = false
always_show_remote = true
disabled = false
[git_commit]
format = '[\($hash$tag\)]($style)'
style = 'fg:blue dimmed'
commit_hash_length = 7
only_detached = false
tag_symbol = ' 笠'
tag_disabled = false
disabled = false
[git_state]
format = '\( [$state($progress_current/$progress_total)]($style)\)'
style = 'fg:blue dimmed'
rebase = 'REBASING'
merge = 'MERGING'
revert = 'REVERTING'
cherry_pick = 'CHERRY-PICKING'
bisect = 'BISECTING'
am = 'AM'
am_or_rebase = 'AM/REBASE'
disabled = false
[git_status]
format = '[\[$all_status$ahead_behind\]]($style)'
style = 'fg:cyan dimmed bold'
stashed = '\$'
ahead = '⇡${count}'
behind = '⇣${count}'
diverged = '⇕⇡${ahead_count}⇣${behind_count}'
conflicted = '='
deleted = '✘'
renamed = '»'
modified = '!'
staged = '+'
untracked = '?'
disabled = false
[directory]
format = '[$read_only]($read_only_style)[ $path]($style)'
truncation_length = 3
truncate_to_repo = false
fish_style_pwd_dir_length = 0
use_logical_path = true
style = 'bg:blue fg:black'
read_only_style = 'bg:blue fg:200'
read_only = '[]'
truncation_symbol = '…'
disabled = false
[directory.substitutions]
"~/.config" = " "
"~/workspace" = " "
"~" = " "
[custom.kakfile]
description = 'The current Kakoune buffername'
format = '[/$output ]($style)'
style = 'bold bg:blue fg:black'
command = 'printf ${kak_buffile##*/}'
when = 'true'
shell = ['sh']
disabled = false
[custom.kaksession]
description = 'The current Kakoune session'
format = '($style)[  %val{client}:%val{session} ]($style)'
style = 'bg:yellow fg:black italic'
when = ''
shell = ['true']
disabled = false
[custom.kakcursor]
description = 'The current Kakoune cursor position'
format = '[%val{cursor_line}:%val{cursor_char_column}]($style)'
style = 'fg:white'
when = ''
shell = ['true']
disabled = false
[custom.kakmode]
description = 'The current Kakoune mode'
format = ' {{mode_info}}'
when = ''
shell = ['true']
disabled = false
[custom.kakcontext]
description = 'The current Kakoune context'
format = ' {{context_info}}'
when = ''
shell = ['true']
disabled = false
[custom.kakfiletype]
description = 'The current buffer filetype'
format = ' \[%opt{filetype}\] '
when = ''
shell = ['true']
disabled = false
[custom.kakposition]
description = 'Relative position of the cursor inside the buffer'
format = '[ $output]($style)'
style = 'white'
command = 'printf $(($kak_cursor_line * 100 / $kak_buf_line_count))%'
when = '[ -n "$kak_cursor_line" ]'
shell = ['sh']
disabled = false
[custom.kaklsp_err]
description = "Show errors number from kak-lsp if any"
format = "[  %opt{lsp_diagnostic_error_count}]($style)"
style = "red bold"
when = '[ -n "$kak_opt_lsp_diagnostic_error_count" -a "$kak_opt_lsp_diagnostic_error_count" -ne 0 ]'
shell = ['sh']
disabled = false
[custom.kaklsp_warn]
description = "Show warnings number from kak-lsp if any"
format = "[  %opt{lsp_diagnostic_warning_count}]($style)"
style = "yellow bold"
when = '[ -n "$kak_opt_lsp_diagnostic_warning_count" -a "$kak_opt_lsp_diagnostic_warning_count" -ne 0 ]'
shell = ['sh']
disabled = false
[custom.kaklsp_hint]
description = "Show hints number from kak-lsp if any"
format = "[ ﯦ %opt{lsp_diagnostic_hint_count}]($style)"
style = "white bold"
when = '[ -n "$kak_opt_lsp_diagnostic_hint_count" -a "$kak_opt_lsp_diagnostic_hint_count" -ne 0 ]'
shell = ['sh']
disabled = false
[custom.kaklsp_code_actions]
description = "Show lsp code actions"
format = "[ %opt{lsp_modeline_code_actions} ]($style)"
style = "yellow bold"
when = '[ -n "$kak_opt_lsp_modeline_code_actions" ]'
shell = ['sh']
disabled = false
[custom.kaklsp_progress]
description = "Show activity of kak-lsp if any"
format = "[ ]($style)"
style = "bright-white bold"
when = '[ -n "$kak_opt_lsp_modeline_progress" ]'
shell = ['sh']
disabled = false

View file

@ -0,0 +1,90 @@
# https://capnproto.org/
hook global BufCreate .*[.](capnp) %{
set-option buffer filetype capnp
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook global WinSetOption filetype=capnp %{
require-module capnp
set-option window static_words %opt{capnp_static_words}
hook window ModeChange pop:insert:.* -group capnp-trim-indent capnp-trim-indent
hook window InsertChar .* -group capnp-indent capnp-indent-on-char
hook window InsertChar \n -group capnp-indent capnp-indent-on-new-line
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window capnp-.+ }
}
hook -group capnp-highlight global WinSetOption filetype=capnp %{
add-highlighter window/capnp ref capnp
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/capnp }
}
provide-module capnp %@
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
add-highlighter shared/capnp regions
add-highlighter shared/capnp/code default-region group
add-highlighter shared/capnp/line_comment region '#' '$' fill comment
add-highlighter shared/capnp/string region '"' (?<!\\)(\\\\)*" fill string
add-highlighter shared/capnp/code/ regex '(?i)\b0b[01]+l?\b' 0:value
add-highlighter shared/capnp/code/ regex '(?i)\b0x[\da-f]+l?\b' 0:value
add-highlighter shared/capnp/code/ regex '(?i)\b0o?[0-7]+l?\b' 0:value
add-highlighter shared/capnp/code/ regex '(?i)\b([1-9]\d*|0)l?\b' 0:value
add-highlighter shared/capnp/code/ regex '\b\d+[eE][+-]?\d+\b' 0:value
add-highlighter shared/capnp/code/ regex '(\b\d+)?\.\d+\b' 0:value
add-highlighter shared/capnp/code/ regex '\b\d+\.' 0:value
evaluate-commands %sh{
builtin_types="Void Bool Text Data List union group Int8 Int16 Int32 Int64 UInt8 UInt16 UInt32 UInt64 Float32 Float64"
declarations="struct union enum interface const annotation"
keywords="using extends import"
values="true false inf"
join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; }
printf %s\\n "declare-option str-list capnp_static_words $(join "${builtin_types}" ' ') $(join "${declarations}" ' ') $(join "${keywords}" ' ') $(join "${values}" ' ')"
printf %s\\n "add-highlighter shared/capnp/code/ regex '\b($(join "${builtin_types}" '|'))\b' 0:type"
printf %s\\n "add-highlighter shared/capnp/code/ regex '\b($(join "${declarations}" '|'))\b' 0:keyword"
printf %s\\n "add-highlighter shared/capnp/code/ regex '\b($(join "${keywords}" '|'))\b' 0:keyword"
printf %s\\n "add-highlighter shared/capnp/code/ regex '\b($(join "${values}" '|'))\b' 0:value"
}
# Commands
# ‾‾‾‾‾‾‾‾
define-command -hidden capnp-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden capnp-indent-on-char %<
evaluate-commands -draft -itersel %<
# align closer token to its opener when alone on a line
try %< execute-keys -draft <a-h> <a-k> ^\h+[\]}]$ <ret> m <a-S> 1<a-&> >
>
>
define-command -hidden capnp-indent-on-new-line %<
evaluate-commands -draft -itersel %<
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# filter previous line
try %{ execute-keys -draft k : capnp-trim-indent <ret> }
# indent after lines ending with opener token
try %< execute-keys -draft k x <a-k> [[{]\h*$ <ret> j <a-gt> >
# deindent closer token(s) when after cursor
try %< execute-keys -draft x <a-k> ^\h*[}\]] <ret> gh / [}\]] <ret> m <a-S> 1<a-&> >
>
>
@

View file

@ -0,0 +1,97 @@
# https://kdl.dev
hook global BufCreate .*[.](kdl) %{
set-option buffer filetype kdl
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook global WinSetOption filetype=kdl %{
require-module kdl
hook window ModeChange pop:insert:.* -group kdl-trim-indent kdl-trim-indent
hook window InsertChar .* -group kdl-indent kdl-indent-on-char
hook window InsertChar \n -group kdl-indent kdl-indent-on-new-line
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window kdl-.+ }
}
hook -group kdl-highlight global WinSetOption filetype=kdl %{
add-highlighter window/kdl ref kdl
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/kdl }
}
provide-module kdl %@
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
add-highlighter shared/kdl regions
add-highlighter shared/kdl/code default-region group
add-highlighter shared/kdl/raw_string region -match-capture 'r(#*)"' '"(#*)' fill string
add-highlighter shared/kdl/string region '"' (?<!\\)(\\\\)*" fill string
add-highlighter shared/kdl/comment region -recurse /\* /\* \*/ fill comment
add-highlighter shared/kdl/line_comment region // $ fill comment
# Slashdash (/-) comments are annoying to highlight properly without a proper parser due to the fact that they can comment
# out any kdl construct..
# The below is, at best, an approximation, and there are almost certainly edge cases missed.
add-highlighter shared/kdl/slashdash_child region -recurse \{ /-[^\n]+\{ \} fill comment
add-highlighter shared/kdl/slashdash_string region '/-\s+"' (?<!\\)(\\\\)*" fill comment
add-highlighter shared/kdl/slashdash_raw_string region -match-capture '/-\s+r"(#*)' '"(#*)' fill comment
add-highlighter shared/kdl/slashdash_builtin_value region /-\s+(true|false|null) \s fill comment
add-highlighter shared/kdl/slashdash_binary region /-\s+0b[01_]+ \s fill comment
add-highlighter shared/kdl/slashdash_octal region /-\s+0o[0-7_]+ \s fill comment
add-highlighter shared/kdl/slashdash_hex region /-\s+0x[a-fA-F0-9_]+ \s fill comment
add-highlighter shared/kdl/slashdash_decimal region /-\s+[0-9-+][0-9_]* \s fill comment
add-highlighter shared/kdl/slashdash_float region /-\s+[0-9-+][0-9_]*\.[0-9_]+ \s fill comment
add-highlighter shared/kdl/slashdash_float_exp region /-\s+[0-9-+][0-9_]*(\.[0-9_]+)?[eE][-+]?[0-9_]+ \s fill comment
add-highlighter shared/kdl/slashdash_prop_string region '/-\s+[\u000021-\u00FFFF]+="' (?<!\\)(\\\\)*" fill comment
add-highlighter shared/kdl/slashdash_prop_raw_string region -match-capture '/-\s+[\u000021-\u00FFFF]+=r"(#*)' '"(#*)' fill comment
add-highlighter shared/kdl/slashdash_prop_other region /-\s+[\u000021-\u00FFFF]+= \s fill comment
add-highlighter shared/kdl/slashdash_node region /-\s+[\u000021-\u00FFFF]+ $ fill comment
add-highlighter shared/kdl/code/node regex \b([\u000021-\u00FFFF]*)\b 0:variable # Everything not covered below is a node
add-highlighter shared/kdl/code/property regex \b([\u000021-\u00FFFF]+)(=) 0:operator 1:attribute
add-highlighter shared/kdl/code/builtin_value regex \b(true|false|null)\b 0:value
add-highlighter shared/kdl/code/binary regex \b(0b[01_]+)\b 0:value
add-highlighter shared/kdl/code/octal regex \b(0o[0-7_]+)\b 0:value
add-highlighter shared/kdl/code/hex regex \b(0x[a-fA-F0-9_]+)\b 0:value
add-highlighter shared/kdl/code/decimal regex \b([0-9-+][0-9_]*)\b 0:value
add-highlighter shared/kdl/code/float regex \b([0-9-+][0-9_]*\.[0-9_]+)\b 0:value
add-highlighter shared/kdl/code/float_exp regex \b([0-9-+][0-9_]*(\.[0-9_]+)?[eE][-+]?[0-9_]+)\b 0:value
# Commands
# ‾‾‾‾‾‾‾‾
define-command -hidden kdl-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden kdl-indent-on-char %<
evaluate-commands -draft -itersel %<
# align closer token to its opener when alone on a line
try %< execute-keys -draft <a-h> <a-k> ^\h+[\]}]$ <ret> m <a-S> 1<a-&> >
>
>
define-command -hidden kdl-indent-on-new-line %<
evaluate-commands -draft -itersel %<
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# filter previous line
try %{ execute-keys -draft k : kdl-trim-indent <ret> }
# indent after lines ending with opener token
try %< execute-keys -draft k x <a-k> [[{]\h*$ <ret> j <a-gt> >
# deindent closer token(s) when after cursor
try %< execute-keys -draft x <a-k> ^\h*[}\]] <ret> gh / [}\]] <ret> m <a-S> 1<a-&> >
>
>
@

View file

@ -0,0 +1,32 @@
# Opinionated rainbow csv implementation
hook global BufCreate .*[.](csv) %{
set-option buffer filetype csv
}
hook global WinSetOption filetype=csv %{
try %{
remove-highlighter window/csv
}
lua %{
rgx = "(^[^\n,]*[,$])?"
-- These colors are designed to match the Everforest Dark colorscheme.
colors = {"blue", "green", "magenta", "rgb:e69875"}
faces = {}
for idx, color in pairs(colors) do
if idx > 1 then
rgx = rgx .. "([^\n,]*[,$])?"
end
faces[idx] = idx .. ":" .. color
end
kak.add_highlighter("window/csv", "regions")
kak.add_highlighter("window/csv/comment", "region", "^", "\n", "group")
kak.add_highlighter("window/csv/comment/", "regex", rgx, table.unpack(faces))
}
}
hook global WinSetOption filetype=(?!csv).* %{
try %{
remove-highlighter window/csv
}
}

View file

@ -0,0 +1,116 @@
hook global BufCreate .*/\.ssh/config %{
set-option buffer filetype ssh
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook global WinSetOption filetype=ssh %{
require-module ssh
set-option window static_words %opt{ssh_static_words}
hook window InsertChar \n -group ssh-insert ssh-insert-on-new-line
hook window InsertChar \n -group ssh-indent ssh-indent-on-new-line
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window ssh-.+ }
}
hook -group ssh-highlight global WinSetOption filetype=ssh %{
add-highlighter window/ssh ref ssh
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/ssh }
}
provide-module ssh %@
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
add-highlighter shared/ssh regions
add-highlighter shared/ssh/code default-region group
add-highlighter shared/ssh/double_string region %{(?<!\\)(?:\\\\)*\K"} %{(?<!\\)(?:\\\\)*"} group
add-highlighter shared/ssh/single_string region %{(?<!\\)(?:\\\\)*\K'} %{'} fill string
add-highlighter shared/ssh/comment region (?<!\\)(?:\\\\)*(?:^|\h)\K# '$' fill comment
add-highlighter shared/ssh/double_string/fill fill string
evaluate-commands %sh{
keywords="AddKeysToAgent AddressFamily AskPassGUI BatchMode BindAddress CanonicalDomains CanonicalizeFallbackLocal CanonicalizeHostname
CanonicalizeMaxDots CanonicalizePermittedCNAMEs ChallengeResponseAuthentication CheckHostIP Cipher Ciphers ClearAllForwardings
Compression CompressionLevel ConnectionAttempts ConnectTimeout ControlMaster ControlPath ControlPersist DynamicForward
EnableSSHKeysign EscapeChar ExitOnForwardFailure FingerprintHash ForwardAgent ForwardX11 ForwardX11Timeout ForwardX11Trusted
GatewayPorts GlobalKnownHostsFile GSSAPIAuthentication GSSAPIClientIdentity GSSAPIDelegateCredentials GSSAPIKeyExchange
GSSAPIRenewalForcesRekey GSSAPIServerIdentity GSSAPITrustDns HashKnownHosts Host HostbasedAuthentication HostbasedKeyTypes
HostKeyAlgorithms HostKeyAlias HostName IdentitiesOnly IdentityFile IgnoreUnknown IPQoS KbdInteractiveAuthentication
KbdInteractiveDevices KexAlgorithms KeychainIntegration LocalCommand LocalForward LogLevel MACs Match NoHostAuthenticationForLocalhost
NumberOfPasswordPrompts PasswordAuthentication PermitLocalCommand PKCS11Provider Port PreferredAuthentications Protocol ProxyCommand
ProxyJump ProxyUseFdpass PubkeyAuthentication RekeyLimit RemoteForward RequestTTY RevokedHostKeys RhostsRSAAuthentication
RSAAuthentication SendEnv ServerAliveCountMax ServerAliveInterval SmartcardDevice StreamLocalBindMask StreamLocalBindUnlink
StrictHostKeyChecking TCPKeepAlive Tunnel TunnelDevice UpdateHostKeys UseKeychain UsePrivilegedPort User UserKnownHostsFile
VerifyHostKeyDNS VisualHostKey XAuthLocation"
join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; }
printf %s\\n "declare-option str-list ssh_static_words $(join "${keywords}" ' ') $(join "${builtins}" ' ')"
printf %s\\n "add-highlighter shared/ssh/code/ regex (?<!-)\b($(join "${keywords}" '|'))\b(?!-) 0:keyword"
}
add-highlighter shared/ssh/code/ regex ^host\s+ 0:keyword
# Commands
# ‾‾‾‾‾‾‾‾
define-command -hidden ssh-insert-on-new-line %{ evaluate-commands -itersel -draft %{
execute-keys <semicolon>
try %{
evaluate-commands -draft -save-regs '/"' %{
# Ensure previous line is a comment
execute-keys -draft kxs^\h*#+\h*<ret>
# now handle the coment continuation logic
try %{
# try and match a regular block comment, copying the prefix
execute-keys -draft -save-regs '' k x 1s^(\h*#+\h*)\S.*$ <ret> y
execute-keys -draft P
} catch %{
try %{
# try and match a regular block comment followed by a single
# empty comment line
execute-keys -draft -save-regs '' kKx 1s^(\h*#+\h*)\S+\n\h*#+\h*$ <ret> y
execute-keys -draft P
} catch %{
try %{
# try and match a pair of empty comment lines, and delete
# them if we match
execute-keys -draft kKx <a-k> ^\h*#+\h*\n\h*#+\h*$ <ret> <a-d>
} catch %{
# finally, we need a special case for a new line inserted
# into a file that consists of a single empty comment - in
# that case we can't expect to copy the trailing whitespace,
# so we add our own
execute-keys -draft -save-regs '' k x1s^(\h*#+)\h*$<ret> y
execute-keys -draft P
execute-keys -draft i<space>
}
}
}
}
# trim trailing whitespace on the previous line
try %{ execute-keys -draft k x s\h+$<ret> d }
}
} }
define-command -hidden ssh-indent-on-new-line %<
evaluate-commands -draft -itersel %<
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# cleanup trailing whitespaces from previous line
try %{ execute-keys -draft k x s \h+$ <ret> d }
>
>
@

View file

@ -0,0 +1,7 @@
# https://github.com/jesseduffield/lazygit
define-command lazygit %{
popup lazygit
}
alias global lg lazygit

View file

@ -0,0 +1,21 @@
# https://xplr.dev/
# Seriously, xplr is awesome. Get it if you haven't already.
define-command xplr-open -params 1 %{
evaluate-commands %sh{
for xplr_file in $1; do
if [ -f "$xplr_file" ]; then
printf "%s\n" "edit $xplr_file"
fi
done
}
} -hidden
define-command xplr -params ..1 %{
popup --title open --kak-script %{ xplr-open %opt{popup_output} } -- xplr %arg{@}
}
# Utility command to edit a kak config file with xplr
define-command edit-config %{
xplr %val{config}
}

View file

@ -0,0 +1,87 @@
# This script flashes the current line when the cursor moves or the window is focused,
# to help highlight where the cursor is.
# Heavily inspired by the Beacon.nvim plugin: https://github.com/DanilaMihailov/beacon.nvim
declare-option str beacon_final_bg "5c6a72"
declare-option str beacon_refresh_interval "0.03"
declare-option -hidden str beacon_transition
declare-option -hidden str beacon_keys_normal "<c-f> <c-b> <c-d> <c-u> <pageup> <pagedown> ( ) m M <a-semicolon> n <a-n> N <a-N> u U"
declare-option -hidden str beacon_keys_goto "g k j e ."
lua %opt{beacon_final_bg} %{
bg = tonumber(arg[1], 16)
colors = ""
-- Split the background into individual bytes.
-- This will help ensure a smooth transition.
bg_left = bg >> 16
bg_center = (bg >> 8) & 0xFF
bg_right = bg & 0xFF
while true do
bg_left = bg_left + 0x11
if bg_left > 0xFF then
break
end
-- Prevent the center bytes and rightmost bytes from "overflowing"
-- and yielding an overall red color (which would look bad)
bg_center = bg_center + 0x11
if bg_center > 0xFF then
bg_center = 0xFF
end
bg_right = bg_right + 0x11
if bg_right > 0xFF then
bg_right = 0xFF
end
bg = bg_right + (bg_center << 8) + (bg_left << 16)
colors = "rgb:" .. string.format("%X", bg) .. " " .. colors
end
kak.set_option("global", "beacon_transition", colors)
}
define-command beacon %{
# Since this requires running kak commands at a set time rather than all at the end,
# using %sh{} instead of %lua{} is better here.
nop %sh{
(
printf "%s\n" "evaluate-commands -client $kak_client %{ try %{
add-highlighter buffer/beacon group
}}" | kak -p $kak_session
for color in $kak_opt_beacon_transition; do
printf "%s\n" "
evaluate-commands -client $kak_client %{
evaluate-commands -draft %{
execute-keys x
declare-option range-specs beacon_range %val{timestamp} \"%val{selection_desc}|default,$color\"
}
try %{ add-highlighter buffer/beacon/$color ranges beacon_range }
}" | kak -p $kak_session
sleep $kak_opt_beacon_refresh_interval
done
printf "%s\n" "evaluate-commands -client $kak_client %{
try %{ remove-highlighter buffer/beacon }
}" | kak -p $kak_session
) >/dev/null 2>&1 </dev/null &
}
} -hidden
hook global FocusIn .* beacon
hook global WinCreate .* %{
lua %opt{beacon_keys_normal} %opt{beacon_keys_goto} %{
for key in string.gmatch(arg[1], "[^%s]+") do
kak.map("window", "normal", key, key .. ":beacon<ret>")
end
for key in string.gmatch(arg[2], "[^%s]+") do
kak.map("window", "goto", key, key .. ":beacon<ret>")
end
}
hook window RawKey '<mouse:press:left:.*>' beacon
}

View file

@ -0,0 +1,22 @@
add-highlighter global/indent show-whitespaces -tab "│" -indent "│" -spc " " -lf " "
define-command softtab-enable %{
hook buffer InsertChar \t %{ try %{
execute-keys -draft "h<a-h><a-k>\A\h+\z<ret><a-;>;%opt{indentwidth}@"
}}
hook buffer InsertDelete ' ' %{ try %{
execute-keys -draft 'h<a-h><a-k>\A\h+\z<ret>i<space><esc><lt>'
}}
}
define-command toggle-whitespace %{
try %{
add-highlighter global/whitespaces show-whitespaces
remove-highlighter global/indent
} catch %{
remove-highlighter global/whitespaces
add-highlighter global/indent show-whitespaces -tab "│" -indent "│" -spc " " -lf " "
}
}