Skip to content

In unsaved new tab with a project root, could $CWD be set to to project root instead of home directory? #26

Description

@vergenzt

I'd like $CWD to be set to the particular folder that the open file is in if available, but if it's not available I'd prefer to try to fall back to the project root first before falling all the way back to the home directory.

Relevant tests:

it('returns the directory of the current file if currentDirectoryKind is set to "currentFile"', () => {
const execContext = new ShellCommandExecContext(fakeWorkspaceAdapter('currentFile'), {env: {}});
assert.deepStrictEqual(execContext.getCwd('DIR/FILE'), 'DIR');
});
it('returns user\'s home directory if currentDirectoryKind is set to "currentFile" but not available', () => {
const execContext = new ShellCommandExecContext(fakeWorkspaceAdapter('currentFile'), {env: {HOME: 'USER_HOME_DIR'}});
assert.deepStrictEqual(execContext.getCwd(), 'USER_HOME_DIR');
});
it('returns project root directory if currentDirectoryKind is set to "workspaceRoot"', () => {
const execContext = new ShellCommandExecContext(fakeWorkspaceAdapter('workspaceRoot', 'PROJECT_ROOT_PATH'), {env: {}});
assert.deepStrictEqual(execContext.getCwd(), 'PROJECT_ROOT_PATH');
});
it('returns user\'s home directory if currentDirectoryKind is set to "workspaceRoot" but not available', () => {
const execContext = new ShellCommandExecContext(fakeWorkspaceAdapter('workspaceRoot'), {env: {HOME: 'USER_HOME_DIR'}});
assert.deepStrictEqual(execContext.getCwd(), 'USER_HOME_DIR');
});

Quick screengrab I recorded demonstrating current behavior:

Screen.Recording.2021-09-09.at.1.22.58.PM.mov

Current result of ^ looks like:

currentFile   -> /Users/tim.vergenz
workspaceRoot -> /Users/tim.vergenz/code/vscode-edit-with-shell

I'd prefer that it look like:

currentFile   -> /Users/tim.vergenz/code/vscode-edit-with-shell
workspaceRoot -> /Users/tim.vergenz/code/vscode-edit-with-shell

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions