Skip to content

Commit 8056a5b

Browse files
committed
helix: xit like binds and wip case stuff
case stuff copied, and needs work, it's not great. Signed-off-by: clux <[email protected]>
1 parent c74e797 commit 8056a5b

File tree

2 files changed

+61
-38
lines changed

2 files changed

+61
-38
lines changed

config/helix/config.toml

+30-17
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,39 @@ p = ":toggle-option lsp.display-inlay-hints"
1818
f = ":theme ayu_dark"
1919
d = ":theme catppuccin_mocha_transparent"
2020

21+
[keys.normal."A-\\"] # case convert, underlying tool seems so-so
22+
S = ":pipe ccase -t screamingsnake"
23+
c = ":pipe ccase -t camel"
24+
k = ":pipe ccase -t kebab"
25+
K = ":pipe ccase -t upperkebab"
26+
p = ":pipe ccase -t pascal"
27+
s = ":pipe ccase -t snake"
28+
l = ":pipe ccase -t lower"
29+
u = ":pipe ccase -t upper"
30+
2131
[keys.normal."A-m"] # markdown menu
2232
# Turn into heading
23-
"A-1" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/# /'", "collapse_selection"]
24-
"A-2" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/## /'", "collapse_selection"]
25-
"A-3" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/### /'", "collapse_selection"]
26-
"A-4" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/#### /'", "collapse_selection"]
27-
"A-5" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/##### /'", "collapse_selection"]
28-
"A-6" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/###### /'", "collapse_selection"]
33+
"1" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/# /'", "move_char_right", "insert_newline", "move_char_left"]
34+
"2" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/## /'", "move_char_right", "insert_newline", "move_char_left"]
35+
"3" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/### /'", "move_char_right", "insert_newline", "move_char_left"]
36+
"4" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/#### /'", "move_char_right", "insert_newline", "move_char_left"]
37+
"5" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/##### /'", "move_char_right", "insert_newline", "move_char_left"]
38+
"6" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/###### /'", "move_char_right", "insert_newline", "move_char_left"]
39+
40+
# xit todo manipulation from any line
41+
x = ["extend_to_line_bounds", ":pipe ~/.config/helix/helix-commands md tick", "move_char_right", "insert_newline", "move_char_left"]
42+
z = ["extend_to_line_bounds", ":pipe ~/.config/helix/helix-commands md untick", "move_char_right", "insert_newline", "move_char_left"]
43+
c = ["extend_to_line_bounds", ":pipe ~/.config/helix/helix-commands md cancel", "move_char_right", "insert_newline", "move_char_left"]
44+
2945
# useful, but can we do these with standard ms* ms**?
30-
i = [":pipe ~/.config/helix/helix-commands markdown italic"]
31-
b = [":pipe ~/.config/helix/helix-commands markdown bold"]
32-
s = [":pipe ~/.config/helix/helix-commands markdown strikethrough"]
33-
"`" = [":pipe ~/.config/helix/helix-commands markdown backtick"]
34-
h = [":pipe ~/.config/helix/helix-commands markdown link"]
35-
36-
# list creators, awkward, want something like this
37-
o = ["split_selection_on_newline", "goto_first_nonwhitespace", ":insert-output printf '1. '", "rotate_selections_backward", 'keep_primary_selection', "collapse_selection", "goto_line_end"]
38-
q = ["split_selection_on_newline", "goto_first_nonwhitespace", ":insert-output printf '> '", "rotate_selections_backward", 'keep_primary_selection', "collapse_selection", "goto_line_end"]
39-
u = ["split_selection_on_newline", "goto_first_nonwhitespace", ":insert-output printf -- '- '", "rotate_selections_backward", 'keep_primary_selection', "collapse_selection", "goto_line_end"]
40-
t = ["split_selection_on_newline", "goto_first_nonwhitespace", ":insert-output printf -- '- [ ] '", "rotate_selections_backward", 'keep_primary_selection', "collapse_selection", "goto_line_end"]
46+
# relying on :pipe is quirky; drops your select, strips trailing newlines
47+
# stuff is never what you truly want...
48+
i = ":pipe ~/.config/helix/helix-commands md italic"
49+
b = ":pipe ~/.config/helix/helix-commands md bold"
50+
s = ":pipe ~/.config/helix/helix-commands mdstrikethrough"
51+
"`" = ":pipe ~/.config/helix/helix-commands md backtick"
52+
h = ":pipe ~/.config/helix/helix-commands md link"
53+
#c = ":pipe ~/.config/helix/helix-commands md code"
4154

4255
[editor]
4356
cursorline = true

config/helix/helix-commands

+31-21
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
#!/usr/bin/env bash
22

3-
function markdown_command() {
3+
# experiments
4+
#
5+
# best when surrounding single line substrings or cleanly delimited strings (with trailing newlines) as;
6+
# - any excess newlines are stripped from helix :pipe
7+
# - after :pipe, stuff is no longer aligned nicely on multiline replace
8+
9+
ccase_cmd() {
10+
local to=$1
11+
local text=$2
12+
result=$(ccase -t "${to}" "${text}")
13+
printf "%s" "$result"
14+
}
15+
16+
md_cmd() {
417
local action=$1
518
local text=$2
619
case $action in
720
link)
8-
title=$(curl -fsSL "$text" | htmlq -t 'html head title')
21+
title="$(curl -fsSL "$text" | htmlq -t 'html head title')"
922
printf "[%s](%s)" "$title" "$text"
1023
;;
1124
bold)
@@ -21,41 +34,38 @@ function markdown_command() {
2134
printf "\`%s\`" "$text"
2235
;;
2336
code)
24-
echo "\`\`\`"
25-
printf "%s" "$text"
26-
echo "\`\`\`"
37+
echo -e "\`\`\`\n${text}\n\`\`\`"
38+
;;
39+
untick)
40+
output="$(sd '\[.\]' '[ ]' <<< "$text")"
41+
printf "%s\n" "$output"
42+
;;
43+
tick)
44+
output="$(sd '\[.\]' '[x]' <<< "$text")"
45+
printf "%s\n" "$output"
46+
;;
47+
cancel)
48+
output="$(sd '\[.\]' '[~]' <<< "$text")"
49+
printf "%s\n" "$output"
2750
;;
2851
*)
2952
printf "%s" "$text"
3053
;;
3154
esac
3255
}
3356

34-
function ccase_command() {
35-
local to=$1
36-
local text=$2
37-
result=$(ccase -t $to "$text")
38-
printf "%s" "$result"
39-
}
40-
41-
function default_command() {
42-
echo "Usage: helix-command [markdown|ccase] action"
43-
}
44-
4557
category="$1"
46-
4758
case $category in
48-
markdown)
59+
md)
4960
action="$2"
5061
text=$(</dev/stdin)
51-
markdown_command "$action" "$text"
62+
md_cmd "$action" "$text"
5263
;;
5364
ccase)
5465
to="$2"
5566
text=$(</dev/stdin)
56-
ccase_command "$to" "$text"
67+
ccase_cmd "$to" "$text"
5768
;;
5869
*)
59-
default_command
6070
;;
6171
esac

0 commit comments

Comments
 (0)