fix(completion): move d2 related functions to completion file

This commit is contained in:
EmilyGraceSeville7cf 2024-10-05 23:39:35 +10:00
parent fce17a90a7
commit e45a8acda4
3 changed files with 26 additions and 24 deletions

View file

@ -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 set -l command kroki
complete -c $command -f complete -c $command -f

View file

@ -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

View file

@ -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