| 217 | } |
| 218 | |
| 219 | int main(){ |
| 220 | printf("Lemon SHell\n"); |
| 221 | |
| 222 | if(const char* h = getenv("HOME"); h){ |
| 223 | chdir(h); |
| 224 | } |
| 225 | |
| 226 | getcwd(currentDir, PATH_MAX); |
| 227 | tcgetattr(STDOUT_FILENO, &execAttributes); |
| 228 | readAttributes = execAttributes; |
| 229 | readAttributes.c_lflag &= ~(ICANON | ECHO); // Disable canonical mode and echo when reading user input |
| 230 | |
| 231 | builtins.push_back(builtinPwd); |
| 232 | builtins.push_back(builtinCd); |
| 233 | builtins.push_back(builtinExport); |
| 234 | builtins.push_back(builtinClear); |
| 235 | |
| 236 | std::string pathEnv = getenv("PATH"); |
| 237 | std::string temp; |
| 238 | for(char c : pathEnv){ |
| 239 | if(c == ':' && temp.length()){ |
| 240 | path.push_back(temp); |
| 241 | temp.clear(); |
| 242 | } else { |
| 243 | temp += c; |
| 244 | } |
| 245 | } |
| 246 | if(temp.length()){ |
| 247 | path.push_back(temp); |
| 248 | temp.clear(); |
| 249 | } |
| 250 | |
| 251 | fflush(stdin); |
| 252 | |
| 253 | for(;;) { |
| 254 | printf("\n\e[33mLemon \e[91m%s\e[m$ ", currentDir); |
| 255 | fflush(stdout); |
| 256 | |
| 257 | ReadLine(); |
| 258 | ParseLine(); |
| 259 | } |
| 260 | } |