97static gboolean
exec_cmd(
const char *cmd,
int run_in_term) {
99 if (!cmd || !cmd[0]) {
102 gsize lf_cmd_size = 0;
103 gchar *lf_cmd = g_locale_from_utf8(cmd, -1, NULL, &lf_cmd_size, &error);
105 g_warning(
"Failed to convert command to locale encoding: %s",
115 run_in_term ? &context : NULL)) {
175 unsigned int num_favorites) {
178 FILE *inp = fdopen(fd,
"r");
181 size_t buffer_length = 0;
183 while (getline(&buffer, &buffer_length, inp) > 0) {
186 if (buffer[strlen(buffer) - 1] ==
'\n') {
187 buffer[strlen(buffer) - 1] =
'\0';
192 for (
unsigned int j = 0; found == 0 && j < num_favorites; j++) {
193 if (strcasecmp(buffer, retv[j].entry) == 0) {
203 retv = g_realloc(retv, ((*length) + 2) *
sizeof(
RunEntry));
204 retv[(*length)].
entry = g_strdup(buffer);
205 retv[(*length)].
icon = NULL;
211 if (buffer != NULL) {
214 if (fclose(inp) != 0) {
215 g_warning(
"Failed to close stdout off executor script: '%s'",
220 retv[(*length)].
entry = NULL;
221 retv[(*length)].
icon = NULL;
231 GError *error = NULL;
233 unsigned int num_favorites = 0;
236 if (g_getenv(
"PATH") == NULL) {
243 for (
unsigned int i = 0; i < *length; i++) {
244 retv[i].
entry = hretv[i];
249 num_favorites = (*length);
251 path = g_strdup(g_getenv(
"PATH"));
254 gchar *homedir = g_locale_to_utf8(g_get_home_dir(), -1, NULL, &l, &error);
256 g_debug(
"Failed to convert homedir to UTF-8: %s", error->message);
257 for (
unsigned int i = 0; retv[i].
entry != NULL; i++) {
258 g_free(retv[i].entry);
261 g_clear_error(&error);
266 const char *
const sep =
":";
267 char *strtok_savepointer = NULL;
268 for (
const char *dirname = strtok_r(path, sep, &strtok_savepointer);
269 dirname != NULL; dirname = strtok_r(NULL, sep, &strtok_savepointer)) {
271 DIR *dir = opendir(fpath);
272 g_debug(
"Checking path %s for executable.", fpath);
278 gchar *dirn = g_locale_to_utf8(dirname, -1, NULL, &dirn_len, &error);
280 g_debug(
"Failed to convert directory name to UTF-8: %s",
282 g_clear_error(&error);
286 gboolean is_homedir = g_str_has_prefix(dirn, homedir);
289 while ((dent = readdir(dir)) != NULL) {
290 if (dent->d_type != DT_REG && dent->d_type != DT_LNK &&
291 dent->d_type != DT_UNKNOWN) {
295 if (dent->d_name[0] ==
'.') {
299 gchar *full_path = g_build_filename(dirname, dent->d_name, NULL);
300 gboolean b = g_file_test(full_path, G_FILE_TEST_IS_EXECUTABLE);
309 g_filename_to_utf8(dent->d_name, -1, NULL, &name_len, &error);
311 g_debug(
"Failed to convert filename to UTF-8: %s", error->message);
312 g_clear_error(&error);
319 for (
unsigned int j = 0; found == 0 && j < num_favorites; j++) {
320 if (g_strcmp0(name, retv[j].entry) == 0) {
330 retv = g_realloc(retv, ((*length) + 2) *
sizeof(
RunEntry));
331 retv[(*length)].
entry = name;
332 retv[(*length)].
icon = NULL;
335 retv[(*length) + 1].
entry = NULL;
336 retv[(*length) + 1].
icon = NULL;
352 if ((*length) == 0) {
356 if ((*length) > num_favorites) {
357 g_qsort_with_data(&(retv[num_favorites]), (*length) - num_favorites,
362 unsigned int removed = 0;
363 for (
unsigned int index = num_favorites; index < ((*length) - 1); index++) {
364 if (g_strcmp0(retv[index].entry, retv[index + 1].entry) == 0) {
365 g_free(retv[index].entry);
366 retv[index].
entry = NULL;
371 if ((*length) > num_favorites) {
372 g_qsort_with_data(&(retv[num_favorites]), (*length) - num_favorites,
376 (*length) -= removed;
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)
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)