From e45a8acda4abdf77fa5255e66196c3cfd0ef6936 Mon Sep 17 00:00:00 2001 From: EmilyGraceSeville7cf Date: Sat, 5 Oct 2024 23:39:35 +1000 Subject: [PATCH] fix(completion): move d2 related functions to completion file --- share/completions/d2.fish | 26 +++++++++++++++++++ .../__fish_d2__complete_layouts.fish | 18 ------------- .../functions/__fish_d2__complete_themes.fish | 6 ----- 3 files changed, 26 insertions(+), 24 deletions(-) delete mode 100644 share/functions/__fish_d2__complete_layouts.fish delete mode 100644 share/functions/__fish_d2__complete_themes.fish diff --git a/share/completions/d2.fish b/share/completions/d2.fish index 89a74e17b..3301a5562 100644 --- a/share/completions/d2.fish +++ b/share/completions/d2.fish @@ -1,3 +1,29 @@ +function __fish_d2__complete_themes + d2 themes | + sed -n '3,$p' | + string match --entire --regex '^-' | + string replace --regex -- '- ([^:]+): (.+)' '$2\t$1' +end + +function __fish_d2__complete_layouts + set -l layouts (d2 layout | + sed -n '3,$p' | + sed -n '/^$/,$d; p' | + string replace --regex '^(\w+)\s+\(bundled\)' '$1') + + set -l identifiers + set -l descriptions + + for layout in $layouts + set -a identifiers (string replace --regex ' - .+$' '' -- $layouts) + set -a descriptions (string replace --regex '^\w+ - ' '' -- $layouts) + end + + for index in (seq (count $layouts)) + printf '%s\t%s\n' $identifiers[$index] $descriptions[$index] + end +end + set -l command kroki complete -c $command -f diff --git a/share/functions/__fish_d2__complete_layouts.fish b/share/functions/__fish_d2__complete_layouts.fish deleted file mode 100644 index e0752313e..000000000 --- a/share/functions/__fish_d2__complete_layouts.fish +++ /dev/null @@ -1,18 +0,0 @@ -function __fish_d2__complete_layouts - set -l layouts (d2 layout | - sed -n '3,$p' | - sed -n '/^$/,$d; p' | - string replace --regex '^(\w+)\s+\(bundled\)' '$1') - - set -l identifiers - set -l descriptions - - for layout in $layouts - set -a identifiers (string replace --regex ' - .+$' '' -- $layouts) - set -a descriptions (string replace --regex '^\w+ - ' '' -- $layouts) - end - - for index in (seq (count $layouts)) - printf '%s\t%s\n' $identifiers[$index] $descriptions[$index] - end -end diff --git a/share/functions/__fish_d2__complete_themes.fish b/share/functions/__fish_d2__complete_themes.fish deleted file mode 100644 index 4335044b9..000000000 --- a/share/functions/__fish_d2__complete_themes.fish +++ /dev/null @@ -1,6 +0,0 @@ -function __fish_d2__complete_themes - d2 themes | - sed -n '3,$p' | - string match --entire --regex '^-' | - string replace --regex -- '- ([^:]+): (.+)' '$2\t$1' -end