add custom commands "cd" and "pwd" to the LAMMPS shell
This commit is contained in:
@ -498,9 +498,16 @@ regular LAMMPS commands:
|
|||||||
help (or ?) print a brief help message
|
help (or ?) print a brief help message
|
||||||
history display the current command history list
|
history display the current command history list
|
||||||
clear_history wipe out the current command history list
|
clear_history wipe out the current command history list
|
||||||
|
pwd print current working directory
|
||||||
|
cd <directory> change current working directory (same as pwd if no directory)
|
||||||
\|<command> execute <command> as a shell command and return to the command prompt
|
\|<command> execute <command> as a shell command and return to the command prompt
|
||||||
exit exit the LAMMPS shell cleanly (unlike the "quit" command)
|
exit exit the LAMMPS shell cleanly (unlike the "quit" command)
|
||||||
|
|
||||||
|
Please note that some known shell operations are implemented in the
|
||||||
|
LAMMPS :doc:`shell command <shell>` in a platform neutral fashion,
|
||||||
|
while using the '\|' character will always pass the following text
|
||||||
|
to the operating system's shell command.
|
||||||
|
|
||||||
Compilation
|
Compilation
|
||||||
===========
|
===========
|
||||||
|
|
||||||
|
|||||||
@ -84,11 +84,13 @@ Additional commands
|
|||||||
The followind commands are added to the LAMMPS shell on top of the
|
The followind commands are added to the LAMMPS shell on top of the
|
||||||
regular LAMMPS commands:
|
regular LAMMPS commands:
|
||||||
|
|
||||||
- help (or ?) print a brief help message
|
- help (or ?) print a brief help message
|
||||||
- history display the current command history list
|
- history display the current command history list
|
||||||
- clear_history wipe out the current command history list
|
- clear_history wipe out the current command history list
|
||||||
- |<command> execute <command> as a shell command and return to the command prompt
|
- pwd print current working directory
|
||||||
- exit exit the LAMMPS shell cleanly (unlike the "quit" command)
|
- cd <directory> change current working directory (same as pwd if no directory)
|
||||||
|
- |<command> execute <command> as a shell command and return to the command prompt
|
||||||
|
- exit exit the LAMMPS shell cleanly (unlike the "quit" command)
|
||||||
|
|
||||||
Compilation
|
Compilation
|
||||||
===========
|
===========
|
||||||
|
|||||||
@ -25,6 +25,7 @@
|
|||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#define isatty(x) _isatty(x)
|
#define isatty(x) _isatty(x)
|
||||||
|
#define getcwd(buf, len) _getcwd(buf, len)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
@ -460,6 +461,8 @@ static void init_commands()
|
|||||||
// store LAMMPS shell specific command names
|
// store LAMMPS shell specific command names
|
||||||
commands.push_back("help");
|
commands.push_back("help");
|
||||||
commands.push_back("exit");
|
commands.push_back("exit");
|
||||||
|
commands.push_back("pwd");
|
||||||
|
commands.push_back("cd");
|
||||||
commands.push_back("history");
|
commands.push_back("history");
|
||||||
commands.push_back("clear_history");
|
commands.push_back("clear_history");
|
||||||
|
|
||||||
@ -549,6 +552,16 @@ static int shell_cmd(const std::string &cmd)
|
|||||||
} else if (words[0] == "exit") {
|
} else if (words[0] == "exit") {
|
||||||
free(text);
|
free(text);
|
||||||
return shell_end();
|
return shell_end();
|
||||||
|
} else if ((words[0] == "pwd") || ((words[0] == "cd") && (words.size() == 1))) {
|
||||||
|
if (getcwd(buf, buflen)) std::cout << buf << "\n";
|
||||||
|
free(text);
|
||||||
|
return 0;
|
||||||
|
} else if (words[0] == "cd") {
|
||||||
|
std::string shellcmd = "shell ";
|
||||||
|
shellcmd += text;
|
||||||
|
lammps_command(lmp, shellcmd.c_str());
|
||||||
|
free(text);
|
||||||
|
return 0;
|
||||||
} else if (words[0] == "history") {
|
} else if (words[0] == "history") {
|
||||||
free(text);
|
free(text);
|
||||||
HIST_ENTRY **list = history_list();
|
HIST_ENTRY **list = history_list();
|
||||||
|
|||||||
Reference in New Issue
Block a user