Add gitignore function
This commit is contained in:
parent
87308cbce9
commit
1684aaa50f
2 changed files with 61 additions and 0 deletions
15
git/.config/zsh/completions/_gitignore
Executable file
15
git/.config/zsh/completions/_gitignore
Executable file
|
@ -0,0 +1,15 @@
|
||||||
|
#compdef _gitignore gitignore
|
||||||
|
#
|
||||||
|
# Requires gitignore script in path
|
||||||
|
#
|
||||||
|
# Enables completion for zsh of gitignore function.
|
||||||
|
|
||||||
|
_gitignore_get_command_list() {
|
||||||
|
curl -sL https://www.gitignore.io/api/list | tr ',' '\n'
|
||||||
|
}
|
||||||
|
|
||||||
|
_gitignore() {
|
||||||
|
_arguments \
|
||||||
|
'1::flags:((-f\:"Save output to .gitignore file in current directory"))' \
|
||||||
|
":listopts: _values -s, 'modules' $(_gitignore_get_command_list)"
|
||||||
|
}
|
46
git/.local/bin/gitignore
Executable file
46
git/.local/bin/gitignore
Executable file
|
@ -0,0 +1,46 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
#
|
||||||
|
# Adds call to gitignore.sh api to automatically
|
||||||
|
# generate a .gitignore file with the individual arguments
|
||||||
|
# passed in included as ignored packages.
|
||||||
|
#
|
||||||
|
# Pass in -f as first argument to save the file as .gitignore
|
||||||
|
# in the current directory in addition to printing to stdout.
|
||||||
|
# Will *overwrite* any previous .gitignore file that exists in
|
||||||
|
# current directory.
|
||||||
|
#
|
||||||
|
# Enables completion for zsh in git/.config/shell/zshrc.d/_gitignore_completions.zsh
|
||||||
|
|
||||||
|
__get_items() {
|
||||||
|
if [ "$savetofile" = "true" ]; then
|
||||||
|
__call_url "$@" | tee .gitignore
|
||||||
|
else
|
||||||
|
__call_url "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
__call_url() {
|
||||||
|
IFS=","
|
||||||
|
curl -L -s https://www.gitignore.io/api/"$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
gitignore() {
|
||||||
|
# just print to stdout or save locally?
|
||||||
|
if [ "$1" = "-f" ]; then
|
||||||
|
savetofile=true
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
IFS=","
|
||||||
|
if [ "$#" -eq 0 ]; then
|
||||||
|
for item in $(__get_items list); do
|
||||||
|
echo "$item"
|
||||||
|
done | fzf --multi --ansi | paste -s -d "," - |
|
||||||
|
{ read -r result && __get_items "$result"; }
|
||||||
|
cat
|
||||||
|
else
|
||||||
|
__get_items "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
gitignore "$@"
|
Loading…
Reference in a new issue