diff options
| author | Mike Vink <ivi@vinkies.net> | 2025-03-10 16:40:55 +0000 |
|---|---|---|
| committer | Mike Vink <ivi@vinkies.net> | 2025-03-10 16:40:55 +0000 |
| commit | ea9b11e81210251630553409be1655072d251287 (patch) | |
| tree | 02f9e4ba75672c7b6c2b183499d892607723f10e /.config | |
| parent | e923c6db209ff5b6f6ac4891cc2a691022965f6f (diff) | |
edit-relative command
Diffstat (limited to '.config')
| -rw-r--r-- | .config/kak/kakrc | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/.config/kak/kakrc b/.config/kak/kakrc index 0bbf98f..d13adbd 100644 --- a/.config/kak/kakrc +++ b/.config/kak/kakrc @@ -9,7 +9,30 @@ map -docstring "Jump to previous grep match" global goto p <esc>:grep-previous-m map -docstring "Jump to next make error" global goto ] <esc>:make-next-error<ret> map -docstring "Jump to previous make error" global goto [ <esc>:make-previous-error<ret> -# define-command -docstring "edit relative" hook global RegisterModified '"' %{ nop %sh{ printf %s "$kak_main_reg_dquote" | vis-clipboard --copy }} + +define-command -docstring "Edit file relative to current buf" -params 1 edit-relative %{ edit "%sh{dirname ""${kak_buffile}""}/%arg{@}" } +alias global er edit-relative +complete-command -menu edit-relative shell-script %{ + orig="$(realpath --relative-to . $(dirname "$kak_buffile"))" + q="${1}" + if [ "$(basename "$q")" = ".." ]; then + d="$(realpath --relative-to . "$q")" + elif [ "$(basename "$q")" = "." ]; then + d="$(realpath --relative-to . "$q")" + elif [ -n "$q" ]; then + if [ "$(printf "$q" | tail -c 1)" = / ]; then + d="$q" + else + d="$(dirname "$q")" + fi + else + d="." + fi + # echo "orig:$orig" + # echo "q:$q" + # echo "d:$d" + fdfind --base-directory "$orig" --full-path --hidden --exact-depth 1 -- . "$d" | fzf --filter "$q" +} |
