plugin_init.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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_ext("nop", klish_nop,
  22. KSYM_USERDEFINED_PERMANENT, KSYM_SYNC, KSYM_SILENT));
  23. kplugin_add_syms(plugin, ksym_new("tsym", klish_tsym));
  24. kplugin_add_syms(plugin, ksym_new("print", klish_print));
  25. kplugin_add_syms(plugin, ksym_new("printl", klish_printl));
  26. kplugin_add_syms(plugin, ksym_new_ext("pwd", klish_pwd,
  27. KSYM_PERMANENT, KSYM_SYNC, KSYM_NONSILENT));
  28. kplugin_add_syms(plugin, ksym_new_ext("prompt", klish_prompt,
  29. KSYM_USERDEFINED_PERMANENT, KSYM_SYNC, KSYM_SILENT));
  30. // Log
  31. kplugin_add_syms(plugin, ksym_new_ext("syslog", klish_syslog,
  32. KSYM_USERDEFINED_PERMANENT, KSYM_SYNC, KSYM_SILENT));
  33. // Navigation
  34. // Navigation must be permanent (no dry-run) and sync. Because unsync
  35. // actions will be fork()-ed so it can't change current path.
  36. kplugin_add_syms(plugin, ksym_new_ext("nav", klish_nav,
  37. KSYM_PERMANENT, KSYM_SYNC, KSYM_SILENT));
  38. // PTYPEs
  39. // These PTYPEs are simple and fast so set SYNC flag
  40. kplugin_add_syms(plugin, ksym_new_ext("COMMAND", klish_ptype_COMMAND,
  41. KSYM_USERDEFINED_PERMANENT, KSYM_SYNC, KSYM_SILENT));
  42. kplugin_add_syms(plugin, ksym_new_ext("completion_COMMAND", klish_completion_COMMAND,
  43. KSYM_USERDEFINED_PERMANENT, KSYM_SYNC, KSYM_NONSILENT));
  44. kplugin_add_syms(plugin, ksym_new_ext("help_COMMAND", klish_help_COMMAND,
  45. KSYM_USERDEFINED_PERMANENT, KSYM_SYNC, KSYM_NONSILENT));
  46. kplugin_add_syms(plugin, ksym_new_ext("COMMAND_CASE", klish_ptype_COMMAND_CASE,
  47. KSYM_USERDEFINED_PERMANENT, KSYM_SYNC, KSYM_SILENT));
  48. kplugin_add_syms(plugin, ksym_new_ext("INT", klish_ptype_INT,
  49. KSYM_USERDEFINED_PERMANENT, KSYM_SYNC, KSYM_SILENT));
  50. kplugin_add_syms(plugin, ksym_new_ext("UINT", klish_ptype_UINT,
  51. KSYM_USERDEFINED_PERMANENT, KSYM_SYNC, KSYM_SILENT));
  52. kplugin_add_syms(plugin, ksym_new_ext("STRING", klish_ptype_STRING,
  53. KSYM_USERDEFINED_PERMANENT, KSYM_SYNC, KSYM_SILENT));
  54. return 0;
  55. }
  56. int kplugin_klish_fini(kcontext_t *context)
  57. {
  58. // fprintf(stderr, "Plugin 'klish' fini\n");
  59. context = context;
  60. return 0;
  61. }