104static gboolean
exec_cmd(
const char *cmd,
int run_in_term,
const char *orig) {
105 GError *error = NULL;
106 if (!cmd || !cmd[0]) {
109 gsize lf_cmd_size = 0;
110 gchar *lf_cmd = g_locale_from_utf8(cmd, -1, NULL, &lf_cmd_size, &error);
112 g_warning(
"Failed to convert command to locale encoding: %s",
120 char *hist = g_strdup_printf(
"%s\x1f%s", orig, cmd);
123 run_in_term ? &context : NULL)) {
248 GError *error = NULL;
250 unsigned int num_favorites = 0;
253 if (g_getenv(
"PATH") == NULL) {
260 for (
unsigned int i = 0; i < *length; i++) {
261 gchar **rs = g_strsplit(hretv[i],
"\x1f", 2);
262 retv[i].
entry = rs[0];
263 retv[i].
exec = rs[1];
264 if (retv[i].exec == NULL) {
265 retv[i].
exec = g_strdup(rs[0]);
273 num_favorites = (*length);
275 path = g_strdup(g_getenv(
"PATH"));
278 gchar *homedir = g_locale_to_utf8(g_get_home_dir(), -1, NULL, &l, &error);
280 g_debug(
"Failed to convert homedir to UTF-8: %s", error->message);
281 for (
unsigned int i = 0; retv[i].
entry != NULL; i++) {
282 g_free(retv[i].entry);
283 g_free(retv[i].exec);
286 g_clear_error(&error);
291 const char *
const sep =
":";
292 char *strtok_savepointer = NULL;
293 for (
const char *dirname = strtok_r(path, sep, &strtok_savepointer);
294 dirname != NULL; dirname = strtok_r(NULL, sep, &strtok_savepointer)) {
296 DIR *dir = opendir(fpath);
297 g_debug(
"Checking path %s for executable.", fpath);
303 gchar *dirn = g_locale_to_utf8(dirname, -1, NULL, &dirn_len, &error);
305 g_debug(
"Failed to convert directory name to UTF-8: %s",
307 g_clear_error(&error);
311 gboolean is_homedir = g_str_has_prefix(dirn, homedir);
314 while ((dent = readdir(dir)) != NULL) {
315 if (dent->d_type != DT_REG && dent->d_type != DT_LNK &&
316 dent->d_type != DT_UNKNOWN) {
320 if (dent->d_name[0] ==
'.') {
324 gchar *full_path = g_build_filename(dirname, dent->d_name, NULL);
325 gboolean b = g_file_test(full_path, G_FILE_TEST_IS_EXECUTABLE);
334 g_filename_to_utf8(dent->d_name, -1, NULL, &name_len, &error);
336 g_debug(
"Failed to convert filename to UTF-8: %s", error->message);
337 g_clear_error(&error);
344 for (
unsigned int j = 0; found == 0 && j < num_favorites; j++) {
345 if (g_strcmp0(name, retv[j].entry) == 0) {
355 retv = g_realloc(retv, ((*length) + 2) *
sizeof(
RunEntry));
356 retv[(*length)].
entry = name;
357 retv[(*length)].
exec = g_shell_quote(name);
359 retv[(*length)].
icon = NULL;
363 retv[(*length) + 1].
entry = NULL;
364 retv[(*length) + 1].
exec = NULL;
366 retv[(*length) + 1].
icon = NULL;
383 if ((*length) == 0) {
387 if ((*length) > num_favorites) {
388 g_qsort_with_data(&(retv[num_favorites]), (*length) - num_favorites,
393 unsigned int removed = 0;
394 for (
unsigned int index = num_favorites; index < ((*length) - 1); index++) {
395 if (g_strcmp0(retv[index].entry, retv[index + 1].entry) == 0) {
396 g_free(retv[index].entry);
397 retv[index].
entry = NULL;
398 g_free(retv[index].exec);
399 retv[index].
exec = NULL;
404 if ((*length) > num_favorites) {
405 g_qsort_with_data(&(retv[num_favorites]), (*length) - num_favorites,
409 (*length) -= removed;
456 unsigned int selected_line) {
485 char *epath = g_shell_quote(path);
486 char *arg = g_strdup_printf(
"%s %s", earg, epath);
505 if (!
exec_cmd(*input, run_in_term, *input)) {
520 if (selected_line < rmpd->cmd_list_length) {
void history_set(const char *filename, const char *entry)
void history_remove(const char *filename, const char *entry)
char ** history_get_list(const char *filename, unsigned int *length)
const Mode * rofi_get_completer(void)
static char * _get_display_value(const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, G_GNUC_UNUSED GList **list, int get_entry)