DEV Community

killDevils
killDevils

Posted on

1

Bash | How to source a file from GitHub?

When you are invoking BootStrap in HTML file, don't bother to download related files, just paste the link:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">

Often, for future convenience, I gather all Bash functions created by myself in a single file named funkfunc.sh, so I can source it whenever I need. But, in different projects, I still have to copy the file respectively. In most cases, the hosts are allowed to access Internet, why don't make an online version of funkfunc.sh?

Source a file from a public repo in GitHub

For example, I have a public repo: killDevils/PublicSource, there is a file named "bashKit.sh". When I view the "Raw" file of it, the Browser shows me the link: https://raw.githubusercontent.com/killDevils/PublicSource/master/bashKit.sh

Now, add a line at the top of .sh file (below shebang tag #!/bin/bash):

source <(curl -s https://raw.githubusercontent.com/killDevils/PublicSource/master/bashKit.sh)

Source a file from a PRIVATE repo in GitHub

First, please read my old post:GitHub | Download a file from a Private Repository in GitHub, get to know how to generate the link we need.

For example, The link I got is https://1234abc45678cde6543edca@raw.githubusercontent.com/killDevils/PrivateRepo/master/funkfunc.sh

Now, add a line at the top of .sh file (below shebang tag #!/bin/bash):

source <(curl -s https://1234abc45678cde6543edca@raw.githubusercontent.com/killDevils/PrivateRepo/master/funkfunc.sh)

🍻

Hope this would help! Cheers!

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more