sublime_merge icon indicating copy to clipboard operation
sublime_merge copied to clipboard

Show in Terminal and Show in Finder/Explorer/etc buttons

Open chere005 opened this issue 6 years ago • 21 comments

A button on top to quickly navigate to the repo in terminal or file browser

chere005 avatar Oct 25 '18 19:10 chere005

Maybe follow the Enhancement request template? Same as #178 ?

jasonycw avatar Oct 26 '18 01:10 jasonycw

Maybe follow the Enhancement request template? Same as #178 ?

Maybe if the enhancement request template were useful for my requests I would

chere005 avatar Oct 26 '18 02:10 chere005

How about the existing: Menu > Repository > Open Containing Folder ...? It would open the file browser.

Opening Terminal is not yet available.

Remarks: The meaning of "button on top" is unclear to me. Do you want a button in the toolbar?

deathaxe avatar Oct 26 '18 15:10 deathaxe

@jasonycw to be more specific, I would basically be filling out this:

Problem description

There is not "A button on top to quickly navigate to the repo in terminal or file browser"

Preferred solution

Add "A button on top to quickly navigate to the repo in terminal or file browser"

Alternatives

None

Screenshots

I could draw a fake button, but the only useful info above was " Please add a button on top to quickly navigate to the repo in terminal or file browser". I thought it was best to just make my point briefly. Thanks for the comment.

chere005 avatar Oct 26 '18 19:10 chere005

@deathaxe Thanks for pointing out this menu option. It would be good to 1) add this to the command palette, 2) add a button on the top bar (or a setting to add said button in preferences) 3) add these features for terminal as well when possible. It would help a lot, and I'm only a few features away from being able to replace my existing git workflow with Sublime Merge, thus purchasing a license.

chere005 avatar Oct 26 '18 19:10 chere005

Extending the Command Palette or even add key bindings is as easy as in ST, except there is no side-by-side view to see the defaults.

Just add ...

Packages/User/Default.sublime-commands

[
    {
        "caption": "Open Containing Folder…",
        "command": "open_dir",
        "args": { "dir": "$working_dir" },
    },
]

You can have a look at the different *.sublime-menu files in the Default package to get an idea about the available functions.

Note: Not all variables like $commit work in main menu or command palette.

deathaxe avatar Oct 27 '18 09:10 deathaxe

I've just added the missing commands to such Packages/User/Default.sublime-commands

[
    // Start
    {
        "caption": "New Repository",
        "command": "prompt_new_repository"
    },
    {
        "caption": "Clone Repository…",
        "command": "display_clone_page"
    },
    {
        "caption": "Open Repository…",
        "command": "prompt_open_repository"
    },
    {
        "caption": "Select Repository…",
        "command": "quick_open_repository"
    },
    {
        "caption": "Switch Repository…",
        "command": "quick_switch_repository"
    },

    // Repository
    {
        "caption": "Search",
        "command": "toggle_search"
    },
    {
        "caption": "Stage All Modified\tgit stage -A --modified",
        "command": "stage_all_modified"
    },
    {
        "caption": "Repository: Edit .gitattributes…",
        "command": "open_in_editor",
        "args": {
            "path": "$working_dir/.gitattributes", "line": "$line", "col": "$col",
            "default": "# Specify filepatterns you want to assign special attributes.\n\n.git export-ignore\n.gitattributes export-ignore\n.gitignore export-ignore\n\n"
        },
    },
    {
        "caption": "Repository: Edit .gitignore…",
        "command": "open_in_editor",
        "args": {
            "path": "$working_dir/.gitignore", "line": "$line", "col": "$col",
            "default": "# Specify filepatterns you want git to ignore.\n\n"
        },
    },
    {
        "caption": "Open Containing Folder…",
        "command": "open_dir",
        "args": { "dir": "$working_dir" },
    },

    // Preferences
    {
        "caption": "Preferences: Edit Settings…",
        "command": "open_in_editor",
        "args":
        {
            "path": "${packages}/User/Preferences.sublime-settings",
            "default": "// Settings in here override those in \"Default/Preferences.sublime-settings\",\n// and are overridden in turn by syntax-specific settings.\n{\n\n}\n"
        },
    },
    {
        "caption": "Preferences: Edit Commit Message Settings…",
        "command": "open_in_editor",
        "args":
        {
            "path": "${packages}/User/Commit Message.sublime-settings",
            "default": "// Settings in here override those in \"Default/Commit Message.sublime-settings\"\n{\n\n}\n"
        },
    },
    {
        "caption": "Preferences: Browse Packages…",
        "command": "open_dir",
        "args": { "dir": "$packages" },
    }
]

deathaxe avatar Oct 27 '18 09:10 deathaxe

@deathaxe these are great, thanks!

Now I'm trying to figure out how to add open in terminal, which seems to involve a little python when done in SublimeText.

I still think these merit being buttons at the top similar to SourceTree

chere005 avatar Nov 07 '18 04:11 chere005

@chere005 Unfortunately the specifics of your request aren't clear to me. A screenshot would help. It appears you've used other programs that behave this way, so a screenshot of that may be helpful.

In general, "opening a terminal" isn't really very easy to implement cross-platform while supporting many popular terminal editors. The Terminal package for Sublime Text (https://github.com/wbond/sublime_terminal) does this, but from looking at issues, you can see that getting this basic task working isn't exactly trivial. Partially this is because many terminal emulators don't offer a way to just open a specific folder. This results in horrible hacks where you have to use AppleScript to tell Terminal to open a new window and then write commands including cd and clear. Then users want to customize if opening a new terminal means a new window, or a new tab in an existing window.

That said, it may be good to take a step back and understand why you want to open a terminal from Merge. Are you trying to execute git commands that aren't available in Merge, or don't work properly?

wbond avatar Jan 02 '19 15:01 wbond

@wbond really appreciate you taking the time to respond. Just wanted to quickly say Sublime Text is without a doubt my favorite tool.

The screenshot at the top of this page shows the buttons I'm looking for: https://www.sourcetreeapp.com/

In the top right there's "Show in Terminal" and "Show in Finder". I realize on linux this is less straightforward (with all the flavors of DEs etc), and even on windows too. Standard cmd shell usually isn't what people want. Plus, many osx folks would probably prefer that button opens iTerm2 etc. But on OS X I have become very used to hitting these buttons and getting Terminal.app to the directory. And yes, it looks like sourcetree just opens Terminal.app and calls cd, and doesn't bother to clear. I think always being a new window is a fine default behavior. These things don't bother me as a user, but I can see how maintaining it is more annoying. I'm not even convincing myself here as I type that out.. but..

This may be a little out there, but even if I could add it manually to command palette, and if Merge supported dragging commands to the top bar as buttons, then I could drag the button for my specific open a terminal command, as well as customize which other buttons I'd like to have on the top (another one I miss is a Fetch button, but that's probably not for everyone). Then the burden doesn't fall on you to come up with something general, but I realize asking for customizable buttons is a sizeable request.

I can say one of the most common things I will do is hit "show in terminal" then run subl . I just realized I can open in Sublime Text from the command palette, but I still wish it were a button out of habit. But to be quite honest I'm just more used to running a lot of git commands on the command line and I have a ton of aliases stored in my bash_profile. I primarily used SourceTree as a gui to view the graphs in the past, and for the most part I've been happy replacing it with Merge, but these small things interrupt the flow I'm used to. Another reason I may want to switch to the terminal is to run builds/ tests etc.

chere005 avatar Jan 02 '19 17:01 chere005

@chere005 Awesome, thanks for taking the time to reply with an example and info about your workflow. That helps us to think about possible solutions and also to understand if there are workarounds, or if requests are kind of foundational to workflows.

wbond avatar Jan 02 '19 17:01 wbond

For those hoping to find here a way to launch macOS Terminal application at repository path.

  1. Create Default.sublime-commands file at ~/Library/Application Support/Sublime Merge/Packages/User/ unless you already have it.
  2. Add Open Repository in Terminal command
[
    { 
        "caption": "Open Repository in Terminal", 
        "command": "git", 
        "args": {
            "argv": ["openterminalatpath", "$working_dir"]
        }
    }
]
  1. Create git alias by running following command git config --global alias.openterminalatpath '!f() { open -a Terminal "$1" ; }; f'

The new command will be present in Command Palette after restarting Sublime Merge.

wnagrodzki avatar Apr 23 '20 07:04 wnagrodzki

Thank you, this has worked for me! I just changed the alias to open iTerm. :)

iodic avatar Aug 26 '20 12:08 iodic

@wnagrodzki do you have a Windows version? After I added the alias for the git, open command is not a thing in Windows sadly

image

jasonycw avatar Sep 01 '20 04:09 jasonycw

@jasonycw No, I am using macOS only.

wnagrodzki avatar Sep 01 '20 15:09 wnagrodzki

For the time being, can you add the "command": "execute" variety?

This is taking forever (since 2018!) for no reason. While this https://github.com/sublimehq/sublime_merge/issues/186#issuecomment-618228195 is somewhat okay, I don't think it's a suitable workaround for two years.

stdedos avatar Dec 24 '20 20:12 stdedos

To launch a terminal in Windows (at repository path):

If you have Cmder installed (https://cmder.net/), you can

  1. use the following git-alias: openterminalatpath = "!f() { C:\\\\cmder\\\\cmderlauncher.bat $1 ; }; f"
  2. create the following batch-file cmderlauncher.bat:
@echo off
set CMDER_ROOT=%~dp0
%CMDER_ROOT%\vendor\conemu-maximus5\ConEmu.exe /icon "%CMDER_ROOT%\cmder.exe" /title Cmder /loadcfgfile "%CMDER_ROOT%\config\ConEmu.xml" /cmd cmd /k "%CMDER_ROOT%\vendor\init.bat"

Obviously you want to adjust the path to the batch-file in the alias accordingly

gb4711de avatar Dec 31 '20 10:12 gb4711de

With the latest fix from git team, it´s now possible to use get wt git alias in @wnagrodzki ´s solution. See https://forum.sublimetext.com/t/solution-open-repository-in-terminal-windows-terminal-and-others/56972

andrejohansson avatar Apr 07 '21 10:04 andrejohansson

Adding few cents here. It's kinda hard to believe that I have to justify the need for such a feature, but anyway. I'd like to talk about my scenario.

reason I may want to switch to the terminal is to run builds/ tests etc.

Yes and yes. Me too. I'm kinda an old fart who does things in a more traditional way. I may press some big green buttons in Qt Creator or IntelliJ CLion when I feel like it, but for the most of the time I'm chilling with ANSI xterm-256color.

However, it does not stop me from using Sublime Merge. Scrolling through history, quickly editing past commits, merging, rebasing, rearranging — it's all very nice to use. In fact, I often use SM as an entry point for a research and development. Here is my typical workflow:

  • Came in the morning, turned on a laptop. It's cold boot, nothing's running yet. (I don't like the autostart feature, because usually the closer to the evening, the more unrelated stuff I tend to run, including Discord and whatnot. I don't want them now)
  • Start Sublime Text and Sublime Merge.
  • If the project I need are already opened, I'm all good. If not, I can usually find them in the Quick Switch menu. Note: I can always find a recent repo in SM's menu, but not in ST, because ST requires extra work like creating a workspace, storing it somewhere etc., which I usually don't bother with.
  • Some time later found a new repo on GitHub.
    • Copy URL
    • Switch to SM; New tab; URL is already in the source field (magic :star2: ); cloned.
    • Skim through latest commits; then Open in Sublime Text and browse some code.
    • Now it's time to build, test, run etc. This is when I need to switch to a terminal.
    • Currently the shortest path is Open Containing folder, and then in Dolphin (I'm on Linux/KDE) right click > Open Terminal here. By the way, they recently have added a default shortcut for that, I think it was Shift+F4.

And that last step is when Sublime Merge should've kicked in with a build-in command and a pre-defined shortcut to fire up the terminal in one click, to avoid unnecessary interactions and redundant opened windows.

Sometimes the workflow may be opposite though. I may start from the Konsole, navigate to the project's repo directory, and then smerge . && st . — whichever path I choose is entirely circumstantial, and most certainly depends on the current direction of wind and phase of moon. :new_moon_with_face:

ratijas avatar Jun 27 '21 16:06 ratijas

Thanks a ton to @wnagrodzki for explaining how to add this to the command palette. After adding the git global alias, you can also add a key binding this way:

{ "keys": ["super+alt+t"], "command": "git", "args": {"argv": [ "openterminalatpath", "$working_dir" ]}}

nk9 avatar Nov 21 '22 16:11 nk9

@deathaxe Thanks a million. I have been looking the prompt_open_repository for almost 3 hours

SuleymanAli avatar Jun 09 '24 15:06 SuleymanAli