-
-
Notifications
You must be signed in to change notification settings - Fork 165
GitHub custom hotkeys
A userscript that allows you to add custom GitHub keyboard hotkeys
- Keyboard shortcuts are added using GitHub's "hotkey" method.
- A hotkey will not execute any code, it is set up to only be associated with a URL.
- Custom hotkeys in this userscript can be scoped to specific GitHub URLs so they only work on those pages.
- Adding a definition using this script will override GitHub's built-in hotkeys, so please be aware of this fact!
- It might be best to use a key sequence that GitHub doesn't already use (e.g. g 1, g 2, etc).
- JSON code can be copied from or pasted into this userscript settings panel to make it easy to transfer your hotkeys to and from other computers.
- Definitions set by this userscript are not added to GitHub's "Keyboard shortcuts" panel (opened by pressing ?).
- Click this link to install from GitHub; or, install from GreasyFork or OpenUserJS.
-
Open the settings panel by pressing "F1" (default setting). Feel free to change this hotkey as desired.
-
Or, click on your avatar and select "GitHub Hotkey Settings".
- The help (
?
) button will open this wiki page. - The code (
{}
) button will toggle the view of a textarea containing the JSON code equivalent of the current settings. - The close (
x
) button will save the settings and close the panel.
Each scope block contains:
- An editable label (except for the first block).
- A delete (
x
) button next to the label to completely remove that scope. - A
+ Click to add a new hotkey
button which adds a new hotkey block.
Below the last scope block is a + Click to add a new scope
button to add a new scope block.
Each hotkey block contains:
- A hotkey & URL input.
- A delete (
x
) button to the right of the inputs will remove the hotkey block.
Below the last hotkey block is a + Click to add a new hotkey
button to add a new hotkey block.
- A scope is a grouping of hotkeys that will only be applied to a set URL.
- The "All of GitHub..." scope applies to all GitHub pages and subdomains.
- A custom scope can be added to:
- Target a specific page (e.g.
http://github.com/search
, or{root}/search
using a placeholder). - Target a type of page (e.g.
{repo}/issue
will only apply to the issue pages of the current repository).
- Target a specific page (e.g.
- To add a new scope, click on the
+ Click to add a new scope
button at the bottom of the settings panel. - Click on the
Enter Scope
label to edit the scope. - A scope with an invalid URL will silently fail & any hotkeys within the scope will be ignored.
- Closing the settings panel will update all changes which will be immediately available for use.
- A hotkey is a keyboard key or sequence of keys that when pressed will apply the associated URL.
- Hotkeys can only be added inside a defined scope.
- Hotkeys will not be active outside their scope.
- To add a hotkey, click on the
+ Click to add a new hotkey
button inside the desired scope. - Two inputs will be added for every entry, because a hotkey is a combination of the a keyboard key (or sequence) and a URL.
- Enter any hotkey or sequence of hotkeys. Please review the valid hotkeys section below.
- Enter the target URL (full URL, URL using a placeholder, or hash) to be applied after the sequence has been completed (e.g.
{repo}/issues
- see the valid hotkey URLs section below. - Closing the settings panel will update all changes which will be immediately available for use.
- In the hotkey settings panel header is a code (
{}
) button which will toggle the view of a textarea that contains the current hotkey settings in JSON format. - Copy this JSON to other computers to transfer your desired settings quickly and easily.
- Note: changes to the JSON will only be applied
- If the JSON is valid
- Immediately after content is pasted into the textarea (ctrl or Command v).
- If you want to edit the JSON instead of using the main settings panel, then edit, select all, copy and then repaste the JSON into the textarea.
- To remove a scope, click the delete (
x
) button to the right of the scope label. Thex
will turn red when hovered. - Any hotkeys within the scope will be removed & can not be restored.
- To remove a hotkey block, click the delete (
x
) button to the right of the hotkey inputs. Thex
will turn red when hovered. - Any values within the hotkey and url inputs will be remove & can not be restored.
- To remove all hotkey settings & scopes, click on the code (
{}
) button to reveal the textarea. - Enter
[]
. - All hotkeys & scopes will be removed from the panel.
- Any active hotkeys applied to the page will be removed once the settings panel is closed.
- Only a sequence of hotkeys will work in GitHub's hotkey module; e.g.
g g
means that theg
key is pressed & released, then theg
key is pressed & released again. - More than two hotkeys in the sequence is also valid; e.g.
"g 1 2"
. - Hotkey combinations (e.g.
ctrl+q
) can not be used.
From looking at the source, it appears the following keys are permitted:
backspace, tab, enter, shift, ctrl, alt, pause, capslock, esc, space, pageup, pagedown, end, home, left, up, right, down, insert, del, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, meta, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, *, +, -, ., /, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, numlock, scroll, =, ,, -, ., /, `, [, \, ], '
These keys can be added (as a sequence, not a combo) after an alt, ctrl, meta or shift key.
), !, @, #, $, %, ^, &, *, (, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, :, +, <, _, >, ?, ~, {, |, }, "
Note:
Ok, this is really weird, but it is how GitHub set it up... when you use a modifier key like shift, the modifier key is first pressed then released, followed by the pressing and releasing of the next key.
That being said, this method does not appear to work for the alt key in Windows because pressing that key once takes focus away from the browser window. Pressing it a second time will return focus, but then this appears to break the hotkey sequence.
Your results may vary.
The following placeholders can be used within the hotkey scope & URL.
Placeholder | Description |
---|---|
{root} |
Always points to https://github.com
|
{origin} |
Points to the (sub)domain, e.g on any gist page it will be https://gist.github.com
|
{me} |
Points to your user profile page. This uses your login name. |
{m} |
Contains your user name. |
{user} |
Points to the current user profile page, e.g. https://github.com/Mottie
|
{u} |
Contains the current user name, e.g. Mottie
|
{repo} |
Points to the current repo home page, e.g. https://github.com/Mottie/GitHub-userscripts
|
{r} |
Contains the current repo name, e.g. GitHub-userscripts
|
{tab} |
Points to the current repo tab, e.g. https://github.com/Mottie/GitHub-userscripts/issues
|
{t} |
Contains the current tab name, e.g. issues
|
{upstream} |
Points to the upstream repository only if the current repository is a fork. |
{issue} |
Contains the current issue number, if on an issue page. |
{issue+#} or {issue-#}
|
Gets replaces with the current issue number plus or minus a number. Here are some examples:
|
{page+#} or {page-#}
|
Gets replaces the page search parameter with the page plus or minus a number. Here are some examples:
|
- If the placeholder data doesn't exist, then the URL is considered invalid and associated hotkeys will not be applied.
- For example, if a hotkey is in the "All of GitHub..." scope and can not be defined, then the hotkey will not work; e.g. when the browser is set to
http://github.com
, then the{repo}
placeholder will not be valid and any associated hotkeys will not be active. - Hotkey URLs can also contain hash tags. This userscript opens the settings panel when a
#hotkey-settings
hash exists in the URL.
Any of the following actions will close the custom hotkey settings panel:
- Press Esc.
- Click outside the panel.
- Click the close (
x
) key in the header.
Before the panel disappears, all settings are saved. So do not close the browser tab if any changes were made to these settings.
Here is a basic hotkey example (paste this JSON into the code window)
{
"all": [
{ "f1" : "#hotkey-settings" },
{ "g g": "{repo}/graphs/code-frequency" },
{ "g p": "{repo}/pulse" },
{ "g u": "{user}" },
{ "g s": "{upstream}" }
],
"{repo}/issues": [
{ "g right": "{issue+1}" },
{ "g left": "{issue-1}" }
],
"{root}/search": [
{ "g right": "{page+1}" },
{ "g left": "{page-1}" }
]
}
- The
"all"
scope refers to hotkeys that are applied to all GitHub pages, including subdomains. - The "f1" entry opens the hotkeys settings panel for this userscript; alternatively, click on your avatar in the upper right corner and select "GitHub Hotkey Settings".
- The first entry
"g g"
is the sequence of g followed by another g key pressed and released separately. Use a space between key definitions if more than one hotkey is added. - The second entry
"g p"
is already set by GitHub as a hotkey that goes to the current repository's pull request page. This setting will override the original and the key sequence will go to the pulse page instead. -
"g u"
points to the owner of the current repo. Use a{me}
placeholder instead of{user}
to point to your own profile page. - The
"g s"
hotkey example will only work when viewing a forked repository, otherwise the{upstream}
hotkey sequence will not be active. - There are special placeholders in the custom scopes:
-
{issue+#}
and{issue-#}
- these placeholders will only work on issue pages, allowing incrementing or decrementing the current issue number. It can not determine if the targeted issue is open or closed. -
{page+#}
and{page-#}
- these placeholders only work when a search query (?q=
) is active in the current URL. It increments or decrements the result page number.
-
- Update header selector.
- Update GitHub icon.
- Update reserved names list.
- Update reserved names list.
- Fix default graph code link.
- Update reserved names list.
- Update reserved names list.
- Update reserved names list.
- Update reserved names list.
- Update reserved names list.
- Update reserved names list.
- Add build for reserved names & update.
- Update GitHub reserved names.
- Fix JSON selection.
- Prevent wrapping on zoom.
- Update assets.
- Update reserved names
- Prevent reserved name partial matches. Fixes issue #26.
- Fix the "{me}" reference. See issue #26.
- Fix other placeholder issues
- Pull requests are now treated as an issue.
- Extract
page=#
orp=#
from query string.
- Include reserved names version.
- Update to use new header class.
- Update list of reserved (non-user) pages
- Change license to MIT.
- Add additional non-user pages.
- Fix linting.
- Add additional non-user page.
- Convert to ES6 & beautify.
- More ES6 cleanup.
- Fix JS error on pages with no header.
- Correct default settings. Fixes issue #3.
- Add another non-user page.
- Add more non-user pages.
- Add missing comma!
- Add more non-user pages.
- Add more to the list of non-user pages (e.g. "github.com/contact").
- Initial commit