1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Add /executable command

This is used to set the openers for various commands.
So far for /avatar and /urlopen.
This commit is contained in:
Michael Vetter 2020-05-20 14:14:49 +02:00
parent 21cc53bdfd
commit 7b541d0a6d
6 changed files with 68 additions and 12 deletions

View File

@ -124,6 +124,7 @@ static char* _correction_autocomplete(ProfWin *window, const char *const input,
static char* _correct_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _software_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _urlopen_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _executable_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _script_autocomplete_func(const char *const prefix, gboolean previous, void *context);
@ -256,6 +257,7 @@ static Autocomplete logging_group_ac;
static Autocomplete color_ac;
static Autocomplete correction_ac;
static Autocomplete avatar_ac;
static Autocomplete executable_ac;
void
cmd_ac_init(void)
@ -988,8 +990,11 @@ cmd_ac_init(void)
avatar_ac = autocomplete_new();
autocomplete_add(avatar_ac, "get");
autocomplete_add(avatar_ac, "cmd");
autocomplete_add(avatar_ac, "open");
executable_ac = autocomplete_new();
autocomplete_add(executable_ac, "avatar");
autocomplete_add(executable_ac, "urlopen");
}
void
@ -1306,6 +1311,7 @@ cmd_ac_reset(ProfWin *window)
autocomplete_reset(color_ac);
autocomplete_reset(correction_ac);
autocomplete_reset(avatar_ac);
autocomplete_reset(executable_ac);
autocomplete_reset(script_ac);
if (script_show_ac) {
@ -1464,6 +1470,7 @@ cmd_ac_uninit(void)
autocomplete_free(color_ac);
autocomplete_free(correction_ac);
autocomplete_free(avatar_ac);
autocomplete_free(executable_ac);
}
static void
@ -1724,6 +1731,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ
g_hash_table_insert(ac_funcs, "/correct", _correct_autocomplete);
g_hash_table_insert(ac_funcs, "/software", _software_autocomplete);
g_hash_table_insert(ac_funcs, "/urlopen", _urlopen_autocomplete);
g_hash_table_insert(ac_funcs, "/executable", _executable_autocomplete);
int len = strlen(input);
char parsed[len+1];
@ -3930,3 +3938,15 @@ _urlopen_autocomplete(ProfWin *window, const char *const input, gboolean previou
return result;
}
static char*
_executable_autocomplete(ProfWin *window, const char *const input, gboolean previous)
{
char *result = NULL;
result = autocomplete_param_with_ac(input, "/executable", executable_ac, TRUE, previous);
if (result) {
return result;
}
return NULL;
}

View File

@ -2340,26 +2340,23 @@ static struct cmd_t command_defs[] =
},
{ "/avatar",
parse_args, 2, 2, &cons_avatar_setting,
parse_args, 2, 2, NULL,
CMD_NOSUBFUNCS
CMD_MAINFUNC(cmd_avatar)
CMD_TAGS(
CMD_TAG_CHAT)
CMD_SYN(
"/avatar get <barejid>",
"/avatar open <barejid>",
"/avatar cmd <command>")
"/avatar open <barejid>")
CMD_DESC(
"Download avatar (XEP-0084) for a certain contact. "
"If nothing happens after using this command the user either doesn't have an avatar set at all "
"or doesn't use XEP-0084 to publish it.")
CMD_ARGS(
{ "get <barejid>", "Download the avatar. barejid is the JID to download avatar from."},
{ "cmd <command>", "Set a command to execute with 'avatar open'. Use your favourite image viewer here."},
{ "open <barejid>", "Download avatar and open it with command."})
CMD_EXAMPLES(
"/avatar get thor@valhalla.edda",
"/avatar cmd xdg-open",
"/avatar open freyja@vanaheimr.edda")
},
@ -2466,6 +2463,26 @@ static struct cmd_t command_defs[] =
{ "<url>", "URL to open."})
CMD_NOEXAMPLES
},
{ "/executable",
parse_args, 2, 2, &cons_executable_setting,
CMD_NOSUBFUNCS
CMD_MAINFUNC(cmd_executable)
CMD_TAGS(
CMD_TAG_DISCOVERY)
CMD_SYN(
"/executable avatar <cmd>",
"/executable urlopen <cmd>")
CMD_DESC(
"Configure executable that should be called upon a certain command."
"Default is xdg-open.")
CMD_ARGS(
{ "avatar", "Set executable that is run in /avatar open. Use your favourite image viewer." },
{ "urlopen", "Set executable that is run in /urlopen. Use your favourite browser." })
CMD_EXAMPLES(
"/executable avatar xdg-open",
"/executable urlopen firefox")
},
};
static GHashTable *search_index;

View File

@ -8878,3 +8878,19 @@ cmd_urlopen(ProfWin *window, const char *const command, gchar **args)
return TRUE;
}
gboolean
cmd_executable(ProfWin *window, const char *const command, gchar **args)
{
if (g_strcmp0(args[0], "avatar") == 0) {
prefs_set_string(PREF_AVATAR_CMD, args[1]);
cons_show("Avatar command set to: %s", args[1]);
} else if (g_strcmp0(args[0], "urlopen") == 0) {
prefs_set_string(PREF_URL_OPEN_CMD, args[1]);
cons_show("urlopen command set to: %s", args[1]);
} else {
cons_bad_cmd_usage(command);
}
return TRUE;
}

View File

@ -233,5 +233,6 @@ gboolean cmd_correct(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_slashguard(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_serversoftware(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_urlopen(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_executable(ProfWin *window, const char *const command, gchar **args);
#endif

View File

@ -2051,13 +2051,15 @@ cons_correction_setting(void)
}
void
cons_avatar_setting(void)
cons_executable_setting(void)
{
char *pref = prefs_get_string(PREF_AVATAR_CMD);
char *avatar = prefs_get_string(PREF_AVATAR_CMD);
cons_show("Avatar command (/executable avatar) : %s", avatar);
prefs_free_string(avatar);
cons_show("Avatar command (/avatar cmd) : %s", pref);
prefs_free_string(pref);
char *exec = prefs_get_string(PREF_URL_OPEN_CMD);
cons_show("urlopen command (/executable urlopen) : %s", exec);
prefs_free_string(exec);
}
void

View File

@ -319,7 +319,7 @@ void cons_winpos_setting(void);
void cons_color_setting(void);
void cons_os_setting(void);
void cons_correction_setting(void);
void cons_avatar_setting(void);
void cons_executable_setting(void);
void cons_slashguard_setting(void);
void cons_show_contact_online(PContact contact, Resource *resource, GDateTime *last_activity);
void cons_show_contact_offline(PContact contact, char *resource, char *status);