084e6fb9ca
- Add comprehensive `--description` flags to all fish functions for better `help` and `functions` output. - Introduce and correct `--wraps` flags to ensure proper completions for aliased commands (e.g., `top` wrapping `btop`, `zellij`, `upgrade` wrapping `paru`). - Prepend descriptive comments before function definitions for better source readability. - Add standard copyright and SPDX license identifiers to shell scripts. - Enhance script robustness by ensuring consistent terminal checks (Kitty, WezTerm) and graceful fallbacks in window/tab spawning functions (`spwin`, `tab`). - Implement graceful fallbacks to basic core utilities when preferred modern alternatives are missing (e.g., `top` falling back to system `top` if `btop` is missing, `view` falling back to `less` or `cat` if `nvim` is unavailable). - Improve overall code consistency across the `functions/` directory.
56 lines
1.8 KiB
Fish
56 lines
1.8 KiB
Fish
# Generate .gitignore files using the gitignore.io API
|
|
function gi --description 'Generate .gitignore files using the gitignore.io API'
|
|
# Define the flags
|
|
argparse h/help d/description l/list -- $argv
|
|
or return 1
|
|
|
|
# Help output
|
|
if set -q _flag_help
|
|
echo "Usage: gi [TARGETS...] [FLAGS]"
|
|
echo ""
|
|
echo "Arguments:"
|
|
echo " TARGETS Comma-separated list of languages or tools (e.g., c++,neovim,archlinux)"
|
|
echo ""
|
|
echo "Flags:"
|
|
echo " -h, --help Show this help message"
|
|
echo " -d, --description Show the Fish function description"
|
|
echo " -l, --list List all supported targets from the API"
|
|
echo ""
|
|
echo "Examples:"
|
|
echo " gi c++ # Print C++ gitignore to stdout"
|
|
echo " gi python,venv > .gitignore # Create a file for Python and venv"
|
|
echo " gi -l | grep -i linux # Search for specific OS support"
|
|
return 0
|
|
end
|
|
|
|
# Print the function description
|
|
if set -q _flag_description
|
|
functions -D gi
|
|
return 0
|
|
end
|
|
|
|
# Handle the list flag
|
|
if set -q _flag_list
|
|
curl -sL https://www.toptal.com/developers/gitignore/api/list
|
|
return 0
|
|
end
|
|
|
|
# Error if no arguments provided
|
|
if not set -q argv[1]
|
|
echo "Error: No targets provided. Use 'gi --help' for usage." >&2
|
|
return 1
|
|
end
|
|
|
|
# Execute the API call
|
|
# We replace any spaces with commas just in case you pass them as separate args
|
|
set -l targets (string join "," $argv)
|
|
|
|
echo "## Generating .gitignore for: $targets"
|
|
curl -f -sL "https://www.toptal.com/developers/gitignore/api/$targets"
|
|
|
|
if test $status -ne 0
|
|
echo "Error: Failed to fetch gitignore. Are the targets spelled correctly?" >&2
|
|
return 1
|
|
end
|
|
end
|