Comment on page
Advanced Command Line
Here are some advanced command line improvements for gitignore.io
this allows invocations as the previous but also permits passing arguments to curl like: gi --proxy somewhere:8080 -- linux python
function gi() (
gi_args=()
for arg; do
if [[ $arg = -- ]]; then
curl_args=("${gi_args[@]}")
gi_args=()
else
gi_args+=("$arg")
fi
done
IFS=,
curl "${curl_args[@]}" https://www.toptal.com/developers/gitignore/api/"${gi_args[*]}"
)
Adds a check to see if curl or wget is installed.
if hash curl; then
curl "${curl_args[@]}" https://www.toptal.com/developers/gitignore/api/"${gi_args[*]}"
elif hash wget; then
wget -O- "${curl_args[@]}" https://www.toptal.com/developers/gitignore/api/"${gi_args[*]}"
else
echo "please install curl or wget to run this command" >&2
exit 1
fi
Bash one-liner
function gi { curl https://www.toptal.com/developers/gitignore/api/"$(IFS=, ; echo "$*")"; }
Create a file for the function using vim ~/.config/fish/functions/gi.fish and enter the below code
function gi
curl -L -s https://www.toptal.com/developers/gitignore/api/$argv;
end
Provides completion for zsh
function gi() { curl -sL https://www.toptal.com/developers/gitignore/api/$@ ;}
_gitignoreio_get_command_list() {
curl -sL https://www.toptal.com/developers/gitignore/api/list | tr "," "\n"
}
_gitignoreio () {
compset -P '*,'
compadd -S '' `_gitignoreio_get_command_list`
}
compdef _gitignoreio gi
Provides completion for fish
complete -f -c git -n '__fish_git_using_command ignore' -a '(__fish_print_gitignore_list)'
function __fish_print_gitignore_list
if ! set -q __FISH_PRINT_GITIGNORE_LIST
set -g __FISH_PRINT_GITIGNORE_LIST (curl -sL https://www.toptal.com/developers/gitignore/api/list)
end
echo $__FISH_PRINT_GITIGNORE_LIST | string split ","
end
Improved git alias
tee
to .gitignore
and accept multiple parametersgit config --global alias.ignore \
'!gi() { IFS=","; curl -L -s "https://www.toptal.com/developers/gitignore/api/$*" | tee .gitignore;}; \
gi'
Last modified 3yr ago