From 5d823bbd19dc8589cfacdbe51ee5260042dacab2 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sat, 25 Oct 2025 17:22:00 +0530 Subject: Add terminal singleton command + use with gitu and daffm --- autoload/+init.kak | 1 - autoload/files.kak | 2 +- autoload/git.kak | 4 +--- autoload/window.kak | 18 ++++++++++++++++++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/autoload/+init.kak b/autoload/+init.kak index aa105f5..8352000 100644 --- a/autoload/+init.kak +++ b/autoload/+init.kak @@ -77,4 +77,3 @@ map global code :casecamel -docstring 'camelCasing' # Editorconfig hook global BufOpenFile .* %{ try %{ editorconfig-load } } hook global BufNewFile .* %{ try %{ editorconfig-load } } - diff --git a/autoload/files.kak b/autoload/files.kak index b928c33..001ef07 100644 --- a/autoload/files.kak +++ b/autoload/files.kak @@ -3,7 +3,7 @@ def find -docstring "find files" -menu -params 1 \ -shell-script-candidates %{ fd -t f --hidden --color=never -E .git } def file-manager -params .. %{ - connect terminal env "EDITOR=kcr edit" sh -c "DAFFM_PATH_RELATIVE_TO=$PWD daffm -c @kak %arg{@};" + terminal-singleton files env "EDITOR=kcr edit" sh -c "DAFFM_PATH_RELATIVE_TO=$PWD daffm -c @kak %arg{@};" } declare-user-mode buffer diff --git a/autoload/git.kak b/autoload/git.kak index e786fcb..c8426db 100644 --- a/autoload/git.kak +++ b/autoload/git.kak @@ -1,6 +1,4 @@ -define-command gitui -params .. %{ - connect terminal env "GIT_EDITOR=kak -c %val{session}" "EDITOR=kcr edit" "VISUAL=kcr edit" gitu %arg{@} -} +define-command gitui -params .. %{ terminal-singleton git gitu %arg{@} } declare-user-mode git declare-user-mode git-r diff --git a/autoload/window.kak b/autoload/window.kak index 8986914..ba1fab7 100644 --- a/autoload/window.kak +++ b/autoload/window.kak @@ -10,3 +10,21 @@ map global win j ': nop %sh{tmux select-pane -D}' -docstring 'Jump down' map global win k ': nop %sh{tmux select-pane -U}' -docstring 'Jump up' map global win l ': nop %sh{tmux select-pane -R}' -docstring 'Jump right' map global win z ': wq' + +define-command terminal-singleton -params 2.. -docstring 'terminal-singleton [args...]' %{ + eval %sh{ + name="$1"; shift; + open-term-win() { + printf "terminal -n '$name' env" + printf " 'KAKOUNE_SESSION=$kak_session' 'KAKOUNE_CLIENT=$kak_client'" + printf " 'GIT_EDITOR=kak -c \"$kak_session\"' 'EDITOR=kcr edit' 'VISUAL=kcr edit'" + printf " %q" "$@" + echo "" + } + focus-term-win() { + tmux select-window -t "$name" >/dev/null 2>&1 + } + + focus-term-win || open-term-win "$@"; + } +} -- cgit v1.3.1