gio-tool-list: Add an option to print display names

There are some GVfs locations (i.e. google-drive://, recent://), where
G_FILE_ATTRIBUTE_STANDARD_NAME is something tottaly different than
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME. Thus it would be nice to have
an easy way to show the display names. The only way currently to show
the display names is to use --attributes option, which is a bit
cumbersome. Let's add new --show-display-names option.

https://gitlab.gnome.org/GNOME/gvfs/issues/402
This commit is contained in:
Ondrej Holy 2019-12-17 10:27:24 +01:00
parent 5bae85eccc
commit e6f5b9bf89

View File

@ -29,6 +29,7 @@ static char *attributes = NULL;
static gboolean show_hidden = FALSE;
static gboolean show_long = FALSE;
static gboolean nofollow_symlinks = FALSE;
static gboolean print_display_names = FALSE;
static gboolean print_uris = FALSE;
static const GOptionEntry entries[] = {
@ -36,6 +37,7 @@ static const GOptionEntry entries[] = {
{ "hidden", 'h', 0, G_OPTION_ARG_NONE, &show_hidden, N_("Show hidden files"), NULL },
{ "long", 'l', 0, G_OPTION_ARG_NONE, &show_long, N_("Use a long listing format"), NULL },
{ "nofollow-symlinks", 'n', 0, G_OPTION_ARG_NONE, &nofollow_symlinks, N_("Dont follow symbolic links"), NULL},
{ "print-display-names", 'd', 0, G_OPTION_ARG_NONE, &print_display_names, N_("Print display names"), NULL },
{ "print-uris", 'u', 0, G_OPTION_ARG_NONE, &print_uris, N_("Print full URIs"), NULL},
{ NULL }
};
@ -54,7 +56,11 @@ show_file_listing (GFileInfo *info, GFile *parent)
if ((g_file_info_get_is_hidden (info)) && !show_hidden)
return;
name = g_file_info_get_name (info);
if (print_display_names)
name = g_file_info_get_display_name (info);
else
name = g_file_info_get_name (info);
if (name == NULL)
name = "";
@ -81,7 +87,8 @@ show_file_listing (GFileInfo *info, GFile *parent)
char *val_as_string;
if (!show_long ||
strcmp (attributes[i], G_FILE_ATTRIBUTE_STANDARD_NAME) == 0 ||
(!print_display_names && strcmp (attributes[i], G_FILE_ATTRIBUTE_STANDARD_NAME) == 0) ||
(print_display_names && strcmp (attributes[i], G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME) == 0) ||
strcmp (attributes[i], G_FILE_ATTRIBUTE_STANDARD_SIZE) == 0 ||
strcmp (attributes[i], G_FILE_ATTRIBUTE_STANDARD_TYPE) == 0 ||
strcmp (attributes[i], G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN) == 0)
@ -195,7 +202,8 @@ handle_list (int argc, char *argv[], gboolean do_help)
if (attributes != NULL)
show_long = TRUE;
attributes = g_strconcat (G_FILE_ATTRIBUTE_STANDARD_NAME ","
attributes = g_strconcat (!print_display_names ? G_FILE_ATTRIBUTE_STANDARD_NAME "," : "",
print_display_names ? G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "," : "",
G_FILE_ATTRIBUTE_STANDARD_TYPE ","
G_FILE_ATTRIBUTE_STANDARD_SIZE ","
G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN,