Skip to content

workbench.action.terminal.rename should accept name as an argument #82105

Closed

Description

@vintprox

Currently, workbench.action.terminal.rename command doesn't accept any argument. I wanted to make macros that renames current terminal after performing some other actions.

At the moment, it requires user prompt interaction.

public run(entry?: TerminalEntry): Promise<any> {
const terminalInstance = entry ? entry.instance : this.terminalService.getActiveInstance();
if (!terminalInstance) {
return Promise.resolve(undefined);
}
return this.quickInputService.input({
value: terminalInstance.title,
prompt: nls.localize('workbench.action.terminal.rename.prompt', "Enter terminal name"),
}).then(name => {
if (name) {
terminalInstance.setTitle(name, TitleEventSource.Api);
}
});
}

Activity

  1. vscodebot commented on Oct 8, 2019

    @vscodebot

    (Experimental duplicate detection)
    Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

  2. Tyriar commented on Oct 8, 2019

    @Tyriar
    Contributor
  3. added
    info-needed
    on Oct 8, 2019
  4. vintprox commented on Oct 8, 2019

    @vintprox
    Author

    Daniel Imms (@Tyriar) no, I am using custom fork of macros, which is addressed here. I needed some delays between sending terminal sequences, as provided in this example: geddski/macros#9 (comment)

    Fortunatelly, it solves issues with providing some dynamic input at right time like passphrase (because I couldn't establish SSH without passphrase prompt, unluckily, so I have to use bad technique atm), running console program on remote computer after SSH login, REPL commands to 3DX MQL.

    Thank you for advising fabiospampinato.vscode-terminals extension! I will try it tomorrow on the subject of having right delay between sequences (to replicate macros I've made).

  5. vintprox commented on Oct 8, 2019

    @vintprox
    Author

    I think I know how to make rename command have simple title argument, but it takes a time to contribute here, hehe.

  6. added
    feature-request
    good first issue
    help wanted
    terminal
    and removed
    info-needed
    on Oct 8, 2019
  7. added this to the Backlog milestone on Oct 8, 2019
  8. vijayksingh commented on Oct 16, 2019

    @vijayksingh

    Vint Prox (@vintprox) Daniel Imms (@Tyriar) I would like to help you guys out, can you explain me a little bit, what changes exactly needs to be done.

  9. Tyriar commented on Oct 16, 2019

    @Tyriar
    Contributor

    @perceptron007 right now the rename command is defined here:

    export class RenameTerminalAction extends Action {
    public static readonly ID = TERMINAL_COMMAND_ID.RENAME;
    public static readonly LABEL = nls.localize('workbench.action.terminal.rename', "Rename");
    constructor(
    id: string, label: string,
    @IQuickOpenService protected quickOpenService: IQuickOpenService,
    @IQuickInputService protected quickInputService: IQuickInputService,
    @ITerminalService protected terminalService: ITerminalService
    ) {
    super(id, label);
    }
    public run(entry?: TerminalEntry): Promise<any> {
    const terminalInstance = entry ? entry.instance : this.terminalService.getActiveInstance();
    if (!terminalInstance) {
    return Promise.resolve(undefined);
    }
    return this.quickInputService.input({
    value: terminalInstance.title,
    prompt: nls.localize('workbench.action.terminal.rename.prompt', "Enter terminal name"),
    }).then(name => {
    if (name) {
    terminalInstance.setTitle(name, TitleEventSource.Api);
    }
    });
    }
    }

    I think we need to convert it into a Command to accept an arg like this one:

    export class CreateNewWithCwdTerminalCommand extends Command {
    public static readonly ID = TERMINAL_COMMAND_ID.NEW_WITH_CWD;
    public static readonly LABEL = nls.localize('workbench.action.terminal.newWithCwd', "Create New Integrated Terminal Starting in a Custom Working Directory");
    public static readonly CWD_ARG_LABEL = nls.localize('workbench.action.terminal.newWithCwd.cwd', "The directory to start the terminal at");
    public runCommand(accessor: ServicesAccessor, args: { cwd: string } | undefined): Promise<void> {
    const terminalService = accessor.get(ITerminalService);
    const configurationResolverService = accessor.get(IConfigurationResolverService);
    const workspaceContextService = accessor.get(IWorkspaceContextService);
    const historyService = accessor.get(IHistoryService);
    const activeWorkspaceRootUri = historyService.getLastActiveWorkspaceRoot(Schemas.file);
    const lastActiveWorkspaceRoot = activeWorkspaceRootUri ? withNullAsUndefined(workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined;
    let cwd: string | undefined;
    if (args && args.cwd) {
    cwd = configurationResolverService.resolve(lastActiveWorkspaceRoot, args.cwd);
    }
    const instance = terminalService.createTerminal({ cwd });
    if (!instance) {
    return Promise.resolve(undefined);
    }
    terminalService.setActiveInstance(instance);
    return terminalService.showPanel(true);
    }
    }

  10. vintprox commented on Oct 18, 2019

    @vintprox
    Author

    @perceptron007 Sorry for late response. I made some changes to code, please review it and cover with some test if needed. I'm not ready to make pull request yet, so I derive it to you, guys.

  11. Tyriar commented on Oct 18, 2019

    @Tyriar
    Contributor

    Vint Prox (@vintprox) I would have thought you'd need to convert it to a Command, does passing in the arg in a keybinding work there?

    We want this keybinding to be able to rename the terminal by executing it:

    {
      "key": "cmd+shift+h",
      "command": "workbench.action.terminal.rename",
      "args": {
        "title": "My term"
      }
    }

    Also you can get intellisense for title, see the workbench.action.terminal.newWithCwd command for how to do this:

    image

  12. vintprox commented on Oct 18, 2019

    @vintprox
    Author

    Daniel Imms (@Tyriar)
    Oh, didn't think about that. How do I deal with entry?: TerminalEntry though?
    Made another commit for review that excludes possibly ambiguous argument entry.

  13. Tyriar commented on Oct 18, 2019

    @Tyriar
    Contributor

    Vint Prox (@vintprox) hmm, we may just need to make a new command just like newWithCwd I guess renameActiveTerminal? You're pretty close, you can put a PR out as it will be easier to give feedback there.

  14. vintprox commented on Oct 18, 2019

    @vintprox
    Author

    You are right! I completely forgot what pull requests are for here.

  15. sksaifuddin commented on Oct 30, 2019

    @sksaifuddin

    Hello Vint Prox (@vintprox) did you create the PR ? is this issue resolved ?

  16. vintprox commented on Oct 30, 2019

    @vintprox
    Author

    Uh-oh, I'm kind of busy right now and cannot find a right time. You can make it, if you want to solve the issue!

  17. pjvan commented on Nov 10, 2019

    @pjvan
    Contributor

    Hey, if this issue is open I'd like to pick it up!

  18. vintprox commented on Nov 10, 2019

    @vintprox
    Author

    Of course, why not, proceed! @petevdp
    You can look into my diffs for clues.

  19. added a commit that references this issue on Nov 25, 2019
  20. locked and limited conversation to collaborators on Jan 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

feature-requestgood first issuehelp wantedterminal

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions