plugin_init.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_ext("pwd", klish_pwd,
  26. KSYM_PERMANENT, KSYM_SYNC));
  27. // Navigation
  28. // Navigation must be permanent (no dry-run) and sync. Because unsync
  29. // actions will be fork()-ed so it can't change current path.
  30. kplugin_add_syms(plugin, ksym_new_ext("nav", klish_nav,
  31. KSYM_PERMANENT, KSYM_SYNC));
  32. // PTYPEs
  33. // These PTYPEs are simple and fast so set SYNC flag
  34. kplugin_add_syms(plugin, ksym_new_ext("COMMAND", klish_ptype_COMMAND,
  35. KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
  36. kplugin_add_syms(plugin, ksym_new_ext("COMMAND_CASE", klish_ptype_COMMAND_CASE,
  37. KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
  38. kplugin_add_syms(plugin, ksym_new_ext("INT", klish_ptype_INT,
  39. KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
  40. kplugin_add_syms(plugin, ksym_new_ext("UINT", klish_ptype_UINT,
  41. KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
  42. kplugin_add_syms(plugin, ksym_new_ext("STRING", klish_ptype_STRING,
  43. KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
  44. return 0;
  45. }
  46. int kplugin_klish_fini(kcontext_t *context)
  47. {
  48. // fprintf(stderr, "Plugin 'klish' fini\n");
  49. context = context;
  50. return 0;
  51. }