Sublime Forum

Can I have GIT push, pull, commit,... in the menu of mouse right click?

#1

Hi. I want to have, when i click my right mouse button on the file that i am editing from my git repository options push, pull, commit, merge…

I am using GIT package in sublime text 3.

Is this possible and how can I achieve this?

Thank you.

0 Likes

#2

You could add an Context.sublime-menu file to your User directory with all the commands you want.

I would cascade all commands into a ‘Git’ menu item. The following example may be a good starting point for you.

[
    {
        "caption": "Git",
        "children":
        [
            {
                    "caption": "Pull",
                    "command": "git_raw", "args": { "command": "git pull" }
            },
            {
                    "caption": "Pull Using Rebase",
                    "command": "git_raw", "args": { "command": "git pull --rebase" }
            },
            { "caption": "-" },
            {
                "caption": "Unstage Current File",
                "command": "git_raw", "args": { "command": "git reset HEAD", "append_current_file": true, "show_in": "suppress" }
            },
            {
                "caption": "Stage Current File",
                "command": "git_raw", "args": { "command": "git stage HEAD", "append_current_file": true, "show_in": "suppress" }
            },
            { "caption": "-" },
            {
                "caption": "Git: Commit",
                "command": "git_commit"
            },
            {
                "caption": "Git: Amend Commit",
                "command": "git_commit_amend"
            },
            {
                "caption": "Git: Quick Commit (current file)",
                "command": "git_quick_commit"
            },
            { "caption": "-" },
            {
        "caption": "Push",
        "command": "git_raw", "args": { "command": "git push", "may_change_files": false }
            }
        ]
    }
]

See here to get a list off all commands supported by git package.

2 Likes

#3

Just to clarify quickly.

In Sublime Text, everything you run is called a command. For example, when you hit ctrl+s, you run the command save, which, you guessed it, saves your file. When you do File → Save, you run the exact same command. Some commands can take arguments (such as edit_settings, the command you run when you select Preferences → Settings. (and plugins creates new commands)

Now, something I love about Sublime Text: everything’s changeable. Menu’s included.

So, a Main.sublime-menu adds items to the main menu (it’s the Main.sublime-menu file contained in the Default Package that sets the File, Edit etc). And every Main.sublime-menu adds up to each other.

But there is also Context.sublime-menu, that, as @deathaxe said, manages the context menu’s items. There is plenty of .sublime-menu in fact (one for the sidebar, the indentation menu, the syntax one, etc).

So, all of them must have the extension .sublime-menu, and all of them are written in JSON. Here’s the structure:

// Whichever .sublime-menu has the following configuration:

// it's a list
[
    {
        "caption": "the title, what you're going to click one",
        "command": "the command to run",
        "args": {
            "the": "arguments",
            "for": "the command"
        }
    },
    {
        "caption": "A sub menu",
        "children": [
            {
                "caption": "in my sub-menu",
                "command": "a command"
            },
            {
                "caption": "in my sub-menu",
                "command": "an other command"
            }
        ]
    }

]

Hope it helped. If you want to learn more, I recommend having a look at the unofical doc

1 Like