├── .gitignore ├── LICENSE.md ├── README.md ├── index.coffee ├── keymaps ├── darwin.cson ├── linux.cson └── win32.cson ├── menus ├── darwin.cson ├── linux.cson └── win32.cson ├── package.json ├── screenshot.png ├── terminal-tab.scpt └── terminal-tab.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Sebastian Tschan 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Open Terminal Here 2 | 3 | Open the Terminal (Mac OS X, Linux) or Command Prompt (Windows) 4 | in the given directory via context menu or keyboard shortcut. 5 | 6 | ![Screenshot of the "Open Terminal Here" menu item displayed][1] 7 | 8 | ## Keyboard shortcuts 9 | 10 | ### Open the Terminal in the current directory 11 | 12 | Platform | Keyboard shortcut 13 | -------- | ----------------- 14 | Mac OS X | `ctrl-cmd-t` 15 | Windows | `ctrl-alt-t` 16 | Linux | `ctrl-alt-t` 17 | 18 | ### Open the Terminal in the project directory 19 | 20 | Platform | Keyboard shortcut 21 | -------- | ----------------- 22 | Mac OS X | `alt-cmd-t` 23 | Windows | `ctrl-alt-shift-t` 24 | Linux | `ctrl-alt-shift-t` 25 | 26 | ## FAQ 27 | 28 | ### How to open a new tab instead of a new window? 29 | 30 | #### Mac OS X 31 | 32 | 1. Open [Automator][2] and select `Application` as new document. 33 | 2. From the Library, add `Run Applescript` as Automator action. 34 | 3. Replace the sample AppleScript code with the code from 35 | [terminal-tab.scpt][3]. 36 | 4. Save the Automator app as `TerminalTab.app` to your Applications folder. 37 | 5. In the `open-terminal-here` settings, set `Command` to 38 | `open -a TerminalTab.app "$PWD"`. 39 | 40 | #### Ubuntu Linux 41 | 42 | 1. Install [xdotool][4]: 43 | `sudo apt-get install -y xdotool` 44 | 2. Download [terminal-tab.sh][5] and make it executable: 45 | `chmod +x ./terminal-tab.sh` 46 | 3. Move the script to a directory in your path: 47 | `sudo mv ./terminal-tab.sh /usr/local/bin/terminal-tab` 48 | 4. In the `open-terminal-here` settings, set `Command` to 49 | `terminal-tab`. 50 | 51 | [1]: https://raw.githubusercontent.com/blueimp/atom-open-terminal-here/master/screenshot.png 52 | [2]: https://en.wikipedia.org/wiki/Automator_(software) 53 | [3]: https://github.com/blueimp/atom-open-terminal-here/blob/master/terminal-tab.scpt 54 | [4]: http://www.semicomplete.com/projects/xdotool/ 55 | [5]: https://raw.githubusercontent.com/blueimp/atom-open-terminal-here/master/terminal-tab.sh 56 | -------------------------------------------------------------------------------- /index.coffee: -------------------------------------------------------------------------------- 1 | ### 2 | * Open Terminal Here - Atom package 3 | * https://github.com/blueimp/atom-open-terminal-here 4 | * 5 | * Copyright 2015, Sebastian Tschan 6 | * https://blueimp.net 7 | * 8 | * Licensed under the MIT license: 9 | * https://opensource.org/licenses/MIT 10 | ### 11 | 12 | getActiveFilePath = () -> 13 | document.querySelector('.tree-view .selected')?.getPath?() || 14 | atom.workspace.getActivePaneItem()?.buffer?.file?.path 15 | 16 | getRootDir = () -> 17 | dirs = atom.project.getDirectories() 18 | defaultPath = dirs[0]?.path 19 | return defaultPath if dirs.length < 2 20 | activeFilePath = getActiveFilePath() 21 | return defaultPath if not activeFilePath 22 | for dir in dirs 23 | return dir.path if activeFilePath.indexOf(dir.path + '/') is 0 24 | defaultPath 25 | 26 | filterProcessEnv = () -> 27 | env = {} 28 | for key, value of process.env 29 | env[key] = value if key not in [ 30 | # Filter out environment variables leaked by the Atom process: 31 | 'NODE_PATH', 'NODE_ENV', 'GOOGLE_API_KEY', 'ATOM_HOME' 32 | ] 33 | env 34 | 35 | open = (filepath) -> 36 | if not filepath 37 | dirpath = getRootDir() 38 | else 39 | fs = require('fs') 40 | try 41 | isFile = fs.lstatSync(fs.realpathSync(filepath)).isFile() 42 | catch 43 | isFile = true 44 | if isFile 45 | dirpath = require('path').dirname(filepath) 46 | else 47 | dirpath = filepath 48 | return if not dirpath 49 | command = atom.config.get 'open-terminal-here.command' 50 | try 51 | require('child_process').exec command, cwd: dirpath, env: filterProcessEnv() 52 | catch error 53 | if error.code is 'EACCES' 54 | message = 'Permission denied to open Terminal at ' + dirpath 55 | atom.notifications.addError message, {dismissable: true} 56 | else 57 | throw error 58 | 59 | switch require('os').platform() 60 | when 'darwin' 61 | defaultCommand = 'open -a Terminal.app "$PWD"' 62 | when 'win32' 63 | defaultCommand = 'start /D "%cd%" cmd' 64 | else 65 | defaultCommand = 'x-terminal-emulator' 66 | 67 | module.exports = 68 | config: 69 | command: 70 | type: 'string' 71 | default: defaultCommand 72 | activate: -> 73 | atom.commands.add '.tree-view .selected, atom-text-editor, atom-workspace', 74 | 'open-terminal-here:open': (event) -> 75 | event.stopImmediatePropagation() 76 | open @getPath?() || @getModel?().getPath?() || getActiveFilePath() 77 | atom.commands.add 'atom-workspace', 78 | 'open-terminal-here:open-root': (event) -> 79 | event.stopImmediatePropagation() 80 | open() 81 | -------------------------------------------------------------------------------- /keymaps/darwin.cson: -------------------------------------------------------------------------------- 1 | '.platform-darwin atom-workspace': 2 | 'ctrl-cmd-t': 'open-terminal-here:open' 3 | 'alt-cmd-t': 'open-terminal-here:open-root' 4 | -------------------------------------------------------------------------------- /keymaps/linux.cson: -------------------------------------------------------------------------------- 1 | '.platform-linux atom-workspace': 2 | 'ctrl-alt-t': 'open-terminal-here:open' 3 | 'ctrl-alt-shift-t': 'open-terminal-here:open-root' 4 | -------------------------------------------------------------------------------- /keymaps/win32.cson: -------------------------------------------------------------------------------- 1 | '.platform-win32 atom-workspace': 2 | 'ctrl-alt-t': 'open-terminal-here:open' 3 | 'ctrl-alt-shift-t': 'open-terminal-here:open-root' 4 | -------------------------------------------------------------------------------- /menus/darwin.cson: -------------------------------------------------------------------------------- 1 | 'context-menu': 2 | '.platform-darwin .tree-view, .platform-darwin atom-text-editor': [ 3 | { 4 | label: 'Open Terminal Here', 5 | command: 'open-terminal-here:open' 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /menus/linux.cson: -------------------------------------------------------------------------------- 1 | 'context-menu': 2 | '.platform-linux .tree-view, .platform-linux atom-text-editor': [ 3 | { 4 | label: 'Open Terminal Here', 5 | command: 'open-terminal-here:open' 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /menus/win32.cson: -------------------------------------------------------------------------------- 1 | 'context-menu': 2 | '.platform-win32 .tree-view, .platform-win32 atom-text-editor': [ 3 | { 4 | label: 'Open Terminal Here', 5 | command: 'open-terminal-here:open' 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "open-terminal-here", 3 | "version": "2.3.2", 4 | "description": "Open the Terminal (OSX, Linux) or Command Prompt (Windows) in the given directory via context menu or keyboard shortcut.", 5 | "activationCommands": { 6 | ".tree-view .selected, atom-text-editor, atom-workspace": [ 7 | "open-terminal-here:open" 8 | ], 9 | "atom-workspace": [ 10 | "open-terminal-here:open-root" 11 | ] 12 | }, 13 | "repository": "https://github.com/blueimp/atom-open-terminal-here", 14 | "license": "MIT", 15 | "engines": { 16 | "atom": ">=1.0.0" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blueimp/atom-open-terminal-here/493df9b71b1958ba82b6b586a3007faeecfdc28a/screenshot.png -------------------------------------------------------------------------------- /terminal-tab.scpt: -------------------------------------------------------------------------------- 1 | (* 2 | * OSX Automator AppleScript to open the input directory in a new Terminal tab 3 | * 4 | * Copyright 2015, Sebastian Tschan 5 | * https://blueimp.net 6 | * 7 | * Licensed under the MIT license: 8 | * https://opensource.org/licenses/MIT 9 | *) 10 | 11 | on run {input} 12 | set dir to quoted form of POSIX path of (input as text) 13 | set inNewTab to (application "Terminal" is running) 14 | tell application "Terminal" 15 | activate 16 | if inNewTab then 17 | tell application "System Events" 18 | tell application process "Terminal" 19 | set frontmost to true 20 | keystroke "t" using command down 21 | end tell 22 | end tell 23 | end if 24 | do script "cd " & dir & ";clear" in front window 25 | end tell 26 | end run 27 | -------------------------------------------------------------------------------- /terminal-tab.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Open a new terminal emulator tab in the current working directory. 5 | # 6 | # Usage: 7 | # ./terminal-tab.sh [-t terminal_emulator] [-w window_name] [-k keystroke] 8 | # 9 | # Requires xdotool: 10 | # http://www.semicomplete.com/projects/xdotool/ 11 | # 12 | # Copyright 2015, Sebastian Tschan 13 | # https://blueimp.net 14 | # 15 | # Licensed under the MIT license: 16 | # https://opensource.org/licenses/MIT 17 | # 18 | 19 | # Keyboard shortcut to open a new terminal emulator tab: 20 | KEYSTROKE='ctrl+shift+t' 21 | # Pattern to identify a terminal emulator window by name: 22 | WINDOW_NAME="$USER@$(hostname)" 23 | # Terminal emulator command: 24 | TERMINAL_EMULATOR='x-terminal-emulator' 25 | 26 | # Parse command-line options: 27 | while getopts t:w:k: opt; do 28 | case $opt in 29 | t) TERMINAL_EMULATOR="$OPTARG" 30 | ;; 31 | w) WINDOW_NAME="$OPTARG" 32 | ;; 33 | k) KEYSTROKE="$OPTARG" 34 | ;; 35 | ?) echo "Usage: $0 [-t terminal_emulator] [-w window_name] [-k keystroke]" 36 | exit 2 37 | ;; 38 | esac 39 | done 40 | 41 | # Search for an open terminal emulator window and bring it into focus: 42 | xdotool search --limit 1 --name "$WINDOW_NAME" windowactivate 43 | 44 | # Check if xdotool found a matching window: 45 | if [ $? -eq 0 ]; then 46 | # Open a new terminal emulator tab in the current working directory: 47 | xdotool key "$KEYSTROKE" \ 48 | type --delay 0 "cd '$(pwd | sed "s/'/'\\\''/g")';clear" && \ 49 | xdotool key Return 50 | else 51 | # Open a new terminal emulator window: 52 | $TERMINAL_EMULATOR 53 | fi 54 | --------------------------------------------------------------------------------