From 51803f7c747835a66962cc285881c1ac34818d07 Mon Sep 17 00:00:00 2001 From: Shedrack akintayo Date: Fri, 4 Aug 2023 10:58:56 +0100 Subject: [PATCH 1/4] fix --- cmd/goignore/main.go | 2 +- go.mod | 4 ++-- go.sum | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd/goignore/main.go b/cmd/goignore/main.go index 8d8448e..d6fc4a8 100644 --- a/cmd/goignore/main.go +++ b/cmd/goignore/main.go @@ -1,4 +1,4 @@ -//go:generate go run github.com/hacktivist123/goignore +//go:generate go run github.com/hacktivist123/goignore/cmd/goignore package main import ( diff --git a/go.mod b/go.mod index a555f27..2dfe4a0 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,8 @@ require github.com/spf13/cobra v1.7.0 require ( github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.17 // indirect - golang.org/x/sys v0.6.0 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect + golang.org/x/sys v0.10.0 // indirect ) require ( diff --git a/go.sum b/go.sum index 33fab66..8deaf8b 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= @@ -16,5 +18,7 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= +golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 3270ad960db69e440953d2f5a555a0a8b341867c Mon Sep 17 00:00:00 2001 From: Shedrack akintayo Date: Fri, 4 Aug 2023 11:01:58 +0100 Subject: [PATCH 2/4] update readme --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d4c8439..9beb230 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,13 @@ To use `goignore`, you need to have Go (Golang) installed on your system. If you Once you have Go installed, you can install `goignore` using the following command: ```sh -go install github.com/hacktivist123/goignore +go install github.com/hacktivist123/goignore/cmd/goignore ``` +Go pkg: +```sh +go get -u github.com/hacktivist123/goignore/cmd/goignore +``` ## Usage ### Generating .gitignore File To generate a .gitignore file for a specific programming language, you can use the following command: From 07bd86d7d2345b637fe1c5243404894f0a0c22b0 Mon Sep 17 00:00:00 2001 From: Shedrack akintayo Date: Fri, 4 Aug 2023 11:43:13 +0100 Subject: [PATCH 3/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9beb230..86a1be1 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ go install github.com/hacktivist123/goignore/cmd/goignore Go pkg: ```sh -go get -u github.com/hacktivist123/goignore/cmd/goignore +go get -u github.com/hacktivist123/goignore/cmd/goignore@latest ``` ## Usage ### Generating .gitignore File From 18e6c2c443365c6be9a94d4248f44a0e811e5793 Mon Sep 17 00:00:00 2001 From: Kwame Akuamoah-Boateng Date: Fri, 4 Aug 2023 11:57:40 +0000 Subject: [PATCH 4/4] Improve language detection code and add new gitignore files --- cmd/goignore/main.go | 39 ++++++++++++++------- cmd/goignore/templates/c.txt | 52 +++++++++++++++++++++++++++ cmd/goignore/templates/haskell.txt | 23 ++++++++++++ cmd/goignore/templates/ruby.txt | 56 ++++++++++++++++++++++++++++++ cmd/goignore/templates/rust.txt | 14 ++++++++ 5 files changed, 171 insertions(+), 13 deletions(-) create mode 100644 cmd/goignore/templates/c.txt create mode 100644 cmd/goignore/templates/haskell.txt create mode 100644 cmd/goignore/templates/ruby.txt create mode 100644 cmd/goignore/templates/rust.txt diff --git a/cmd/goignore/main.go b/cmd/goignore/main.go index d6fc4a8..7cc0149 100644 --- a/cmd/goignore/main.go +++ b/cmd/goignore/main.go @@ -11,6 +11,17 @@ import ( "github.com/spf13/cobra" ) +var extensions = map[string][]string{ + "golang": {".go"}, + "javascript": {".js", ".ts", ".tsx"}, + "python": {".py"}, + "c++": {".cpp", ".h"}, + "rust": {".rs"}, + "ruby": {".rb"}, + "c": {".c"}, + "haskell": {".hs"}, +} + var language string var autoDetect bool @@ -91,26 +102,28 @@ func detectLanguage() string { } for _, file := range files { - if !file.IsDir() { - ext := filepath.Ext(file.Name()) - if ext == ".go" { - return "golang" - } else if ext == ".js" || ext == ".ts" || ext == ".tsx" { - return "javaScript" - } else if ext == ".py" { - return "python" - } else if ext == ".cpp" || ext == ".h" { - return "c++" + if file.IsDir() { + continue + } + ext := filepath.Ext(file.Name()) + for lang, exts := range extensions{ + for _, e := range exts { + if ext == e { + return lang + } } } } - return "" } func getSupportedLanguages() []string { - // Add any additional supported languages here - return []string{"python", "javascript", "golang", "c++"} + result := []string{} + + for lang := range extensions { + result = append(result, lang) + } + return result } func init() { diff --git a/cmd/goignore/templates/c.txt b/cmd/goignore/templates/c.txt new file mode 100644 index 0000000..c6127b3 --- /dev/null +++ b/cmd/goignore/templates/c.txt @@ -0,0 +1,52 @@ +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf diff --git a/cmd/goignore/templates/haskell.txt b/cmd/goignore/templates/haskell.txt new file mode 100644 index 0000000..4c9e245 --- /dev/null +++ b/cmd/goignore/templates/haskell.txt @@ -0,0 +1,23 @@ +dist +dist-* +cabal-dev +*.o +*.hi +*.hie +*.chi +*.chs.h +*.dyn_o +*.dyn_hi +.hpc +.hsenv +.cabal-sandbox/ +cabal.sandbox.config +*.prof +*.aux +*.hp +*.eventlog +.stack-work/ +cabal.project.local +cabal.project.local~ +.HTF/ +.ghc.environment.* diff --git a/cmd/goignore/templates/ruby.txt b/cmd/goignore/templates/ruby.txt new file mode 100644 index 0000000..e3200e0 --- /dev/null +++ b/cmd/goignore/templates/ruby.txt @@ -0,0 +1,56 @@ +*.gem +*.rbc +/.config +/coverage/ +/InstalledFiles +/pkg/ +/spec/reports/ +/spec/examples.txt +/test/tmp/ +/test/version_tmp/ +/tmp/ + +# Used by dotenv library to load environment variables. +# .env + +# Ignore Byebug command history file. +.byebug_history + +## Specific to RubyMotion: +.dat* +.repl_history +build/ +*.bridgesupport +build-iPhoneOS/ +build-iPhoneSimulator/ + +## Specific to RubyMotion (use of CocoaPods): +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# +# vendor/Pods/ + +## Documentation cache and generated files: +/.yardoc/ +/_yardoc/ +/doc/ +/rdoc/ + +## Environment normalization: +/.bundle/ +/vendor/bundle +/lib/bundler/man/ + +# for a library or gem, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# Gemfile.lock +# .ruby-version +# .ruby-gemset + +# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: +.rvmrc + +# Used by RuboCop. Remote config files pulled in from inherit_from directive. +# .rubocop-https?--* diff --git a/cmd/goignore/templates/rust.txt b/cmd/goignore/templates/rust.txt new file mode 100644 index 0000000..6985cf1 --- /dev/null +++ b/cmd/goignore/templates/rust.txt @@ -0,0 +1,14 @@ +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb