mirror of
https://github.com/tj/git-extras.git
synced 2026-09-12 00:16:27 -04:00
125 lines
2.9 KiB
Plaintext
Executable file
125 lines
2.9 KiB
Plaintext
Executable file
#/bin/sh
|
|
|
|
gitignore_io_url="https://www.gitignore.io/api/"
|
|
|
|
default_path="$HOME/.gi_list"
|
|
gi_list=`cat $default_path | tr "," "\n"`
|
|
|
|
update_gi_list() {
|
|
curl -L -s "${gitignore_io_url}/list" > ~/.gi_list
|
|
}
|
|
|
|
print_in_alphabetical_order() {
|
|
for i in {a..z};
|
|
do
|
|
echo "$gi_list" | grep "^$i" | tr "\n" " "
|
|
echo
|
|
done
|
|
}
|
|
|
|
print_in_table_format() {
|
|
table_width=5
|
|
coulumn_width=25
|
|
|
|
counter=0
|
|
for item in $gi_list; do
|
|
printf "%-${coulumn_width}s" $item
|
|
counter=$(($counter+1))
|
|
if [[ $(($counter%$table_width)) -eq 0 ]]; then
|
|
echo
|
|
fi
|
|
done
|
|
echo
|
|
}
|
|
|
|
search() {
|
|
for type in $gi_list;
|
|
do
|
|
if [[ $type == *$1* ]]
|
|
then
|
|
echo $type
|
|
fi
|
|
done
|
|
}
|
|
|
|
print_last_modified_time() {
|
|
local gi_list_date=`stat -f "%t%Sm" $default_path`
|
|
echo "Last update time: $gi_list_date"
|
|
}
|
|
|
|
gi() {
|
|
curl -L -s $gitignore_io_url/$1
|
|
}
|
|
|
|
gi_export() {
|
|
gi $1 > .gitignore
|
|
}
|
|
|
|
gi_append() {
|
|
gi $1 >> .gitignore
|
|
}
|
|
|
|
show_usage() {
|
|
echo "Usage:"
|
|
echo " git ignore-io <types>... Show gitignore template"
|
|
echo " [-a|--append] <types>... Append new .gitignore content to .gitignore under the current directory"
|
|
echo " [-e|--export] <types>... Export new .gitignore to the current directory (The old one will be replaced)"
|
|
echo " [-l] Print available types in alphabetical order "
|
|
echo " [-L] Print available types in table format"
|
|
echo " [-s|--search] <word> Search word in available types"
|
|
echo " [-t|--show-update-time] Show the last modified time of ~/.gi_list (where the list of available types stored)"
|
|
echo " [-u|--update-list] Update ~/.gi_list"
|
|
}
|
|
|
|
|
|
update_gi_list &
|
|
if [[ $# -eq 0 ]]; then
|
|
show_usage
|
|
else
|
|
case $1 in
|
|
-a|--append|-e|--export)
|
|
opt=$1
|
|
shift
|
|
if [[ $# -eq 0 ]]; then
|
|
show_usage
|
|
exit
|
|
fi
|
|
|
|
gi_to_curl=`echo $@ | tr " " ","`
|
|
case $opt in
|
|
-a|--append)
|
|
gi_append $gi_to_curl
|
|
;;
|
|
-e|--export)
|
|
gi_export $gi_to_curl
|
|
;;
|
|
esac
|
|
|
|
exit
|
|
;;
|
|
-t|--show-update-time)
|
|
print_last_modified_time
|
|
;;
|
|
-u|--update-list)
|
|
update_gi_list
|
|
;;
|
|
-s|--search)
|
|
search $2
|
|
;;
|
|
-L)
|
|
print_in_alphabetical_order
|
|
;;
|
|
-l)
|
|
print_in_table_format
|
|
;;
|
|
-*)
|
|
echo No Such option
|
|
show_usage
|
|
;;
|
|
*)
|
|
gi_to_curl=`echo $@ | tr " " ","`
|
|
gi $gi_to_curl
|
|
;;
|
|
esac
|
|
fi
|