1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-05 17:23:15 +02:00

core: add optional default path (evaluated) in completion "filename" (issue #60)

This commit is contained in:
Sébastien Helleu
2019-10-06 09:24:10 +02:00
parent 88aa82d672
commit 6e382d26a9
21 changed files with 124 additions and 49 deletions
+22 -2
View File
@@ -1,3 +1,4 @@
/*
* wee-completion.c - completion for WeeChat commands
*
@@ -36,6 +37,7 @@
#include "weechat.h"
#include "wee-arraylist.h"
#include "wee-config.h"
#include "wee-eval.h"
#include "wee-hashtable.h"
#include "wee-hook.h"
#include "wee-list.h"
@@ -435,6 +437,7 @@ completion_list_add_filename_cb (const void *pointer, void *data,
char home[3] = { '~', DIR_SEPARATOR_CHAR, '\0' };
char *ptr_home, *pos, buf[PATH_MAX], *real_prefix, *prefix, *path_dir;
char *path_base, *dir_name;
const char *pos_args;
int length_path_base;
DIR *dp;
struct dirent *entry;
@@ -448,6 +451,10 @@ completion_list_add_filename_cb (const void *pointer, void *data,
completion->add_space = 0;
pos_args = strchr (completion_item, ':');
if (pos_args)
pos_args++;
ptr_home = getenv ("HOME");
real_prefix = NULL;
@@ -466,7 +473,18 @@ completion_list_add_filename_cb (const void *pointer, void *data,
if (!completion->base_word[0]
|| completion->base_word[0] != DIR_SEPARATOR_CHAR)
{
real_prefix = strdup (weechat_home);
real_prefix = NULL;
if (pos_args && pos_args[0])
{
real_prefix = eval_expression (pos_args, NULL, NULL, NULL);
if (real_prefix && !real_prefix[0])
{
free (real_prefix);
real_prefix = NULL;
}
}
if (!real_prefix)
real_prefix = strdup (weechat_home);
prefix = strdup ("");
}
else
@@ -1714,7 +1732,9 @@ completion_init ()
N_("configuration files"),
&completion_list_add_config_files_cb, NULL, NULL);
hook_completion (NULL, "filename", /* formerly "%f" */
N_("filename"),
N_("filename; "
"optional argument: default path (evaluated, "
"see /help eval)"),
&completion_list_add_filename_cb, NULL, NULL);
hook_completion (NULL, "filters_names", /* formerly "%F" */
N_("names of filters"),