GitHub Commit Hash Copy Bookmarklet
This bookmarklet allows you to quickly copy the latest commit hash from a GitHub project page along with a project-specific prefix.
Code
Create a new bookmark in your browser and paste the following code as the URL:
javascript:(function() {
var str = "!deploy " + [].slice.call(document.querySelectorAll(".text-right > code > a")).pop().innerHTML;
var project = window.location.pathname.split("/")[2];
switch (project) {
case "custom-app":
str += " custom/";
break;
case "another-custom-app":
str += " ac/";
break;
default:
str += " " + project + "/";
}
navigator.clipboard.writeText(str);
})();
How It Works
- Navigate to a GitHub project page.
- Click the bookmark you created.
- The script finds the most recent commit hash on the page.
- Based on the project name, it appends a shorthand (e.g.,
shop/,blog/,custom/). - The final string (like
!deploy abc123 shop/) is copied to your clipboard.
Example
If you are on a repository with the path:
https://github.com/yourusername/shopping-app/commits/main
And the latest commit hash is abc1234, clicking the bookmark will copy:
!deploy abc1234 shop/