Skip to content

Instantly share code, notes, and snippets.

@jeetsukumaran
Last active October 12, 2021 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeetsukumaran/122ffcf5f011bebb4bc6f11e334e0067 to your computer and use it in GitHub Desktop.
Save jeetsukumaran/122ffcf5f011bebb4bc6f11e334e0067 to your computer and use it in GitHub Desktop.
# Colorized ``ls``
#
# ``ls`` has native support for colorizing the entries themselves, which can
# be seen by running ``ls --color`` or ``ls --color=auto``, and this can be
# made standard by aliasing these to ``ls`` in your ``.bashrc.
#
# The colors of the file/directory entries themselves can be customized by
# adding the following in your ``~/.bashrc`` :
#
# ~~~
# export LS_COLORS='di=0;96:fi=1;94:ln=4;94:pi=5:so=5:bd=5:cd=5:or=1;5;40:mi=1;5;40:ex=32'
# ~~~
#
# However, when doing long lists (``ls -l``) the other columns of the table
# are not colorized.
#
# The following function, placed in your ``~/,bashrc.``, "fixes" this ... :)
#
# (You can make this the 'default' view by adding ``alias ll=llc`` or ``alias
# ls=llc`` in your ``~/.bashrc``
#
function llc() {
ls -lh --color $@ | awk '
BEGIN {
FPAT = "([[:space:]]*[^[:space:]]+)";
OFS = "";
}
{
$1 = "\033[0;95m" $1 "\033[0m";
$2 = "\033[1;94m" $2 "\033[0m";
$3 = "\033[1;34m" $3 "\033[0m";
$4 = "\033[1;34m" $4 "\033[0m";
$5 = "\033[0;32m" $5 "\033[0m";
$6 = "\033[0;33m" $6 "\033[0m";
$7 = "\033[0;33m" $7 "\033[0m";
$8 = "\033[1;33m" $8 "\033[0m";
print
}
'
}
# Colorized ``ls``
#
# ``ls`` has native support for colorizing the entries themselves, which can
# be seen by running ``ls --color`` or ``ls --color=auto``, and this can be
# made standard by aliasing these to ``ls`` in your ``.bashrc.
#
# The colors of the file/directory entries themselves can be customized by
# adding the following in your ``~/.bashrc`` :
#
# ~~~
# export LS_COLORS='di=0;96:fi=1;94:ln=4;94:pi=5:so=5:bd=5:cd=5:or=1;5;40:mi=1;5;40:ex=32'
# ~~~
#
# However, when doing along lists (``ls -l``) the other columns of the table
# are not colorized.
#
# The following function, placed in your ``~/,bashrc.``, "fixes" this ... :)
#
# (You can make this the 'default' view by adding ``alias ll=llc`` or ``alias
# ls=llc`` in your ``~/.bashrc``
#
#
function llc() {
ls -lh --color $@ | awk '
BEGIN {
FPAT = "([[:space:]]*[^[:space:]]+)";
OFS = "";
}
{
$1 = "\033[38;5;102m" $1 "\033[0m";
$2 = "\033[38;5;166m" $2 "\033[0m";
$3 = "\033[38;5;180m" $3 "\033[0m";
$4 = "\033[38;5;180m" $4 "\033[0m";
$5 = "\033[38;5;202m" $5 "\033[0m";
$6 = "\033[38;5;222m" $6 "\033[0m";
$7 = "\033[38;5;222m" $7 "\033[0m";
$8 = "\033[38;5;178m" $8 "\033[0m";
print
}
'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment