├── README.md ├── UnzipAndOpen.java ├── uao.sh └── unzip-and-open.py /README.md: -------------------------------------------------------------------------------- 1 | # A Simple Python Program to Unzip and Open Projects in IntellIJ 2 | -------------------------------------------------------------------------------- /UnzipAndOpen.java: -------------------------------------------------------------------------------- 1 | 2 | // java --enable-preview --source 21 ~/josh-env/bin/UnzipAndOpen.java $HOME/Downloads/demo.zip 3 | 4 | import java.io.*; 5 | import java.util.function.*; 6 | import java.util.* ; 7 | 8 | void main(String[] args) throws Exception { 9 | var zipFile = new File(args[0]); 10 | var zipFileAbsolutePath = zipFile.getAbsolutePath(); 11 | var folder = new File(zipFileAbsolutePath.substring(0, zipFileAbsolutePath.lastIndexOf("."))); 12 | new ProcessBuilder().command("unzip", "-a", zipFileAbsolutePath).inheritIO().start().waitFor(); 13 | for (var k : Set.of("build.gradle", "build.gradle.kts", "pom.xml")) { 14 | var buildFile = new File(folder, k); 15 | if (buildFile.exists()) { 16 | new ProcessBuilder().command("idea", buildFile.getAbsolutePath()).inheritIO().start().waitFor(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /uao.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function run() { 4 | echo "Running: $1" 5 | eval "$1" 6 | } 7 | 8 | if [ $# -lt 2 ]; then 9 | echo "Usage: $0 [--ide=idea|vsc]" 10 | exit 1 11 | fi 12 | 13 | zip_file="$(cd "$(dirname "$1")" && pwd)/$(basename "$1")" 14 | dest_folder="$(cd "$(dirname "$2")" && pwd)/$(basename "$2")" 15 | ide="idea" 16 | 17 | if [ $# -eq 3 ] && [[ $3 == --ide=* ]]; then 18 | ide="${3#*=}" 19 | fi 20 | 21 | if [[ ! $zip_file == *.zip ]]; then 22 | echo "You must specify a .zip file to open." 23 | exit 1 24 | fi 25 | 26 | if [ ! -f "$zip_file" ]; then 27 | echo "The zip file '$zip_file' does not exist." 28 | exit 1 29 | fi 30 | 31 | folder_name="${zip_file%.zip}" 32 | folder_name="$(basename "$folder_name")" 33 | 34 | run "unzip -a \"$zip_file\" -d \"$dest_folder\"" 35 | 36 | project_folder="$dest_folder/$folder_name" 37 | gradle_build="$project_folder/build.gradle" 38 | mvn_pom="$project_folder/pom.xml" 39 | 40 | if [ ! -f "$gradle_build" ] && [ ! -f "$mvn_pom" ]; then 41 | echo "There must be a 'build.gradle' or a 'pom.xml' in the root of the folder '$project_folder'." 42 | exit 1 43 | fi 44 | 45 | if [ -f "$gradle_build" ]; then 46 | if [ "$ide" == "idea" ]; then 47 | run "open -na \"IntelliJ IDEA.app\" --args \"$gradle_build\"" 48 | elif [ "$ide" == "vsc" ] && command -v code >/dev/null 2>&1; then 49 | run "code \"$project_folder\"" 50 | else 51 | echo "The specified IDE ('$ide') is not installed or not found on the PATH." 52 | exit 1 53 | fi 54 | else 55 | if [ "$ide" == "idea" ]; then 56 | run "open -na \"IntelliJ IDEA.app\" --args \"$mvn_pom\"" 57 | elif [ "$ide" == "vsc" ] && command -v code >/dev/null 2>&1; then 58 | run "code \"$project_folder\"" 59 | else 60 | echo "The specified IDE ('$ide') is not installed or not found on the PATH." 61 | exit 1 62 | fi 63 | fi 64 | -------------------------------------------------------------------------------- /unzip-and-open.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import os 4 | import subprocess 5 | import sys 6 | 7 | if __name__ == '__main__': 8 | 9 | def run(c): 10 | print('running: %s' % c) 11 | return subprocess.check_call(c, shell=True) 12 | 13 | assert len(sys.argv) > 1 and sys.argv[1].endswith('.zip'), 'you must specify a .zip file to open.' 14 | zip = os.path.abspath(sys.argv[1]) 15 | assert os.path.exists(zip), 'zip file not found.' 16 | folder_name = zip.split('.')[0] 17 | try: 18 | run('unzip -a %s' % zip) 19 | except: 20 | print("non-zero exit code but we proceed anyway..") 21 | 22 | gradle_build_groovy = os.path.join(folder_name, 'build.gradle') 23 | gradle_build_kotlin = os.path.join (folder_name , 'build.gradle.kts') 24 | mvn_pom = os.path.join(folder_name, 'pom.xml') 25 | success = False 26 | build_files = [ gradle_build_groovy , gradle_build_kotlin , mvn_pom] 27 | 28 | for fn in build_files: 29 | if os.path.exists (fn ) : 30 | run ('idea %s' % fn ) 31 | success = True 32 | assert success , 'valid build file (one of: %s) not found' % ','.join(build_files) 33 | --------------------------------------------------------------------------------