Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save CouldBeThis/15ed568de8054c49d3885f7d067c0253 to your computer and use it in GitHub Desktop.
Save CouldBeThis/15ed568de8054c49d3885f7d067c0253 to your computer and use it in GitHub Desktop.

Change column order for exa long listing

Related issue:

Temporary workaround

exa -lg --time-style=long-iso --color=always \
  | sed -E 's/^ *([^ ]*) *([^ ]*) *([^ ]*) *([^ ]*) *([^ ]* *[^ ]*) *(.*)$/\1\t\3\t\4\t\2\t\5\t\6/' \
  | column -t -s $'\t' -o ' '

I had to use --time-style=long-iso because the default timestamp format caused a problem when day of month was a single digit.

Explanation of sed invocation:

-E      Use modern regex syntax (ERE as opposed to BRE)
s/      begin substitution
^       beginning of line
 *      skip zero or more spaces (for good measure)
([^ ]*) capture zero or more non-SPACE characters into group 1: permissions bits
 *      skip zero or more spaces
([^ ]*) capture zero or more non-SPACE characters into group 2: size
 *      skip zero or more spaces
([^ ]*) capture zero or more non-SPACE characters into group 3: user
 *      skip zero or more spaces
([^ ]*) capture zero or more non-SPACE characters into group 4: group
 *      skip zero or more spaces
([^ ]* *[^ ]*) capture timestamp into group 5: timestamp
 *      skip zero or more spaces
(.*)$   capture remainder of line into group 6
/       begin replacement
\1\t\3\t\4\t\2\t\5\t\6  order the captured groups as you wish, separated by TABs
/       end

The column invocation creates a table from the TAB delimited input it is given. The column delimiter in the output table is set to one space.

.bashrc

To use this approach, I suggest the following additions to your ~/.bashrc:

exa_long () {
  exa -lg --time-style=long-iso --color=always --group-directories-first "$@" \
  | sed -E 's/^ *([^ ]*) *([^ ]*) *([^ ]*) *([^ ]*) *([^ ]* *[^ ]*) *(.*)$/\1\t\3\t\4\t\2\t\5\t\6/' \
  | column -t -s $'\t' -o ' '
}
exa_huge () {
  # exa -lgHi  # No -S though; we don't want blocks.
  #            # Add -h if you want want a header row.
  # 1 - inode number
  # 2 - permission bits
  # 3 - number of hard links
  # 4 - size
  # 5 - user
  # 6 - group
  # 7 - timestamp
  # 8 - Remainder
  exa -lgHi --time-style=long-iso --color=always --group-directories-first "$@" \
  | sed -E 's/^ *([^ ]*) *([^ ]*) *([^ ]*) *([^ ]*) *([^ ]*) *([^ ]*) *([^ ]* *[^ ]*) *(.*)$/\1\t\3\t\2\t\5\t\6\t\4\t\7\t\8/' \
  | column -t -s $'\t' -o ' '
}

alias ll='exa_long'        # Long listing
alias ldir='exa_long -D'   # Just directories
alias l.='exa_long -d .*'  # Just dot files and dot directories
alias lh='exa_huge'        # Huge mode
alias ltr='exa_long --sort newest' # Like `ls -ltr`

The huge mode adds inode number and the number of hard links to the beginning of the line.

Screenshots

image

image

EXA_COLORS

Incidently, I use the following EXA_COLORS environment variable:

export EXA_COLORS="in=0;38:lc=0;38:ur=0;33:uw=0;33:ux=0;33:ue=0;33:gr=0;37:gw=0;37:gx=0;37:tr=0;31:tw=0;31:tx=0;31:da=0;36:uu=0;33:gu=0;37"

The default coloring of the permission bits was too colorful.

The above EXA_COLORS makes the color of the owner rwx permission bits match the color of the user owner, and the color of the group rwx permission bits match the group owner. The rwx permission bits of other is set to magenta.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment