├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── build.gradle.kts ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle.kts └── src └── main ├── java ├── actions │ ├── OpenInCurrentDirAction.java │ ├── OpenInModuleDirAction.java │ └── OpenInTerminalAction.java └── settings │ ├── OpenInTerminalSettings.java │ ├── OpenInTerminalSettingsConfigurable.java │ ├── OpenInTerminalSettingsForm.form │ ├── OpenInTerminalSettingsForm.java │ └── OpenInTerminalSettingsState.java └── resources ├── META-INF └── plugin.xml └── string.properties /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | .idea 3 | build -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # OpenInTerminal plugin Changelog 2 | 3 | ## Unreleased 4 | ### Changed 5 | - Plugin migrated to Gradle build system with usage of Kotlin DSL. 6 | 7 | ### Fixed 8 | - Compatibility with Intellij platform version higher than 193. 9 | 10 | ## 1.5.1 11 | ### Fixed 12 | - Minor fix to make it workable on Windows systems. 13 | 14 | ## 1.5.0 15 | ### Added 16 | - Another action added to open terminal in module directory of current file instead of switch in plugin settings. 17 | 18 | ## 1.0.0 19 | ### Added 20 | - Initial version of the plugin. 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## OpenInTerminal plugin 2 | This is plugin for Intellij IDEA IDE. It's provide ability to open terminal with current file location by corresponding action in context menu (in editor and project view). 3 | You can also choose to open terminal in module directory instead of just parent directory of file. 4 | 5 | ## Configuration 6 | Before usage please set command and options for terminal app in plugin settings. 7 | 8 | #### Linux: 9 | 10 | * Terminal command: _gnome-terminal_ 11 | * Options: _--working-directory_ 12 | 13 | #### Windows: 14 | 15 | * Terminal command: _cmd /C start cmd.exe /K_ 16 | * Options: _cd /D_ 17 | 18 | #### Windows (with babun or cygwin): 19 | 20 | * Terminal command: _C:\\.babun\cygwin\bin\mintty.exe_ 21 | * Options: _-i /Cygwin-Terminal.ico C:\\.babun\cygwin\bin\bash.exe -l -c "cd \"$0\" ; exec bash"_ 22 | 23 | #### Mac OS: 24 | 25 | * Terminal command: _open -a Terminal_ 26 | 27 | If you are a Mac OS X user, please make sure that options mentioned in [following post on StackOverflow](http://stackoverflow.com/a/7054045) are enabled. 28 | 29 | For all above configurations directory path will be added at the end of full command. For example full command which will be executed on above Linux configuration will be following: _gnome-terminal_ _--working-directory_ _"path_to_file_or_directory"_. 30 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.changelog.closure 2 | 3 | plugins { 4 | id("java") 5 | id("org.jetbrains.intellij") version "0.7.2" 6 | id("org.jetbrains.changelog") version "1.1.2" 7 | } 8 | 9 | group = "pl.lksztmczk" 10 | version = "2.0.0" 11 | 12 | var platformVersion = "2020.1" 13 | var pluginSinceBuild = "201" 14 | var pluginVerifierIdeVersions = "2020.1.4, 2020.2.4, 2020.3.3, 2021.1" 15 | 16 | repositories { 17 | mavenCentral() 18 | } 19 | 20 | intellij { 21 | pluginName = "Open in terminal" 22 | version = platformVersion 23 | updateSinceUntilBuild = true 24 | } 25 | 26 | changelog { 27 | version = project.version.toString() 28 | unreleasedTerm = "Unreleased" 29 | groups = emptyList() 30 | } 31 | 32 | java { 33 | sourceCompatibility = JavaVersion.VERSION_1_8 34 | targetCompatibility = JavaVersion.VERSION_1_8 35 | } 36 | 37 | tasks { 38 | withType { 39 | options.encoding = "UTF-8" 40 | } 41 | 42 | patchPluginXml { 43 | version(version) 44 | sinceBuild(pluginSinceBuild) 45 | changeNotes( 46 | closure { 47 | changelog.getAll().values.joinToString("\n") { 48 | it.withHeader(true).toHTML() 49 | } 50 | } 51 | ) 52 | } 53 | 54 | runPluginVerifier { 55 | ideVersions(pluginVerifierIdeVersions) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luktom/OpenInTerminal/d8e60ed91333f6aa904bb09c60622db224c1b7f3/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "OpenInTerminal" 2 | -------------------------------------------------------------------------------- /src/main/java/actions/OpenInCurrentDirAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 Łukasz Tomczak . 3 | * 4 | * This file is part of OpenInTerminal plugin. 5 | * 6 | * OpenInTerminal plugin is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * OpenInTerminal plugin is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with OpenInTerminal plugin. If not, see . 18 | */ 19 | package actions; 20 | 21 | import com.intellij.openapi.actionSystem.AnActionEvent; 22 | import com.intellij.openapi.vfs.VirtualFile; 23 | import org.jetbrains.annotations.NotNull; 24 | import settings.OpenInTerminalSettingsState; 25 | 26 | /** 27 | * @author Łukasz Tomczak 28 | */ 29 | public class OpenInCurrentDirAction extends OpenInTerminalAction { 30 | 31 | @NotNull 32 | @Override 33 | protected String getPath(AnActionEvent e, VirtualFile file, OpenInTerminalSettingsState openInTerminalSettingsState) { 34 | return file.isDirectory() ? file.getPath() : file.getParent().getPath(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/actions/OpenInModuleDirAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 Łukasz Tomczak . 3 | * 4 | * This file is part of OpenInTerminal plugin. 5 | * 6 | * OpenInTerminal plugin is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * OpenInTerminal plugin is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with OpenInTerminal plugin. If not, see . 18 | */ 19 | package actions; 20 | 21 | import com.intellij.openapi.actionSystem.AnActionEvent; 22 | import com.intellij.openapi.module.Module; 23 | import com.intellij.openapi.module.ModuleUtil; 24 | import com.intellij.openapi.roots.ModuleRootManager; 25 | import com.intellij.openapi.vfs.VirtualFile; 26 | import org.jetbrains.annotations.NotNull; 27 | import settings.OpenInTerminalSettingsState; 28 | 29 | /** 30 | * @author Łukasz Tomczak 31 | */ 32 | public class OpenInModuleDirAction extends OpenInTerminalAction { 33 | 34 | @NotNull 35 | @Override 36 | protected String getPath(AnActionEvent e, VirtualFile file, OpenInTerminalSettingsState openInTerminalSettingsState) { 37 | Module moduleForFile = ModuleUtil.findModuleForFile(file, e.getProject()); 38 | 39 | if(moduleForFile != null) { 40 | VirtualFile[] contentRoots = ModuleRootManager.getInstance(moduleForFile).getContentRoots(); 41 | if(contentRoots.length > 0) { 42 | return ModuleRootManager.getInstance(moduleForFile).getContentRoots()[0].getPath(); 43 | } 44 | } 45 | 46 | return e.getProject().getBasePath(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/actions/OpenInTerminalAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 Łukasz Tomczak . 3 | * 4 | * This file is part of OpenInTerminal plugin. 5 | * 6 | * OpenInTerminal plugin is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * OpenInTerminal plugin is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with OpenInTerminal plugin. If not, see . 18 | */ 19 | package actions; 20 | 21 | import com.google.common.base.Joiner; 22 | import com.intellij.notification.Notification; 23 | import com.intellij.notification.NotificationType; 24 | import com.intellij.notification.Notifications; 25 | import com.intellij.openapi.actionSystem.AnAction; 26 | import com.intellij.openapi.actionSystem.AnActionEvent; 27 | import com.intellij.openapi.actionSystem.CommonDataKeys; 28 | import com.intellij.openapi.vfs.VirtualFile; 29 | import org.jetbrains.annotations.NotNull; 30 | import settings.OpenInTerminalSettings; 31 | import settings.OpenInTerminalSettingsState; 32 | 33 | import java.io.IOException; 34 | 35 | /** 36 | * @author Łukasz Tomczak 37 | */ 38 | public abstract class OpenInTerminalAction extends AnAction { 39 | 40 | protected static final String ERROR_DURING_OPENING_TERMINAL_MESSAGE = "Error during opening terminal app. You current command for opening terminal is: %s %s. Check if it is correct."; 41 | 42 | protected static final String OPTIONS_NOT_PROVIDED_MESSAGE = "You do not provide needed settings for OpenInTerminal plugin. Please set them before usage."; 43 | 44 | protected static final String NOTIFICATION_DISPLAY_ID = "OpenInTerminal"; 45 | 46 | protected static final String NOTIFICATION_TITLE = "OpenInTerminal plugin"; 47 | 48 | public void actionPerformed(AnActionEvent e) { 49 | 50 | VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE); 51 | 52 | OpenInTerminalSettingsState openInTerminalSettingsState = OpenInTerminalSettings.getInstance().getState(); 53 | 54 | if (openInTerminalSettingsState != null) { 55 | 56 | String directoryPath = getPath(e, file, openInTerminalSettingsState); 57 | 58 | String openTerminalCmd = Joiner.on(" ").join( 59 | openInTerminalSettingsState.getTerminalCommand(), 60 | openInTerminalSettingsState.getTerminalCommandOptions(), 61 | directoryPath); 62 | try { 63 | Runtime.getRuntime().exec(openTerminalCmd); 64 | } catch (IOException e1) { 65 | notifyAboutIncorrectOptions(openInTerminalSettingsState); 66 | } 67 | } else { 68 | notifyAboutUnsetOptions(); 69 | } 70 | } 71 | 72 | @NotNull 73 | protected abstract String getPath(AnActionEvent e, VirtualFile file, OpenInTerminalSettingsState openInTerminalSettingsState); 74 | 75 | @Override 76 | public void update(AnActionEvent e) { 77 | e.getPresentation().setVisible(e.getData(CommonDataKeys.VIRTUAL_FILE) != null); 78 | } 79 | 80 | protected void notifyAboutIncorrectOptions(OpenInTerminalSettingsState openInTerminalSettingsState) { 81 | Notifications.Bus.notify(new Notification(NOTIFICATION_DISPLAY_ID, NOTIFICATION_TITLE, 82 | String.format(ERROR_DURING_OPENING_TERMINAL_MESSAGE, 83 | openInTerminalSettingsState.getTerminalCommand(), 84 | openInTerminalSettingsState.getTerminalCommandOptions()), 85 | NotificationType.ERROR)); 86 | } 87 | 88 | protected void notifyAboutUnsetOptions() { 89 | Notifications.Bus.notify(new Notification(NOTIFICATION_DISPLAY_ID, NOTIFICATION_TITLE, 90 | OPTIONS_NOT_PROVIDED_MESSAGE, 91 | NotificationType.WARNING)); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/settings/OpenInTerminalSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 - 2021 Łukasz Tomczak . 3 | * 4 | * This file is part of OpenInTerminal plugin. 5 | * 6 | * OpenInTerminal plugin is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * OpenInTerminal plugin is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with OpenInTerminal plugin. If not, see . 18 | */ 19 | package settings; 20 | 21 | import com.intellij.openapi.components.*; 22 | import org.jetbrains.annotations.NotNull; 23 | import org.jetbrains.annotations.Nullable; 24 | 25 | /** 26 | * @author Łukasz Tomczak 27 | */ 28 | @State( 29 | name = "OpenInTerminalSettings", 30 | storages = @Storage("openinterminal.xml") 31 | ) 32 | public class OpenInTerminalSettings implements PersistentStateComponent { 33 | 34 | private OpenInTerminalSettingsState openInTerminalSettingsState; 35 | 36 | public static OpenInTerminalSettings getInstance() { 37 | return ServiceManager.getService(OpenInTerminalSettings.class); 38 | } 39 | 40 | @Nullable 41 | @Override 42 | public OpenInTerminalSettingsState getState() { 43 | return openInTerminalSettingsState; 44 | } 45 | 46 | @Override 47 | public void loadState(@NotNull OpenInTerminalSettingsState state) { 48 | openInTerminalSettingsState = state; 49 | } 50 | } -------------------------------------------------------------------------------- /src/main/java/settings/OpenInTerminalSettingsConfigurable.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 Łukasz Tomczak . 3 | * 4 | * This file is part of OpenInTerminal plugin. 5 | * 6 | * OpenInTerminal plugin is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * OpenInTerminal plugin is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with OpenInTerminal plugin. If not, see . 18 | */ 19 | package settings; 20 | 21 | import com.intellij.openapi.options.Configurable; 22 | import com.intellij.openapi.options.ConfigurationException; 23 | import org.jetbrains.annotations.Nls; 24 | import org.jetbrains.annotations.Nullable; 25 | 26 | import javax.swing.*; 27 | 28 | /** 29 | * @author Łukasz Tomczak 30 | */ 31 | public class OpenInTerminalSettingsConfigurable implements Configurable { 32 | 33 | private OpenInTerminalSettingsForm openInTerminalSettingsForm; 34 | 35 | private OpenInTerminalSettings openInTerminalSettings; 36 | 37 | public OpenInTerminalSettingsConfigurable() { 38 | this.openInTerminalSettingsForm = new OpenInTerminalSettingsForm(); 39 | this.openInTerminalSettings = OpenInTerminalSettings.getInstance(); 40 | } 41 | 42 | @Nls 43 | @Override 44 | public String getDisplayName() { 45 | return "OpenInTerminal"; 46 | } 47 | 48 | @Nullable 49 | @Override 50 | public String getHelpTopic() { 51 | return null; 52 | } 53 | 54 | @Nullable 55 | @Override 56 | public JComponent createComponent() { 57 | return openInTerminalSettingsForm.getSettingsPanel(); 58 | } 59 | 60 | @Override 61 | public boolean isModified() { 62 | return !openInTerminalSettingsForm.getSettingsState().equals(openInTerminalSettings.getState()); 63 | } 64 | 65 | @Override 66 | public void apply() throws ConfigurationException { 67 | openInTerminalSettings.loadState(openInTerminalSettingsForm.getSettingsState()); 68 | } 69 | 70 | @Override 71 | public void reset() { 72 | if(openInTerminalSettings.getState() != null) { 73 | openInTerminalSettingsForm.setSettingsState(openInTerminalSettings.getState()); 74 | } 75 | } 76 | 77 | @Override 78 | public void disposeUIResources() { 79 | 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/settings/OpenInTerminalSettingsForm.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 |
53 | -------------------------------------------------------------------------------- /src/main/java/settings/OpenInTerminalSettingsForm.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 Łukasz Tomczak . 3 | * 4 | * This file is part of OpenInTerminal plugin. 5 | * 6 | * OpenInTerminal plugin is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * OpenInTerminal plugin is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with OpenInTerminal plugin. If not, see . 18 | */ 19 | package settings; 20 | 21 | import javax.swing.*; 22 | 23 | /** 24 | * @author Łukasz Tomczak 25 | */ 26 | public class OpenInTerminalSettingsForm { 27 | private JTextField terminalCommand; 28 | 29 | private JTextField terminalCommandOptions; 30 | 31 | private JPanel settingsPanel; 32 | 33 | public JPanel getSettingsPanel() { 34 | return settingsPanel; 35 | } 36 | 37 | public OpenInTerminalSettingsState getSettingsState() { 38 | return new OpenInTerminalSettingsState(terminalCommand.getText(), terminalCommandOptions.getText()); 39 | } 40 | 41 | public void setSettingsState(OpenInTerminalSettingsState settingsState) { 42 | terminalCommand.setText(settingsState.getTerminalCommand()); 43 | terminalCommandOptions.setText(settingsState.getTerminalCommandOptions()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/settings/OpenInTerminalSettingsState.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 Łukasz Tomczak . 3 | * 4 | * This file is part of OpenInTerminal plugin. 5 | * 6 | * OpenInTerminal plugin is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * OpenInTerminal plugin is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with OpenInTerminal plugin. If not, see . 18 | */ 19 | package settings; 20 | 21 | /** 22 | * @author Łukasz Tomczak 23 | */ 24 | public class OpenInTerminalSettingsState { 25 | private String terminalCommand; 26 | 27 | private String terminalCommandOptions; 28 | 29 | public OpenInTerminalSettingsState() { 30 | } 31 | 32 | public OpenInTerminalSettingsState(String terminalCommand, String terminalCommandOptions) { 33 | this.terminalCommand = terminalCommand; 34 | this.terminalCommandOptions = terminalCommandOptions; 35 | } 36 | 37 | public String getTerminalCommand() { 38 | return terminalCommand; 39 | } 40 | 41 | public void setTerminalCommand(String terminalCommand) { 42 | this.terminalCommand = terminalCommand; 43 | } 44 | 45 | public String getTerminalCommandOptions() { 46 | return terminalCommandOptions; 47 | } 48 | 49 | public void setTerminalCommandOptions(String terminalCommandOptions) { 50 | this.terminalCommandOptions = terminalCommandOptions; 51 | } 52 | 53 | @Override 54 | public boolean equals(Object o) { 55 | if (this == o) return true; 56 | if (o == null || getClass() != o.getClass()) return false; 57 | 58 | OpenInTerminalSettingsState that = (OpenInTerminalSettingsState) o; 59 | 60 | if (!terminalCommand.equals(that.terminalCommand)) return false; 61 | return terminalCommandOptions.equals(that.terminalCommandOptions); 62 | 63 | } 64 | 65 | @Override 66 | public int hashCode() { 67 | int result = terminalCommand.hashCode(); 68 | result = 31 * result + terminalCommandOptions.hashCode(); 69 | return result; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/plugin.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | pl.lksztmczk.openinterminal 21 | Open in terminal 22 | Łukasz Tomczak 23 | 24 | 26 | ]]> 27 | 28 | com.intellij.modules.lang 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 38 | 39 | 40 | 41 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/main/resources/string.properties: -------------------------------------------------------------------------------- 1 | openinterminal.settings.terminalCommand=Terminal command 2 | openinterminal.settings.terminalCommandOptions=Options --------------------------------------------------------------------------------