fix(gi): soften boilerplate errors and add empty-prompt message
- Missing GITIGNORE_BOILERPLATE var/file now prints error but continues to the API prompt instead of exiting the function - Empty Enter at the pattern prompt now prints "No patterns selected. Skipping API fetch." instead of silently returning
This commit is contained in:
+20
-21
@@ -89,30 +89,27 @@ function gi --description 'Generate .gitignore files using the gitignore.io API'
|
|||||||
if not set -q GITIGNORE_BOILERPLATE
|
if not set -q GITIGNORE_BOILERPLATE
|
||||||
set_color red --bold
|
set_color red --bold
|
||||||
echo "Error:" (set_color normal)"\$GITIGNORE_BOILERPLATE environment variable is not defined" >&2
|
echo "Error:" (set_color normal)"\$GITIGNORE_BOILERPLATE environment variable is not defined" >&2
|
||||||
return 1
|
else if not test -f "$GITIGNORE_BOILERPLATE"
|
||||||
end
|
|
||||||
if not test -f "$GITIGNORE_BOILERPLATE"
|
|
||||||
set_color red --bold
|
set_color red --bold
|
||||||
echo "Error:" (set_color normal)"Boilerplate file not found at '$GITIGNORE_BOILERPLATE'" >&2
|
echo "Error:" (set_color normal)"Boilerplate file not found at '$GITIGNORE_BOILERPLATE'" >&2
|
||||||
return 1
|
|
||||||
end
|
|
||||||
|
|
||||||
set -l template_hash ""
|
|
||||||
if command -q md5sum
|
|
||||||
set template_hash (md5sum "$GITIGNORE_BOILERPLATE" | string split ' ')[1]
|
|
||||||
else if command -q md5
|
|
||||||
set template_hash (md5 -q "$GITIGNORE_BOILERPLATE")
|
|
||||||
end
|
|
||||||
|
|
||||||
set -l sig "# id: gitig-boilerplate-$template_hash"
|
|
||||||
|
|
||||||
if test -f "$gitignore_path"; and grep -qF "$sig" "$gitignore_path"
|
|
||||||
set_color yellow --bold
|
|
||||||
echo "Notice:" (set_color normal)"Boilerplate already present in "(set_color cyan)"$readable_path"(set_color normal)"."
|
|
||||||
else
|
else
|
||||||
printf "\n%s\n" "$sig" >>"$gitignore_path"
|
set -l template_hash ""
|
||||||
cat "$GITIGNORE_BOILERPLATE" >>"$gitignore_path"
|
if command -q md5sum
|
||||||
echo (set_color green)"✔"(set_color normal)" Appended boilerplate to "(set_color cyan)"$readable_path"(set_color normal)
|
set template_hash (md5sum "$GITIGNORE_BOILERPLATE" | string split ' ')[1]
|
||||||
|
else if command -q md5
|
||||||
|
set template_hash (md5 -q "$GITIGNORE_BOILERPLATE")
|
||||||
|
end
|
||||||
|
|
||||||
|
set -l sig "# id: gitig-boilerplate-$template_hash"
|
||||||
|
|
||||||
|
if test -f "$gitignore_path"; and grep -qF "$sig" "$gitignore_path"
|
||||||
|
set_color yellow --bold
|
||||||
|
echo "Notice:" (set_color normal)"Boilerplate already present in "(set_color cyan)"$readable_path"(set_color normal)"."
|
||||||
|
else
|
||||||
|
printf "\n%s\n" "$sig" >>"$gitignore_path"
|
||||||
|
cat "$GITIGNORE_BOILERPLATE" >>"$gitignore_path"
|
||||||
|
echo (set_color green)"✔"(set_color normal)" Appended boilerplate to "(set_color cyan)"$readable_path"(set_color normal)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -132,6 +129,8 @@ function gi --description 'Generate .gitignore files using the gitignore.io API'
|
|||||||
end
|
end
|
||||||
__gi_append_dedup "$content" "$pattern" "$gitignore_path" "$readable_path"
|
__gi_append_dedup "$content" "$pattern" "$gitignore_path" "$readable_path"
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
echo (set_color brblack)"No patterns selected. Skipping API fetch."(set_color normal)
|
||||||
end
|
end
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user