Skip to content

Commit

Permalink
helix: xit like binds and wip case stuff
Browse files Browse the repository at this point in the history
case stuff copied, and needs work, it's not great.

Signed-off-by: clux <[email protected]>
  • Loading branch information
clux committed Oct 28, 2024
1 parent c74e797 commit 8056a5b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 38 deletions.
47 changes: 30 additions & 17 deletions config/helix/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,39 @@ p = ":toggle-option lsp.display-inlay-hints"
f = ":theme ayu_dark"
d = ":theme catppuccin_mocha_transparent"

[keys.normal."A-\\"] # case convert, underlying tool seems so-so
S = ":pipe ccase -t screamingsnake"
c = ":pipe ccase -t camel"
k = ":pipe ccase -t kebab"
K = ":pipe ccase -t upperkebab"
p = ":pipe ccase -t pascal"
s = ":pipe ccase -t snake"
l = ":pipe ccase -t lower"
u = ":pipe ccase -t upper"

[keys.normal."A-m"] # markdown menu
# Turn into heading
"A-1" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/# /'", "collapse_selection"]
"A-2" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/## /'", "collapse_selection"]
"A-3" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/### /'", "collapse_selection"]
"A-4" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/#### /'", "collapse_selection"]
"A-5" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/##### /'", "collapse_selection"]
"A-6" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/###### /'", "collapse_selection"]
"1" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/# /'", "move_char_right", "insert_newline", "move_char_left"]
"2" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/## /'", "move_char_right", "insert_newline", "move_char_left"]
"3" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/### /'", "move_char_right", "insert_newline", "move_char_left"]
"4" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/#### /'", "move_char_right", "insert_newline", "move_char_left"]
"5" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/##### /'", "move_char_right", "insert_newline", "move_char_left"]
"6" = ["extend_to_line_bounds", ":pipe sed -E 's/^(#{1,} )?/###### /'", "move_char_right", "insert_newline", "move_char_left"]

# xit todo manipulation from any line
x = ["extend_to_line_bounds", ":pipe ~/.config/helix/helix-commands md tick", "move_char_right", "insert_newline", "move_char_left"]
z = ["extend_to_line_bounds", ":pipe ~/.config/helix/helix-commands md untick", "move_char_right", "insert_newline", "move_char_left"]
c = ["extend_to_line_bounds", ":pipe ~/.config/helix/helix-commands md cancel", "move_char_right", "insert_newline", "move_char_left"]

# useful, but can we do these with standard ms* ms**?
i = [":pipe ~/.config/helix/helix-commands markdown italic"]
b = [":pipe ~/.config/helix/helix-commands markdown bold"]
s = [":pipe ~/.config/helix/helix-commands markdown strikethrough"]
"`" = [":pipe ~/.config/helix/helix-commands markdown backtick"]
h = [":pipe ~/.config/helix/helix-commands markdown link"]

# list creators, awkward, want something like this
o = ["split_selection_on_newline", "goto_first_nonwhitespace", ":insert-output printf '1. '", "rotate_selections_backward", 'keep_primary_selection', "collapse_selection", "goto_line_end"]
q = ["split_selection_on_newline", "goto_first_nonwhitespace", ":insert-output printf '> '", "rotate_selections_backward", 'keep_primary_selection', "collapse_selection", "goto_line_end"]
u = ["split_selection_on_newline", "goto_first_nonwhitespace", ":insert-output printf -- '- '", "rotate_selections_backward", 'keep_primary_selection', "collapse_selection", "goto_line_end"]
t = ["split_selection_on_newline", "goto_first_nonwhitespace", ":insert-output printf -- '- [ ] '", "rotate_selections_backward", 'keep_primary_selection', "collapse_selection", "goto_line_end"]
# relying on :pipe is quirky; drops your select, strips trailing newlines
# stuff is never what you truly want...
i = ":pipe ~/.config/helix/helix-commands md italic"
b = ":pipe ~/.config/helix/helix-commands md bold"
s = ":pipe ~/.config/helix/helix-commands mdstrikethrough"
"`" = ":pipe ~/.config/helix/helix-commands md backtick"
h = ":pipe ~/.config/helix/helix-commands md link"
#c = ":pipe ~/.config/helix/helix-commands md code"

[editor]
cursorline = true
Expand Down
52 changes: 31 additions & 21 deletions config/helix/helix-commands
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
#!/usr/bin/env bash

function markdown_command() {
# experiments
#
# best when surrounding single line substrings or cleanly delimited strings (with trailing newlines) as;
# - any excess newlines are stripped from helix :pipe
# - after :pipe, stuff is no longer aligned nicely on multiline replace

ccase_cmd() {
local to=$1
local text=$2
result=$(ccase -t "${to}" "${text}")
printf "%s" "$result"
}

md_cmd() {
local action=$1
local text=$2
case $action in
link)
title=$(curl -fsSL "$text" | htmlq -t 'html head title')
title="$(curl -fsSL "$text" | htmlq -t 'html head title')"
printf "[%s](%s)" "$title" "$text"
;;
bold)
Expand All @@ -21,41 +34,38 @@ function markdown_command() {
printf "\`%s\`" "$text"
;;
code)
echo "\`\`\`"
printf "%s" "$text"
echo "\`\`\`"
echo -e "\`\`\`\n${text}\n\`\`\`"
;;
untick)
output="$(sd '\[.\]' '[ ]' <<< "$text")"
printf "%s\n" "$output"
;;
tick)
output="$(sd '\[.\]' '[x]' <<< "$text")"
printf "%s\n" "$output"
;;
cancel)
output="$(sd '\[.\]' '[~]' <<< "$text")"
printf "%s\n" "$output"
;;
*)
printf "%s" "$text"
;;
esac
}

function ccase_command() {
local to=$1
local text=$2
result=$(ccase -t $to "$text")
printf "%s" "$result"
}

function default_command() {
echo "Usage: helix-command [markdown|ccase] action"
}

category="$1"

case $category in
markdown)
md)
action="$2"
text=$(</dev/stdin)
markdown_command "$action" "$text"
md_cmd "$action" "$text"
;;
ccase)
to="$2"
text=$(</dev/stdin)
ccase_command "$to" "$text"
ccase_cmd "$to" "$text"
;;
*)
default_command
;;
esac

0 comments on commit 8056a5b

Please sign in to comment.