Giter Club home page Giter Club logo

Comments (8)

joeblau avatar joeblau commented on May 11, 2024

Those are all great suggestions. Which OS and Shell are you using? I'll have to test it across a few different platforms to make sure I can roll it into everything.

from gitignore.io.

git2samus avatar git2samus commented on May 11, 2024

I use Bash and Linux mostly.

from gitignore.io.

git2samus avatar git2samus commented on May 11, 2024

btw any reason you use curl instead of wget?

from gitignore.io.

joeblau avatar joeblau commented on May 11, 2024

wget is not installed on OSX by default. That would mean that users would have to brew install wget to run the command as listed.

In your first comment what does IFS=, do?

from gitignore.io.

git2samus avatar git2samus commented on May 11, 2024

wget is not installed on OSX by default. That would mean that users would have to brew install wget to run the command as listed.

the same goes for curl in Linux, maybe we could add a check to see which one is installed? something like:

if hash curl; then
    curl "${curl_args[@]}" http://gitignore.io/api/"${gi_args[*]}"
elif hash wget; then
    wget -O- "${curl_args[@]}" http://gitignore.io/api/"${gi_args[*]}"
else
    echo "please install curl or wget to run this command" >&2
    exit 1
fi

In your first comment what does IFS=, do?

IFS is a variable bash uses in several situations, in this case I use it so when the "${gi_args[*]}" array gets expanded bash doesn't separate each term with a space but use a comma instead.

notice that in order to do this I used [*] and not [@] also notice the entire function is enclosed in parenthesis and not braces, this creates a subshell when it's run and that prevents the modification of IFS to leak to the user's environment.

there's other ways to prevent that but this works fine.

from gitignore.io.

joeblau avatar joeblau commented on May 11, 2024

Thanks for the explanation. I feel like I need an advanced section to the site to explain some of these options. My goal was to keep the installation script as simple as possible, but you're showing that there are definitely a lot of use cases that I did not take into account. When I get a few hours, I'll have to try these out and see what would be simplest to implement

Thanks a lot of your input, it's been very helpful.

from gitignore.io.

GeorgeErickson avatar GeorgeErickson commented on May 11, 2024

If you want a one line version for bash.

function gi { curl http://www.gitignore.io/api/$(IFS=, ; echo "$*"); }

from gitignore.io.

git2samus avatar git2samus commented on May 11, 2024

that's a good one, equivalent to the first form proposed (the one without additional arguments for curl/wget)

the command substitution should be quoted tho, otherwise it might break if there's a whitespace literal on any argument, which is unlikely but should be covered I guess

function gi { curl http://www.gitignore.io/api/"$(IFS=, ; echo "$*")"; }

from gitignore.io.

Related Issues (20)

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.