From 1ef5ad920b1c3391bbee55e9310684f5adf513ae Mon Sep 17 00:00:00 2001 From: Andre Ramnitz Date: Fri, 29 Dec 2023 13:02:19 +0100 Subject: [PATCH] kak: replace powerline with kakship --- .gitmodules | 3 + config/kak/kakrc | 85 ++++++---- config/kak/languagecmd.kak | 77 +++++++++ config/kak/plugins/dabruin.kak | 2 +- config/kak/plugins/kakship | 1 + config/kak/plugins/powerline.kak | 2 +- config/kak/reload-kakrc.kak | 28 +++ config/kak/starship.toml | 283 +++++++++++++++++++++++++++++++ 8 files changed, 447 insertions(+), 34 deletions(-) create mode 100644 config/kak/languagecmd.kak create mode 160000 config/kak/plugins/kakship create mode 100644 config/kak/reload-kakrc.kak create mode 100644 config/kak/starship.toml diff --git a/.gitmodules b/.gitmodules index 9b844ea1..909d55e5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -62,3 +62,6 @@ path = config/qutebrowser/catppuccin url = https://github.com/catppuccin/qutebrowser branch = main +[submodule "config/kak/plugins/kakship"] + path = config/kak/plugins/kakship + url = https://github.com/eburghar/kakship diff --git a/config/kak/kakrc b/config/kak/kakrc index 715f9e4c..c0be3f2a 100644 --- a/config/kak/kakrc +++ b/config/kak/kakrc @@ -1,3 +1,9 @@ +# +# ────────────────────────────────────────────────────────────────────────────── +def import -override -params 1 %{ + source %sh{echo ${kak_config}/$1.kak} +} + # Clipboard (wayland) integration # ────────────────────────────────────────────────────────────────────────────── hook global NormalKey y %{ nop %sh{ @@ -60,12 +66,11 @@ plug "andreyorst/plug.kak" noload plug "occivink/kakoune-find" plug "foot.kak" plug "https://git.sr.ht/~nasmevka/dabruin.kak" noload - plug "andreyorst/powerline.kak" defer powerline_freerunner %{ - powerline-format global 'mode_info git bufname session client line_column position ' - powerline-theme freerunner - powerline-separator triangle + plug "eburghar/kakship" do %{ + cargo install --force --path . --root ~/.local + [ ! -e $kak_config/starship.toml ] && cp starship.toml $kak_config/ } config %{ - powerline-start + kakship-enable } plug "raiguard/kak-harpoon" %{ hook global WinCreate .* harpoon-add-bindings @@ -77,43 +82,25 @@ plug "andreyorst/plug.kak" noload add-highlighter global/trailing-whitespace regex '\h+$' 0:Error # trailing whitespaces in red add-highlighter global/todos regex '(//|#|/\*)\h*(TODO|WARNING|FIXME)[:]?[^\n]*' 2:+bu # highlight comment tags add-highlighter global/ show-matching # show matching brackets -add-highlighter global/ number-lines -min-digits 3 # absolute line nums everywhere +add-highlighter global/ number-lines -hlcursor -min-digits 3 # absolute line nums everywhere declare-option str dabruin_accent 'rgb:A1B56C' declare-option str dabruin_background 'rgb:242124' colorscheme dabruin set-option global tabstop 4 set-option global indentwidth 4 - +add-highlighter global/ wrap -word -indent # Different Cursor color in insert mode # ────────────────────────────────────────────────────────────────────────────── -# Shades of blue/cyan for normal mode -set-face global PrimarySelection white,blue+F -set-face global SecondarySelection black,blue+F -set-face global PrimaryCursor black,bright-cyan+F -set-face global SecondaryCursor black,bright-blue+F -set-face global PrimaryCursorEol black,bright-cyan -set-face global SecondaryCursorEol black,bright-blue - # Shades of green/yellow for insert mode. -hook global ModeChange (push|pop):.*:insert %{ - set-face window PrimarySelection black,yellow+F - set-face window SecondarySelection black,yellow+F - set-face window PrimaryCursor black,bright-red+F - set-face window SecondaryCursor black,bright-yellow+F - set-face window PrimaryCursorEol black,bright-red - set-face window SecondaryCursorEol black,bright-yellow -} +# hook global ModeChange (push|pop):.*:insert %{ +# set-face window StatusLine black,red +# } # Undo colour changes when we leave insert mode. -hook global ModeChange (push|pop):insert:.* %{ - unset-face window PrimarySelection - unset-face window SecondarySelection - unset-face window PrimaryCursor - unset-face window SecondaryCursor - unset-face window PrimaryCursorEol - unset-face window SecondaryCursorEol -} +# hook global ModeChange (push|pop):insert:.* %{ +# unset-face window StatusLine +# } # Extra editor commands @@ -165,7 +152,7 @@ map global normal -docstring 'file browser' ': kks-connect terminal-pa map global user -docstring 'Buffer mode' b ':enter-user-mode buffermode' map global user -docstring 'Selection mode' s ':enter-user-mode selectionmode' map global user -docstring 'edit kakrc' e ': e ~/.config/kak/kakrc' -map global user -docstring 'relative line numbers enable' r ': add-highlighter window/nl number-lines -relative -hlcursor' +map global user -docstring 'relative line numbers enable' r ': add-highlighter window/nl number-lines -min-digits 3 -relative -hlcursor' map global user -docstring 'relative line numbers disable' R ': remove-highlighter window/nl' @@ -197,3 +184,37 @@ set-option global foot_normal_flags '' set-option global foot_popup_flags '-a kakpopup' set-option global foot_panel_cmd 'foot' +# language config +# ────────────────────────────────────────────────────────────────────────────── +import languagecmd + +# Reload kakrc and .kak when saving. +# ────────────────────────────────────────────────────────────────────────────── +# Adds -override to definitions (unless they seem to be python defs!) +# Evals provide module directly + +def resource -params 1 %{ + eval %sh{ + file=$(dirname "$1")/.reload.kak + cat "$1" | + sed 's/^def \([^:]*\)$/def -override \1/' | + sed 's/^define-command /def -override /' | + sed 's/^addhl /addhl -override/' | + sed 's/^add-highlighter /addhl -override /' | + sed 's/^provide-module \w\+ /eval /' | + cat > "$file" + printf %s " + source $file + nop %sh{ + rm $file + } + " + } + echo Reloaded %arg{1} +} + +rmhooks global reload-kak +hook -group reload-kak global BufWritePost (.*kakrc|.*\.kak) %{ + resource %val{hook_param} +} + diff --git a/config/kak/languagecmd.kak b/config/kak/languagecmd.kak new file mode 100644 index 00000000..e5827736 --- /dev/null +++ b/config/kak/languagecmd.kak @@ -0,0 +1,77 @@ +## Languages +# ────────────────────────────────────────────────────────────────────────────── +# stolen from git.sr.ht/~nasmevka/kak +### golang +hook -group languagecmd global WinSetOption filetype=go %{ + set-option buffer formatcmd 'gofumpt' + set-option buffer lintcmd "golangci-lint run --out-format=line-number --uniq-by-line=true --allow-parallel-runners | grep %val{bufname} #" +} + +### python +hook -group languagecmd global WinSetOption filetype=python %{ + set-option buffer formatcmd 'black --line-length 150 -' + set-option buffer lintcmd 'ruff check --format=text --line-length=150' +} + +### shell +hook -group languagecmd global WinSetOption filetype=sh %{ + set-option buffer formatcmd 'shfmt -i 4 -ci -sr -' + set-option buffer lintcmd 'shellcheck -f gcc' + try %{ + alias buffer subprocess surround-with-proc + alias buffer variable surround-with-env + } +} + +### C +hook -group languagecmd global WinSetOption filetype=c %{ + set-option buffer formatcmd 'clang-format -' + set-option buffer lintcmd "clang-check --analyze %val{buffile} 2>&1 | sed '/^[^/]/d' #" +} + +### scheme (CHICKEN) +hook -group languagecmd global WinSetOption filetype=scheme %{ + set-option buffer formatcmd '' + set-option buffer lintcmd '' + # spaces for indent, using only two since scheme can have a lot of indentation + set-option buffer tabstop 2 + set-option buffer indentwidth 2 + + enter-spacemode + enable-replkak-bindings + # launch parinfer last since we want the tabulation->space transformation before + parinfer-enable-window -indent +} + +hook -group languagecmd global WinSetOption filetype=markdown %{ + try %{ + declare-surrounding-pair 'surround selection with italic syntax' ital * * + declare-surrounding-pair 'surround selection with bold syntax' bold ** ** + declare-surrounding-pair 'surround selection with inline code syntax' icode ` ` + declare-surrounding-pair 'surround selection with bloc code syntax' bcode ``` ``` + alias buffer italic surround-with-ital + alias buffer bold surround-with-bold + alias buffer inline surround-with-icode + alias buffer bloc surround-with-bcode + } +} + +### Javascript +hook -group languagecmd global WinSetOption filetype=javascript %{ + set-option buffer formatcmd '2>/dev/null npx standard --stdin --fix ||:' + set-option buffer lintcmd '2>/dev/null npx standard' +} + +### D +hook -group languagecmd global WinSetOption filetype=d %{ + set-option buffer formatcmd '' # no need for format + set-option buffer lintcmd 'dscanner -S -f "{filepath}:{line}:{column}: {type}: {message}"' +} + +### Hare +hook -group languagecmd global WinSetOption filetype=hare %{ + set-option buffer tabstop 8 + set-option buffer indentwidth 8 +} + + diff --git a/config/kak/plugins/dabruin.kak b/config/kak/plugins/dabruin.kak index c73536f6..c3e33f1e 160000 --- a/config/kak/plugins/dabruin.kak +++ b/config/kak/plugins/dabruin.kak @@ -1 +1 @@ -Subproject commit c73536f61defb252fa973fa9d5410e0014ab34a4 +Subproject commit c3e33f1e0fa8d19cfae85baaeee5f91ccabd0108 diff --git a/config/kak/plugins/kakship b/config/kak/plugins/kakship new file mode 160000 index 00000000..c58d5920 --- /dev/null +++ b/config/kak/plugins/kakship @@ -0,0 +1 @@ +Subproject commit c58d592051d65d004129185c5f0bb48c11a63801 diff --git a/config/kak/plugins/powerline.kak b/config/kak/plugins/powerline.kak index 16be282e..e5e9a0e5 160000 --- a/config/kak/plugins/powerline.kak +++ b/config/kak/plugins/powerline.kak @@ -1 +1 @@ -Subproject commit 16be282ec6aa514997ec370049babd3a070f2e1f +Subproject commit e5e9a0e5734da8f7338ead7f55f9ed04f88adfc6 diff --git a/config/kak/reload-kakrc.kak b/config/kak/reload-kakrc.kak new file mode 100644 index 00000000..8bc50e67 --- /dev/null +++ b/config/kak/reload-kakrc.kak @@ -0,0 +1,28 @@ +# Reload kakrc and .kak when saving. +# Adds -override to definitions (unless they seem to be python defs!) +# Evals provide module directly + +def resource -params 1 %{ + eval %sh{ + file=$(dirname "$1")/.reload.kak + cat "$1" | + sed 's/^def \([^:]*\)$/def -override \1/' | + sed 's/^define-command /def -override /' | + sed 's/^addhl /addhl -override/' | + sed 's/^add-highlighter /addhl -override /' | + sed 's/^provide-module \w\+ /eval /' | + cat > "$file" + printf %s " + source $file + nop %sh{ + rm $file + } + " + } + echo Reloaded %arg{1} +} + +rmhooks global reload-kak +hook -group reload-kak global BufWritePost (.*kakrc|.*\.kak) %{ + resource %val{hook_param} +} diff --git a/config/kak/starship.toml b/config/kak/starship.toml new file mode 100644 index 00000000..5a61b3de --- /dev/null +++ b/config/kak/starship.toml @@ -0,0 +1,283 @@ +add_newline = false +format = """\ +${custom.kaklsp_progress}\ +${custom.kakcursor}\ +${custom.kakposition}\ +${custom.kakmode}\ +${custom.kakcontext}\ +$directory\ +${custom.kakfile}\ +${custom.kakfiletype}\ +${custom.kaklsp_err}\ +${custom.kaklsp_warn}\ +${custom.kaklsp_hint}\ +${custom.kaklsp_code_actions}\ +$package\ +$git_branch\ +$git_commit\ +$git_state\ +$git_status\ +${custom.kaksession}\ +$memory_usage\ +$battery\ +$time\ +${custom.kaktime} +""" + + +[time] +format = "[]($style)[  $time ]($style)" +style = "fg:black bg:bright-green" +time_format = "%H:%M" +disabled = true + +[git_branch] +format = '[  $branch]($style)' +style = 'fg:bright-blue italic' +truncation_length = 10 +truncation_symbol = '…' +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)' +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 = '[]($style)[$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] +"~/dotfiles" = " " +"~/.config" = " " +"~/.workspace/rust" = "" +"~/.workspace/docker" = " " +"~/.workspace/alpine" = " " +"~/.workspace/arch" = " " +"~/.workspace/kustomize" = "ﴱ " +"~/.workspace/node" = "" +"~/.workspace" = " " +"~/scm" = " " +"~" = " " + +[package] +format = '[  $version]($style)[ ]($style)' +style = 'cyan' +display_private = true +disabled = false + +[battery] +format = "[ $symbol$percentage]($style) " +charging_symbol = ' ' +discharging_symbol = ' ' +disabled = true + +[[battery.display]] +threshold = 10 +style = "red" +charging_symbol = ' ' +discharging_symbol = ' ' + +[[battery.display]] +threshold = 20 +style = "red" +charging_symbol = ' ' +discharging_symbol = ' ' + +[[battery.display]] +threshold = 30 +style = "yellow" +charging_symbol = ' ' +discharging_symbol = ' ' + +[[battery.display]] +threshold = 40 +style = "yellow" +charging_symbol = ' ' +discharging_symbol = ' ' + +[[battery.display]] +threshold = 50 +style = "blue" +charging_symbol = ' ' +discharging_symbol = ' ' + +[[battery.display]] +threshold = 60 +style = "blue" +charging_symbol = ' ' +discharging_symbol = ' ' + +[[battery.display]] +threshold = 70 +style = "blue" +charging_symbol = ' ' +discharging_symbol = ' ' + +[[battery.display]] +threshold = 80 +style = "green" +charging_symbol = ' ' +discharging_symbol = ' ' + +[[battery.display]] +threshold = 90 +style = "green" +charging_symbol = ' ' +discharging_symbol = ' ' + +[[battery.display]] +threshold = 100 +style = "green" +charging_symbol = ' ' +discharging_symbol = ' ' + +[memory_usage] +format = "[  ${ram}]($style)" +style = "fg:bright-cyan" +threshold = -1 +disabled = true + +[custom.kakfile] +description = 'The current Kakoune buffername' +format = '[/$output ]($style)[]($style inverted)' +style = 'bold bg:blue fg:black' +command = 'echo -n ${kak_buffile##*/}' +when = 'true' +shell = ['sh'] +disabled = false + +[custom.kaksession] +description = 'The current Kakoune session' +format = '[]($style)[  %val{client}:%val{session} ]($style)[]($style inverted)' +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 = true + +[custom.kakposition] +description = 'Relative position of the cursor inside the buffer' +format = '[  $output]($style)[ ]($style)' +style = 'white' +command = 'echo -n $(($kak_cursor_line * 100 / $kak_buf_line_count))%' +when = '[ -n "$kak_cursor_line" ]' +shell = ['sh'] +disabled = false + +[custom.kaktime] +description = "Alternate time segment using kakoune evaluation" +format = "[]($style)[  %sh{date +%T} ]($style)" +style = "fg:black bg:bright-green" +when = '' +shell = ['true'] +disabled = true + +[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 = true + +[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 = true + +[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 = true + +[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 = true + +[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 = true -- 2.51.2