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
1
function gi() (
2
gi_args=()
3
for arg; do
4
if [[ $arg = -- ]]; then
5
curl_args=("${gi_args[@]}")
6
gi_args=()
7
else
8
gi_args+=("$arg")
9
fi
10
done
11
IFS=,
12
curl "${curl_args[@]}" https://www.toptal.com/developers/gitignore/api/"${gi_args[*]}"
13
)
Copied!
Adds a check to see if curl or wget is installed.
1
if hash curl; then
2
curl "${curl_args[@]}" https://www.toptal.com/developers/gitignore/api/"${gi_args[*]}"
3
elif hash wget; then
4
wget -O- "${curl_args[@]}" https://www.toptal.com/developers/gitignore/api/"${gi_args[*]}"
5
else
6
echo "please install curl or wget to run this command" >&2
7
exit 1
8
fi
Copied!
Bash one-liner
1
function gi { curl https://www.toptal.com/developers/gitignore/api/"$(IFS=, ; echo "$*")"; }
Copied!
Create a file for the function using vim ~/.config/fish/functions/gi.fish and enter the below code
1
function gi
2
curl -L -s https://www.toptal.com/developers/gitignore/api/$argv;
3
end
Copied!

oh-my-zsh

Provides completion for zsh
1
function gi() { curl -sL https://www.toptal.com/developers/gitignore/api/[email protected] ;}
2
3
_gitignoreio_get_command_list() {
4
curl -sL https://www.toptal.com/developers/gitignore/api/list | tr "," "\n"
5
}
6
7
_gitignoreio () {
8
compset -P '*,'
9
compadd -S '' `_gitignoreio_get_command_list`
10
}
11
12
compdef _gitignoreio gi
Copied!

@zubin

Provides completion for fish
1
complete -f -c git -n '__fish_git_using_command ignore' -a '(__fish_print_gitignore_list)'
2
3
function __fish_print_gitignore_list
4
if ! set -q __FISH_PRINT_GITIGNORE_LIST
5
set -g __FISH_PRINT_GITIGNORE_LIST (curl -sL https://www.toptal.com/developers/gitignore/api/list)
6
end
7
echo $__FISH_PRINT_GITIGNORE_LIST | string split ","
8
end
Copied!
Improved git alias tee to .gitignore and accept multiple parameters
1
git config --global alias.ignore \
2
'!gi() { IFS=","; curl -L -s "https://www.toptal.com/developers/gitignore/api/$*" | tee .gitignore;}; \
3
gi'
4
Copied!
Last modified 1yr ago