Compare commits

...

5 Commits

Author SHA1 Message Date
fc0cf2ff0a vim:keys: Make git hunk mappings shorter
I act very rarely on the whole file but quite often on hunks, so it
makes sense to have the mappings for the latter shorter.

The new mappings I wanted to use for the whole file are conflicting with
`<leader>gf` (i.e. `:GFiles`), so I've disabled them for now.
2025-08-05 10:57:00 +02:00
4a12ed8567 hooks:commit-msg: Allow links being overly long
Allow links on single lines and in git trailers.
2025-08-04 17:53:24 +02:00
8380d4cc29 bin: Add no-ansi to remove ANSI escape sequences
Similar to `no-ansi-sgr` but removes all ANSI escape sequence, not just
the SGR ones.

See the previous commit bbf9a1da58 (bin:no-ansi-sgr: Set LC_ALL=C for
`[0-?]` range, 2025-07-30) for an explanation of why LC_ALL has to be
set.
2025-08-04 11:00:14 +02:00
bbf9a1da58 bin:no-ansi-sgr: Set LC_ALL=C for [0-?] range
Setting LC_ALL=C makes it possible to use the range `[0-?]` instead of
splitting it into `[0-9:-?]` as done previously. Without LC_ALL, sed
complains with:

	sed: -e expression #1, char 21: Invalid range end

The GNU manual explains this partially, although I still don't quite
understand why this range specifically does not work in `en_US.utf8`.
See:

> Within a bracket expression, a *range expression* consists of two
> characters separated by a hyphen. It matches any single character that
> sorts between the two characters, inclusive. In the default C locale,
> the sorting sequence is the native character order; for example,
> `[a-d]` is equivalent to `[abcd]`.

Link: https://www.gnu.org/software/sed/manual/sed.html#Character-Classes-and-Bracket-Expressions
2025-08-04 11:00:01 +02:00
75fb2f56a2 bin:no-ansi-sgr: Conform to specification
Previously - in the existence of other ANSI escape sequences - the
script deleted text due to the too broad regex. For example in:

    foo^[[K bar m

everything behind `foo` was deleted. Thus, only remove SGR sequences by
only matching the spec-allowed bytes.
2025-08-04 11:00:00 +02:00
4 changed files with 24 additions and 14 deletions

View File

@@ -153,9 +153,10 @@ nmap <leader>grc :let subject=system('git show -s --date=short --pretty="format:
nmap <leader>gso :r!git config --get user.name<CR>:r!git config --get user.email<CR>I<<ESC>A><ESC>kJISigned-off-by: <ESC>
" Add, stash or checkout the current file
nmap <leader>ga <Cmd>!git add -- %<CR>
nmap <leader>gs <Cmd>!git stash -- %<CR>
nmap <leader>gu <Cmd>!git checkout -- %<CR>
" TODO: Conflict with <leader>gf
"nmap <leader>gfa <Cmd>!git add -- %<CR>
"nmap <leader>gfs <Cmd>!git stash -- %<CR>
"nmap <leader>gfu <Cmd>!git checkout -- %<CR>
if exists('g:loaded_fugitive')
" Interactive `git status`
@@ -176,15 +177,12 @@ else
endif
if exists('g:loaded_gitgutter')
" Add `g` prefix to hunk bindings
" Mnemonic: "git hunk <add|undo|preview>"
nmap <leader>gha <Plug>(GitGutterStageHunk)
" TODO: nmap <leader>ghs <Plug>(GitGutterStashHunk)
nmap <leader>ghu <Plug>(GitGutterUndoHunk)
nmap <leader>ghp <Plug>(GitGutterPreviewHunk)
" StageHunk can be used for single lines. Mnemonic w/o `h`unk
" Mnemonic: "git <add|undo|preview>"
nmap <leader>ga <Plug>(GitGutterStageHunk)
xmap <leader>ga <Plug>(GitGutterStageHunk)
" TODO: nmap <leader>gs <Plug>(GitGutterStashHunk)
nmap <leader>gu <Plug>(GitGutterUndoHunk)
nmap <leader>gp <Plug>(GitGutterPreviewHunk)
" Add hunk/h version to textobject bindings that use `c` (for `change I
" presume?) (e.g. ic -> ih)

7
.local/bin/no-ansi Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/sh
# SPDX-License-Identifier: MIT
# Copyright (c) 2025 Julian Prein
#
# Remove ANSI escape sequences.
env LC_ALL=C sed 's/\[[0-?]*[ -/]*[@-z]//g'

View File

@@ -1,8 +1,8 @@
#!/bin/sed -f
#!/bin/sh
# SPDX-License-Identifier: MIT
# Copyright (c) 2025 Julian Prein
#
# Remove ANSI SGR (Select Graphic Rendition) escape sequences, e.g. setting
# color or bold font.
s/\[[^m]*m//g
env LC_ALL=C sed 's/\[[0-?]*[ -/]*m//g'

View File

@@ -68,6 +68,11 @@ BKP_IFS="$IFS"
IFS='
'
for line in $body; do
[[ ${#line} -le 72 ]] || die "Body lines too long. (<= 72)"
[[ ${#line} -gt 72 ]] || continue
# Allow links on single lines and in trailers
[[ ! $line =~ ^([-A-Za-z0-9]*:)?[\ \ ]*https?://[^\ ]*$ ]] || continue
die "Body lines too long. (<= 72)"
done
IFS="$BKP_IFS"