diff options
Diffstat (limited to 'Source/Applications/Shell')
-rw-r--r-- | Source/Applications/Shell/Applets/pwd.cpp | 15 | ||||
-rw-r--r-- | Source/Applications/Shell/Makefile | 3 | ||||
-rw-r--r-- | Source/Applications/Shell/Shell-fs.class.cpp | 31 | ||||
-rw-r--r-- | Source/Applications/Shell/Shell.class.cpp | 31 | ||||
-rw-r--r-- | Source/Applications/Shell/Shell.class.h | 3 |
5 files changed, 41 insertions, 42 deletions
diff --git a/Source/Applications/Shell/Applets/pwd.cpp b/Source/Applications/Shell/Applets/pwd.cpp new file mode 100644 index 0000000..4b27eb0 --- /dev/null +++ b/Source/Applications/Shell/Applets/pwd.cpp @@ -0,0 +1,15 @@ +#include <App/ShellApp.proto.h> +#include <Binding/FSNode.class.h> + +class pwd : public ShellApp { + public: + pwd() : ShellApp("pwd", "Shows the current directory") { + addFlag("f", "frugal", "Do not show 'Current directory: ' prefix", FT_BOOL, ""); + } + int run() { + if (!bFlag("frugal")) outvt << "Current directory: "; + outvt << FS::cwdNode().path() << ENDL; + } +}; + +APP(pwd); diff --git a/Source/Applications/Shell/Makefile b/Source/Applications/Shell/Makefile index 1bce0f4..dff539c 100644 --- a/Source/Applications/Shell/Makefile +++ b/Source/Applications/Shell/Makefile @@ -10,7 +10,8 @@ Objects = Shell.class.o \ Shell-fs.class.o OutFile = Shell -Applets = Applets/cat Applets/halt Applets/reboot Applets/uptime Applets/free Applets/ls +Applets = Applets/cat Applets/halt Applets/reboot Applets/uptime Applets/free Applets/ls \ + Applets/pwd all: $(OutFile) $(Applets) echo "* Done with $(OutFile)." diff --git a/Source/Applications/Shell/Shell-fs.class.cpp b/Source/Applications/Shell/Shell-fs.class.cpp index bb1990d..7607f34 100644 --- a/Source/Applications/Shell/Shell-fs.class.cpp +++ b/Source/Applications/Shell/Shell-fs.class.cpp @@ -2,26 +2,6 @@ #include <TextFile.class.h> #include <Binding/Process.class.h> -void Shell::cd(Vector<String>& args) { - if (args.size() != 2) { - outvt << "Invalid argument count.\n"; - } else { - FSNode ncwd = FS::find(args[1], cwd); - if (!ncwd.valid()) { - outvt << "No such directory : " << args[1] << "\n"; - } else if (ncwd.type() == NT_DIRECTORY) { - ncwd.setCwd(); - cwd = ncwd; - } else { - outvt << "Not a directory.\n"; - } - } -} - -void Shell::pwd(Vector<String>& args) { - outvt << "Current directory : " << cwd.path() << "\n"; -} - void Shell::rm(Vector<String>& args) { if (args.size() == 1) outvt << "No file to remove.\n"; for (u32int i = 1; i < args.size(); i++) { @@ -59,14 +39,3 @@ void Shell::wf(Vector<String>& args) { } } -void Shell::run(Vector<String>& args) { - if (args.size() == 1) { - outvt << "Nothing to run...\n"; - } else { - Vector<String> appargs; - for (u32int i = 1; i < args.size(); i++) appargs.push(args[i]); - if (!appRun(args[1], appargs)) { - outvt << "Error while launching process.\n"; - } - } -} diff --git a/Source/Applications/Shell/Shell.class.cpp b/Source/Applications/Shell/Shell.class.cpp index 1b7f25e..971b913 100644 --- a/Source/Applications/Shell/Shell.class.cpp +++ b/Source/Applications/Shell/Shell.class.cpp @@ -23,12 +23,9 @@ int Shell::run() { String name; void (Shell::*cmd)(Vector<String>&); } commands[] = { - {"cd", &Shell::cd}, - {"pwd", &Shell::pwd}, {"rm", &Shell::rm}, {"mkdir", &Shell::mkdir}, {"wf", &Shell::wf}, - {"run", &Shell::run}, {"", 0} }; @@ -70,6 +67,7 @@ int Shell::run() { } } + //Look for variables to replace for (u32int i = 0; i < cmd.size(); i++) { if (cmd[i][0] == WChar("$")) { String k = cmd[i].substr(1); @@ -82,7 +80,7 @@ int Shell::run() { } //Run command - if (cmd[0] == "exit") { + if (cmd[0] == "exit") { // * * * INTEGRATED COMMANDS * * * // if (cmd.size() == 1) return 0; return cmd[1].toInt(); } else if (cmd[0] == "help") { @@ -98,7 +96,21 @@ int Shell::run() { outvt << cmd[i]; } outvt << ENDL; - } else { + } else if (cmd[0] == "cd") { + if (cmd.size() != 2) { + outvt << "Invalid argument count.\n"; + } else { + FSNode ncwd = FS::find(cmd[1], cwd); + if (!ncwd.valid()) { + outvt << "No such directory : " << cmd[1] << ENDL; + } else if (ncwd.type() != NT_DIRECTORY) { + outvt << "Not a directory : " << cmd[1] << ENDL; + } else { + ncwd.setCwd(); + cwd = ncwd; + } + } + } else { // * * * CALL AN EXTERNAL COMMAND * * * // u32int i = 0; bool found = false; while (!commands[i].name.empty()) { @@ -114,8 +126,13 @@ int Shell::run() { i++; } if (!found) { - if (!appRun(appletsDir + cmd[0], cmd)) - outvt << "Unknown command : " << cmd[0] << "\n"; + if (FS::basename(cmd[0]) != cmd[0]) { + if (!appRun(cmd[0], cmd)) + outvt << "No such file : " << cmd[0] << "\n"; + } else { + if (!appRun(appletsDir + cmd[0], cmd)) + outvt << "Unknown command : " << cmd[0] << "\n"; + } } } } diff --git a/Source/Applications/Shell/Shell.class.h b/Source/Applications/Shell/Shell.class.h index 94a6c2a..49208fe 100644 --- a/Source/Applications/Shell/Shell.class.h +++ b/Source/Applications/Shell/Shell.class.h @@ -32,12 +32,9 @@ class Shell : public ShellApp { bool appRun(const String& name, Vector<String>& args); - void cd(Vector<String>& args); - void pwd(Vector<String>& args); void rm(Vector<String>& args); void mkdir(Vector<String>& args); void wf(Vector<String>& args); - void run(Vector<String>& args); }; #endif |