Skip to content

Commit b329754

Browse files
authored
Merge pull request #6 from easterapps/fix/default_value_filename_filepath
Added option to set filename or filepath as default text
2 parents 1cd061c + 5749f81 commit b329754

5 files changed

Lines changed: 95 additions & 36 deletions

File tree

README.md

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
- [Use your defined Commands from Status Bar](#use-your-defined-commands-from-status-bar)
1212
- [Use keyboard shortcut for specific defined commands](#use-keyboard-shortcut-for-specific-defined-commands)
1313
- [Use a different shell](#use-a-different-shell)
14-
- [Latest Development Build](#latest-development-build)
1514
- [Contributing](#contributing)
1615

1716
## What is Script Runner
@@ -73,19 +72,21 @@ Sample command definition:
7372
}
7473
```
7574

76-
| Name | Description | Required | Type |
77-
| ------------------- | ----------------------------------------------------------------------------------- | -------- | ------- |
78-
| `identifier` | Identifier used to do key binding. Use alphanumerical and hyphen/underscore only. | yes | string |
79-
| `description` | Description of the command. | yes | string |
80-
| `command` | Command to execute (with variables). | yes | string |
81-
| `working_directory` | The working directory in which to execute the script. | | string |
82-
| `form` | A list of questions to ask in order to obtain values for variables. | | array |
83-
| `variable` | The variable name. | | string |
84-
| `question` | The question to ask the user. | |
85-
| `password` | Input is a password. Default is false. Suggestion: use also show_in_console: false | | boolean |
86-
| `default` | The default value to put in the field. Only for text inputs. | | string |
87-
| `options` | List of options (string) | | array |
88-
| `variables` | List of variables (string) | | array |
75+
| Name | Description | Required | Type |
76+
| ---------------------- | ------------------------------------------------------------------------------------------------------ | -------- | ------- |
77+
| `identifier` | Identifier used to do key binding. Use alphanumerical and hyphen/underscore only. | yes | string |
78+
| `description` | Description of the command. | yes | string |
79+
| `command` | Command to execute (with variables). | yes | string |
80+
| `working_directory` | The working directory in which to execute the script. | | string |
81+
| `form` | A list of questions to ask in order to obtain values for variables. | | array |
82+
| `variable` | The variable name. | | string |
83+
| `question` | The question to ask the user. | | string |
84+
| `password` | Input is a password. Default is false. Suggestion: use also show_in_console: false | | boolean |
85+
| `default` | The default value to put in the field. Only for text inputs. | | string |
86+
| `defaultValuePath` | Overrides the default value with the current file path. Empty if no file open. password option ignored | | boolean |
87+
| `defaultValueFilename` | Overrides the default value with the current filename. Empty if no file open. password option ignored | | boolean |
88+
| `options` | List of options (string) | | array |
89+
| `variables` | List of variables (string) | | array |
8990

9091
## Full Configuration Sample
9192

@@ -127,6 +128,19 @@ Sample command definition:
127128
"default": "Test 1"
128129
}
129130
]
131+
},
132+
{
133+
"identifier": "filepath1",
134+
"description": "Filepath",
135+
"command": "echo $path ",
136+
"working_directory": "$tmp",
137+
"form": [
138+
{
139+
"variable": "$path",
140+
"question": "What is the path",
141+
"defaultValuePath": true
142+
}
143+
]
130144
}
131145
],
132146
"variables": {

package-lock.json

Lines changed: 23 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@
120120
"items": {
121121
"type": "string"
122122
}
123+
},
124+
"defaultValuePath": {
125+
"type": "boolean",
126+
"description": "The default value to put in the field. Only for text inputs.",
127+
"default": false
128+
},
129+
"defaultValueFilename": {
130+
"type": "boolean",
131+
"description": "The default value to put in the field. Only for text inputs.",
132+
"default": false
123133
}
124134
}
125135
}
@@ -151,4 +161,4 @@
151161
"@types/node": "^7.0.43",
152162
"@types/mocha": "^2.2.42"
153163
}
154-
}
164+
}

src/command_runner.ts

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { workspace, window, OutputChannel, TerminalOptions } from "vscode";
33
import { IConfiguration, ICommandConfiguration, IFormConfiguration } from "./configuration";
44
import { VariableManager } from "./variable_manager";
55
import { Terminal } from "./terminal";
6+
var path = require("path");
7+
var vscode = require("vscode");
68

79
export class CommandRunner {
810
private outputChannel: OutputChannel;
@@ -61,6 +63,14 @@ export class CommandRunner {
6163
if (form && form.length > 0) {
6264
let currentStep = 0;
6365
const firstStep = form[currentStep];
66+
let currentlyOpenTabfilePath = ""
67+
let currentlyOpenTabfileName = ""
68+
try {
69+
currentlyOpenTabfilePath = vscode.window.activeTextEditor.document.fileName;
70+
currentlyOpenTabfileName = path.basename(currentlyOpenTabfilePath);
71+
} catch (error) {
72+
73+
}
6474

6575
const askQuestion = (step: IFormConfiguration) => {
6676
if (step.options) {
@@ -69,13 +79,27 @@ export class CommandRunner {
6979
ignoreFocusOut: true,
7080
});
7181
} else {
72-
73-
return window.showInputBox({
74-
prompt: step.question,
75-
value: step.default,
76-
password: step.password,
77-
ignoreFocusOut: true,
78-
});
82+
if (step.defaultValuePath) {
83+
return window.showInputBox({
84+
prompt: step.question,
85+
value: currentlyOpenTabfilePath,
86+
ignoreFocusOut: true,
87+
});
88+
} else {
89+
if (step.defaultValueFilename) {
90+
return window.showInputBox({
91+
prompt: step.question,
92+
value: currentlyOpenTabfileName,
93+
ignoreFocusOut: true,
94+
});
95+
}
96+
return window.showInputBox({
97+
prompt: step.question,
98+
value: step.default,
99+
password: step.password,
100+
ignoreFocusOut: true,
101+
});
102+
}
79103
}
80104
};
81105

src/configuration.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export interface IFormConfiguration {
1818
default?: string;
1919
password?: boolean;
2020
options?: string[];
21+
defaultValuePath?: boolean;
22+
defaultValueFilename?: boolean;
2123
}
2224

2325
export type IVariableConfiguration = { [id: string]: string };

0 commit comments

Comments
 (0)