Skip to content

Commit 6c27253

Browse files
Problem Solved
1 parent 3b3238b commit 6c27253

20 files changed

+422
-0
lines changed

README.md

Whitespace-only changes.

installer/mycmd.iss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[Setup]
2+
AppName=MyCMD
3+
AppVersion=1.0
4+
DefaultDirName={pf}\MyCMD
5+
DefaultGroupName=MyCMD
6+
OutputBaseFilename=MyCMD-Installer
7+
SetupIconFile=icons\mycmd.ico
8+
9+
[Files]
10+
Source: "dist\bin\MyCMD.exe"; DestDir: "{app}\bin"
11+
Source: "dist\lib\dependencies.jar"; DestDir: "{app}\lib"
12+
Source: "dist\icons\mycmd.ico"; DestDir: "{app}\icons"
13+
14+
[Icons]
15+
Name: "{group}\MyCMD"; Filename: "{app}\bin\MyCMD.exe"
16+
Name: "{commondesktop}\MyCMD"; Filename: "{app}\bin\MyCMD.exe"
17+
18+
[Run]
19+
Filename: "{app}\bin\MyCMD.exe"; Description: "Launch MyCMD"; Flags: nowait postinstall skipifsilent

pom.xml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
4+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.mycmd</groupId>
8+
<artifactId>MyCMD</artifactId>
9+
<version>1.0</version>
10+
<packaging>jar</packaging>
11+
12+
<name>MyCMD</name>
13+
<description>A custom CMD shell written in Java</description>
14+
15+
<properties>
16+
<maven.compiler.source>17</maven.compiler.source>
17+
<maven.compiler.target>17</maven.compiler.target>
18+
</properties>
19+
20+
<build>
21+
<plugins>
22+
<!-- Creates executable jar -->
23+
<plugin>
24+
<groupId>org.apache.maven.plugins</groupId>
25+
<artifactId>maven-jar-plugin</artifactId>
26+
<version>3.3.0</version>
27+
<configuration>
28+
<archive>
29+
<manifest>
30+
<mainClass>com.mycmd.App</mainClass>
31+
</manifest>
32+
</archive>
33+
</configuration>
34+
</plugin>
35+
</plugins>
36+
</build>
37+
</project>

scripts/build-linux.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
echo "=== Building MyCMD for Linux ==="
3+
4+
mvn clean package
5+
6+
rm -rf dist
7+
mkdir -p dist/bin dist/lib dist/icons
8+
9+
cp target/MyCMD-1.0.jar dist/lib/dependencies.jar
10+
cp icons/mycmd.ico dist/icons/mycmd.ico
11+
12+
# Example jpackage usage
13+
jpackage \
14+
--name MyCMD \
15+
--input dist/lib \
16+
--main-jar dependencies.jar \
17+
--main-class com.mycmd.App \
18+
--icon icons/mycmd.ico \
19+
--type deb \
20+
--dest dist
21+
22+
echo "Build complete. Installer is in dist/"

scripts/build-windows.bat

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@echo off
2+
echo === Building MyCMD for Windows ===
3+
4+
REM Clean and build jar
5+
mvn clean package
6+
7+
REM Create dist structure
8+
rmdir /s /q dist
9+
mkdir dist\bin
10+
mkdir dist\lib
11+
mkdir dist\icons
12+
13+
REM Copy jar + icon
14+
copy target\MyCMD-1.0.jar dist\lib\dependencies.jar
15+
copy icons\mycmd.ico dist\icons\mycmd.ico
16+
17+
echo Build complete. Use Launch4j + Inno Setup to package installer.

src/main/java/com/mycmd/App.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.mycmd;
2+
3+
import com.mycmd.commands.*;
4+
import java.util.*;
5+
6+
public class App {
7+
public static void main(String[] args) {
8+
ShellContext context = new ShellContext();
9+
10+
// Register commands
11+
Map<String, Command> commands = new HashMap<>();
12+
registerCommands(commands);
13+
14+
System.out.println("MyCMD [Version 1.0]");
15+
System.out.println("(c) 2025 MyCMD Organization. All rights reserved.");
16+
17+
Scanner sc = new Scanner(System.in);
18+
19+
while (true) {
20+
System.out.print(context.getCurrentDir().getAbsolutePath() + ">");
21+
String input = sc.nextLine().trim();
22+
if (input.isEmpty()) continue;
23+
24+
String[] parts = input.split("\\s+");
25+
String cmd = parts[0].toLowerCase();
26+
String[] cmdArgs = Arrays.copyOfRange(parts, 1, parts.length);
27+
28+
Command command = commands.get(cmd);
29+
if (command != null) {
30+
try {
31+
command.execute(cmdArgs, context);
32+
} catch (Exception e) {
33+
System.out.println("Error: " + e.getMessage());
34+
}
35+
} else {
36+
System.out.println("'" + cmd + "' is not recognized as an internal or external command.");
37+
}
38+
}
39+
}
40+
41+
private static void registerCommands(Map<String, Command> commands) {
42+
commands.put("dir", new DirCommand());
43+
commands.put("cd", new CdCommand());
44+
commands.put("echo", new EchoCommand());
45+
commands.put("mkdir", new MkdirCommand());
46+
commands.put("rmdir", new RmdirCommand());
47+
commands.put("copy", new CopyCommand());
48+
commands.put("del", new DelCommand());
49+
commands.put("type", new TypeCommand());
50+
commands.put("cls", new ClsCommand());
51+
commands.put("help", new HelpCommand(commands));
52+
commands.put("exit", new ExitCommand());
53+
commands.put("ver", new VersionCommand());
54+
}
55+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.mycmd;
2+
3+
public interface Command {
4+
void execute(String[] args, ShellContext context);
5+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.mycmd;
2+
3+
import java.io.File;
4+
5+
public class ShellContext {
6+
private File currentDir;
7+
8+
public ShellContext() {
9+
this.currentDir = new File(System.getProperty("user.dir"));
10+
}
11+
12+
public File getCurrentDir() {
13+
return currentDir;
14+
}
15+
16+
public void setCurrentDir(File dir) {
17+
this.currentDir = dir;
18+
}
19+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.mycmd.commands;
2+
3+
import com.mycmd.Command;
4+
import com.mycmd.ShellContext;
5+
import java.io.File;
6+
7+
public class CdCommand implements Command {
8+
@Override
9+
public void execute(String[] args, ShellContext context) {
10+
if (args.length == 0) {
11+
System.out.println(context.getCurrentDir().getAbsolutePath());
12+
return;
13+
}
14+
File newDir = new File(args[0]);
15+
if (!newDir.isAbsolute()) {
16+
newDir = new File(context.getCurrentDir(), args[0]);
17+
}
18+
if (newDir.exists() && newDir.isDirectory()) {
19+
context.setCurrentDir(newDir);
20+
} else {
21+
System.out.println("The system cannot find the path specified.");
22+
}
23+
}
24+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.mycmd.commands;
2+
3+
import com.mycmd.Command;
4+
import com.mycmd.ShellContext;
5+
6+
public class ClsCommand implements Command {
7+
@Override
8+
public void execute(String[] args, ShellContext context) {
9+
for (int i = 0; i < 50; i++) {
10+
System.out.println();
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)