Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set environment variable $f to the active filename #62

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions lib/atom-terminal.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)

Expand All @@ -39,19 +43,24 @@ open_terminal = (dirpath) ->
else
exec cmdline if dirpath?

get_file_path = ->
editor = atom.workspace.getActivePaneItem()
file = editor?.buffer?.file
file?.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
if filepath
open_terminal path.dirname(filepath)
filepath = get_file_path()
if filepath?
open_terminal path.dirname(filepath), path.basename(filepath)
openroot: ->
open_terminal pathname for pathname in atom.project.getPaths()
filepath = get_file_path()
filename = path.basename(filepath)
open_terminal pathname, filename for pathname in atom.project.getPaths()

# Set per-platform defaults
if platform() == 'darwin'
Expand Down