fish: color variable validation function

This commit is contained in:
Charles Gould 2020-03-22 18:02:04 -05:00
parent 7755591a38
commit fdaf147217
2 changed files with 47 additions and 1 deletions

View File

@ -0,0 +1,46 @@
function fish_colors_check --description 'Validate the fish color variables' --argument-names fish_srcdir
if test -z "$fish_srcdir"
echo "Usage: fish_colors_check <fish_srcdir>"
return 1
end
if not test -d "$fish_srcdir"
echo "Error: not a directory: $fish_srcdir"
return 2
end
set --local allcolors (string collect (rg --no-line-number --no-filename --only-matching 'fish(?:_pager)?_color[a-z_]*[a-z]+' $fish_srcdir | sort | uniq))
set --local setcolors (string collect (set --names | string match 'fish*_color*'))
set --local missingcolors
set --local unknowncolors
for color in $allcolors
if not contains -- $color $setcolors
set missingcolors $missingcolors $color
end
end
for color in $setcolors
if not contains -- $color $allcolors
set unknowncolors $unknowncolors $color
end
end
if test (count $missingcolors) -gt 0
# *current regex matches some invalid cases
#
# example: set -l color_name fish_color_git_$i
# match: fish_color_git
echo "These color variables are (potentially*) defined, but unset:"
for color in $missingcolors
echo " - $color"
end
end
if test (count $unknowncolors) -gt 0
echo "These color variables are set, but undefined:"
for color in $unknowncolors
echo " - $color"
end
end
end

View File

@ -1,6 +1,6 @@
function video_compress --argument-names srcfile
if test -z "$srcfile"
echo "Error: missing argument"
echo "Usage: video_compress <srcfile>"
return 1
end
if not test -f "$srcfile"