esh_misc.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "esh_misc.h"
  2. void EShOptimiseCurrentWorkingDirectory() {
  3. if (strstr(esh_info_global->current_working_dir, esh_info_global->user_data->pw_dir) == esh_info_global->current_working_dir) {
  4. char new_cwd[PATH_MAX + 1];
  5. memset(new_cwd, 0, PATH_MAX + 1);
  6. strcat(new_cwd, "~");
  7. strcat(new_cwd, esh_info_global->current_working_dir + strlen(esh_info_global->user_data->pw_dir));
  8. strcpy(esh_info_global->current_working_dir, new_cwd);
  9. }
  10. }
  11. void EShUpdateInviteMessage() {
  12. memset(esh_info_global->invite_message, 0, (esh_info_global->max_invite_message_len + 1) * sizeof(char));
  13. strcat(esh_info_global->invite_message, ANSI_COLOR_BLUE);
  14. strcat(esh_info_global->invite_message, esh_info_global->user_data->pw_name);
  15. strcat(esh_info_global->invite_message, ANSI_COLOR_RESET);
  16. strcat(esh_info_global->invite_message, "@");
  17. strcat(esh_info_global->invite_message, ANSI_COLOR_GREEN);
  18. strcat(esh_info_global->invite_message, esh_info_global->current_working_dir);
  19. strcat(esh_info_global->invite_message, ANSI_COLOR_RESET);
  20. strcat(esh_info_global->invite_message, " » ");
  21. }
  22. void EShShowHelpAndExit() {
  23. printf(ANSI_COLOR_RED "ESh (Endevir Shell) build %.8s\n" ANSI_COLOR_RESET
  24. "\n"
  25. "Usage: esh [-h] [-config FILENAME] [-history FILENAME] [-history_limit INT] [-max_active_jobs INT]\n"
  26. "\n"
  27. "Description:\n"
  28. "This is a simple shell, written in C\n"
  29. "\n"
  30. "Parameters:\n"
  31. "-h shows this message and exits\n"
  32. "-config FILENAME uses file with name FILENAME as config file (default: ~/.esh_conf)\n"
  33. "-history_path FILENAME uses file with name FILENAME as storage for entered commands history (default: ~/.esh_history)\n"
  34. "-history_limit INT limits commands number to keep up to INT (default: 5000 lines)\n"
  35. "-max_active_jobs INT limits shell active jobs number up to INT (default: 64)\n"
  36. "\n"
  37. "\n"
  38. "Copyleft. Written by Ivan Arkhipov aka Endevir (me@endevir.ru), MIPT, Dolgoprudny, Russia, 2019.\n",
  39. esh_info_global->build_ref);
  40. exit(0);
  41. }