diff --git a/Commands.md b/Commands.md index bda485a67..b8622826d 100644 --- a/Commands.md +++ b/Commands.md @@ -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) @@ -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 ` 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 ` or `--search ` + +```bash +$ git ignore-io -s ja + + django + jabref + java + ninja +``` + + ## git info Show information about the repo: diff --git a/bin/git-ignore-io b/bin/git-ignore-io new file mode 100755 index 000000000..6b616f2dc --- /dev/null +++ b/bin/git-ignore-io @@ -0,0 +1,137 @@ +#!/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_replace() { + gi "$1" > .gitignore +} + +gi_append() { + gi "$1" >> .gitignore +} + +show_usage() { + echo "Usage:" + echo " git ignore-io ... Show gitignore template" + echo " [-a|--append] ... Append new .gitignore content to .gitignore under the current directory" + echo " [-r|--replace] ... 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] Search word in available types" + echo " [-t|--show-update-time] Show the last modified time of ~/.gi_list (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|-r|--replace) + opt=$1 + shift + if [[ $# -eq 0 ]]; then + echo "There should be at least one type" + echo + show_usage + exit + fi + + gi_to_curl=$(echo "$@" | tr " " ",") + case $opt in + -a|--append) + gi_append "$gi_to_curl" + ;; + -r|--replace) + gi_replace "$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 + 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 diff --git a/man/git-ignore-io.1 b/man/git-ignore-io.1 new file mode 100644 index 000000000..d5b2f082b --- /dev/null +++ b/man/git-ignore-io.1 @@ -0,0 +1,140 @@ +.\" 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 [] +. +.SH "DESCRIPTION" +Get sample gitignore file from gitignore\.io \fIhttps://www\.gitignore\.io\fR +. +.SH "OPTIONS" + +. +.P +\-a, \-\-append \.\.\. +. +.br +Append new \.gitignore content to \.gitignore under the current directory +. +.P +\-r, \-\-replace \.\.\. +. +.br +Export new \.gitignore to the current directory (The old one will be replaced) +. +.P +\-l, \-\-list\-in\-table +. +.br +Print available types in table format +. +.P +\-L, \-\-list\-alphabetically +. +.br +Print available types in alphabetical order +. +.P +\-s, \-\-search +. +.br +Search word in available types +. +.P +\-t, \-\-show\-update\-time +. +.br +Show the last modified time of ~/\.gi_list (where the list of available types is stored) +. +.P +\-u, \-\-update\-list +. +.br +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> diff --git a/man/git-ignore-io.1.html b/man/git-ignore-io.1.html new file mode 100644 index 000000000..bcc311d7c --- /dev/null +++ b/man/git-ignore-io.1.html @@ -0,0 +1,174 @@ + + + + + + git-ignore-io(1) - Get sample gitignore file + + + + +
+ + + +
    +
  1. git-ignore-io(1)
  2. +
  3. +
  4. git-ignore-io(1)
  5. +
+ +

NAME

+

+ git-ignore-io - Get sample gitignore file +

+ +

SYNOPSIS

+ +

git ignore-io [<OPTIONS>]

+ +

DESCRIPTION

+ +

Get sample gitignore file from gitignore.io

+ +

OPTIONS

+ +

<OPTIONS>

+ +

-a, --append <types>...
+ Append new .gitignore content to .gitignore under the current directory

+ +

-r, --replace <types>...
+ Export new .gitignore to the current directory (The old one will be replaced)

+ +

-l, --list-in-table
+ Print available types in table format

+ +

-L, --list-alphabetically
+ Print available types in alphabetical order

+ +

-s, --search <word>
+ Search word in available types

+ +

-t, --show-update-time
+ Show the last modified time of ~/.gi_list (where the list of available types is stored)

+ +

-u, --update-list
+ Update ~/.gi_list

+ +

EXAMPLES

+ +

Show sample gitignore file for vim

+ +
$ 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
+    *~
+
+ +

Append sample gitignore for vim and python to .gitignore in current directory.

+ +
$ git ignore-io -a vim python
+
+ +

Show all available types

+ +
$ git ignore-io -l
+
+    actionscript             ada                      agda                     android                  anjuta
+    appceleratortitanium     appcode                  appengine                archives                 archlinuxpackages
+    autotools                basercms                 bazel                    bluej                    bower
+    bricxcc                  c                        c++                      cakephp                  carthage
+    ......
+
+ +

Search ja in all available types

+ +
$ git ignore-io -s ja
+
+    django
+    jabref
+    java
+    ninja
+
+ +

AUTHOR

+ +

Written by Lee-W cl87654321@gmail.com

+ +

REPORTING BUGS

+ +

<https://github.com/tj/git-extras/issues>

+ +

SEE ALSO

+ +

<https://github.com/tj/git-extras>

+ + +
    +
  1. +
  2. September 2015
  3. +
  4. git-ignore-io(1)
  5. +
+ +
+ + diff --git a/man/git-ignore-io.md b/man/git-ignore-io.md new file mode 100644 index 000000000..8d0edbe21 --- /dev/null +++ b/man/git-ignore-io.md @@ -0,0 +1,94 @@ +git-ignore-io(1) -- Get sample gitignore file +================================ + +## SYNOPSIS + +`git ignore-io` [<OPTIONS>] + +## DESCRIPTION + +Get sample gitignore file from [gitignore.io](https://www.gitignore.io) + +## OPTIONS + + <OPTIONS> + + -a, --append <types>... + Append new .gitignore content to .gitignore under the current directory + + -r, --replace <types>... + Export new .gitignore to the current directory (The old one will be replaced) + + -l, --list-in-table + Print available types in table format + + -L, --list-alphabetically + Print available types in alphabetical order + + -s, --search <word> + Search word in available types + + -t, --show-update-time + Show the last modified time of ~/.gi\_list (where the list of available types is stored) + + -u, --update-list + Update ~/.gi\_list + + +## EXAMPLES +Show sample gitignore file for vim + +```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 + *~ +``` + +Append sample gitignore for vim and python to .gitignore in current directory. + +```bash +$ git ignore-io -a vim python +``` + +Show all available types + +```bash +$ git ignore-io -l + + actionscript ada agda android anjuta + appceleratortitanium appcode appengine archives archlinuxpackages + autotools basercms bazel bluej bower + bricxcc c c++ cakephp carthage + ...... +``` + +Search ja in all available types + +```bash +$ git ignore-io -s ja + + django + jabref + java + ninja +``` + + +## AUTHOR + +Written by Lee-W +## REPORTING BUGS + +<> + +## SEE ALSO + +<>