How to Add 'Publish to Github' to Windows Context Menu
A comprehensive guide on adding a 'Publish to Github' option to your Windows context menu.
Overview
This guide will help you add a 'Publish to Github' option to your Windows context menu, enabling quick access to publishing directories or files to your GitHub repository.
Where to Create Context Menu Entry?
-
FILES
HKEY_CURRENT_USER\Software\Classes\*\shell\
Opens on a file -
DIRECTORY
HKEY_CURRENT_USER\Software\Classes\Directory\shell
Opens on a directory -
DIRECTORY_BACKGROUND
HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell
Opens on the background of the Directory -
DRIVE
HKEY_CURRENT_USER\Software\Classes\Drive\shell
Opens on the drives (e.g., USBs)
Python Script for Committing
Below is a script to automate the committing process:
import subprocess
import os
import re
import unicodedata
USER_NAMESPACE="YOUR_USER_NAME_HERE"
def slugify(value, allow_unicode=False):
value = str(value)
if allow_unicode:
value = unicodedata.normalize('NFKC', value)
else:
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
value = re.sub(r'[^\w\s-]', '', value)
return re.sub(r'[-\s]+', '-', value).strip('-_')
if os.path.exists(os.path.join(os.getcwd(),'.git')):
print("ERROR: Git repo already exists")
exit(0)
current_folder_name=os.path.basename(os.getcwd())
current_folder_name=slugify(current_folder_name)
subprocess.run('git init -b main')
subprocess.run('git add .')
subprocess.run('git commit -m "Auto Publish"')
cmd='git push --set-upstream git@gitlab.com:'+USER_NAMESPACE+'/'+current_folder_name+'.git main'
subprocess.run(cmd)
print("SUCCESS!")
input()
Adding to Context Menu
Add a context menu item for all directories or files in Windows with these registry files:
For Directories
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\Run Batch script]
@="&Run Batch script"
[HKEY_CLASSES_ROOT\Directory\shell\Run Batch script\command]
@="\"H:\\BATCH_FILE_PATH\\context-batch.bat\" \"%1\""
For Individual Files
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\Run script]
@="Run &script"
[HKEY_CLASSES_ROOT\*\shell\Run script\command]
@="\"H:\\BATCH_FILE_PATH\\context-batch.bat\" \"%1\""
Add to 'Send To' List
Create a shortcut to your batch script and place it under %APPDATA%\Microsoft\Windows\SendTo (or enter shell:sendto into the address bar).
For Directory Background
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\Run Batch script]
@="&Run Batch script"
"Icon"="%SystemRoot%\\System32\\shell32.dll,71"
[HKEY_CLASSES_ROOT\Directory\Background\shell\Run Batch script\command]
@="H:\\BATCH_FILE_PATH\\context-batch.bat \"%V\""
Advanced Context Menu Options
Creating a Basic Context Menu Option
Example: Add an option called Open Command Prompt.
- Create a new
keyunder theshellkey. - Name the
keyas "Open Command Prompt". - Add a subkey named
command. - Set the default value of
commandtocmd.exe.
Adding an Icon
- Add a
String ValuecalledIconto the base key. - Set its value to the path of the
.icofile.
Creating Cascading Context Menus
Create nested context menus:
- Create a base key in the desired location.
- Add a
String ValuecalledMUIVerbwith the base key's display name. - Add a
String Valuenamedsubcommands. - Create a
shellkey under the base key. - Create sub-menus by repeating the steps above.
Repeat these steps to create nested cascading menu options and customize as needed.