typing a directory alone cds you to it
This commit is contained in:
parent
e0a751eec3
commit
ce504f4448
3 changed files with 18 additions and 6 deletions
|
|
@ -136,6 +136,11 @@ void msh_lexer_execute(msh_lexer *lexer) {
|
||||||
if (msh_try_builtin(cmd, args)) {
|
if (msh_try_builtin(cmd, args)) {
|
||||||
exec_success = 1;
|
exec_success = 1;
|
||||||
}
|
}
|
||||||
|
/* If the command is a folder, cd to it */
|
||||||
|
else if (msh_path_is_directory(cmd)) {
|
||||||
|
msh_builtin_cd(cmd);
|
||||||
|
exec_success = 1;
|
||||||
|
}
|
||||||
/* If the command is a file, first try and execute it. */
|
/* If the command is a file, first try and execute it. */
|
||||||
else if (msh_path_exists(cmd)) {
|
else if (msh_path_exists(cmd)) {
|
||||||
msh_execute(cmd, args);
|
msh_execute(cmd, args);
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
char msh_path_seperator = '/';
|
char msh_path_seperator = '/';
|
||||||
|
|
@ -128,11 +129,12 @@ void msh_set_working_directory(const char *dir) { SYSCALL(chdir, dir); }
|
||||||
|
|
||||||
int msh_path_exists(char *file) { return SYSCALL(access, file, F_OK) == 0; };
|
int msh_path_exists(char *file) { return SYSCALL(access, file, F_OK) == 0; };
|
||||||
|
|
||||||
void msh_backend_init() {
|
int msh_path_is_directory(char *path) {
|
||||||
msh_linux_env_map_init();
|
struct stat path_stat;
|
||||||
|
SYSCALL(stat, path, &path_stat);
|
||||||
msh_env_set("TERMF", "test");
|
return S_ISDIR(path_stat.st_mode);
|
||||||
msh_env_set("TERM", "test");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void msh_backend_init() { msh_linux_env_map_init(); };
|
||||||
|
|
||||||
void msh_backend_deinit() { msh_linux_env_map_deinit(); };
|
void msh_backend_deinit() { msh_linux_env_map_deinit(); };
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,12 @@ SIZE_TYPE msh_file_size(msh_file *file);
|
||||||
/*
|
/*
|
||||||
* Return whether the path exists
|
* Return whether the path exists
|
||||||
*/
|
*/
|
||||||
int msh_path_exists(char *file);
|
int msh_path_exists(char *path);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return whether the path is a directory.
|
||||||
|
*/
|
||||||
|
int msh_path_is_directory(char *path);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read up to x characters from file into ptr
|
* Read up to x characters from file into ptr
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue