plugin_init.c 2.1 KB

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