Chào mọi người, lần trước mình có làm cái video nhưng do hệ thống quay của mình cứ lỗi liên tục nên mình cũng đành bó tay . Hôm nay mình ngồi viết code thì nãy ra ý tưởng này cho các anh em newbie (các bạn mới học) và xin các góp ý từ cao nhân luôn. . Mình tạo một project mã nguồn mở về Shell (bạn nào hứng thú thì cứ viết code chung luôn ).
Đây là mã nguồn project của mình (viết bằng java):
Project: TrueShell
File:TrueShell.java
/**True Corporation
*True Java Development Office
*
*TrueShell Project - a shell console application
*Begin in 22 Jan 2016
*Developer: Pham Quoc Hung
*/
//TrueShell - Runtime, traffic and main class
package tdp;
import java.util.*;
import static java.lang.Thread.sleep;
public class TrueShell {
public static void main(String[] args) throws Exception {
Scanner Read = new Scanner (System.in);
fileiolib fLib = new fileiolib();
stdiolib stdio = new stdiolib();
String cmd = "";
String[] key;
String skey;
System.out.println ("True Corporation @ 2016");
System.out.println ("TrueShell Workscape version 0.1$b");
System.out.println ("=================================");
System.out.println ("Loading Libraries..."); sleep(1500);
System.out.println ("Ready");
while (!cmd.equals("exit")) {
System.out.print ("$_/> ");
cmd = Read.next();
switch (cmd){
case "echo" : {
skey = Read.nextLine();
stdio.echo(skey);
} break;
case "exit" : stdio.$sys_exit(); break;
case "end" : stdio.$sys_exit(); break;
case "mkOut" : stdio.$sys_exit(); break;
case "mkExit" : stdio.$sys_exit(); break;
case "$wtf_end" : stdio.$sys_exit(); break;
case "plus" : {
int a = Read.nextInt();
int b = Read.nextInt();
stdio.plus(a,b);
} break;
case "//" : String cmt = Read.nextLine(); break;
case "crt_f" : {
skey = Read.nextLine();
fLib.mkFile(skey);
} break;
case "crt_d" : {
skey=Read.nextLine();
fLib.mkFol(skey);
} break;
case "del_f" : {
skey = Read.nextLine();
if(skey.equals("")) {
fLib.delFile();
} else fLib.delFile(skey);
} break;
case "del_d" : {
skey = Read.nextLine();
if(skey.equals("")) {
fLib.delFol(); }
else fLib.delFol(skey);
} break;
case "dir_f~get" : {
fLib.getfileDir(); break;
}
default: stdio.$er_wrong();
}
}
}
}
File:fileiolib.java
//TrueShell Project Source code
//fileiolib - File and disk storage system interactivities Library
package tdp;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class fileiolib {
private File file, folder;
private String dir, foldir;
void mkFile(String filedir) {
file = new File(filedir);
dir = filedir;
System.out.println (dir);
try {
file.createNewFile();
} catch (IOException ex) {
Logger.getLogger(fileiolib.class.getName()).log(Level.SEVERE, null, ex);
System.out.println("This command has been stopped immerdiately because some reasons");
}
}
void mkFol (String filedir){
folder = new File(filedir);
folder.mkdir();
foldir = filedir;
}
void delFile() {
if (dir != null) {
file = new File(dir);
file.delete();
System.out.println(dir+" has been deleted");
dir = null;
} else System.out.println("File created define not found");
}
void delFile(String filedir) {
file = new File(filedir);
file.delete();
System.out.println(filedir + " has been deleted");
}
void delFol () {
if (foldir != null) {
folder = new File(foldir);
folder.delete();
System.out.println (foldir + " has been deleted");
foldir = null;
} else System.out.println("Folder created define not found");
}
void delFol (String filedir) {
folder = new File (filedir);
folder.delete();
System.out.println(filedir + " has been deleted");
}
void getfileDir () throws IOException {
file = new File("test.vf");
file.createNewFile();
System.out.println(file.getPath()); //tc
System.out.println(file.getParent()); //tcd
}
}
File: stdiolib.java
//TrueShell Project Source Code - Core libraries
//stdiolib - Core library of base commands and analyzers
package tdp;
import static java.lang.Thread.sleep;
public class stdiolib {
void echo(String text){
System.out.println (text);
}
void plus(int a,int b) {
System.out.println(a+b);
}
void $er_wrong() {
System.out.println ("Wrong command or the library contain it is not imported.");
}
void $sys_exit() throws InterruptedException {
System.out.println("Closing and unloading loaded packages and libraries...");
System.out.println("Good bye"); sleep(750); System.exit(0);
}
}