Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFE: Follow active file in existed terminal #9

Closed
Frodox opened this issue Dec 10, 2017 · 17 comments
Closed

RFE: Follow active file in existed terminal #9

Frodox opened this issue Dec 10, 2017 · 17 comments

Comments

@Frodox
Copy link

Frodox commented Dec 10, 2017

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
Copy link
Owner

Tyriar commented Dec 11, 2017

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
Copy link

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
Copy link
Owner

Tyriar commented Dec 11, 2017

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
Copy link

scriptum commented Dec 11, 2017

@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
Copy link
Owner

Tyriar commented Dec 11, 2017

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

let terminal = vscode.window.createTerminal();

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
Copy link

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
Copy link
Owner

Tyriar commented Dec 14, 2017

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

@scriptum
Copy link

@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
Copy link
Owner

Tyriar commented Dec 15, 2017

@scriptum there's no way until microsoft/vscode#13267 is done

@gertcuykens
Copy link

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

@scriptum
Copy link

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

@Tyriar
Copy link
Owner

Tyriar commented Dec 18, 2017

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
Copy link

johnbendi commented May 30, 2018

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

@Tyriar
Copy link
Owner

Tyriar commented May 30, 2018

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

@con-f-use
Copy link

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
Copy link
Owner

Tyriar commented Aug 12, 2019

This extension is now deprecated, see #20

@Tyriar Tyriar closed this as completed Aug 12, 2019
@macdems
Copy link

macdems commented Aug 14, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants