diff options
| author | Akshay Nair <phenax5@gmail.com> | 2026-07-02 12:02:50 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2026-07-02 12:03:32 +0530 |
| commit | 10bd058d848464257eb00cbf419295d97baa42f6 (patch) | |
| tree | e45b0117f64c9c38dc8b1e1c9c9a911e57817adb | |
| parent | 13a2f89ecbda892aeaf5533a2779a96fec2968e2 (diff) | |
| download | kakoune-config-main.tar.gz kakoune-config-main.zip | |
Diffstat (limited to '')
| -rw-r--r-- | autoload/+init.kak | 6 | ||||
| -rw-r--r-- | autoload/git.kak | 26 | ||||
| -rwxr-xr-x | scripts/git.clj | 21 |
3 files changed, 39 insertions, 14 deletions
diff --git a/autoload/+init.kak b/autoload/+init.kak index 0bf78d9..5cd4c15 100644 --- a/autoload/+init.kak +++ b/autoload/+init.kak @@ -20,7 +20,11 @@ set-option global tabstop 2 set-option -add global path "**" set-option global startup_info_version 20260521 set-option global scrolloff 10,3 -set-option -add global ui_options terminal_enable_mouse=false terminal_status_on_top=true +set-option -add global ui_options \ + terminal_assistant=clippy \ + terminal_status_on_top=true \ + terminal_synchronized=true \ + terminal_enable_mouse=false # Modeline set-option global modelinefmt \ diff --git a/autoload/git.kak b/autoload/git.kak index 1b58a6e..3e12f8c 100644 --- a/autoload/git.kak +++ b/autoload/git.kak @@ -20,6 +20,7 @@ map global git d ': enter-user-mode git-d<ret>' -docstring 'Diff mode' map global git-d d ': git-open-diff<ret>' -docstring 'Open staged files' map global git-d c ': git-open-commit<ret>' -docstring 'Open files changed in last commit' map global git-d x ': git-grep-conflict-markers<ret>' -docstring 'Find conflicts' +map global git-d b ': git-diff-base-branch<ret>' -docstring 'Show diff against base branch' define-command git-grep-conflict-markers %{ grep <<<< } # rebase @@ -49,9 +50,7 @@ define-command git-line-blame %{ "git -p log -u -L '%sh{echo ""$kak_selection_desc"" | sed -E 's/\.[0-9]+//g'}:%val{buffile}' --color=always | delta" } -define-command git-file-blame %{ - terminal-singleton git-blame gitu blame %val{buffile} -} +define-command git-file-blame %{ terminal-singleton git-blame gitu blame %val{buffile} } define-command git-open-diff -params 0..1 %{ eval %sh{ git diff --name-only "${1:-HEAD}" | sed 's/^/edit /' } @@ -59,15 +58,34 @@ define-command git-open-diff -params 0..1 %{ define-command git-open-commit -params 0..1 %{ eval %sh{ git show --name-only --pretty="" "$@" | sed 's/^/edit /' } } +define-command git-diff-base-branch -params 0..1 %{ + info %sh{ echo "origin/$("$kak_config/scripts/git.clj" base-branch)" } + terminal-singleton git-diff git diff %sh{ echo "origin/$("$kak_config/scripts/git.clj" base-branch)" } +} define-command git-link %{ eval %sh{ line_start=${kak_selection_desc%%.*} tmp=${kak_selection_desc#*,} - line_end=${tmp%%.*} + line_end=${tmp%%.*} link=$("$kak_config/scripts/git.clj" link "$kak_buffile" "$line_start" "$line_end") xdg-open "$link" || true >/dev/null echo "info '$link'" } } +# # enable flag-lines hl for git diff +# hook global WinCreate .* %{ +# add-highlighter window/git-diff flag-lines Default git_diff_flags +# } +# # trigger update diff if inside git dir +# hook global BufOpenFile .* %{ +# evaluate-commands -draft %sh{ +# cd $(dirname "$kak_buffile") +# if [ $(git rev-parse --git-dir 2>/dev/null) ]; then +# for hook in WinCreate BufReload BufWritePost; do +# printf "hook buffer -group git-update-diff $hook .* 'git update-diff'\n" +# done +# fi +# } +# } diff --git a/scripts/git.clj b/scripts/git.clj index a721b3a..b7fabc2 100755 --- a/scripts/git.clj +++ b/scripts/git.clj @@ -46,33 +46,36 @@ (when (not-empty (git dir "branch" "-r" "--contains" commit)) commit))) -#_ (todo add branch?) -#_ (defn git-current-branch [dir] ) +#_(todo add branch?) +#_(defn git-current-branch [dir]) (defn git-base-branch [dir] - (some->> (git dir "rev-parse" "--abbrev-ref" "origin/HEAD") :out - not-empty - (sh "basename") :out - not-empty)) + #_(todo handle non-clone set head (git remote set-head origin --auto)) + (or (some->> (git dir "rev-parse" "--abbrev-ref" "origin/HEAD") :out + not-empty + (sh "basename") :out + not-empty) "main")) (defn git-remote-url [dir file-path revision line-start line-end] (some-> (or (git-remote-origin dir) (git-first-remote dir)) (prepare-link revision file-path line-start line-end))) -(defn git-root [path] +(defn git-root [& [path]] (let [file-dir (if (empty? path) "." (dirname path))] (some->> (git file-dir "rev-parse" "--absolute-git-dir") dirname))) (defn cmd-link [[file-path line-start line-end rev]] (let [dir (git-root file-path) - revision (or rev (git-current-rev dir) (git-base-branch dir) "main") + revision (or rev (git-current-rev dir) (git-base-branch dir)) relative-file-path (str/trim (:out (sh "realpath" "--relative-to" dir file-path))) remote-url (git-remote-url dir relative-file-path revision line-start line-end)] (println remote-url))) +(defn cmd-base-branch [[]] (println (git-base-branch (git-root)))) + (def commands - {"link" cmd-link}) + {"link" cmd-link, "base-branch" cmd-base-branch}) (let [[cmd & args] *command-line-args*] (if-let [command-fn (commands cmd)] |
