plugin_init.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. *
  3. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <stdint.h>
  7. #include <assert.h>
  8. #include <faux/faux.h>
  9. #include <klish/kplugin.h>
  10. #include <klish/kcontext.h>
  11. #include "private.h"
  12. const uint8_t kplugin_klish_major = KPLUGIN_MAJOR;
  13. const uint8_t kplugin_klish_minor = KPLUGIN_MINOR;
  14. int kplugin_klish_init(kcontext_t *context)
  15. {
  16. kplugin_t *plugin = NULL;
  17. assert(context);
  18. plugin = kcontext_plugin(context);
  19. assert(plugin);
  20. // Misc
  21. kplugin_add_syms(plugin, ksym_new_fast("nop", klish_nop));
  22. kplugin_add_syms(plugin, ksym_new_fast("tsym", klish_tsym));
  23. kplugin_add_syms(plugin, ksym_new_fast("print", klish_print));
  24. kplugin_add_syms(plugin, ksym_new_fast("printl", klish_printl));
  25. kplugin_add_syms(plugin, ksym_new_fast("prompt", klish_prompt));
  26. // Log
  27. kplugin_add_syms(plugin, ksym_new_fast("syslog", klish_syslog));
  28. // Navigation
  29. // Navigation must be permanent (no dry-run) and sync. Because unsync
  30. // actions will be fork()-ed so it can't change current path.
  31. kplugin_add_syms(plugin, ksym_new_ext("nav", klish_nav,
  32. KSYM_PERMANENT, KSYM_SYNC, KSYM_SILENT));
  33. kplugin_add_syms(plugin, ksym_new_ext("pwd", klish_pwd,
  34. KSYM_PERMANENT, KSYM_SYNC, KSYM_SILENT));
  35. // PTYPEs
  36. // These PTYPEs are simple and fast so set SYNC flag
  37. kplugin_add_syms(plugin, ksym_new_fast("COMMAND", klish_ptype_COMMAND));
  38. kplugin_add_syms(plugin, ksym_new_fast("completion_COMMAND",
  39. klish_completion_COMMAND));
  40. kplugin_add_syms(plugin, ksym_new_fast("help_COMMAND",
  41. klish_help_COMMAND));
  42. kplugin_add_syms(plugin, ksym_new_fast("COMMAND_CASE",
  43. klish_ptype_COMMAND_CASE));
  44. kplugin_add_syms(plugin, ksym_new_fast("INT", klish_ptype_INT));
  45. kplugin_add_syms(plugin, ksym_new_fast("UINT", klish_ptype_UINT));
  46. kplugin_add_syms(plugin, ksym_new_fast("STRING", klish_ptype_STRING));
  47. return 0;
  48. }
  49. int kplugin_klish_fini(kcontext_t *context)
  50. {
  51. // fprintf(stderr, "Plugin 'klish' fini\n");
  52. context = context;
  53. return 0;
  54. }