Skip to content

Instantly share code, notes, and snippets.

@nonplus
Last active October 19, 2018 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nonplus/075410ecff106127743ad7bc705d1cf7 to your computer and use it in GitHub Desktop.
Save nonplus/075410ecff106127743ad7bc705d1cf7 to your computer and use it in GitHub Desktop.
Puts a "git branch -b branch-name" on the clipboard where branch-name is based on your initials and issue id

Usage

  • Add the compiled bookmarklet to your browser's bookmarks
  • Go to a YouTrack issue page
  • Click on the bookmarklet
  • An alert shows the git branch command that has been copied to the clipboard

Compiled bookmarklet:

javascript:(function()%7B%24name%20%3D%20document.querySelectorAll('%5Bdata-test%3D%22ring-dropdown%20ring-profile%22%5D')%5B0%5D%3Bissueid%20%3D%20location.pathname.split(%22%2F%22).pop()%20%7C%7C%20%22%22%3Bbranch%20%3D%20%22%22%3Bif%20(%24name%20%26%26%20issueid.match(%2F-%5Cd%2B%24%2F))%20%7Binls%20%3D%20(%24name.title%20%7C%7C%20%22%22).split(%2F%5Cs%2B%2F).map(s%20%3D%3E%20s%5B0%5D%20%7C%7C%20%22%22).join(%22%22).toLowerCase()%3Bbranch%20%3D%20inls%20%2B%20%22%2F%22%20%2B%20issueid%3Bconsole.log(%22branch%3A%20%22%20%2B%20branch)%7D%20else%20%7Bconsole.log(%22could%20not%20create%20branch%20name%22)%7Dif%20(branch)%20%7Bvar%20cb%20%3D%20document.createElement('TEXTAREA')%3Bvar%20cmd%20%3D%20%22git%20checkout%20-b%20%22%20%2B%20branch%3Bcb.value%20%3D%20cmd%3Bdocument.body.appendChild(cb)%3Bcb.select()%3Bdocument.execCommand('copy')%3Bdocument.body.removeChild(cb)%3Balert(cmd)%3B%7D%7D)()

$name = document.querySelectorAll('[data-test="ring-dropdown ring-profile"]')[0];
issueid = location.pathname.split("/").pop() || "";
branch = "";
if ($name && issueid.match(/-\d+$/)) {
inls = ($name.title || "").split(/\s+/).map(s => s[0] || "").join("").toLowerCase();
branch = inls + "/" + issueid;
console.log("branch: " + branch)
} else {
console.log("could not create branch name")
}
if (branch) {
var cb = document.createElement('TEXTAREA');
var cmd = "git checkout -b " + branch;
cb.value = cmd;
document.body.appendChild(cb);
cb.select();
document.execCommand('copy');
document.body.removeChild(cb);
alert(cmd);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment