From 6ae6c14c8e51a94af74c27484acfd79fff45a8d1 Mon Sep 17 00:00:00 2001 From: Jacob Wahlgren Date: Sun, 28 Jun 2015 02:25:14 +0200 Subject: [PATCH 1/4] Set $f to active file path in shell Set the environment variable 'f' to the full path of the active file in launched shells. --- lib/atom-terminal.coffee | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/atom-terminal.coffee b/lib/atom-terminal.coffee index f462c67..5ae6398 100644 --- a/lib/atom-terminal.coffee +++ b/lib/atom-terminal.coffee @@ -5,7 +5,7 @@ platform = require('os').platform ### Opens a terminal in the given directory, as specefied by the config ### -open_terminal = (dirpath) -> +open_terminal = (dirpath, filename) -> # Figure out the app and the arguments app = atom.config.get('atom-terminal.app') args = atom.config.get('atom-terminal.args') @@ -30,6 +30,10 @@ open_terminal = (dirpath) -> if platform() == "win32" && !runDirectly cmdline = "start \"\" " + cmdline + # Export filename to $f + if filename? + cmdline = "f=\"#{filename}\" " + cmdline + # log the command so we have context if it fails console.log("atom-terminal executing: ", cmdline) @@ -49,9 +53,12 @@ module.exports = file = editor?.buffer?.file filepath = file?.path if filepath - open_terminal path.dirname(filepath) + open_terminal path.dirname(filepath), filepath openroot: -> - open_terminal pathname for pathname in atom.project.getPaths() + editor = atom.workspace.getActivePaneItem() + file = editor?.buffer?.file + filepath = file?.path + open_terminal pathname, filepath for pathname in atom.project.getPaths() # Set per-platform defaults if platform() == 'darwin' From 10720cfe2ce2dcc7279b5faf1d4b4b14d8648dc4 Mon Sep 17 00:00:00 2001 From: Jacob Wahlgren Date: Sun, 28 Jun 2015 03:28:10 +0200 Subject: [PATCH 2/4] Set $f to file name The full path is not as useful/intuitive on the command line. --- lib/atom-terminal.coffee | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/atom-terminal.coffee b/lib/atom-terminal.coffee index 5ae6398..0d3b4b4 100644 --- a/lib/atom-terminal.coffee +++ b/lib/atom-terminal.coffee @@ -43,22 +43,25 @@ open_terminal = (dirpath, filename) -> else exec cmdline if dirpath? +get_file_name_and_path = -> + editor = atom.workspace.getActivePaneItem() + file = editor?.buffer?.file + path = file?.path + name = file?.getBaseName() + return [name, path] + module.exports = activate: -> atom.commands.add "atom-workspace", "atom-terminal:open", => @open() atom.commands.add "atom-workspace", "atom-terminal:open-project-root", => @openroot() open: -> - editor = atom.workspace.getActivePaneItem() - file = editor?.buffer?.file - filepath = file?.path + [filename, filepath] = get_file_name_and_path() if filepath - open_terminal path.dirname(filepath), filepath + open_terminal path.dirname(filepath), filename openroot: -> - editor = atom.workspace.getActivePaneItem() - file = editor?.buffer?.file - filepath = file?.path - open_terminal pathname, filepath for pathname in atom.project.getPaths() + [filename, filepath] = get_file_name_and_path() + open_terminal pathname, filename for pathname in atom.project.getPaths() # Set per-platform defaults if platform() == 'darwin' From 16765afa31b5394141e2f817ecbbaeb283cd2a4e Mon Sep 17 00:00:00 2001 From: Jacob Wahlgren Date: Sun, 28 Jun 2015 03:32:13 +0200 Subject: [PATCH 3/4] Remove redundant 'return' --- lib/atom-terminal.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/atom-terminal.coffee b/lib/atom-terminal.coffee index 0d3b4b4..8a90b61 100644 --- a/lib/atom-terminal.coffee +++ b/lib/atom-terminal.coffee @@ -48,7 +48,7 @@ get_file_name_and_path = -> file = editor?.buffer?.file path = file?.path name = file?.getBaseName() - return [name, path] + [name, path] module.exports = From 015818c1292ca694b7f175958f7e0bb8001b180d Mon Sep 17 00:00:00 2001 From: Jacob Wahlgren Date: Sun, 28 Jun 2015 12:44:59 +0200 Subject: [PATCH 4/4] Use node.js path module --- lib/atom-terminal.coffee | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/atom-terminal.coffee b/lib/atom-terminal.coffee index 8a90b61..16472e8 100644 --- a/lib/atom-terminal.coffee +++ b/lib/atom-terminal.coffee @@ -43,12 +43,10 @@ open_terminal = (dirpath, filename) -> else exec cmdline if dirpath? -get_file_name_and_path = -> +get_file_path = -> editor = atom.workspace.getActivePaneItem() file = editor?.buffer?.file - path = file?.path - name = file?.getBaseName() - [name, path] + file?.path module.exports = @@ -56,11 +54,12 @@ module.exports = atom.commands.add "atom-workspace", "atom-terminal:open", => @open() atom.commands.add "atom-workspace", "atom-terminal:open-project-root", => @openroot() open: -> - [filename, filepath] = get_file_name_and_path() - if filepath - open_terminal path.dirname(filepath), filename + filepath = get_file_path() + if filepath? + open_terminal path.dirname(filepath), path.basename(filepath) openroot: -> - [filename, filepath] = get_file_name_and_path() + filepath = get_file_path() + filename = path.basename(filepath) open_terminal pathname, filename for pathname in atom.project.getPaths() # Set per-platform defaults