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)) {
246 GError *error = NULL;
248 unsigned int num_favorites = 0;
251 if (g_getenv(
"PATH") == NULL) {
258 for (
unsigned int i = 0; i < *length; i++) {
259 gchar **rs = g_strsplit(hretv[i],
"\x1f", 2);
260 retv[i].
entry = rs[0];
261 retv[i].
exec = rs[1];
262 if (retv[i].exec == NULL) {
263 retv[i].
exec = g_strdup(rs[0]);
271 num_favorites = (*length);
273 path = g_strdup(g_getenv(
"PATH"));
276 gchar *homedir = g_locale_to_utf8(g_get_home_dir(), -1, NULL, &l, &error);
278 g_debug(
"Failed to convert homedir to UTF-8: %s", error->message);
279 for (
unsigned int i = 0; retv[i].
entry != NULL; i++) {
280 g_free(retv[i].entry);
281 g_free(retv[i].exec);
284 g_clear_error(&error);
289 const char *
const sep =
":";
290 char *strtok_savepointer = NULL;
291 for (
const char *dirname = strtok_r(path, sep, &strtok_savepointer);
292 dirname != NULL; dirname = strtok_r(NULL, sep, &strtok_savepointer)) {
294 DIR *dir = opendir(fpath);
295 g_debug(
"Checking path %s for executable.", fpath);
301 gchar *dirn = g_locale_to_utf8(dirname, -1, NULL, &dirn_len, &error);
303 g_debug(
"Failed to convert directory name to UTF-8: %s",
305 g_clear_error(&error);
309 gboolean is_homedir = g_str_has_prefix(dirn, homedir);
312 while ((dent = readdir(dir)) != NULL) {
313 if (dent->d_type != DT_REG && dent->d_type != DT_LNK &&
314 dent->d_type != DT_UNKNOWN) {
318 if (dent->d_name[0] ==
'.') {
322 gchar *full_path = g_build_filename(dirname, dent->d_name, NULL);
323 gboolean b = g_file_test(full_path, G_FILE_TEST_IS_EXECUTABLE);
332 g_filename_to_utf8(dent->d_name, -1, NULL, &name_len, &error);
334 g_debug(
"Failed to convert filename to UTF-8: %s", error->message);
335 g_clear_error(&error);
342 for (
unsigned int j = 0; found == 0 && j < num_favorites; j++) {
343 if (g_strcmp0(name, retv[j].entry) == 0) {
353 retv = g_realloc(retv, ((*length) + 2) *
sizeof(
RunEntry));
354 retv[(*length)].
entry = name;
355 retv[(*length)].
exec = g_shell_quote(name);
357 retv[(*length)].
icon = NULL;
360 retv[(*length) + 1].
entry = NULL;
361 retv[(*length) + 1].
exec = NULL;
363 retv[(*length) + 1].
icon = NULL;
379 if ((*length) == 0) {
383 if ((*length) > num_favorites) {
384 g_qsort_with_data(&(retv[num_favorites]), (*length) - num_favorites,
389 unsigned int removed = 0;
390 for (
unsigned int index = num_favorites; index < ((*length) - 1); index++) {
391 if (g_strcmp0(retv[index].entry, retv[index + 1].entry) == 0) {
392 g_free(retv[index].entry);
393 retv[index].
entry = NULL;
394 g_free(retv[index].exec);
395 retv[index].
exec = NULL;
400 if ((*length) > num_favorites) {
401 g_qsort_with_data(&(retv[num_favorites]), (*length) - num_favorites,
405 (*length) -= removed;
452 unsigned int selected_line) {
481 char *epath = g_shell_quote(path);
482 char *arg = g_strdup_printf(
"%s %s", earg, epath);
501 if (!
exec_cmd(*input, run_in_term, *input)) {
516 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)