env.c
changeset 3 490c62fe90eb
parent 0 53ef7728edcf
child 4 2c5225ab6eb7
equal deleted inserted replaced
2:06943b72945e 3:490c62fe90eb
    21 
    21 
    22 #include <glib.h>
    22 #include <glib.h>
    23 #include <gmodule.h>
    23 #include <gmodule.h>
    24 #include <string.h>
    24 #include <string.h>
    25 #include <stdlib.h>
    25 #include <stdlib.h>
       
    26 #include <unistd.h>
       
    27 #include <errno.h>
    26 
    28 
    27 #include "utils.h"
    29 #include "utils.h"
    28 #include "compl.h"
    30 #include "compl.h"
    29 #include "logprint.h"
    31 #include "logprint.h"
    30 
    32 
    94 		setenv (var, val, 1);
    96 		setenv (var, val, 1);
    95 
    97 
    96 	free_arg_lst (args);
    98 	free_arg_lst (args);
    97 }
    99 }
    98 
   100 
       
   101 // /cd [path]
       
   102 static void do_cd (char *arg)
       
   103 {
       
   104 	if (!*arg) { // get
       
   105 		char cwd[256];
       
   106 		if (getcwd (cwd, 256) == NULL)
       
   107 			scr_LogPrint (LPRINT_NORMAL, "Cannot obtain current working directory: %s.", strerror (errno));
       
   108 		else
       
   109 			scr_LogPrint (LPRINT_NORMAL, "%s", cwd);
       
   110 	} else if (chdir (arg) == -1) // set
       
   111 		scr_LogPrint (LPRINT_NORMAL, "Cannot change current working directory: %s.", strerror (errno));
       
   112 }
       
   113 
    99 const gchar *g_module_check_init(GModule *module)
   114 const gchar *g_module_check_init(GModule *module)
   100 {
   115 {
   101 	// command
   116 	// command
   102 	cmd_add ("env", "", 0, 0, do_env, NULL);
   117 	cmd_add ("env", "", 0, 0, do_env, NULL);
       
   118 	cmd_add ("cd", "", COMPL_FILENAME, 0, do_cd, NULL);
   103 
   119 
   104 	return NULL;
   120 	return NULL;
   105 }
   121 }
   106 
   122 
   107 void g_module_unload(GModule *module)
   123 void g_module_unload(GModule *module)
   108 {
   124 {
   109 	// command
   125 	// command
       
   126 	cmd_del ("cd");
   110 	cmd_del ("env");
   127 	cmd_del ("env");
   111 }
   128 }
   112 
   129 
   113 /* vim: se ts=4: */
   130 /* vim: se ts=4 sw=4: */