Tyriar / vscode-terminal-here

VS Code extensions that creates an integrated terminal session at the current file's directory
https://marketplace.visualstudio.com/items?itemName=Tyriar.vscode-terminal-here
33 stars 11 forks source link

RFE: Follow active file in existed terminal #9

Closed Frodox closed 4 years ago

Frodox commented 6 years ago

Very useful feature --- is it hard to follow directory of active file in last active terminal? Like by hotKey or permanently when file changed (as option) ?

Tyriar commented 6 years ago

It's a bit tough to do as the current working directory of the terminal is not tracked currently. It might be easier once more API is added to VS Code but right now this is definitely out of the scope of this extension.

scriptum commented 6 years ago

Actually @Frodox wanted to say that it would be nice to have an alternative option to send cd "${dir}" command to the current terminal instead of creating a new one.

Tyriar commented 6 years ago

Actually I retract my statement, cd "${dir} would work just fine provided that the directory is absolute.

How would a feature like this work if there are multiple terminals in a single window? Do all of them follow the active file?

scriptum commented 6 years ago

@Tyriar here is my proposal for requested feature. It is very sad that is didn't find a way to do that without altering clipboard. The main idea in possibility of changing cwd of terminal depending on current file you're working on.

'use strict';

import * as vscode from 'vscode';
import path = require('path');
import copy_paste = require('copy-paste');

export function activate(context: vscode.ExtensionContext) {
    let disposable = vscode.commands.registerCommand('terminalHere.cd', () => {
        let editor = vscode.window.activeTextEditor;
        if (!editor) {
            return;
        }

        let document = editor.document;
        if (!document) {
            return;
        }

        let uri = document.uri;
        if (!uri) {
            return;
        }

        let dir = path.dirname(uri.fsPath);

        copy_paste.copy(`cd "${dir}"\n`);
        vscode.commands.executeCommand("workbench.action.terminal.paste");
    });

    context.subscriptions.push(disposable);
}

export function deactivate() {
}
Tyriar commented 6 years ago

Oh I wouldn't want this to happen on any terminal, only the ones that are launched via the extension, you can then send text directly to them by keeping a reference to this terminal object https://github.com/Tyriar/vscode-terminal-here/blob/cc20d67d3e22f63c470ffaa00fcb27cec991219d/src/extension.ts#L24

I'd still like to figure out the UX for what happens when multiple terminals are up before we go ahead with a PR though.

scriptum commented 6 years ago

I'd still like to figure out the UX for what happens when multiple terminals are up before we go ahead with a PR though.

It should behave like what workbench.action.terminal.paste do: send cd <dir of current document> to the current active terminal.

Tyriar commented 6 years ago

@scriptum sounds good, I'll accept a PR similar to above that adds a new command 👍

scriptum commented 6 years ago

@Tyriar I finished implementation but I have to ask a question about better implementation. I'm new in TS ans VS Code API and didn't find better way to sent text into active terminal except using a trick - copy necessary code into system clipboard and paste into terminal. Is there a way to get current active instance of integrated terminal and just use sendText method without altering clipboard? User can be discouraged by discovering cd <somepath> in clibboard 😞

Furthermore in Linux copy-paste module executes external command xclip to place text into clipboard.

Tyriar commented 6 years ago

@scriptum there's no way until https://github.com/Microsoft/vscode/issues/13267 is done

gertcuykens commented 6 years ago

Suggest a toggle button to activate to follow you around placed here image

scriptum commented 6 years ago

I would be nice if VSCode provide API for that. Not sure that this is possible with extension.

Tyriar commented 6 years ago

Yes there is no extension API for that, VS Code doesn't expose many ways to modify UI to keep the editor feeling lightweight even with many extensions.

johnbendi commented 6 years ago

@Tyriar @scriptum I believe Microsoft/vscode#13267 is done. What's next?

Tyriar commented 6 years ago

It's still only a proposed API, can't use it yet in a shipped extension.

con-f-use commented 5 years ago

I'm eagerly waiting for that addition. Surprised it doesn't come with stock VS Code, because it's pretty common in other IDEs, e.g. PyCharm, Eclipse, geany and even gedit.

Tyriar commented 4 years ago

This extension is now deprecated, see https://github.com/Tyriar/vscode-terminal-here/issues/20

macdems commented 3 years ago

I have implemented a simple extension that sends cd command to the active terminal. Take a look at https://marketplace.visualstudio.com/items?itemName=maciejdems.terminal-sync.