diff --git a/user/home.nix b/user/home.nix index bda284d..654f90f 100644 --- a/user/home.nix +++ b/user/home.nix @@ -252,6 +252,8 @@ in { alias _fish_prompt_accent "_fish_prompt_color '$__accent_color'" ''; shellAbbrs = { + v = "kak"; + # system sv = "sudo systemct"; suv = "sudo systemct --user"; # git abbrs @@ -281,6 +283,109 @@ in { # ".config/sway/config".source = ./sway; ".config/fish/conf.d/prompt.fish".source = ./fish_prompt.fish; ".local/share/backgrounds".source = ./backgrounds; + ".config/kak/rc".source = ./kak/rc; + ".config/kak/kakrc".source = ./kak/kakrc; + ".config/kak/colors.kak".text =let + colors = lib.mapAttrs (_: lib.replaceStrings ["#"] ["rgb:"]) { + accent_fg = accent.fg ; + accent_color = accent.color ; + bg_light = color.bg_light ; + bg_dark = color.bg_dark ; + nontxt = color.nontxt ; + orange = color.normal.orange ; + brown = color.normal.brown ; + }; + in with colors; '' + face global crosshairs_line default,${ bg_dark } + face global crosshairs_column default+b + + # For Code + face global value magenta + face global type yellow + face global variable blue + face global module ${ brown } + face global function ${ orange } + face global string green + face global keyword ${ accent_color } + face global operator yellow + face global attribute cyan + face global comment ${ bg_light } + face global documentation comment + face global meta +i@function + face global builtin blue + + # For markup + face global title blue + face global header cyan + face global mono green + face global block magenta + face global link cyan + face global bullet cyan + face global list yellow + + # builtin faces + face global Default default,default + + face global PrimaryCursor ${ accent_fg },${ accent_color }+fg + face global PrimaryCursorEol PrimaryCursor + face global PrimarySelection default,${ bg_light }+f + + face global SecondaryCursor default,default+rfg + face global SecondaryCursorEol SecondaryCursor + face global SecondarySelection PrimarySelection + + face global InactiveCursor ${ accent_fg },${ bg_light }+fg + + face global MenuForeground ${ accent_fg },${ accent_color } + face global MenuBackground default,${ bg_dark } + face global MenuInfo cyan + + face global Information default,${ bg_dark } + face global Error default,red+g + + face global StatusLine %sh{ + printf "rgb:" + head /dev/urandom | + base64 | + rg --text -o "${ color.random_range }" | + head -n 6 | + sd '\n' "" + } + face global StatusLineMode StatusLine + face global StatusLineInfo StatusLine + face global StatusLineValue StatusLine + face global StatusCursor ${ accent_fg },${ accent_color } + + face global Prompt yellow,default + try %{add-highlighter global/ show-matching} + face global MatchingChar ${ accent_color },default+b + + # Goodies + try %{add-highlighter global/number-lines number-lines -relative -hlcursor} + face global LineNumbers ${ bg_light },default + face global LineNumberCursor default,${ bg_dark } + face global LineNumbersWrapped red,default + + try %{add-highlighter global/ show-whitespaces} + face global Whitespace ${ nontxt },default+f + face global BufferPadding ${ nontxt },default + ## highlight trailing whitespace + # add-highlighter global/ regex '\h*$' 0:red,red+u + + face global Reference default+bu + face global InlayHint ${ bg_light }+buif + + # Lsp + '' + (lib.concatStringsSep "\n" (lib.mapAttrsToList (name: color: '' + face global HighlightDiagnostic${ name } ${ color },default+bu + face global Diagnostic${ name } ${ color },default+bu + face global TextDiagnostic${ name } ${ color },default+b + face global InlayDiagnostic${ name } ${ color },default+br + '') { + Error = "red"; + Warning = "yellow"; + Hint = "blue"; + })); }; programs.alacritty = { enable = true; @@ -474,7 +579,7 @@ in { }; }; home.sessionVariables = { - EDITOR = "hx"; + EDITOR = "kak"; VOLUME_CHANGE_SOUND = "${pkgs.sound-theme-freedesktop}/share/sounds/freedesktop/stereo/audio-volume-change.oga"; }; diff --git a/user/kak/kakrc b/user/kak/kakrc new file mode 100644 index 0000000..4b38e3c --- /dev/null +++ b/user/kak/kakrc @@ -0,0 +1,19 @@ +# {{@@ header() @@}} +# _ __ _ +# | |/ /__ _| | _____ _ _ _ __ ___ +# | ' // _` | |/ / _ \| | | | '_ \ / _ \ +# | . \ (_| | < (_) | |_| | | | | __/ +# |_|\_\__,_|_|\_\___/ \__,_|_| |_|\___| + + +set global scrolloff 10,20 +set global autoreload yes +set global startup_info_version 20200901 + +source "%val{config}/rc/plug.kak" +source "%val{config}/rc/keys.kak" +source "%val{config}/rc/usermode.kak" +source "%val{config}/rc/hooks.kak" +source "%val{config}/rc/filetypes.kak" +source "%val{config}/rc/indent.kak" +source "%val{config}/colors.kak" diff --git a/user/kak/rc/filetypes.kak b/user/kak/rc/filetypes.kak new file mode 100644 index 0000000..ffdbfbe --- /dev/null +++ b/user/kak/rc/filetypes.kak @@ -0,0 +1,226 @@ + +try %{ + require-module python + add-highlighter shared/python/code/function regex '\b([a-zA-Z_][a-zA-Z0-9_]*)\s*\(' 1:function +} + +hook global WinSetOption filetype=sh %{ + set buffer formatcmd 'shfmt -s -ci -i "4"' +} +hook global WinSetOption filetype=c %{ + set buffer formatcmd 'clang-format' +} + +hook global BufCreate .*\.rs %{ + set buffer formatcmd 'rustfmt' +} + +hook global BufCreate .*\.html %{ + set buffer formatcmd 'prettier --parser html' +} + +hook global BufCreate .*\.js %{ + set buffer formatcmd 'prettier --parser babel' +} + +hook global BufCreate .*\.vue %{ + set buffer formatcmd 'prettier --parser vue' + hook buffer InsertCompletionHide { + execute-keys 'Ghs$1c' + } +} + +# Highlight Dotdrop templating syntax +hook global WinCreate .* %{ + require-module python + add-highlighter window/dotdrop regions + + add-highlighter window/dotdrop/expression region '\{\{@[@]' '[@]@\}\}' group + add-highlighter window/dotdrop/statement region '\{%@[@]' '[@]@%\}' group + add-highlighter window/dotdrop/comment region '\{#@[@]' '[@]@#\}' fill comment + + add-highlighter window/dotdrop/expression/ fill variable + add-highlighter window/dotdrop/statement/ fill variable + + add-highlighter window/dotdrop/expression/ ref python + add-highlighter window/dotdrop/statement/ ref python + + add-highlighter window/dotdrop/expression/ regex '\{\{@[@]|[@]@\}\}' 0:block + add-highlighter window/dotdrop/statement/ regex '\{%@[@]|[@]@%\}' 0:block + add-highlighter window/dotdrop/statement/ regex 'endfor|endif' 0:keyword +} + +hook global BufCreate .*\.jsonc %[ set buffer filetype jsonc ] +hook global BufCreate .*\.blade.php %[ set buffer filetype blade ] +hook global BufCreate .*\.less %[ set buffer filetype less ] +hook global BufCreate .*\.(tera|askama)\.?.* %[ + require-module jinja + add-highlighter buffer/jinja ref jinja +] + +hook global WinSetOption filetype=sql %[ + set buffer comment_line '--' +] + +hook global WinSetOption filetype=jsonc %[ + set buffer comment_line '//' + + require-module json + add-highlighter buffer/jsonc regions + add-highlighter buffer/jsonc/base default-region ref json + add-highlighter buffer/jsonc/double_string region ["] ["] fill string + add-highlighter buffer/jsonc/line-comment region // $ fill comment +] + + +hook global WinSetOption filetype=blade %[ + set buffer formatcmd 'blade-formatter \ + --end-with-newline \ + --indent-size "4" \ + --wrap-line-length "80" \ + --stdin' + set-option buffer extra_word_chars '_' '-' + + hook window ModeChange pop:insert:.* -group blade-trim-indent blade-trim-indent + hook window InsertChar .* -group blade-indent blade-indent-on-char + hook window InsertChar \n -group blade-indent blade-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window blade-.+ } + + require-module php + + add-highlighter buffer/blade regions + add-highlighter buffer/blade/base default-region group + + add-highlighter buffer/blade/string region '"' '"' regions + add-highlighter buffer/blade/string/base default-region fill string + add-highlighter buffer/blade/string/expression region '\{\{(?!--)' '(?!--)\}\}' ref php + add-highlighter buffer/blade/string/raw-expression region '\{!!' '!!\}' ref php + + add-highlighter buffer/blade/base/ ref html + + add-highlighter buffer/blade/php region '@php' '@endphp' group + add-highlighter buffer/blade/php/ ref php + add-highlighter buffer/blade/php/ regex '@((end)?php)' 1:block + + add-highlighter buffer/blade/expression region '\{\{(?!--)' '(?!--)\}\}' ref php + add-highlighter buffer/blade/statement region -recurse '\(' '@(if|for|foreach|section|yield|include)\s*\(' '\)' ref php + add-highlighter buffer/blade/base/ regex '@(else(if)?|include|case|break)' 1:keyword + add-highlighter buffer/blade/base/ regex '@((end)?(if|isset|for|foreach|section|switch))' 1:keyword + + add-highlighter buffer/blade/comment region '\{\{--' '--\}\}' fill comment + set-option buffer comment_block_begin '{{-- ' + set-option buffer comment_block_end ' --}}' + + map buffer user 'c' '_: comment-block;' -docstring 'comment block' +] + +try %§ + +define-command -hidden blade-trim-indent %{ + # remove trailing white spaces + try %{ execute-keys -draft -itersel s \h+$ d } +} + +define-command -hidden blade-indent-on-char %< + evaluate-commands -draft -itersel %< + # align closer token to its opener when alone on a line + try %/ execute-keys -draft ^\h+[\]}]$ m s \A|.\z 1 / + > +> + +define-command -hidden blade-indent-on-new-line %< + evaluate-commands -draft -itersel %< + # copy // comments or docblock * prefix and following white spaces + try %{ execute-keys -draft s [^/] k s ^\h*\K(?://|[*][^/])\h* y gh j P } + # preserve previous line indent + try %{ execute-keys -draft K } + # filter previous line + try %{ execute-keys -draft k : blade-trim-indent } + # indent after lines beginning / ending with opener token + try %_ execute-keys -draft k ^\h*[[{]|[[{]$ j _ + # append " * " on lines starting a multiline /** or /* comment + try %{ execute-keys -draft k s ^\h*/[*][* ]? j gi i * } + # deindent closer token(s) when after cursor + try %_ execute-keys -draft ^\h*[})] gh / [})] m 1 _ + > +> +§ + +hook global WinSetOption filetype=less %[ + set buffer formatcmd 'prettier \ + --tab-width "4" \ + --print-width "80" \ + --parser less' + + set-option buffer extra_word_chars '_' '-' + + set buffer comment_line '//' + set buffer comment_block_begin '/*' + set buffer comment_block_end '*/' + + hook window ModeChange pop:insert:.* -group less-trim-indent less-trim-indent + hook window InsertChar \n -group less-indent less-indent-on-new-line + hook window InsertChar \} -group less-indent less-indent-on-closing-curly-brace + + map buffer insert 'xs\$\d+) c' + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window less-.+ } + + add-highlighter buffer/less regions + add-highlighter buffer/less/code default-region group + + add-highlighter buffer/less/line-comment region // $ fill comment + add-highlighter buffer/less/comment region /[*] [*]/ fill comment + add-highlighter buffer/less/double_string region ["] ["] fill string + add-highlighter buffer/less/single_string region ['] ['] fill string + + add-highlighter buffer/less/code/ regex ([A-Za-z][A-Za-z0-9_-]*)\h*: 1:keyword + add-highlighter buffer/less/code/ regex ::?(\w+) 0:attribute + add-highlighter buffer/less/code/ regex !important 0:keyword + + add-highlighter buffer/less/code/selector group + add-highlighter buffer/less/code/selector/ regex [A-Za-z][A-Za-z0-9_-]* 0:keyword + add-highlighter buffer/less/code/selector/ regex [*]|[#.][A-Za-z][A-Za-z0-9_-]* 0:variable + add-highlighter buffer/less/code/selector/ regex &([A-Za-z0-9_-]*) 1:variable + add-highlighter buffer/less/code/selector/ regex & 0:operator + add-highlighter buffer/less/code/selector/ regex (\.?[A-Za-z][A-Za-z0-9_-]*)\s*\( 1:function + + add-highlighter buffer/less/code/ regex (\b(\d*\.)?\d+(ch|cm|em|ex|mm|pc|pt|px|rem|vh|vmax|vmin|vw|%|s|ms)?) 0:value 3:type + add-highlighter buffer/less/code/ regex (#)[0-9A-Fa-f]{3}([0-9A-Fa-f]{3}([0-9A-Fa-f]{2})?)?\b 0:value 1:operator + + add-highlighter buffer/less/code/ regex (?i)\b(AliceBlue|AntiqueWhite|Aqua|Aquamarine|Azure|Beige|Bisque|Black|BlanchedAlmond|Blue|BlueViolet|Brown|BurlyWood|CadetBlue|Chartreuse|Chocolate|Coral|CornflowerBlue|Cornsilk|Crimson|Cyan|DarkBlue|DarkCyan|DarkGoldenRod|DarkGray|DarkGrey|DarkGreen|DarkKhaki|DarkMagenta|DarkOliveGreen|DarkOrange|DarkOrchid|DarkRed|DarkSalmon|DarkSeaGreen|DarkSlateBlue|DarkSlateGray|DarkSlateGrey|DarkTurquoise|DarkViolet|DeepPink|DeepSkyBlue|DimGray|DimGrey|DodgerBlue|FireBrick|FloralWhite|ForestGreen|Fuchsia|Gainsboro|GhostWhite|Gold|GoldenRod|Gray|Grey|Green|GreenYellow|HoneyDew|HotPink|IndianRed|Indigo|Ivory|Khaki|Lavender|LavenderBlush|LawnGreen|LemonChiffon|LightBlue|LightCoral|LightCyan|LightGoldenRodYellow|LightGray|LightGrey|LightGreen|LightPink|LightSalmon|LightSeaGreen|LightSkyBlue|LightSlateGray|LightSlateGrey|LightSteelBlue|LightYellow|Lime|LimeGreen|Linen|Magenta|Maroon|MediumAquaMarine|MediumBlue|MediumOrchid|MediumPurple|MediumSeaGreen|MediumSlateBlue|MediumSpringGreen|MediumTurquoise|MediumVioletRed|MidnightBlue|MintCream|MistyRose|Moccasin|NavajoWhite|Navy|OldLace|Olive|OliveDrab|Orange|OrangeRed|Orchid|PaleGoldenRod|PaleGreen|PaleTurquoise|PaleVioletRed|PapayaWhip|PeachPuff|Peru|Pink|Plum|PowderBlue|Purple|RebeccaPurple|Red|RosyBrown|RoyalBlue|SaddleBrown|Salmon|SandyBrown|SeaGreen|SeaShell|Sienna|Silver|SkyBlue|SlateBlue|SlateGray|SlateGrey|Snow|SpringGreen|SteelBlue|Tan|Teal|Thistle|Tomato|Turquoise|Violet|Wheat|White|WhiteSmoke|Yellow|YellowGreen)\b 0:value + + add-highlighter buffer/less/code/ regex ([\w-_]+)\s*: 1:attribute + add-highlighter buffer/less/code/ regex @[\w\d-_]+ 0:variable + +] + +try %§ + +define-command -hidden less-trim-indent %{ + # remove trailing white spaces + try %{ execute-keys -draft -itersel s \h+$ d } +} + +define-command -hidden less-indent-on-new-line %[ + evaluate-commands -draft -itersel %[ + # preserve previous line indent + try %[ execute-keys -draft K ] + # filter previous line + try %[ execute-keys -draft k : less-trim-indent ] + # indent after lines ending with with { + try %[ execute-keys -draft k \{$ j ] + # deindent closing brace when after cursor + try %[ execute-keys -draft ^\h*\} gh / \} m 1 ] + ] +] + +define-command -hidden less-indent-on-closing-curly-brace %[ + evaluate-commands -draft -itersel %[ + # align to opening curly brace when alone on a line + try %[ execute-keys -draft ^\h+\}$ m s \A|.\z 1 ] + ] +] + +§ diff --git a/user/kak/rc/hooks.kak b/user/kak/rc/hooks.kak new file mode 100644 index 0000000..2622691 --- /dev/null +++ b/user/kak/rc/hooks.kak @@ -0,0 +1,48 @@ +set global idle_timeout 500 + +hook global NormalIdle .* %{ try %{ + palette-status +} } + +define-command -hidden -override git-try-show-diff %{ + evaluate-commands -draft %sh{ + test -f "$kak_buffile" || exit 0 + cd $(dirname "$kak_buffile") + git rev-parse --git-dir > /dev/null && + echo "git show-diff" + } +} + +evaluate-commands %sh{ + for hook in NormalIdle FocusIn FocusOut BufWritePost BufOpenFile; do + printf "hook global %s .* 'git-try-show-diff'\n" "$hook" + done +} + +define-command -override diffr %{ try %{ + execute-keys -draft 'ggxsdiff' + execute-keys -draft '%J| _diffr' + ansi-render +} } + +hook global BufOpenFile .* diffr + +hook global BufOpenFile .* %{ + modeline-parse +} + +hook global BufOpenFile .*/COMMIT_EDITMSG %{ + execute-keys -draft 'gegit log' + write +} + +hook global RegisterModified '"' %{ nop %sh{ { + printf %s "$kak_reg_dquote" | wl-copy -n + printf %s "$kak_reg_dquote" | xclip -i -selection clipboard +} > /dev/null 2>&1 < /dev/null & }} + +# Trim trailing whitespace +hook global BufWritePre .* %{ try %{ + execute-keys -draft \%s\h+$d +} } -group remove-whitespace + diff --git a/user/kak/rc/indent.kak b/user/kak/rc/indent.kak new file mode 100644 index 0000000..55ee732 --- /dev/null +++ b/user/kak/rc/indent.kak @@ -0,0 +1,29 @@ +# {{@@ header() @@}} +# _ __ _ +# | |/ /__ _| | _____ _ _ _ __ ___ +# | ' // _` | |/ / _ \| | | | '_ \ / _ \ +# | . \ (_| | < (_) | |_| | | | | __/ +# |_|\_\__,_|_|\_\___/ \__,_|_| |_|\___| + +set global tabstop 4 + +hook global BufCreate .*\.py %{ + set global indentwidth 4 +} + +################################################################# +# Spaces +################################################################# + +set global indentwidth 4 + +# use spaces insted of tabs +hook global BufCreate .* %{ + hook buffer InsertChar \t %{ + exec -draft -itersel h@ + } -group replace-tabs-with-spaces +} + +hook global WinSetOption filetype=makefile %{ + remove-hooks buffer replace-tabs-with-spaces +} diff --git a/user/kak/rc/keys.kak b/user/kak/rc/keys.kak new file mode 100644 index 0000000..ad67ebb --- /dev/null +++ b/user/kak/rc/keys.kak @@ -0,0 +1,38 @@ +# {{@@ header() @@}} + +map global normal 10j +map global normal 10k + +# alt i makes searches case insensitive +map global prompt '(?i)' + +###################################################### +# Emacs-like insert +###################################################### + +map global insert "h" +map global insert "l" + +map global insert "b" +map global insert "w" + +map global insert "gi" +map global insert "ghgl" +map global insert "bd" + + +###################################################### +# Other insert binds +###################################################### + +map global insert "" +map global insert "" + + +###################################################### +# Objects +###################################################### + +map global object m %{c^[=|]{4\,}[^\n]*\n,^[=|]{4\,}[^\n]*\n} -docstring 'git conflict markers' +map global object M %{c^{4\,}[^\n]*\n,^{4\,}[^\n]*\n} -docstring 'git conflict' + diff --git a/user/kak/rc/plug.kak b/user/kak/rc/plug.kak new file mode 100644 index 0000000..666c604 --- /dev/null +++ b/user/kak/rc/plug.kak @@ -0,0 +1,92 @@ +nop %sh{ + PLUG_DIR="${HOME}/.cache/kakoune_plugins" + REPO="https://github.com/andreyorst/plug.kak.git" + + mkdir -p "$PLUG_DIR" + + test -d "${PLUG_DIR}/plug.kak" || + git clone "$REPO" "${PLUG_DIR}/plug.kak" +} + +source %sh{ echo "${HOME}/.cache/kakoune_plugins/plug.kak/rc/plug.kak" } + +plug "andreyorst/plug.kak" noload config %{ + # Auto install every pluging + set-option global plug_always_ensure true + set-option global plug_install_dir %sh{ echo "${HOME}/.cache/kakoune_plugins" } +} + +plug 'eraserhd/kak-ansi' + +plug 'alexherbo2/auto-pairs.kak' config %{ + enable-auto-pairs +} + +plug 'lelgenio/kakoune-mirror-colemak' config %{ + map global user "s" ': enter-user-mode mirror' +} + +plug 'delapouite/kakoune-palette' +plug 'greenfork/active-window.kak' +plug 'lelgenio/kak-crosshairs' config %{ + crosshairs-enable +} + +# Search and replace, for every buffer +plug "natasky/kakoune-multi-file" + +plug "lelgenio/kakoune-colemak-neio" + +plug 'kak-lsp/kak-lsp' do %{ + cargo install --locked --force --path . +} config %{ + map global normal ': lsp-rename-prompt' + set global lsp_hover_max_lines 10 + set global lsp_auto_highlight_references true + set global lsp_inlay_diagnostic_sign "●" + set global lsp_diagnostic_line_error_sign "●" + + hook global BufCreate .* %{try lsp-enable} + + define-command -override -hidden lsp-next-placeholder-bind %{ + map global normal ': try lsp-snippets-select-next-placeholders catch %{ execute-keys -with-hooks tab> }' -docstring 'Select next snippet placeholder' + map global insert ': try lsp-snippets-select-next-placeholders catch %{ execute-keys -with-hooks tab> }' -docstring 'Select next snippet placeholder' + } + lsp-next-placeholder-bind + map global insert ": lsp-code-action-sync Fill" + + define-command -override -hidden lsp-enable-decals %{ + lsp-inlay-diagnostics-enable global + lsp-inlay-hints-enable global + } + + define-command -override -hidden lsp-disable-decals %{ + lsp-inlay-diagnostics-disable global + lsp-inlay-hints-disable global + } + lsp-enable-decals + + hook global ModeChange '.*:insert:normal' %{lsp-enable-decals} + hook global ModeChange '.*:normal:insert' %{lsp-disable-decals} + + hook global WinSetOption filetype=(c|cpp|rust) %{ + 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 + } + } + + declare-option -hidden str modeline_progress "" + define-command -hidden -params 6 -override lsp-handle-progress %{ + set global modeline_progress %sh{ + if ! "$6"; then + echo "$2${5:+" ($5%)"}${4:+": $4"}" + fi + } + } + + set global modelinefmt "%%opt{modeline_progress} %opt{modelinefmt}" +} + diff --git a/user/kak/rc/usermode.kak b/user/kak/rc/usermode.kak new file mode 100644 index 0000000..154e82e --- /dev/null +++ b/user/kak/rc/usermode.kak @@ -0,0 +1,180 @@ +try %{ + # declare-user-mode surround + declare-user-mode git + declare-user-mode find +} + +map global user 'w' ': w' -docstring 'write buffer' +map global user 'u' ': config-source' -docstring 'source configuration' +map global user 'g' ': enter-user-mode lsp' -docstring 'lsp mode' +map global user 'z' ':zoxide ' -docstring 'zoxide' +map global user 'n' ': new' -docstring 'new window' + +map global user 'e' 'x|emmet@' -docstring 'process line with emmet' +map global user 'm' ': try lsp-formatting-sync catch format-buffer' -docstring 'format document' +map global user 'M' ': try lsp-range-formatting-sync catch format-selections' -docstring 'format selection' + +map global user 'c' ': comment-line' -docstring 'comment line' +map global user 'C' '_: comment-block' -docstring 'comment block' + +map global user 'p' '! wl-paste -n' -docstring 'clipboard paste' +map global user 'P' 'j! wl-paste -n' -docstring 'clipboard paste on next line' +map global user 'R' '"_d! wl-paste -n ' -docstring 'clipboard replace' + +map global user 'b' ': find_buffer' -docstring 'switch buffer' + +map global user 'l' ': lsp-enable-decals' -docstring 'LSP enable decals' +map global user 'L' ': lsp-disable-decals' -docstring 'LSP disable decals' + +map global user 'v' ': enter-user-mode git' -docstring 'git vcs mode' +map global user 'V' ': enter-user-mode -lock git' -docstring 'git vcs mode' +map global git 's' ': git status' -docstring 'status' +map global git 'S' '_: git show %val{selection} --' -docstring 'show' +map global git 'a' ': git add' -docstring 'add current' +map global git 'd' ': git diff %reg{%}' -docstring 'diff current' +map global git 'r' ': git checkout %reg{%}' -docstring 'restore current' +map global git 'A' ': git add --all' -docstring 'add all' +map global git 'D' ': git diff' -docstring 'diff all' +map global git '' ': git diff --staged' -docstring 'diff staged' +map global git 'c' ': git commit -v' -docstring 'commit' +map global git 'u' ': git update-diff' -docstring 'update gutter diff' +map global git 'n' ': git next-hunk ' -docstring 'next hunk' +map global git 'p' ': git prev-hunk ' -docstring 'previous hunk' +map global git 'm' ': git-merge-head ' -docstring 'merge using head' +map global git 'M' ': git-merge-new ' -docstring 'merge using new' +map global git '' ': git-merge-original ' -docstring 'merge using original' + +map global user 'f' ': enter-user-mode find' -docstring 'find mode' +map global find 't' ': tree' -docstring 'file tree' +map global find 'f' ': find_file' -docstring 'file' +map global find 'l' ': find_line' -docstring 'jump to line' +map global find 'r' ': find_ripgrep' -docstring 'ripgrep all file' +map global find 'g' ': find_git_file' -docstring 'git files' +map global find 'm' ': find_git_modified' -docstring 'git modified files' +map global find 'c' ': find_dir' -docstring 'change dir' +map global find 'd' ': find_delete' -docstring 'file to delete' + +define-command -override -hidden find_file \ +%{ evaluate-commands %sh{ + for line in `fd --strip-cwd-prefix -tf -HE .git | bmenu`; do + echo "edit '$line'" + done +} } + +define-command -override -hidden find_delete \ +%{ nop %sh{ + fd --strip-cwd-prefix -H -E .git -t f | bmenu | xargs -r trash +} } + +define-command -override -hidden find_git_file \ +%{ evaluate-commands %sh{ + for line in `git ls-files | bmenu`; do + echo "edit -existing '$line'" + done +} } + +define-command -override -hidden find_git_modified \ +%{ evaluate-commands %sh{ + for line in `git status --porcelain | sd '^.. ' ''| bmenu`; do + echo "edit -existing '$line'" + done +} } + +define-command -override -hidden find_dir \ +%{ cd %sh{ + for line in `fd --strip-cwd-prefix -Htd | bmenu`; do + echo "edit '$line'" + done +} } + +define-command -override -hidden find_buffer \ +%{ evaluate-commands %sh{ + for line in `printf "%s\n" $kak_buflist | bmenu`; do + echo "buffer '$line'" + done +} } + +define-command -override -hidden find_ripgrep \ +%{ evaluate-commands %sh{ + patter=$( bmenu -p "Regex") + rg --column -n "$patter" | bmenu | + perl -ne 'print "edit \"$1\" \"$2\" \"$3\" " if /(.+):(\d+):(\d+):/' +} } + +define-command -override -hidden find_line \ +%{ evaluate-commands -save-regs a %{ + execute-keys %{Z%"ayz} + execute-keys %sh{ + line=$( + printf "%s\n" "$kak_reg_a" | + nl -ba -w1 | + bmenu -p "Line" | + cut -f1 + ) + test -n "$line" && echo "${line}gx" + } +} } + +define-command -override -hidden tree \ +%{ evaluate-commands %sh{ + file=`mktemp` + terminal --class file_picker ranger --selectfile="$kak_buffile" --choosefiles="$file" + for line in `cat "$file"`; do + echo "edit '$line'" + done + rm "$file" +} } + + +define-command -override -params .. \ +-shell-script-candidates 'zoxide query -l' \ +zoxide %{ + cd %sh{ zoxide query -- "$@" || echo "$@" } + echo %sh{ pwd | sed "s|$HOME|~|" } +} + +define-command -override config-source %{ + source "%val{config}/kakrc" +} + +define-command -override git-merge-head %{ + evaluate-commands -draft %{ + # delete head marker + execute-keys ^{4,}d + try %{ + # select original marker + execute-keys /^[|]{4,} + # extend to theirs marker + execute-keys ?^={4,} + } catch %{ + # select theirs marker + execute-keys /^={4,} + } + # extend to end marker + execute-keys ?^{4,}d + } +} -docstring "merge using head" + +define-command -override git-merge-original %{ + evaluate-commands -draft %{ + # select head marker + execute-keys ^{4,} + # select to middle of conflict + execute-keys ?^[|]{4,}d + # select theirs marker + execute-keys /^={4,} + # extend to end marker + execute-keys ?^{4,}d + } +} -docstring "merge using original" + +define-command -override git-merge-new %{ + evaluate-commands -draft %{ + # select head marker + execute-keys ^{4,} + # extend to theirs marker + execute-keys ?^={4,}\nd + # delete end marker + execute-keys /^{4,}d + } +} -docstring "merge using new"