Coder Social home page Coder Social logo

reemus-dev / gitnr Goto Github PK

View Code? Open in Web Editor NEW
59.0 3.0 3.0 3.31 MB

Create `.gitignore` files using one or more templates from TopTal, GitHub or your own collection

License: MIT License

PowerShell 1.74% Shell 7.04% Rust 91.22%
cli cross-platform git gitignore gitignore-cli gitignore-files gitignore-generator gitignore-templates rust toptal

gitnr's Introduction

gitnr

A cross-platform CLI utility to create .gitignore files using templates.

  • Use templates from the GitHub & TopTal collections
  • Use local files and remote URLs as templates
  • Filter out duplicate ignore lines when using multiple templates
  • Interactive mode to search and select templates
  • Cross-platform support (Windows, macOS, Linux, NetBSD)
# Create an ignore file for Rust with CLion IDE
gitnr create gh:Rust tt:clion+all

# Interactively search and select templates
gitnr search 

gitnr demo

Table of Contents

Install & Update

Linux & Mac

Run any of the commands below in your terminal to get the latest version of gitnr.

Install system-wide

curl -s https://raw.githubusercontent.com/reemus-dev/gitnr/main/scripts/install.sh | sudo bash -s

Install for current user

curl -s https://raw.githubusercontent.com/reemus-dev/gitnr/main/scripts/install.sh | bash -s -- -u

On Linux this defaults to $HOME/.local/bin and on macOS to $HOME/bin. The script will fail if the directory doesn't exist or is not in your system path.

Install in specific directory

curl -s https://raw.githubusercontent.com/reemus-dev/gitnr/main/scripts/install.sh | bash -s -- -d <dir>

Windows

Run the command below in a PowerShell terminal to install the latest version of gitnr.

Set-ExecutionPolicy Unrestricted -Scope Process; iex (iwr "https://raw.githubusercontent.com/reemus-dev/gitnr/main/scripts/install.ps1").Content

Cargo

Install and compile the latest version from crates.io with the command below.

cargo install gitnr

Cargo Binstall

Install the binary directly using cargo-binstall.

cargo-binstall gitnr

Binary Download

See the releases page to download a binary and then add it to a directory in your system path.

NetBSD

On NetBSD a pre-compiled binary is available from the official repositories. To install it, simply run:

pkgin install gitnr

From Source

git clone --depth=1 github.com/reemus-dev/gitnr
cd gitnr
cargo install --path .

Note: This requires that you have Rust and cargo installed on your system.

Usage

There are 3 commands available

Command Description
create Create a .gitignore file and print the content to stdout or save it to a file
search Interactive mode to search and select templates from the GitHub and TopTal collections. You can then copy the result to your clipboard or copy the relevant create command to generate your ignore file
help Display the CLI help message with available flags & commands

Create

The create command accepts a list of templates to generate a .gitignore file with.

gitnr create [FLAGS] [TEMPLATES]...

Create Template Arguments

Templates can be provided to the CLI as:

  • Space separated or comma separated values
  • With or without their source prefix

The following template sources are available:

Template Sources Prefix
URL url:
File file:
GitHub (a file from any public repo) repo:
GitHub Templates gh:
GitHub Community Templates ghc:
GitHub Global Templates ghg:
TopTal Templates tt:

For example:

# With prefix
gitnr create gh:Node

# Without prefix
gitnr create Node

# Combining templates - a project using Node.js + Vue in WebStorm
gitnr create gh:Node ghc:JavaScript/Vue tt:webstorm+all

# Using a remote URL and local file
gitnr create url:https://domain.com/template.gitignore file:path/to/local.template.gitignore

# Using a file from a GitHub repo
gitnr create repo:github/gitignore/main/Rust.gitignore

If you do not prefix the template, the CLI will try to automatically detect the template source. If it can't match the template name to a source, it defaults to checking the GitHub template collection. It's advised to be explicit about the source prefix to avoid any ambiguity.

Templates from the GitHub and TopTal collections do not need to have the .gitignore, .stack or .patch suffixes. Meaning you can use gh:Rust instead of gh:Rust.gitignore or tt:webstorm+all instead of tt:webstorm+all.patch.

The generated template will be created in the order of the template arguments supplied.

Note

The TopTal template collection includes stacks and patches. A stack specifies multiple ignore templates that are combined, e.g. Angular.stack. The patch extension add modifications to the original template from GitHub's collection.

Create Flags

By default, the resulting .gitignore template is printed to stdout. You can customize this behaviour using the CLI flags available:

Flag Short Description
--save -s Write template to .gitignore file in current directory (overwriting any exiting file)
--file <path> -f <path> Write template to the specified file path overwriting any exiting file
--refresh -r Refresh the template cache (templates are cached for 1 hour by default)

Search

The search command allows you to interactively browse, filter and select templates from the GitHub and Toptal collections.

gitnr search

This is useful when you want to see what's available and preview different template combinations. You will be able to preview an individual template as well as preview a template combination.

The search command only has one flag, which is --refresh | -r. This allows you to refresh the template cache which by default caches the template collections for 1 hour. This is to avoid hitting the API rate-limits.

Why This Exists?

  • I wanted a way to template my .gitignore files for all projects to keep things consistent.
  • I wanted to build a .gitignore from multiple templates to keep things modular
  • I wanted to build something with Rust and learn the language
  • And apparently I wanted to waste more time than I'd like to on a simple side project ๐Ÿ˜…

Contributing

Open a PR or create an issue with any suggestions. Given this is my first Rust application, veterans will probably spot a lot of things that can be improved, refactored or removed. So feel free to open a PR or issue with any suggestions.


Improve your software dev skills by learning from my programming struggles at https://reemus.dev

gitnr's People

Contributors

0323pin avatar realfresh avatar shubhisroking avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gitnr's Issues

bug: crashed while creating gitignore

name = "gitnr"
operating_system = "Ubuntu 22.04 (jammy) [64-bit]"
crate_version = "0.1.3"
explanation = """
Panic occurred in file 'src/commands/search/state/view_preview.rs' at line 9
"""
cause = "called `Result::unwrap()` on an `Err` value: XcbConnect(DisplayParsingError)"
method = "Panic"
backtrace = """

   0: 0x561ff355b2ae - <unresolved>
   1: 0x561ff358cfad - <unresolved>
   2: 0x561ff356a36b - <unresolved>
   3: 0x561ff3561415 - <unresolved>
   4: 0x561ff357e9ef - <unresolved>
   5: 0x561ff34ee5e0 - <unresolved>
   6: 0x561ff355a01b - <unresolved>
   7: 0x561ff357e17a - <unresolved>
   8: 0x7faf261a0d90 - <unresolved>
   9: 0x7faf261a0e40 - __libc_start_main
  10: 0x561ff34ec525 - <unresolved>
  11:        0x0 - <unresolved>"""

`gitnr search` view reacts to both `Press` and `Release` events

In fn handle_key_events (here), the event.kind is not checked with keyboard input.

I think this event is created when pressing and releasing a key, so every key is reacted to twice. Trying to select using enter selects and then unselects, or using arrow keys moves 2 items at a time.

This is on Windows, but looking at the crossterm docs, the event kind needs to be opted-in for unix systems so it might not happen for you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.