diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2019-10-06 09:24:10 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2019-10-06 09:38:20 +0200 |
commit | 6e382d26a94a26d5d6034076fa6dbebbab336006 (patch) | |
tree | 500bbe5ec41f07c565f617d0634b2db8e00181b1 /src/core | |
parent | 88aa82d67256f95051c77acf2ce6e0f3bb4edbac (diff) | |
download | weechat-6e382d26a94a26d5d6034076fa6dbebbab336006.zip |
core: add optional default path (evaluated) in completion "filename" (issue #60)
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/wee-completion.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/core/wee-completion.c b/src/core/wee-completion.c index e37b6186e..bc52d72ec 100644 --- a/src/core/wee-completion.c +++ b/src/core/wee-completion.c @@ -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"), |