Skip to content

Commit

Permalink
add row and column numbers as available command replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
formigarafa committed Apr 30, 2017
1 parent 36c0f4c commit 6cc21f4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ values of `env`. They should all be enclosed in curly brackets `{}`
* `{FILE_ACTIVE_PATH}` - Full path to the folder where the currently active file is. E.g. `/home/noseglid/github/atom-build/lib`
* `{FILE_ACTIVE_NAME}` - Full name and extension of active file. E.g., `build.js`
* `{FILE_ACTIVE_NAME_BASE}` - Name of active file WITHOUT extension. E.g., `build`
* `{FILE_ACTIVE_CURSOR_ROW}` - Line number where the last inserted cursor sits. E.g, `21`
* `{FILE_ACTIVE_CURSOR_COLUMN}` - Column number where the last inserted cursor sits. E.g, `42`
* `{PROJECT_PATH}` - Full path to the root of the project. This is normally the path Atom has as root. E.g `/home/noseglid/github/atom-build`
* `{REPO_BRANCH_SHORT}` - Short name of the current active branch (if project is backed by git). E.g `master` or `v0.9.1`
* `{SELECTION}` - Selected text.
Expand Down
3 changes: 3 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ const replace = (value = '', targetEnv) => {
value = value.replace(/{FILE_ACTIVE_NAME}/g, path.basename(activeFile));
value = value.replace(/{FILE_ACTIVE_NAME_BASE}/g, path.basename(activeFile, path.extname(activeFile)));
value = value.replace(/{SELECTION}/g, editor.getSelectedText());
const cursorScreenPosition = editor.getCursorScreenPosition();
value = value.replace(/{FILE_ACTIVE_CURSOR_ROW}/g, cursorScreenPosition.row + 1);
value = value.replace(/{FILE_ACTIVE_CURSOR_COLUMN}/g, cursorScreenPosition.column + 1);
}
value = value.replace(/{PROJECT_PATH}/g, projectPath);
if (atom.project.getRepositories[0]) {
Expand Down
2 changes: 2 additions & 0 deletions spec/build-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ describe('Build', () => {
expect(output.indexOf('FROM_PROCESS_ENV=' + directory + '.atom-build.json')).not.toBe(-1);
expect(output.indexOf('FILE_ACTIVE_NAME=.atom-build.json')).not.toBe(-1);
expect(output.indexOf('FILE_ACTIVE_NAME_BASE=.atom-build')).not.toBe(-1);
expect(output.indexOf('FILE_ACTIVE_CURSOR_ROW=2')).not.toBe(-1);
expect(output.indexOf('FILE_ACTIVE_CURSOR_COLUMN=7')).not.toBe(-1);
expect(output.indexOf('SELECTION=cmd')).not.toBe(-1);
});
});
Expand Down
2 changes: 2 additions & 0 deletions spec/fixture/.atom-build.replace.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"REPO_BRANCH_SHORT={REPO_BRANCH_SHORT}",
"FILE_ACTIVE_NAME={FILE_ACTIVE_NAME}",
"FILE_ACTIVE_NAME_BASE={FILE_ACTIVE_NAME_BASE}",
"FILE_ACTIVE_CURSOR_ROW={FILE_ACTIVE_CURSOR_ROW}",
"FILE_ACTIVE_CURSOR_COLUMN={FILE_ACTIVE_CURSOR_COLUMN}",
"SELECTION={SELECTION}",
"FROM_ENV=$FROM_ENV",
"FROM_PROCESS_ENV=$FROM_PROCESS_ENV"
Expand Down

0 comments on commit 6cc21f4

Please sign in to comment.