From 9a840faa58623f54acb383aa1a64aef825b7a304 Mon Sep 17 00:00:00 2001 From: Mike Vink Date: Sat, 20 May 2023 12:44:16 +0200 Subject: fixup --- home.nix | 13 +++++++ home/kakoune.nix | 103 +++++++++++----------------------------------------- home/packages.nix | 1 - shell-scripts/kakup | 30 ++++++++------- 4 files changed, 52 insertions(+), 95 deletions(-) diff --git a/home.nix b/home.nix index 35f2a30..872c5fb 100644 --- a/home.nix +++ b/home.nix @@ -53,6 +53,19 @@ set-option -sa terminal-overrides ",xterm-256color:RGB" set-option -g focus-events on set-option -sg escape-time 10 + + bind-key -n C-s copy-mode + set-window-option -g mode-keys vi + bind-key -T copy-mode-vi v send -X begin-selection + bind-key -T copy-mode-vi V send -X select-line + bind-key -T copy-mode-vi y send -X copy-pipe-and-cancel 'xclip -in -selection clipboard' + + set-hook -g pane-focus-in 'run-shell "[[ \"$(tmux display-message -p #{pane_in_mode})\" -eq 0 ]] || tmux send-keys -X cancel"' + bind-key -T copy-mode-vi C-w switch-client -T splits + bind-key -T splits j select-pane -t '{down-of}' + bind-key -T splits k select-pane -t '{up-of}' + bind-key -T splits h select-pane -t '{left-of}' + bind-key -T splits l select-pane -t '{right-of}' ''; }; diff --git a/home/kakoune.nix b/home/kakoune.nix index e759474..20567fa 100644 --- a/home/kakoune.nix +++ b/home/kakoune.nix @@ -5,91 +5,32 @@ home-manager, ... }: { + home.activation = { + kakoune-symlink = home-manager.lib.hm.dag.entryAfter ["writeBoundary"] '' + KAK_CONFIG="${config.home.homeDirectory}/kakoune" + XDG_CONFIG_HOME_KAK="${config.xdg.configHome}/kak" + if [ -L $XDG_CONFIG_HOME_KAK ] && [ -e $XDG_CONFIG_HOME_KAK ]; then + $DRY_RUN_CMD echo "kakoune linked" + else + $DRY_RUN_CMD ln -s $KAK_CONFIG $XDG_CONFIG_HOME_KAK + fi + if [ -L $XDG_CONFIG_HOME_KAK/autoload/default ] && [ -e $XDG_CONFIG_HOME_KAK/autoload/default ]; then + $DRY_RUN_CMD echo "kakoune share linked" + else + ln -sf ${pkgs.kakoune-unwrapped}/share/kak/autoload $XDG_CONFIG_HOME_KAK/autoload/default + fi + ''; + }; programs.kakoune = { enable = true; - - extraConfig = '' - colorscheme gruvbox-dark - set-option global autoreload yes - - declare-option -hidden bool init_done - evaluate-commands %sh{ - $kak_opt_init_done && exit - printf ' -set global windowing_modules "" -require-module tmux -require-module tmux-repl -add-highlighter global/ number-lines -relative -declare-user-mode split -' - } - eval %sh{ - $kak_opt_init_done && exit - kak-lsp --kakoune -s $kak_session - } - set-option global init_done true - - hook global WinSetOption filetype=(rust|python|go|javascript|typescript|c|cpp) %{ - lsp-enable-window - lsp-auto-signature-help-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 - } - } - - hook global WinClose .* %{ - echo "Winclosed!" - tmux selectl "even-vertical" - } - - # Source a local project kak config if it exists - # Make sure it is set as a kak filetype - hook global BufCreate (.*/)?(\.kakrc\.local) %{ - set-option buffer filetype kak - } - try %{ source .kakrc.local } - - map global user l %{:enter-user-mode lsp} -docstring "LSP mode" - map global insert ':try lsp-snippets-select-next-placeholders catch %{ execute-keys -with-hooks tab> }' -docstring 'Select next snippet placeholder' - map global object a 'lsp-object' -docstring 'LSP any symbol' - map global object 'lsp-object' -docstring 'LSP any symbol' - map global object e 'lsp-object Function Method' -docstring 'LSP function or method' - map global object k 'lsp-object Class Interface Struct' -docstring 'LSP class interface or struct' - map global object d 'lsp-diagnostic-object --include-warnings' -docstring 'LSP errors and warnings' - map global object D 'lsp-diagnostic-object' -docstring 'LSP errors' - - map global insert 'Bd' -docstring "Delete word before cursor" - - define-command -override -hidden -params 1.. tmux %{ - echo %sh{ - tmux=''${kak_client_env_TMUX} - pane=''${kak_client_env_TMUX_PANE} - if [ -z "$tmux" ]; then - echo "fail 'This command is only available in a tmux session'" - exit - fi - eval TMUX_PANE=$pane TMUX=$tmux tmux ''${@} - } - } - define-command -override -params 0.. split %{ - tmux split-window -t %val{client_env_TMUX_PANE} kak -c %val{session} %val{buffile} - } - alias global sp split - map global normal %{:enter-user-mode split} -docstring "Navigate splits" - map global split j %{:tmux select-pane -t "{down-of}"} -docstring "Down" - map global split k %{:tmux select-pane -t "{up-of}"} -docstring "Up" - map global split h %{:tmux select-pane -t "{left-of}"} -docstring "Left" - map global split l %{:tmux select-pane -t "{right-of}"} -docstring "Right" - map global split = %{:tmux select-layout even-vertical} -docstring "Balance" - map global split o %{:tmux kill-pane -a} -docstring "Only" - - ''; - plugins = with pkgs.kakounePlugins; [ kak-lsp ]; + extraConfig = '' + set global windowing_modules "" + require-module tmux + require-module tmux-repl + alias global terminal tmux-terminal-vertical + ''; }; } diff --git a/home/packages.nix b/home/packages.nix index 436120e..6d44c88 100644 --- a/home/packages.nix +++ b/home/packages.nix @@ -33,7 +33,6 @@ github-cli fd argocd - docker-client parallel ] ++ (import ../shell-scripts.nix {inherit pkgs config;}); diff --git a/shell-scripts/kakup b/shell-scripts/kakup index d7a54f2..321b02a 100755 --- a/shell-scripts/kakup +++ b/shell-scripts/kakup @@ -1,15 +1,19 @@ -client="$(fd -d1 "." -t d $HOME $HOME/projects | - fzf | - { - pushd $(cat -) >/dev/null 2>&1 - servers=kakoune-servers-${USER} - name=${PWD#$HOME/} - client=kakoune@$name - tmux has-session -t $servers || tmux new -d -s $servers kak -s $name -d\; rename-window $name - tmux list-windows -t $servers -F "#{window_name}" | grep $name >/dev/null 2>&1 || tmux new-window -t $servers -d kak -s $name -d\; rename-window $name - tmux has-session -t $client || tmux new -d -s $client kak -c $name - popd >/dev/null 2>&1 +session-or-client() { + { + pushd $(cat -) + export servers=kakoune-servers-${USER} + export name=${PWD#$HOME/} + export name=${name//\//-} + export client=kakoune@$name + + tmux has-session -t $servers || tmux new -d -s $servers kak -s $name -d\; rename-window $name + tmux list-windows -t $servers -F "#{window_name}" | grep $name || tmux new-window -t $servers -d kak -s $name -d + tmux has-session -t $client || tmux new -d -s $client kak -c $name + popd + } /dev/null 2>&1 echo $client - })" -echo "client" +} + +client="$(fd -d1 "." -t d $HOME $HOME/projects | fzf | session-or-client)" +echo "client: $client" tmux attach -t "$client" -- cgit v1.2.3