Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/man/mc.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,14 @@ specifier. This are the available fields you may display:
.B name
displays the file name.
.TP
.B basename
displays the file name without extension. For directories and files
without an extension, this is identical to the full name.
.TP
.B extension
displays the file extension (the part after the last dot).
For directories and files without an extension, this field is empty.
.TP
.B size
displays the file size.
.TP
Expand Down
44 changes: 41 additions & 3 deletions src/filemanager/panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ static const char *string_file_group (const file_entry_t *fe, int len);
static const char *string_marked (const file_entry_t *fe, int len);
static const char *string_space (const file_entry_t *fe, int len);
static const char *string_dot (const file_entry_t *fe, int len);
static const char *string_file_ext (const file_entry_t *fe, int len);
static const char *string_file_basename (const file_entry_t *fe, int len);

/*** file scope variables ************************************************************************/

Expand All @@ -178,9 +180,9 @@ static panel_field_t panel_fields[] = {
{ "extension", 12, TRUE, J_LEFT_FIT,
// TRANSLATORS: one single character to represent 'extension' sort mode
// TRANSLATORS: no need to translate 'sort', it's just a context prefix
N_ ("sort|e"), N_ ("E&xtension"), TRUE, FALSE,
string_file_name, // TODO: string_file_ext
(GCompareFunc) sort_ext },
N_ ("sort|e"), N_ ("E&xtension"), TRUE, FALSE, string_file_ext, (GCompareFunc) sort_ext },
{ "basename", 12, TRUE, J_LEFT_FIT, N_ ("sort|n"), N_ ("&Basename"), TRUE, FALSE,
string_file_basename, (GCompareFunc) sort_name },
{ "size", 7, FALSE, J_RIGHT,
// TRANSLATORS: one single character to represent 'size' sort mode
// TRANSLATORS: no need to translate 'sort', it's just a context prefix
Expand Down Expand Up @@ -355,6 +357,42 @@ string_file_name (const file_entry_t *fe, int len)

/* --------------------------------------------------------------------------------------------- */

static const char *
string_file_ext (const file_entry_t *fe, MC_UNUSED int len)
{
const char *ext = extension (fe->fname->str);

if (ext[0] == '\0' || S_ISDIR (fe->st.st_mode))
g_string_truncate (string_file_name_buffer, 0);
else
g_string_assign (string_file_name_buffer, ext);

return string_file_name_buffer->str;
}

/* --------------------------------------------------------------------------------------------- */

static const char *
string_file_basename (const file_entry_t *fe, MC_UNUSED int len)
{
const char *ext = extension (fe->fname->str);

mc_g_string_copy (string_file_name_buffer, fe->fname);

/* Remove the extension (including the dot) from the name */
if (ext[0] != '\0' && !S_ISDIR (fe->st.st_mode))
{
size_t name_len = (size_t) (ext - fe->fname->str);

if (name_len > 0)
g_string_truncate (string_file_name_buffer, name_len - 1);
}

return string_file_name_buffer->str;
}

/* --------------------------------------------------------------------------------------------- */

static unsigned int
ilog10 (dev_t n)
{
Expand Down
Loading