randy3k / Terminus

Bring a real terminal to Sublime Text
https://packagecontrol.io/packages/Terminus
MIT License
1.39k stars 81 forks source link

Task Feature #203

Closed max2max closed 4 years ago

max2max commented 4 years ago

1. Task Feature

I think it's a great idea to add support for task since you may run different commands for different projects respectively. I've achieved this idea by using the plugin https://github.com/mgutski/sublime-run-task. For example, set your run task in <project-name>.sublime-project file as bellow:

    "Run Task.tasks": 
    [
        {
            "name": "Test bash",
            "type": "shell",
            "command": "echo",
            "windows": {
                "command": "D:\\\\msys64\\usr\\bin\\bash.exe",
                "args": "--login -c 'while :;do echo ok && sleep 1;done'"
            }
        },
        {
            "name": "Test terminals",
            "type": "sublime",
            "command": "terminus_open",
            "args" : {
                "cmd" : [
                    "D:\\\\cygwin\\bin\\bash.exe", "--login", "-c",
                    "/usr/bin/bash --login -c 'while :;do echo ok && sleep 1;done'"
                ]
            }
        }
    ]

and press ctrl + shift + p, search Run Task, enter then you will find these two tasks.

2. Cygwin/Msys Tips

Here provide an setup to create cygwin bash at the dir of the current file i think it's very useful Context.sublime-menu

[
    {
        "caption": "Create Terminals",
        "children": [
            {
                "caption": "Create Msys2 Bash In Tab",
                "command": "terminus_open",
                "args": {
                    "cmd": [
                        "D:\\\\Programs\\msys64\\usr\\bin\\bash.exe",
                        "--login", "-c",
                        "/usr/bin/bash --login -c \"cd '\\$(/usr/bin/cygpath -u '${file_path:${folder}}')' && /usr/bin/bash -i\""
                    ],
                    "cwd": "${file_path:${folder}}"
                }
            }
        ]
    }
]

ps: bash -c means execute command and exit, and -c is the only way to pass command we need to run, so we run bash -i within bash -c

Here we need '--login' for two times, that's because with 1 time you can't get path worked so you will get 'command not found error' for both windows and msys commands. And i don't know why.

In vscode you need --login noly 1 time.

randy3k commented 4 years ago

Does build system not work for you?

max2max commented 4 years ago

Sometimes it'll be convenient to customize the task for each project. Build system select for file suffix, while the task work for project, and i think that's the point.

randy3k commented 4 years ago

You could also have project wise build systems.

max2max commented 4 years ago

Alright