diff --git a/.config/kak/autoload/git-mode.kak b/.config/kak/autoload/git-mode.kak index 96abf5ff..36a55f59 100644 --- a/.config/kak/autoload/git-mode.kak +++ b/.config/kak/autoload/git-mode.kak @@ -1,6 +1,6 @@ -declare-user-mode git +declare-user-mode ficgit map -docstring "git" global user g ": enter-user-mode git" -map -docstring "lazygit kak cwd" global git g ": terminal lazygit" +map -docstring "lazygit kak cwd" global ficgit g ": terminal lazygit" define-command lazygit-buffer-dir %{ evaluate-commands %sh{ @@ -8,16 +8,16 @@ define-command lazygit-buffer-dir %{ printf "terminal lazygit -p %s" "$ROOT" } } -map -docstring "lazygit buffer directory" global git G ": lazygit-buffer-dir" +map -docstring "lazygit buffer directory" global ficgit G ": lazygit-buffer-dir" define-command git-blame %{ info %sh{ git -C $(dirname $(realpath $kak_buffile)) blame -L $kak_cursor_line,$kak_cursor_line $(realpath $kak_buffile) } } -map -docstring "blame" global git b ": git-blame" -map -docstring "show diff" global git d ": git show-diff" -map -docstring "hide diff" global git D ": git hide-diff" +map -docstring "blame" global ficgit b ": git-blame" +map -docstring "show diff" global ficgit d ": git show-diff" +map -docstring "hide diff" global ficgit D ": git hide-diff" provide-module git-diff %~ diff --git a/.config/kak/autoload/git.kak/LICENSE b/.config/kak/autoload/git.kak/LICENSE new file mode 100644 index 00000000..e433d830 --- /dev/null +++ b/.config/kak/autoload/git.kak/LICENSE @@ -0,0 +1,30 @@ +Copyright (c) 2023, Dimitri Sabadie + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of Dimitri Sabadie nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/.config/kak/autoload/git.kak/README.md b/.config/kak/autoload/git.kak/README.md new file mode 100644 index 00000000..74ebce4d --- /dev/null +++ b/.config/kak/autoload/git.kak/README.md @@ -0,0 +1,23 @@ + # git.kak, a complementary set of Git tools for Kakoune + + + ## Installation + + Go in your config path — e.g. `~/.config/kak`, and clone this repository or link it in any + subdirectory of `autoload`. For instance: + + ``` + cd ~/.config/kak + mkdir -p autoload/plugins + cd autoload/plugins + git clone https://git.sr.ht/~hadronized/git.kak + ``` + + ## Usage + + Most of the tools are available via the `git` user-mode. Typical usage would be to place it under the user + mode, for instance: + + ``` + map global user g ':enter-user-mode git' + ``` diff --git a/.config/kak/autoload/git.kak/git-branches.kak b/.config/kak/autoload/git.kak/git-branches.kak new file mode 100644 index 00000000..118c24e2 --- /dev/null +++ b/.config/kak/autoload/git.kak/git-branches.kak @@ -0,0 +1,203 @@ +# Git branches in buffers. +# +# This small script provides convenience mechanisms to operate on Git branches by altering a buffer. +# It can: +# +# - Switch branches. +# - Create new branches with optional starting point. +# - Rename branches. +# - Delete and force-delete branches. + +declare-option str git_bin "git --no-optional-locks" +declare-option str git_list_local_branches "%opt{git_bin} branch" +declare-option str git_branch "xargs %opt{git_bin} branch" +declare-option str git_branch_rename "xargs %opt{git_bin} branch -m" +declare-option str git_branch_switch "xargs %opt{git_bin} switch" + +declare-user-mode git-branches + +# Create a branch listing buffer. +define-command git-branches %{ + edit -scratch "*git-branches*" + set-option buffer filetype git-branches + git-branches-refresh + + # highlighters + add-highlighter buffer/ ref git-branches + + # mappings + map buffer normal ':git-branches-switch' -docstring 'switch branch' + map buffer git-branches ':git-branches-switch' -docstring 'switch branch' + map buffer git-branches c ':git-branches-commit-pending' -docstring 'commit pending changes' + map buffer git-branches d ':git-branches-delete' -docstring 'delete branch' + map buffer git-branches D ':git-branches-force-delete' -docstring 'force-delete branch' + map buffer git-branches g ':git-branches-refresh' -docstring 'refresh' + map buffer git-branches n ':git-branches-new' -docstring 'new branch' + map buffer git-branches r ':git-branches-rename' -docstring 'rename branch' +} + +# Save the content of the current branch (primary sel) in the "b register. +define-command -hidden git-save-branch-name %{ + try %{ + execute-keys ';,ghll"by' + } +} + +# Restore the position of the main selection. Required to have saved something in the "b register. +define-command -hidden git-restore-branch-name %{ + try %{ + execute-keys '/b;' + } +} + +# Refresh the content of the branch buffer. This will lose all information that have been modified in it. +# TODO: support + branches (I don’t recall what they are, but I think it means they are checked out in +# working trees?) +define-command -hidden git-branches-refresh %{ + evaluate-commands -save-regs b %{ + git-save-branch-name + execute-keys -draft "%%|%opt{git_list_local_branches}" + + # replace the * for current branch by c + execute-keys -draft '%s^\*rc' + + git-restore-branch-name + execute-keys 'gh' + } +} + +# Delete a branch. +# +# Various situations are possible, and are acted upon by dispatching to git-branches-delete-- based on the +# first charact of every selection’s line. +define-command -hidden git-branches-delete %{ + execute-keys -itersel 'ghy:git-branches-delete--" d' +} + +# Force delete a branch. +# +# Same as the non-force version. +define-command -hidden git-branches-force-delete %{ + execute-keys -itersel 'ghy:git-branches-delete--" D' +} + +# Switch the branch as pending deletion. +# +# The argument is used for regular deletion (d) or force-deletion (D). +define-command -hidden git-branches-delete-- -params 1 %{ + execute-keys "ghr%arg{1}gh" +} + +# Deletion of a rename line simply removes the rename annotation, and delete. +define-command -hidden git-branches-delete--r -params 1 %{ + git-branches-unrename + git-branches-delete-- %arg{1} +} + +# Undelete. +define-command -hidden git-branches-delete--d -params 1 %{ + execute-keys 'ghr gh' +} + +# Force delete. +define-command -hidden git-branches-delete--D -params 1 %{ + execute-keys 'ghr gh' +} + +# Deletion on current branches is simply not allowed for obvious reasons (Git will refuse it anyway). +define-command -hidden git-branches-delete--c -params 1 %{ + fail 'cannot delete current branches' +} + +# Switch to a given branch (primary selection only). +define-command -hidden git-branches-switch %{ + execute-keys -draft ",ghllGl%opt{git_branch_switch}" + git-branches-refresh +} + +# Rename branches. +# +# Dispatching is done via git-branches-rename--. +define-command -hidden git-branches-rename %{ + execute-keys -itersel 'ghy:git-branches-rename--"' +} + +# Rename branch implementation. +define-command -hidden git-branches-rename-- %{ + execute-keys -save-regs b 'ghrrll"bya b;' +} + +# Renaming a deletion branch. +define-command -hidden git-branches-rename--d %{ + git-branches-rename-- +} + +# Remove renaming annotation. +define-command -hidden git-branches-rename--r %{ + git-branches-unrename +} + +# We forbid renaming current branches. +define-command -hidden git-branches-rename--c %{ + fail 'cannot rename current branches' +} + +# Unrename (remove rename annotations). +define-command -hidden git-branches-unrename %{ + execute-keys 'ghr dgh' +} + +# Create new branches. +# +# This is a handy version that uses the optional second argument by yanking the branches selections are on. +define-command -hidden git-branches-new %{ + execute-keys 'ghllygjoain new-" hh' +} + +# Execute pending deletions. Called on commit. +define-command -hidden git-branches-execute-delete %{ + try %{ + execute-keys -draft -itersel "%%s^(d|D)yllGl%opt{git_branch} -""" + } +} + +# Execute pending renames. Called on commit. +define-command -hidden git-branches-execute-rename %{ + try %{ + execute-keys -draft "%%s^rddx_%opt{git_branch_rename}" + } +} + +# Execute pending creations. Called on commit. +define-command -hidden git-branches-execute-new %{ + try %{ + execute-keys -draft "%%s^nddx_%opt{git_branch}" + } +} + +# Commit pending modifications in the buffer and refresh. +define-command -hidden git-branches-commit-pending %{ + git-branches-execute-delete + git-branches-execute-rename + git-branches-execute-new + git-branches-refresh +} + +# Highlighting. +set-face global GitOpsBranchCurrent green +set-face global GitOpsBranchOther default +set-face global GitOpsBranchDeleted red+s +set-face global GitOpsBranchForceDeleted red+bs +set-face global GitOpsBranchRenameSource blue +set-face global GitOpsBranchRenameDest cyan+b +set-face global GitOpsBranchNewName blue +set-face global GitOpsBranchNewStart yellow+i + +# Highlighters. +add-highlighter shared/git-branches group +add-highlighter shared/git-branches/current-branch regex '^(c)\s+([^\n]+)$' "1:black" "2:GitOpsBranchCurrent" +add-highlighter shared/git-branches/other-branch regex '^\s+([^\n]+)$' "1:GitOpsBranchOther" +add-highlighter shared/git-branches/deleted-branch regex '^(d)\s+([^\n]+)$' "1:black" "2:GitOpsBranchDeleted" +add-highlighter shared/git-branches/force-deleted-branch regex '^(D)\s+([^\n]+)$' "1:black" "2:GitOpsBranchForceDeleted" +add-highlighter shared/git-branches/renamed-branch regex '^(r)\s+([^\n ]+) ([^\n ]*)$' "1:black" "2:GitOpsBranchRenameSource" "3:GitOpsBranchRenameDest" +add-highlighter shared/git-branches/new-branch regex '^(n)\s+([^\n ]+) ?([^\n ]*)?$' "1:black" "2:GitOpsBranchNewName" "3:GitOpsBranchNewStart" diff --git a/.config/kak/autoload/git.kak/git.kak b/.config/kak/autoload/git.kak/git.kak new file mode 100644 index 00000000..04bf726d --- /dev/null +++ b/.config/kak/autoload/git.kak/git.kak @@ -0,0 +1,77 @@ +declare-option str awk_cmd 'awk' + +declare-user-mode git +map global git ':git-show-current-line' -docstring 'open last commit that touched current line' +map global git b ':git-branches' -docstring 'list branches' +map global git B ':git-blame-current-line' -docstring 'blame current line' +map global git n ':git next-hunk' -docstring 'goto next hunk' +map global git p ':git prev-hunk' -docstring 'goto previous hunk' +map global git d ':git diff' -docstring 'diff' + +## Blame current line +set-face global GitBlameLineRef red,black +set-face global GitBlameLineSummary green,black +set-face global GitBlameLineAuthor blue,black +set-face global GitBlameLineTime default,black@comment + +define-command git-blame-current-line %{ + info -markup -style above -anchor "%val{cursor_line}.%val{cursor_column}" -- %sh{ + git blame -L$kak_cursor_line,$kak_cursor_line $kak_bufname --incremental | $kak_opt_awk_cmd '\ +BEGIN { + ref = "" + author = "" + time = "" + summary = "" +} + +/^[a-f0-9]+ [0-9]+ [0-9]+ [0-9]+$/ { + ref = substr($1, 0, 8) +} + +/summary/ { + for (i = 2; i < NF; i++) { + summary = summary $i " " + } + + summary = summary $NF +} + +/author / { + for (i = 2; i < NF; i++) { + author = author $i " " + } + + author = author $NF +} + +/author-time/ { + time = strftime("%a %d %b %Y, %H:%M:%S", $2) +} + +END { + first = sprintf("{GitBlameLineRef}%s {GitBlameLineSummary}%s", ref, summary) + second = sprintf("{GitBlameLineAuthor}%s {GitBlameLineTime}on %s", author, time) + + max_len = length(first) + second_len = length(second) + if (second_len > max_len) { + max_len = second_len + } + fmt_string = sprintf("%%-%ds", max_len) + + printf fmt_string "\n", first + printf fmt_string, second +}' + } +} + +## Show the commit that touched the line under the cursor. +declare-option str git_show_current_line_commit +define-command git-show-current-line %{ + set-option global git_show_current_line_commit %sh{ git blame -L$kak_cursor_line,$kak_cursor_line $kak_bufname | cut -d' ' -f1 } + edit -scratch *git* + set-option buffer filetype git-commit + execute-keys '%|git show --pretty=fuller $kak_opt_git_show_current_line_commitgg' + set-option buffer readonly true +} + diff --git a/.config/nvchecker/old_ver.json~ b/.config/nvchecker/old_ver.json~ index 7d4ca670..90154d0c 100644 --- a/.config/nvchecker/old_ver.json~ +++ b/.config/nvchecker/old_ver.json~ @@ -18,6 +18,11 @@ "ktsctl": { "version": "2.0.0", "url": "https://crates.io/crates/ktsctl/2.0.0" + }, + "tex-fmt-bin": { + "version": "0.5.5", + "gitref": "refs/tags/v0.5.5", + "url": "https://github.com/WGUNDERWOOD/tex-fmt/releases/tag/v0.5.5" } } }