mirror of https://codeberg.org/anemofilia/zero
449 lines
14 KiB
Plaintext
449 lines
14 KiB
Plaintext
#________ Options ___________
|
||
# Keep status bar in the default place
|
||
set-option -add global ui_options terminal_status_on_top=false
|
||
|
||
# Set an invisible padding char
|
||
set-option -add global ui_options terminal_padding_char=
|
||
|
||
# Always keep two lines and two columns displayed around the cursor
|
||
set-option global scrolloff 2,2
|
||
|
||
# Assistant
|
||
set-option -add global ui_options terminal_assistant=cat
|
||
|
||
hook global ModuleLoaded wayland %{
|
||
set-option global termcmd "%sh{echo $TERMINAL}"
|
||
} # Set termcmd
|
||
|
||
# __________ Commands __________
|
||
define-command -override lf-open \
|
||
-docstring 'pick a file with lf' %{
|
||
wayland-terminal /bin/sh -c %{
|
||
# Local variables
|
||
kak_buffile=$1 kak_session=$2 kak_client=$3
|
||
|
||
# Create temporary file for selection
|
||
lf_tmp=$(mktemp "${TMPDIR:-/tmp}"/lf-open.XXXXXXXXXX)
|
||
|
||
# Get working directory of current buffer
|
||
kak_pwd=$(dirname "${kak_buffile}")
|
||
|
||
# Pick a file with lf
|
||
$(lf -selection-path "${lf_tmp}" "${kak_pwd}")
|
||
|
||
# Get first line of selection file (ignoring multiple selections)
|
||
filename=$(head -n 1 "${lf_tmp}")
|
||
|
||
# Only echo a command back if there was a selection
|
||
if [ -n "$filename" ]; then
|
||
# Construct the command to pass to kakoune
|
||
kak_cmd="evaluate-commands -client $kak_client edit $filename"
|
||
|
||
# Echo the command back to the parent session
|
||
echo $kak_cmd | kak -p $kak_session
|
||
fi
|
||
} -- %val{buffile} %val{session} %val{client}
|
||
}
|
||
|
||
define-command -override cron \
|
||
-docstring 'edit cron services' %{
|
||
execute-keys ': e ~/.config/cron/'
|
||
}
|
||
|
||
define-command -override todo \
|
||
-docstring 'edit todo list' %{
|
||
edit '~/areas/meta/todo'
|
||
}
|
||
|
||
define-command -override guix-todo \
|
||
-docstring 'edit todo list' %{
|
||
edit '~/projects/code/org/guix-todo/todo.org'
|
||
}
|
||
|
||
declare-option str radix '~/projects/code/scm/radix'
|
||
define-command -override radix \
|
||
-docstring 'edit files in the radix git repository' %{
|
||
execute-keys ":e %opt{radix}/"
|
||
}
|
||
|
||
declare-option str radix_modules "%opt{radix}/radix"
|
||
define-command -override modules \
|
||
-docstring 'edit radix modules' %{
|
||
execute-keys ":e %opt{radix_modules}/"
|
||
}
|
||
|
||
declare-option str radix_services "%opt{radix_modules}/services"
|
||
define-command -override services \
|
||
-docstring 'edit radix services' %{
|
||
execute-keys ":e %opt{radix_services}/"
|
||
}
|
||
|
||
declare-option str radix_packages "%opt{radix_modules}/packages"
|
||
define-command -override packages \
|
||
-docstring 'edit radix packages' %{
|
||
execute-keys ":e %opt{radix_packages}/"
|
||
}
|
||
|
||
declare-option str radix_home_services "%opt{radix_modules}/home/services"
|
||
define-command -override home-services \
|
||
-docstring 'edit radix home services' %{
|
||
execute-keys ":e %opt{radix_home_services}/"
|
||
}
|
||
|
||
declare-option str zero '~/projects/code/scm/zero'
|
||
define-command -override zero \
|
||
-docstring 'edit files in the zero git repository' %{
|
||
execute-keys ":e %opt{zero}/"
|
||
}
|
||
|
||
declare-option str home "%opt{zero}/home-environments"
|
||
define-command -override home \
|
||
-docstring 'edit home declaration' %{
|
||
execute-keys ":e %opt{home}/"
|
||
}
|
||
|
||
declare-option str system "%opt{zero}/operating-systems"
|
||
define-command -override system \
|
||
-docstring 'edit system declaration' %{
|
||
execute-keys ":e %opt{system}/"
|
||
}
|
||
|
||
declare-option str home_files "%opt{home}/%sh{whoami}/files"
|
||
define-command -override files \
|
||
-docstring 'edit dotfiles' %{
|
||
execute-keys ":e %opt{home_files}/"
|
||
}
|
||
|
||
define-command -override colorscheme-config \
|
||
-docstring 'edit colorscheme configuration file' %{
|
||
edit "%opt{home_files}/.config/kak/autoload/colorscheme.kak"
|
||
}
|
||
|
||
define-command -override config \
|
||
-docstring 'edit kakoune main configuration file' %{
|
||
edit "%opt{home_files}/.config/kak/kakrc"
|
||
}
|
||
|
||
define-command -override rss \
|
||
-docstring 'edit rss feeds file' %{
|
||
edit "%opt{home_files}/.config/newsraft/feeds"
|
||
}
|
||
|
||
define-command -override remind \
|
||
-docstring 'edit reminders' %{
|
||
execute-keys ': e /home/radio/.local/share/reminders/'
|
||
}
|
||
|
||
define-command -params 1 -override tex-project \
|
||
-docstring 'edit or create a new tex-project' %{
|
||
evaluate-commands 'cd ~/Projects/latex/'
|
||
nop %sh{ mkdir -p "$1" }
|
||
evaluate-commands 'cd "%arg{1}"'
|
||
nop %sh{
|
||
[ -s $1.tex ] || cat ../example/example.tex \
|
||
| sed "s/example/$1/" > "$1.tex";
|
||
}
|
||
edit "%arg{1}.tex"
|
||
execute-keys '16gA<esc>'
|
||
}
|
||
define-command -override open-buffer-picker \
|
||
-docstring 'open-buffer-picker: Opens buffer picker.' %{
|
||
prompt buffer: -buffer-completion %{ buffer %val{text} }
|
||
}
|
||
|
||
define-command -override toggle-readonly \
|
||
-docstring 'changes buffer readonly option current state' %{
|
||
set-option buffer readonly %sh{ "$kak_opt_readonly" && echo false || echo true }
|
||
}
|
||
|
||
define-command -override qalc \
|
||
-params .. %{echo %sh{qalc ${@}}} \
|
||
-docstring 'compute equation with Qalculate!'
|
||
complete-command qalc shell-script-candidates %{
|
||
{ echo $(qalc --list-functions | head -n -3)
|
||
echo $(qalc --list-variables | head -n -3) } | tr ' ' '\n' | sort | uniq
|
||
}
|
||
|
||
define-command diff-buffers -override -params 2 \
|
||
-docstring 'show the diff of two buffers'%{
|
||
evaluate-commands %sh{
|
||
file1=$(mktemp)
|
||
file2=$(mktemp)
|
||
echo "
|
||
evaluate-commands -buffer '$1' write -force $file1
|
||
evaluate-commands -buffer '$2' write -force $file2
|
||
edit! -scratch *diff-buffers*
|
||
set buffer filetype diff
|
||
set-register | 'diff -u $file1 $file2; rm $file1 $file2'
|
||
execute-keys !<ret>gg
|
||
"
|
||
}}
|
||
complete-command diff-buffers buffer
|
||
|
||
# __________ Hidden commands __________
|
||
define-command -override -hidden edit-from-file %{
|
||
execute-keys ":edit %sh{dirname $kak_buffile}/"
|
||
}
|
||
|
||
define-command -override -hidden spawn-terminal-from-file %{
|
||
set-register b "%sh{pwd}"
|
||
change-directory "%sh{dirname $kak_buffile}"
|
||
evaluate-commands "wayland-terminal bin/sh -c"
|
||
change-directory "%reg{b}"
|
||
} # Spawn a terminal in the current buffer's file directory
|
||
|
||
# __________ Mappings __________
|
||
map global normal <c-j> ': buffer-previous<ret>'
|
||
map global normal Y ': yank-helper<ret>u' \
|
||
-docstring 'yank non-selections'
|
||
|
||
map global normal D '"ad%d"a<a-P>' \
|
||
-docstring 'yank and delete non-selections'
|
||
|
||
map global normal <a-D> '"ad%<a-d>"a<a-P>' \
|
||
-docstring 'delete non-selections (not yanking)'
|
||
|
||
map global user <ret> ': spawn-terminal-from-file<ret>' \
|
||
-docstring "open a new terminal within the current file's directory"
|
||
|
||
map global user c ': comment-line<ret>' \
|
||
-docstring 'comment-line'
|
||
|
||
map global user <a-c> ': comment-block<ret>' \
|
||
-docstring 'comment-block'
|
||
|
||
map global user D '| date +"%d %b %Y %a" -f -<ret>' \
|
||
-docstring 'parse date to 01 Feb 2001 Tue format'
|
||
|
||
map global user d ': lf-open<ret>' \
|
||
-docstring 'pick a file with lf'
|
||
|
||
map global user e ":edit-from-file<ret>" \
|
||
-docstring "edit a file, searching from current file's directory"
|
||
|
||
map global user l ': enter-user-mode lsp<ret>' \
|
||
-docstring 'enter lsp user mode'
|
||
|
||
try %{ declare-user-mode open-sel }
|
||
map global user o ': enter-user-mode open-sel<ret>' \
|
||
-docstring 'enter open-sel user mode'
|
||
|
||
map global user r ': remind<ret>' \
|
||
-docstring 'edit reminders'
|
||
|
||
map global user s ': enter-user-mode surround<ret>' \
|
||
-docstring 'enter surround user mode'
|
||
|
||
map global user u ': echo -markup "{Information}U+%sh{printf ''%04x'' ""$kak_cursor_char_value""}"<ret>' \
|
||
-docstring 'show the value of the selected unicode char'
|
||
|
||
map global user q ': delete-buffer<ret>' \
|
||
-docstring 'delete current buffer'
|
||
|
||
map global user Q ': delete-buffer!<ret>' \
|
||
-docstring 'delete current buffer'
|
||
|
||
map global open-sel b '$ icecat $kak_reg_dot & disown<ret>' \
|
||
-docstring 'on browser'
|
||
|
||
map global open-sel m '$ mpv $kak_reg_dot & disown<ret>' \
|
||
-docstring 'on mpv'
|
||
|
||
map global goto b '<a-;>: open-buffer-picker<ret>' \
|
||
-docstring 'buffer'
|
||
|
||
map global normal = ': prompt math: %{exec "a %val{text}<lt>esc>|qalc -t +u8 -f -<lt>ret>"}<ret>' \
|
||
-docstring 'Replace selection by the result of some operation over it'
|
||
|
||
map global object <space> 'c<space>,<space><ret>'\
|
||
-docstring 'whitespaces'
|
||
|
||
try %{ declare-user-mode git }
|
||
map global git l ': git log<ret>' -docstring 'log'
|
||
map global git c ': git commit<ret>' -docstring 'commit'
|
||
map global git d ': git diff<ret>' -docstring 'diff'
|
||
map global git s ': git status<ret>' -docstring 'status'
|
||
map global git h ': git show-diff<ret>' -docstring 'show diff'
|
||
map global git H ': git-hide-diff<ret>' -docstring 'hide diff'
|
||
|
||
# __________ Hooks __________
|
||
hook -group config global BufCreate 'kakrc' %{
|
||
set-option buffer filetype kak
|
||
} # Set kakrc's filetype to kak
|
||
|
||
hook global BufCreate '\*scratch\*' %{
|
||
execute-keys '%<a-d>'
|
||
} # Remove the *scratch* message
|
||
|
||
hook global BufCreate .* %{
|
||
add-highlighter buffer/ number-lines -relative -hlcursor
|
||
} # Set relative line numbers and visual line break
|
||
|
||
hook global BufWritePost ".*/.config/kak/kakrc" %{
|
||
source "%val{buffile}"
|
||
} # Source kakrc on save
|
||
|
||
hook global BufWritePost "%val{config}/autoload/colorscheme.kak" %{
|
||
source "%val{config}/autoload/colorscheme.kak"
|
||
evaluate-commands palette-gutter
|
||
} # Automatically source colorscheme.kak on save
|
||
|
||
hook global BufOpenFile "%val{config}/autoload/colorscheme.kak" %{
|
||
evaluate-commands palette-gutter
|
||
} # Display faces in the colorscheme file
|
||
|
||
hook global BufOpenFile .* %{
|
||
add-highlighter buffer/ wrap -word -marker '↩'
|
||
add-highlighter buffer/ show-whitespaces -indent '' -tab '→'
|
||
} # Set highlighters for file buffers
|
||
|
||
hook global BufCreate '\*scratch\*' %{
|
||
add-highlighter buffer/ wrap -indent -word -marker '↩'
|
||
add-highlighter buffer/ show-whitespaces -tab '→'
|
||
} # Set highlighters for scratch buffers
|
||
|
||
hook global InsertCompletionShow .* %{
|
||
map window insert <tab> <c-n>
|
||
map window insert <s-tab> <c-p>
|
||
}
|
||
hook global InsertCompletionHide .* %{
|
||
map window insert <tab> <c-n>
|
||
map window insert <s-tab> <c-p>
|
||
} # Use tab for completion movement
|
||
|
||
try %{ declare-option str line_comment_token '' }
|
||
hook -group config global BufSetOption filetype=kak %{
|
||
set-option buffer indentwidth 2
|
||
set-option buffer line_comment_token '#'
|
||
} # Kakscript comment tokens
|
||
|
||
hook -group config global BufSetOption filetype=scheme %{
|
||
set-option buffer indentwidth 2
|
||
set-option window formatcmd 'guix style --whole-file'
|
||
set-option buffer line_comment_t ';;'
|
||
set-option buffer block_comment_tokens '#|' '|#'
|
||
} # Scheme comment tokens
|
||
|
||
hook -group config global BufSetOption filetype=(c|cpp) %{
|
||
set-option window formatcmd 'clazy'
|
||
set-option buffer line_comment_token '//'
|
||
set-option buffer block_comment_tokens '/*' '*/'
|
||
} # C and C++ comment tokens
|
||
|
||
hook -group config global BufSetOption filetype=(sh|dash) %{
|
||
set-option window formatcmd 'shfmt'
|
||
set-option window lintcmd 'shellharden'
|
||
set-option buffer line_comment_token '#'
|
||
set-option buffer block_comment_tokens "<<'####'" '###'
|
||
} # Shell comment tokens
|
||
|
||
hook -group config global BufSetOption filetype=zig %{
|
||
set-option buffer line_comment_token '//'
|
||
} # Zig comment tokens
|
||
|
||
hook global WinSetOption filetype=kak %{
|
||
hook global NormalIdle .* %{
|
||
evaluate-commands -save-regs 'a' %{
|
||
try %{
|
||
execute-keys -draft <a-i>w"ay
|
||
evaluate-commands %sh{ (
|
||
color="${kak_reg_a}"
|
||
inverted_color=$(echo "${color}" | perl -pe 'tr/0123456789abcdefABCDEF/fedcba9876543210543210/')
|
||
printf "%s\n" "evaluate-commands -client $kak_client %{ try %{
|
||
echo -markup %{{rgb:${inverted_color},rgb:${color}+b} #${color} }
|
||
}}" | kak -p $kak_session
|
||
) >/dev/null 2>&1 </dev/null &
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
# __________ Plugins __________
|
||
source "%val{config}/plugins/plug.kak/rc/plug.kak"
|
||
plug "andreyorst/plug.kak" noload # Manually installed plugin manager
|
||
|
||
# CONFIGURE THIS
|
||
plug "occivink/kakoune-phantom-selection" # Work on multiple selections, one at a time
|
||
|
||
plug "alexherbo2/surround.kak" # Easily surround selections with parentesis or quotes
|
||
|
||
plug "https://gitlab.com/Screwtapello/kakoune-texinfo" # Read info pages inside kakoune
|
||
|
||
plug "https://gitlab.com/Screwtapello/kakoune-state-save" config %{
|
||
hook global KakBegin .* %{
|
||
evaluate-commands 'state-save-reg-load colon'
|
||
evaluate-commands 'state-save-reg-load pipe'
|
||
evaluate-commands 'state-save-reg-load slash'
|
||
}
|
||
|
||
hook global KakEnd .* %{
|
||
evaluate-commands 'state-save-reg-save colon'
|
||
evaluate-commands 'state-save-reg-save pipe'
|
||
evaluate-commands 'state-save-reg-save slash'
|
||
}
|
||
} # Save and restore state between sessions
|
||
|
||
plug 'delapouite/kakoune-buffers' # Ease navigation between opened buffers.
|
||
|
||
plug "NNBnh/coderun.kak" # Run files from within kakoune
|
||
|
||
plug "enricozb/wiki.kak" # Preview and interact with markdown
|
||
|
||
plug "https://gitlab.com/Screwtapello/kakoune-texinfo.git" # TexInfo
|
||
|
||
plug "TeddyDD/kakoune-lf" # lf integration
|
||
|
||
plug "jpcornwell/kakoune-sokoban" # Sokoban because yes
|
||
|
||
plug "lePerdu/kakboard" config %{
|
||
hook global WinCreate .* %{ kakboard-enable }
|
||
} # Sync clipboards
|
||
|
||
plug "gspia/csv.kak" config %{
|
||
set-option global csv_sep ';'
|
||
set-option global csv_colors "blue rgb:f1f1f1 blue rgb:f1f1f1 blue rgb:f1f1f1 blue"
|
||
} # Colorful csv files
|
||
|
||
plug "JJK96/kakoune-rainbow"
|
||
set-option global rainbow_opening "[{[(]"
|
||
declare-option str-list rainbow_faces "rgb:a790d3" "rgb:6cdae0" "rgb:ff7f50" \
|
||
"rgb:ffea8c" "rgb:83dcaf" "rgb:eba4d4" \
|
||
"rgb:8b5be7"
|
||
#Add coloring to matching parenthesis
|
||
|
||
plug "alexherbo2/auto-pairs.kak" config %{
|
||
set-option global auto_pairs ( ) { } [ ] '"' '"' "'" "'" ` ` “ ” ‘ ’ « » ‹ ›
|
||
hook -group config global BufSetOption filetype=scheme %{
|
||
set-option buffer auto_pairs { } '"' '"' ` ` “ ” ‘ ’ « » ‹ ›
|
||
}
|
||
evaluate-commands enable-auto-pairs
|
||
} # Auto-pairing of characters
|
||
|
||
plug "eraserhd/parinfer-rust" config %{
|
||
hook global WinSetOption filetype=(clojure|lisp|scheme|racket) %{
|
||
parinfer-enable-window -smart
|
||
}
|
||
}
|
||
|
||
plug "Delapouite/kakoune-palette" config %{
|
||
hook global BufOpenFile .*colorscheme.kak %{
|
||
evaluate-commands palette-gutter
|
||
}
|
||
} # Preview face colors in kakoune
|
||
|
||
# __________ LSP __________
|
||
eval %sh{kak-lsp --kakoune -s $kak_session}
|
||
hook global BufSetOption filetype=(c|cpp|css|haskell|html|json|scheme|sh|latex|zig) %{
|
||
add-highlighter buffer/ column 80 StatusLine
|
||
hook global BufSetOption filetype=scheme %{
|
||
set-option buffer lsp_cmd 'guile-lsp-server'
|
||
}
|
||
lsp-enable-window
|
||
}
|
||
|
||
# Latex
|
||
set-option -add global lsp_server_configuration texlab.build.onSave=true
|
||
set-option -add global lsp_server_configuration texlab.build.forwardSearchAfter=true
|
||
set-option -add global lsp_server_configuration texlab.build.args=["-pdf","-new-viewer-","-pdflatex\=pdflatex","-silent","-shell-escape","%f"]
|