Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
87d6169
Merge gi_extension project into git extras as git-ignore-io
Lee-W Sep 6, 2015
37aacf3
Init gitignore and ignore vim osx temp files
Lee-W Sep 6, 2015
d87599c
Remove help from git-ignore-io
Lee-W Sep 6, 2015
4a8037f
Implement search function or git-ignore-io
Lee-W Sep 6, 2015
a1d0445
Add description to Commands.md for git-ignore-io
Lee-W Sep 7, 2015
98bbfe7
Fix typo
Lee-W Sep 7, 2015
2ced182
Finish manual for git-ignore-io
Lee-W Sep 7, 2015
967b51c
Generate manual using ronn for git-ignore-io
Lee-W Sep 7, 2015
ccd5303
Update manual and description in Commands
Lee-W Sep 8, 2015
3ad2f6f
Refactor git-ignore-io and remove .gitignore
Lee-W Sep 8, 2015
fed97bf
Not to update list each time git-ignore-io is executed
Lee-W Sep 8, 2015
6073594
Remove redundant \n in tr
Lee-W Sep 8, 2015
469434a
Fix doc error for git-ignore-io
Lee-W Sep 8, 2015
b988558
Fix doc error for git-ignore-io
Lee-W Sep 8, 2015
9b89da3
Merge branch 'master' of https://github.com/Lee-W/git-extras
Lee-W Sep 8, 2015
2c1d766
Modify print_last_modified_time to make it Linux compatible
Lee-W Sep 9, 2015
0393d56
Fix usage error
Lee-W Sep 12, 2015
490d12b
Add full name for list option
Lee-W Sep 12, 2015
61bfc44
Fix ~/.gi_list not exist problem
Lee-W Sep 17, 2015
8d0eae5
Add warning when there is not argument after search, append and export
Lee-W Sep 17, 2015
b517022
Fix typo
Lee-W Sep 18, 2015
88c3437
Remove warning when search without word.
Lee-W Sep 18, 2015
0750551
Remove exclamation mark
Lee-W Sep 18, 2015
37d6012
Replace "export" option with "replace" in git-ignore-io
Lee-W Sep 19, 2015
81e8a45
Update git-ignore-io mannual
Lee-W Sep 20, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- [`git graft`](#git-graft)
- [`git alias`](#git-alias)
- [`git ignore`](#git-ignore)
- [`git ignore-io`](#git-ignore-io)
- [`git info`](#git-info)
- [`git fork`](#git-fork)
- [`git release`](#git-release)
Expand Down Expand Up @@ -408,6 +409,54 @@ build
*.log
```

## git ignore-io

Generate sample gitignore file from [gitignore.io](https://www.gitignore.io)

Without option, `git ignore-io <type>` shows the sample gitignore of specified types on screen.

```bash
$ git ignore-io vim

# Created by https://www.gitignore.io/api/vim

### Vim ###
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
*.un~
Session.vim
.netrwhist
*~
```

To export it to `.gitignore` file you can use the following options:

* `-a` or `--append` to append the result to `.gitignore`
* `-e` or `--export` to replace `.gitignore` with the result

```bash
$ git ignore-io vim python
```

For efficiency, `git ignore-io` store all available typess at `~/.gi_list`.
To list all the available types:

* `-l` or `-L` : These two options will show the list in different format. Just try it.

You can also search type from the list by:

* `-s <word>` or `--search <word>`

```bash
$ git ignore-io -s ja

django
jabref
java
ninja
```


## git info

Show information about the repo:
Expand Down
139 changes: 139 additions & 0 deletions bin/git-ignore-io
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/usr/bin/env bash

gitignore_io_url="https://www.gitignore.io/api/"
default_path="$HOME/.gi_list"

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
echo "$gi_list" | xargs -n $table_width | column -t
}

search() {
for type in $gi_list;
do
if [[ "$type" == *$1* ]]
then
echo "$type"
fi
done
}

print_last_modified_time() {
gi_list_date=$(stat -c "%y" "$default_path" 2> /dev/null)
if [ "$?" -ne 0 ]; then
gi_list_date=$(stat -f "%t%Sm" "$default_path" 2> /dev/null)
if [ "$?" -ne 0 ]; then
gi_list_date=$(date -r "$default_path" +%s 2> /dev/null)
[ "$?" -ne 0 ] && gi_list_date=0
fi
fi
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|--list-in-table] Print available types in table format"
echo " [-L|--list-alphabetically] Print available types in alphabetical order "
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)"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where the list of available types is stored

echo " [-u|--update-list] Update ~/.gi_list"
}


check_list_exist() {
if ! [ -f "$default_path" ]; then
echo "-----Initial gitignore.io list----"
update_gi_list &
echo "-----Save to $default_path-----"
echo
fi
gi_list=$(tr "," "\n" < "$default_path" 2>/dev/null)
}

check_list_exist
if [[ $# -eq 0 ]]; then
show_usage
else
case $1 in
-a|--append|-e|--export)
opt=$1
shift
if [[ $# -eq 0 ]]; then
echo "There should be at least one type!!!"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should remove the exclamation marks here, and on line 177.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean line 80?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

117, sorry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remove the one for search but reserver the one for append and export which I think is needed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe a usage message will suffice, but a warning is okay. But I only meant that you should remove the three exclamation marks.

echo
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)
opt=$1
shift
if [[ $# -eq 0 ]]; then
echo "There should be one word to be searched!!!"
echo
show_usage
exit
fi
search "$2"
;;
-L|--list-alphabetically)
print_in_alphabetical_order
;;
-l|--list-in-table)
print_in_table_format
;;
-*)
echo No Such option
show_usage
;;
*)
gi_to_curl=$(echo "$@" | tr " " ",")
gi "$gi_to_curl"
;;
esac
fi
116 changes: 116 additions & 0 deletions man/git-ignore-io.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-IGNORE\-IO" "1" "September 2015" "" ""
.
.SH "NAME"
\fBgit\-ignore\-io\fR \- Get sample gitignore file
.
.SH "SYNOPSIS"
\fBgit ignore\-io\fR \fIOPTIONS\fR
.
.SH "DESCRIPTION"
Get sample gitignore file from gitignore\.io \fIhttps://www\.gitignore\.io\fR
.
.SH "OPTIONS"
[\-a|\-\-append] \fItypes\fR\.\.\. Append new \.gitignore content to \.gitignore under the current directory
.
.br
[\-e|\-\-export] \fItypes\fR\.\.\. Export new \.gitignore to the current directory (The old one will be replaced)
.
.br
[\-l|\-\-list\-in\-table] Print available types in table format
.
.br
[\-L|\-\-list\-alphabetically] Print available types in alphabetical order
.
.br
[\-s|\-\-search] \fIword\fR Search word in available types
.
.br
[\-t|\-\-show\-update\-time] Show the last modified time of ~/\.gi_list (where the list of available types stored)
.
.br
[\-u|\-\-update\-list] Update ~/\.gi_list
.
.SH "EXAMPLES"
Show sample gitignore file for vim
.
.IP "" 4
.
.nf

$ git ignore\-io vim

# Created by https://www\.gitignore\.io/api/vim

### Vim ###
[\._]*\.s[a\-w][a\-z]
[\._]s[a\-w][a\-z]
*\.un~
Session\.vim
\.netrwhist
*~
.
.fi
.
.IP "" 0
.
.P
Append sample gitignore for vim and python to \.gitignore in current directory\.
.
.IP "" 4
.
.nf

$ git ignore\-io \-a vim python
.
.fi
.
.IP "" 0
.
.P
Show all available types
.
.IP "" 4
.
.nf

$ git ignore\-io \-l

actionscript ada agda android anjuta
appceleratortitanium appcode appengine archives archlinuxpackages
autotools basercms bazel bluej bower
bricxcc c c++ cakephp carthage
\.\.\.\.\.\.
.
.fi
.
.IP "" 0
.
.P
Search ja in all available types
.
.IP "" 4
.
.nf

$ git ignore\-io \-s ja

django
jabref
java
ninja
.
.fi
.
.IP "" 0
.
.SH "AUTHOR"
Written by Lee\-W \fIcl87654321@gmail\.com\fR
.
.SH "REPORTING BUGS"
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
.
.SH "SEE ALSO"
<\fIhttps://github\.com/tj/git\-extras\fR>
Loading