Closed Frodox closed 4 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.
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.
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?
@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() {
}
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.
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.
@scriptum sounds good, I'll accept a PR similar to above that adds a new command 👍
@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.
@scriptum there's no way until https://github.com/Microsoft/vscode/issues/13267 is done
Suggest a toggle button to activate to follow you around placed here
I would be nice if VSCode provide API for that. Not sure that this is possible with extension.
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.
@Tyriar @scriptum I believe Microsoft/vscode#13267 is done. What's next?
It's still only a proposed API, can't use it yet in a shipped extension.
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.
This extension is now deprecated, see https://github.com/Tyriar/vscode-terminal-here/issues/20
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.
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) ?