Download GitHub Release Assets with a Simple Shell Command
Have you ever found yourself grappling with the task of downloading multiple GitHub release assets from a repository? I recently encountered a situation where I needed to fetch and use assets from an open-source GitHub repository, only to discover that there were more than 30 files to contend with. Fortunately, a clever shell command came to the rescue, simplifying the process and saving the day.
The Challenge
The GitHub release page displayed a plethora of assets, each promising to enhance the functionality of the software I was working on. However, the sheer volume of files presented a formidable challenge – downloading them individually would be time-consuming and tedious. It was at this point that I decided to leverage the power of the command line to automate the process.
Crafting the Solution
Here’s where the magic happened. I devised a concise shell command that tapped into the GitHub API, identified the crucial “browser_download_url” key, and effortlessly downloaded the assets to a folder of my choosing. Let’s break down the command step by step:
curl -s https://api.github.com/repos/username/reponame/releases/release_id \
| grep "browser_download_url" \
| cut -d : -f 2,3 \
| tr -d \" \
| wget --show-progress -qi - -P ./destination
Breaking It Down
-
GitHub API Call:
The command initiates with a call to the GitHub release API for the specific repository and release.
-
Extracting Download URLs:
We use grep to isolate the “browser_download_url” key, honing in on the essential information amidst the API response.
-
Refining the URLs:
The cut command trims the unnecessary parts of the string, leaving us with clean download URLs.
-
Removing Double Quotes:
tr -d " steps in to eliminate any lingering double quotes, ensuring a seamless transition to the next stage.
-
Downloading with wget:
The final flourish involves piping the refined URLs to wget, a versatile tool that pulls in the assets with a visual progress display.
A Visual Transformation
Consider the transformation of the response strings:
"browser_download_url": "https://something.com/something.pdf"
"browser_download_url": "https://something.com/something1.pdf"
"browser_download_url": "https://something.com/something2.pdf"
Becomes:
"https://something.com/something.pdf"
"https://something.com/something1.pdf"
"https://something.com/something2.pdf"
In a stroke, the command simplifies the complex task of downloading multiple assets, providing a streamlined and efficient solution.
Conclusion: BINGO!
With this command in hand, downloading GitHub release assets becomes a breeze. The ability to effortlessly handle a multitude of files not only saves time but also enhances the overall development workflow. So, the next time you find yourself faced with a plethora of GitHub release assets, remember this simple shell command – your shortcut to a smoother, more efficient development experience.
Happy coding! #Impigrity #DRY