diff --git a/src/lexer/lexer.c b/src/lexer/lexer.c index 69b4d66..9a7166e 100644 --- a/src/lexer/lexer.c +++ b/src/lexer/lexer.c @@ -136,6 +136,11 @@ void msh_lexer_execute(msh_lexer *lexer) { if (msh_try_builtin(cmd, args)) { 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. */ else if (msh_path_exists(cmd)) { msh_execute(cmd, args); diff --git a/src/system/linux/linux.c b/src/system/linux/linux.c index 00a28ab..0c6425d 100644 --- a/src/system/linux/linux.c +++ b/src/system/linux/linux.c @@ -4,6 +4,7 @@ #include #include +#include #include 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; }; -void msh_backend_init() { - msh_linux_env_map_init(); - - msh_env_set("TERMF", "test"); - msh_env_set("TERM", "test"); +int msh_path_is_directory(char *path) { + struct stat path_stat; + SYSCALL(stat, path, &path_stat); + return S_ISDIR(path_stat.st_mode); }; +void msh_backend_init() { msh_linux_env_map_init(); }; + void msh_backend_deinit() { msh_linux_env_map_deinit(); }; diff --git a/src/system/system.h b/src/system/system.h index 842f3c7..96bf755 100644 --- a/src/system/system.h +++ b/src/system/system.h @@ -45,7 +45,12 @@ SIZE_TYPE msh_file_size(msh_file *file); /* * 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