From 8056a5b64ce33255ce47df557ad545c0505d0042 Mon Sep 17 00:00:00 2001 From: clux Date: Mon, 28 Oct 2024 17:33:51 +0000 Subject: [PATCH] helix: xit like binds and wip case stuff case stuff copied, and needs work, it's not great. Signed-off-by: clux --- config/helix/config.toml | 47 +++++++++++++++++++++------------ config/helix/helix-commands | 52 ++++++++++++++++++++++--------------- 2 files changed, 61 insertions(+), 38 deletions(-) diff --git a/config/helix/config.toml b/config/helix/config.toml index 08f958e..f76f24b 100644 --- a/config/helix/config.toml +++ b/config/helix/config.toml @@ -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 diff --git a/config/helix/helix-commands b/config/helix/helix-commands index d846950..93af28d 100755 --- a/config/helix/helix-commands +++ b/config/helix/helix-commands @@ -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) @@ -21,9 +34,19 @@ 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" @@ -31,31 +54,18 @@ function markdown_command() { 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=$(