#!/bin/sh # An enhanced and more portable ls -l # Licence: LGPLv2 # Author: # http://www.pixelbeat.org/ # Notes: # A symlink target may lose info as there are no mode bits to highlight. # Changes: # V0.1, 18 Sep 2009, Initial release # V0.2, 30 Sep 2009, Correctly strip "total" line for all locales # Modify colors even when dircolors doesn't support $TERM # Don't error for ls without --group-dir or --no-group # V0.3, 21 Oct 2009, Handle older ls' which pepper output with reset codes # # V1.4, 21 Nov 2016 # http://github.com/pixelb/scripts/commits/master/scripts/l # apply thousands separator to file sizes global BLOCK_SIZE := ''''1'; export BLOCK_SIZE # Traditional unix time format with abbreviated month translated from locale. # en_* locales default to ISO format without this for reasons discussed here: # http://lists.gnu.org/archive/html/bug-coreutils/2009-09/msg00433.html # Note as of coreutils 8.6, `ls` will again use traditional rather than ISO # format, unless otherwise specified by translators. global TIME_STYLE := ''+%b %e %Y %b %e %H:%M'' export TIME_STYLE # Add a fancy symlink arrow if echo $LANG | grep -i "utf-*8$" >/dev/null { global SYM_ARROW := '"▪▶'" } else { global SYM_ARROW := '"->'" } global ESC := $[printf '\033] # Disable color if the current $TERM doesn't support it if ! tput setaf 1 >/dev/null !2 > !1 && ! tput AF 1 >/dev/null !2 > !1 { global color_when := '' # enable highlighting if outputting to terminal or forcing } elif test -t 1 || echo "$ifsjoin(Argv)" | grep -E -- "--color( |=always|$)" >/dev/null { # Note if the user specifies --color=auto then that will override this # and hence the output will not be colored :( global color_when := 'always' if tput bold >/dev/null !2 > !1 { #terminfo global BLD := $[tput bold] global RST := $[tput sgr0] global HLI := $[tput smso] } elif tput md >/dev/null !2 > !1 { #termcap global BLD := $[tput md] global RST := $[tput me] global HLI := $[tput so] } global LS_HLI := $[echo $HLI | sed "s/$ESC\[\(.*\)m/\1/] } else { global color_when := 'auto' } global ls := 'ls' #default to standard name do { ls --color -d . >/dev/null !2 > !1; } || do { gls --color -d . >/dev/null !2 > !1 && global ls := 'gls'; } || global NONGNU := '1' if test $color_when { if test $NONGNU { do { colorls -d .; } >/dev/null 2>&1 && global ls := 'colorls' # for OpenBSD $ls -G -d . >/dev/null !2 > !1 && global color_opt := '-G' #not supported on Solaris test $color_when = "always" && do { global CLICOLOR_FORCE := '1'; export CLICOLOR_FORCE; } global color_when := '' # Turn off the confusing different background colors # as we'll highlight the mode bits instead. Also change the # main colors to match the default one on linux (coreutils). global LSCOLORS := '"ExGxcxdxCxegedCxCxExEx'"; export LSCOLORS } else { global color_opt := ''--color='' global color_never := '"--color=never'" # modify the coreutils default colors if distro or user colors not set test $LS_COLORS || eval $[dircolors] # xterm-256color not supported by older dircolors for example test $LS_COLORS || eval $[env TERM=xterm dircolors] # Turn off the confusing entries with different backgrounds # as we'll highlight the mode bits and hardlink count instead. # # Also turn off capability colouring even though we don't # highlight anything in lieu of it, as this will short circuit # the slow capability checks within ls # # Also we reset the dangling symlink color to "highlight" # as it defaults to blinking. We could do all this in ~/.dir_colors # but so this script is more general, we do it here. # Ensure LS_COLORS is delimited with ':' to simplify the following regexes. # Otherwise we'd have to consider using word boundaries (\b, \<, [[:<:]]), # but those are non portable. global LS_COLORS := "":$LS_COLORS:""; export LS_COLORS # Newer ls use "mh" to represent the color for multi hardlinked # files so handle the backwards incompatibility with "hl" if dircolors | grep -F ":mh=" >/dev/null { global hl_no_color := '"s/:hl=[^:]*:/:mh=:/; s/:mh=[^:]*:/:mh=:/'" } elif dircolors | grep -F "hl=" >/dev/null { global hl_no_color := '"s/:mh=[^:]*:/:hl=:/; s/:hl=[^:]*:/:hl=:/'" } # The extra quoting (wrapping in "") is required for # speed in bash where it inefficiently tries to glob # for each *.ext component of LS_COLORS, which is # noticeably slow in directories with many files. eval $[ echo LS_COLORS=''''"'$LS_COLORS'"''''';' | sed '"' $hl_no_color s/:su=[^:]*:/:su=:/ s/:sg=[^:]*:/:sg=:/ s/:ow=[^:]*:/:ow=:/ s/:st=[^:]*:/:st=:/ s/:tw=[^:]*:/:tw=:/ s/:ca=[^:]*:/:ca=:/ s/:mi=[^:]'{'1,'}':/:mi=$LS_HLI:/ '"' echo 'export LS_COLORS] } } # Get locale total string to match on global total := $[$ls -s $color_never / | sed 's/\([^ ]*\).*/\1/;q] # Use these options if available $ls --group-directories-first -d . >/dev/null !2 > !1 && global gdf := '--group-directories' $ls --no-group -d . >/dev/null !2 > !1 && global ng := '--no-group' $ls --quoting=shell-escape -d . >/dev/null !2 > !1 && global quote := '--quoting=shell-escape' # Bypass long format manipulation if any of following formats are specified # FIXME: Matching options like this is a bit brittle global lfmt := 'lfmt' echo "$ifsjoin(Argv)" | grep -E -- "-(m|i|x|s|C|-version|-help)" >/dev/null && global lfmt := ''"" # set -o pipefail is bash/ksh/zsh specific # So manually propagate the exit status from ls. # See http://stackoverflow.com/a/30658405/4421 exec !4 > !1 global ls_status := $[do { do { # Start with the standard long format listing # with colours, and latest files at bottom $ls -lrtq $color_opt$color_when $ng $gdf $quote @Argv; printf $Status !1 > !3; } | # process with sed to... sed " # Remove total line(s) I never use /$total [0-9,. ]\{1,\}$/d # prettify symlink arrows s/ -> / $BLD$SYM_ARROW$RST / # Conditionally process long format output b $lfmt :lfmt # Ignore directory name headings /^[^ ]\{1,\}:$/b # temporarily shrink any prepended reset codes # from older ls' to a single char s/^$ESC\[0*m/0/ # highlight ug+s indicators s/^\(0\{0,1\}.\{3\}\)\([sS]\)/\1$HLI\2$RST/ s/^\(0\{0,1\}.\{6\}\)\([sS]\)/\1$HLI\2$RST/ # highlight +t o+w indicators for directories /^0\{0,1\}d/!b not_dir s/^\(0\{0,1\}.\{9\}\)\([tT]\)/\1$HLI\2$RST/ s/^\(0\{0,1\}.\{8\}\)w/\1$(HLI)w$RST/ s/^\(0\{0,1\}.\{3\}\)\([sS]\)/\1$HLI\2$RST/ s/^\(0\{0,1\}.\{6\}\)\([sS]\)/\1$HLI\2$RST/ :not_dir # highlight multiply linked files /^0\{0,1\}[^d]\{10,\}/!b not_hl /^[^ ]* *1 /b not_hl s/^\(0\{0,1\}[^ ]*\)\( *\)\([0-9]\{1,\}\)/\1\2$HLI\3$RST/ :not_hl # restore any reset codes replaced above s/^0/$(ESC)[0m/ " !1 > !4] global sed_status := $Status # Note if sed fails, then if ls outputs it will usually get # a SIGPIPE and exit with status 141. Though that's dependent # on ls(1) propagating that "error", and also will not be the case # if ls does not output after sed terminates. So factor both # exit values into the final exit status. test $ls_status != 0 && exit $ls_status || exit $sed_status (CommandList children: [ (Sentence child: (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:BLOCK_SIZE) op: Equal rhs: {(EscapedLiteralPart token:) (1)} spids: [54] ) ] spids: [54] ) terminator: ) (C {(export)} {(BLOCK_SIZE)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TIME_STYLE) op: Equal rhs: {(SQ <"+%b %e %Y\n"> <"%b %e %H:%M">)} spids: [79] ) ] spids: [79] ) (C {(export)} {(TIME_STYLE)}) (If arms: [ (if_arm cond: [ (Sentence child: (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_Name "$LANG"))}) (SimpleCommand words: [{(grep)} {(-i)} {(DQ ("utf-*8") (Lit_Other "$"))}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[112])] ) ] negated: False ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:SYM_ARROW) op: Equal rhs: {(DQ ("\u25aa\u25b6"))} spids: [119] ) ] spids: [119] ) ] spids: [-1 116] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:SYM_ARROW) op:Equal rhs:{(DQ ("->"))} spids:[127])] spids: [127] ) ] spids: [124 132] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:ESC) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(printf)} {(SQ <"\\033">)})]) left_token: spids: [136 142] ) } spids: [135] ) ] spids: [135] ) (If arms: [ (if_arm cond: [ (Sentence child: (AndOr children: [ (Pipeline children: [ (SimpleCommand words: [{(tput)} {(setaf)} {(1)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [158] ) (Redir op_id: Redir_GreatAnd fd: 2 arg_word: {(1)} spids: [161] ) ] ) ] negated: True ) (Pipeline children: [ (SimpleCommand words: [{(tput)} {(AF)} {(1)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [174] ) (Redir op_id: Redir_GreatAnd fd: 2 arg_word: {(1)} spids: [177] ) ] ) ] negated: True ) ] op_id: Op_DAmp ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:color_when) op:Equal rhs:{(SQ )} spids:[184])] spids: [184] ) ] spids: [-1 181] ) (if_arm cond: [ (Sentence child: (AndOr children: [ (C {(test)} {(-t)} {(1)}) (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_Star "$*"))}) (SimpleCommand words: [ {(grep)} {(-E)} {(--)} {(DQ ("--color( |=always|") (Lit_Other "$") (")"))} ] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [219] ) ] ) ] negated: False ) ] op_id: Op_DPipe ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:color_when) op:Equal rhs:{(always)} spids:[234])] spids: [234] ) (If arms: [ (if_arm cond: [ (Sentence child: (SimpleCommand words: [{(tput)} {(bold)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [244] ) (Redir op_id: Redir_GreatAnd fd: 2 arg_word: {(1)} spids: [247] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:BLD) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(tput)} {(bold)})]) left_token: spids: [258 262] ) } spids: [257] ) ] spids: [257] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:RST) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(tput)} {(sgr0)})]) left_token: spids: [266 270] ) } spids: [265] ) ] spids: [265] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:HLI) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(tput)} {(smso)})]) left_token: spids: [274 278] ) } spids: [273] ) ] spids: [273] ) ] spids: [-1 251] ) (if_arm cond: [ (Sentence child: (SimpleCommand words: [{(tput)} {(md)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [287] ) (Redir op_id: Redir_GreatAnd fd: 2 arg_word: {(1)} spids: [290] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:BLD) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(tput)} {(md)})]) left_token: spids: [301 305] ) } spids: [300] ) ] spids: [300] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:RST) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(tput)} {(me)})]) left_token: spids: [309 313] ) } spids: [308] ) ] spids: [308] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:HLI) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(tput)} {(so)})]) left_token: spids: [317 321] ) } spids: [316] ) ] spids: [316] ) ] spids: [281 294] ) ] spids: [-1 324] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:LS_HLI) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_Name "$HLI"))}) (C {(sed)} { (DQ (s/) ($ VSub_Name "$ESC") (EscapedLiteralPart token: ) (EscapedLiteralPart token:) (".*") (EscapedLiteralPart token: ) (m/) (EscapedLiteralPart token:) (/) ) } ) ] negated: False ) ] ) left_token: spids: [328 350] ) } spids: [327] ) ] spids: [327] ) ] spids: [189 223] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:color_when) op:Equal rhs:{(auto)} spids:[355])] spids: [355] ) ] spids: [352 358] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:ls) op:Equal rhs:{(ls)} spids:[361])] spids: [361] ) (AndOr children: [ (BraceGroup children: [ (Sentence child: (SimpleCommand words: [{(ls)} {(--color)} {(-d)} {(.)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [377] ) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[380]) ] ) terminator: ) ] spids: [367] ) (AndOr children: [ (BraceGroup children: [ (Sentence child: (AndOr children: [ (SimpleCommand words: [{(gls)} {(--color)} {(-d)} {(.)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [398] ) (Redir op_id: Redir_GreatAnd fd: 2 arg_word: {(1)} spids: [401] ) ] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:ls) op: Equal rhs: {(gls)} spids: [406] ) ] spids: [406] ) ] op_id: Op_DAmp ) terminator: ) ] spids: [388] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:NONGNU) op:Equal rhs:{(1)} spids:[414])] spids: [414] ) ] op_id: Op_DPipe ) ] op_id: Op_DPipe ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$color_when"))} {(Lit_Other "]")}) terminator: ) ] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$NONGNU"))} {(Lit_Other "]")}) terminator: ) ] action: [ (AndOr children: [ (BraceGroup children: [ (Sentence child: (C {(colorls)} {(-d)} {(.)}) terminator: ) ] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [457] ) (Redir op_id: Redir_GreatAnd fd: 2 arg_word: {(1)} spids: [460] ) ] spids: [446] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:ls) op: Equal rhs: {(colorls)} spids: [465] ) ] spids: [465] ) ] op_id: Op_DAmp ) (AndOr children: [ (SimpleCommand words: [{($ VSub_Name "$ls")} {(-G)} {(-d)} {(.)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [480] ) (Redir op_id: Redir_GreatAnd fd: 2 arg_word: {(1)} spids: [483] ) ] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:color_opt) op: Equal rhs: {(-G)} spids: [488] ) ] spids: [488] ) ] op_id: Op_DAmp ) (AndOr children: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$color_when"))} {(Lit_Other "=")} {(DQ (always))} {(Lit_Other "]")} ) (BraceGroup children: [ (Sentence child: (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CLICOLOR_FORCE) op: Equal rhs: {(1)} spids: [513] ) ] spids: [513] ) terminator: ) (Sentence child: (C {(export)} {(CLICOLOR_FORCE)}) terminator: ) ] spids: [511] ) ] op_id: Op_DAmp ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:color_when) op: Equal rhs: {(SQ )} spids: [525] ) ] spids: [525] ) (Sentence child: (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:LSCOLORS) op: Equal rhs: {(DQ (ExGxcxdxCxegedCxCxExEx))} spids: [541] ) ] spids: [541] ) terminator: ) (C {(export)} {(LSCOLORS)}) ] spids: [-1 443] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:color_opt) op: Equal rhs: {(SQ <"--color=">)} spids: [555] ) ] spids: [555] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:color_never) op: Equal rhs: {(DQ ("--color=never"))} spids: [561] ) ] spids: [561] ) (AndOr children: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$LS_COLORS"))} {(Lit_Other "]")}) (C {(eval)} { (CommandSubPart command_list: (CommandList children:[(C {(dircolors)})]) left_token: spids: [583 585] ) } ) ] op_id: Op_DPipe ) (AndOr children: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$LS_COLORS"))} {(Lit_Other "]")}) (C {(eval)} { (CommandSubPart command_list: (CommandList children: [ (SimpleCommand words: [{(dircolors)}] more_env: [(env_pair name:TERM val:{(xterm)} spids:[605])] ) ] ) left_token: spids: [604 609] ) } ) ] op_id: Op_DPipe ) (Sentence child: (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:LS_COLORS) op: Equal rhs: {(DQ (":") ($ VSub_Name "$LS_COLORS") (":"))} spids: [666] ) ] spids: [666] ) terminator: ) (C {(export)} {(LS_COLORS)}) (If arms: [ (if_arm cond: [ (Sentence child: (Pipeline children: [ (C {(dircolors)}) (SimpleCommand words: [{(grep)} {(-F)} {(DQ (":mh="))}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [702] ) ] ) ] negated: False ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:hl_no_color) op: Equal rhs: {(DQ ("s/:hl=[^:]*:/:mh=:/; s/:mh=[^:]*:/:mh=:/"))} spids: [709] ) ] spids: [709] ) ] spids: [-1 706] ) (if_arm cond: [ (Sentence child: (Pipeline children: [ (C {(dircolors)}) (SimpleCommand words: [{(grep)} {(-F)} {(DQ ("hl="))}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [729] ) ] ) ] negated: False ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:hl_no_color) op: Equal rhs: {(DQ ("s/:mh=[^:]*:/:hl=:/; s/:hl=[^:]*:/:hl=:/"))} spids: [736] ) ] spids: [736] ) ] spids: [715 733] ) ] spids: [-1 742] ) (C {(eval)} { (DQ (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {(Lit_VarLike "LS_COLORS=") (EscapedLiteralPart token: ) (EscapedLiteralPart token:) ($ VSub_Name "$LS_COLORS") (EscapedLiteralPart token: ) (EscapedLiteralPart token:) (EscapedLiteralPart token:) } ) (C {(sed)} {(EscapedLiteralPart token:)}) ] negated: False ) (C {($ VSub_Name "$hl_no_color")}) (C {(s/) (Lit_Other ":") (Lit_VarLike "su=") (Lit_Other "[") (Lit_Other "^") (Lit_Other ":") (Lit_Other "]") (Lit_Other "*") (Lit_Other ":") (/) (Lit_Other ":") (Lit_VarLike "su=") (Lit_Other ":") (/) } ) (C {(s/) (Lit_Other ":") (Lit_VarLike "sg=") (Lit_Other "[") (Lit_Other "^") (Lit_Other ":") (Lit_Other "]") (Lit_Other "*") (Lit_Other ":") (/) (Lit_Other ":") (Lit_VarLike "sg=") (Lit_Other ":") (/) } ) (C {(s/) (Lit_Other ":") (Lit_VarLike "ow=") (Lit_Other "[") (Lit_Other "^") (Lit_Other ":") (Lit_Other "]") (Lit_Other "*") (Lit_Other ":") (/) (Lit_Other ":") (Lit_VarLike "ow=") (Lit_Other ":") (/) } ) (C {(s/) (Lit_Other ":") (Lit_VarLike "st=") (Lit_Other "[") (Lit_Other "^") (Lit_Other ":") (Lit_Other "]") (Lit_Other "*") (Lit_Other ":") (/) (Lit_Other ":") (Lit_VarLike "st=") (Lit_Other ":") (/) } ) (C {(s/) (Lit_Other ":") (Lit_VarLike "tw=") (Lit_Other "[") (Lit_Other "^") (Lit_Other ":") (Lit_Other "]") (Lit_Other "*") (Lit_Other ":") (/) (Lit_Other ":") (Lit_VarLike "tw=") (Lit_Other ":") (/) } ) (C {(s/) (Lit_Other ":") (Lit_VarLike "ca=") (Lit_Other "[") (Lit_Other "^") (Lit_Other ":") (Lit_Other "]") (Lit_Other "*") (Lit_Other ":") (/) (Lit_Other ":") (Lit_VarLike "ca=") (Lit_Other ":") (/) } ) (C {(s/) (Lit_Other ":") (Lit_VarLike "mi=") (Lit_Other "[") (Lit_Other "^") (Lit_Other ":") (Lit_Other "]") (EscapedLiteralPart token:) (1) (Lit_Comma ",") (EscapedLiteralPart token: ) (Lit_Other ":") (/) (Lit_Other ":") (Lit_VarLike "mi=") ($ VSub_Name "$LS_HLI") (Lit_Other ":") (/) } ) (C {(EscapedLiteralPart token:)}) (C {(echo)} {(SQ <"export LS_COLORS">)}) ] ) left_token: spids: [765 919] ) ) } ) ] spids: [552 923] ) ] spids: [-1 429] ) ] spids: [-1 925] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:total) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {($ VSub_Name "$ls")} {(-s)} {($ VSub_Name "$color_never")} {(/)}) (C {(sed)} {(SQ <"s/\\([^ ]*\\).*/\\1/;q">)}) ] negated: False ) ] ) left_token: spids: [931 947] ) } spids: [930] ) ] spids: [930] ) (AndOr children: [ (SimpleCommand words: [{($ VSub_Name "$ls")} {(--group-directories-first)} {(-d)} {(.)}] redirects: [ (Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[961]) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[964]) ] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:gdf) op: Equal rhs: {(--group-directories)} spids: [969] ) ] spids: [969] ) ] op_id: Op_DAmp ) (AndOr children: [ (SimpleCommand words: [{($ VSub_Name "$ls")} {(--no-group)} {(-d)} {(.)}] redirects: [ (Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[980]) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[983]) ] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:ng) op:Equal rhs:{(--no-group)} spids:[988])] spids: [988] ) ] op_id: Op_DAmp ) (AndOr children: [ (SimpleCommand words: [{($ VSub_Name "$ls")} {(--quoting) (Lit_Other "=") (shell-escape)} {(-d)} {(.)}] redirects: [ (Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[1001]) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[1004]) ] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:quote) op: Equal rhs: {(--quoting) (Lit_Other "=") (shell-escape)} spids: [1009] ) ] spids: [1009] ) ] op_id: Op_DAmp ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:lfmt) op:Equal rhs:{(lfmt)} spids:[1021])] spids: [1021] ) (AndOr children: [ (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_Star "$*"))}) (SimpleCommand words: [{(grep)} {(-E)} {(--)} {(DQ ("-(m|i|x|s|C|-version|-help)"))}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[1042])] ) ] negated: False ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:lfmt) op:Equal rhs:{(DQ )} spids:[1047])] spids: [1047] ) ] op_id: Op_DAmp ) (SimpleCommand words: [{(exec)}] redirects: [(Redir op_id:Redir_GreatAnd fd:4 arg_word:{(1)} spids:[1064])] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:ls_status) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (BraceGroup children: [ (Sentence child: (Pipeline children: [ (BraceGroup children: [ (Sentence child: (C {($ VSub_Name "$ls")} {(-lrtq)} {($ VSub_Name "$color_opt") ($ VSub_Name "$color_when")} {($ VSub_Name "$ng")} {($ VSub_Name "$gdf")} {($ VSub_Name "$quote")} {(DQ ($ VSub_At "$@"))} ) terminator: ) (Sentence child: (SimpleCommand words: [{(printf)} {($ VSub_QMark "$?")}] redirects: [ (Redir op_id: Redir_GreatAnd fd: 1 arg_word: {(3)} spids: [1102] ) ] ) terminator: ) ] spids: [1071] ) (SimpleCommand words: [ {(sed)} { (DQ ("\n") (" # Remove total line(s) I never use\n") (" /") ($ VSub_Name "$total") (" [0-9,. ]") (EscapedLiteralPart token:) ("1,") (EscapedLiteralPart token: ) (Lit_Other "$") ("/d\n") ("\n") (" # prettify symlink arrows\n") (" s/ -> / ") ($ VSub_Name "$BLD") ($ VSub_Name "$SYM_ARROW") ($ VSub_Name "$RST") (" /\n") ("\n") (" # Conditionally process long format output\n") (" b ") ($ VSub_Name "$lfmt") ("\n") (" :lfmt\n") ("\n") (" # Ignore directory name headings\n") (" /^[^ ]") (EscapedLiteralPart token: ) ("1,") (EscapedLiteralPart token:) (":") (Lit_Other "$") ("/b\n") ("\n") (" # temporarily shrink any prepended reset codes\n") (" # from older ls' to a single char\n") (" s/^") ($ VSub_Name "$ESC") (EscapedLiteralPart token: ) ("0*m/0/\n") ("\n") (" # highlight ug+s indicators\n") (" s/^") (EscapedLiteralPart token: ) (0) (EscapedLiteralPart token:) ("0,1") (EscapedLiteralPart token: ) (.) (EscapedLiteralPart token:) (3) (EscapedLiteralPart token: ) (EscapedLiteralPart token:) (EscapedLiteralPart token:) ("[sS]") (EscapedLiteralPart token:) (/) (EscapedLiteralPart token: ) ($ VSub_Name "$HLI") (EscapedLiteralPart token:) ($ VSub_Name "$RST") ("/\n") (" s/^") (EscapedLiteralPart token:) (0) (EscapedLiteralPart token: ) ("0,1") (EscapedLiteralPart token:) (.) (EscapedLiteralPart token: ) (6) (EscapedLiteralPart token:) (EscapedLiteralPart token: ) (EscapedLiteralPart token:) ("[sS]") (EscapedLiteralPart token: ) (/) (EscapedLiteralPart token:) ($ VSub_Name "$HLI") (EscapedLiteralPart token: ) ($ VSub_Name "$RST") ("/\n") ("\n") (" # highlight +t o+w indicators for directories\n") (" /^0") (EscapedLiteralPart token: ) ("0,1") (EscapedLiteralPart token:) ("d/!b not_dir\n") (" s/^") (EscapedLiteralPart token: ) (0) (EscapedLiteralPart token:) ("0,1") (EscapedLiteralPart token: ) (.) (EscapedLiteralPart token:) (9) (EscapedLiteralPart token: ) (EscapedLiteralPart token:) (EscapedLiteralPart token:) ("[tT]") (EscapedLiteralPart token:) (/) (EscapedLiteralPart token: ) ($ VSub_Name "$HLI") (EscapedLiteralPart token:) ($ VSub_Name "$RST") ("/\n") (" s/^") (EscapedLiteralPart token:) (0) (EscapedLiteralPart token: ) ("0,1") (EscapedLiteralPart token:) (.) (EscapedLiteralPart token: ) (8) (EscapedLiteralPart token:) (EscapedLiteralPart token: ) (w/) (EscapedLiteralPart token:) (${ VSub_Name HLI) (w) ($ VSub_Name "$RST") ("/\n") (" s/^") (EscapedLiteralPart token:) (0) (EscapedLiteralPart token: ) ("0,1") (EscapedLiteralPart token:) (.) (EscapedLiteralPart token: ) (3) (EscapedLiteralPart token:) (EscapedLiteralPart token: ) (EscapedLiteralPart token:) ("[sS]") (EscapedLiteralPart token: ) (/) (EscapedLiteralPart token:) ($ VSub_Name "$HLI") (EscapedLiteralPart token: ) ($ VSub_Name "$RST") ("/\n") (" s/^") (EscapedLiteralPart token:) (0) (EscapedLiteralPart token: ) ("0,1") (EscapedLiteralPart token:) (.) (EscapedLiteralPart token: ) (6) (EscapedLiteralPart token:) (EscapedLiteralPart token: ) (EscapedLiteralPart token:) ("[sS]") (EscapedLiteralPart token: ) (/) (EscapedLiteralPart token:) ($ VSub_Name "$HLI") (EscapedLiteralPart token: ) ($ VSub_Name "$RST") ("/\n") (" :not_dir\n") ("\n") (" # highlight multiply linked files\n") (" /^0") (EscapedLiteralPart token: ) ("0,1") (EscapedLiteralPart token:) ("[^d]") (EscapedLiteralPart token: ) ("10,") (EscapedLiteralPart token:) ("/!b not_hl\n") (" /^[^ ]* *1 /b not_hl\n") (" s/^") (EscapedLiteralPart token:) (0) (EscapedLiteralPart token: ) ("0,1") (EscapedLiteralPart token:) ("[^ ]*") (EscapedLiteralPart token: ) (EscapedLiteralPart token:) (" *") (EscapedLiteralPart token: ) (EscapedLiteralPart token:) ("[0-9]") (EscapedLiteralPart token: ) ("1,") (EscapedLiteralPart token:) (EscapedLiteralPart token: ) (/) (EscapedLiteralPart token:) (EscapedLiteralPart token: ) ($ VSub_Name "$HLI") (EscapedLiteralPart token:) ($ VSub_Name "$RST") ("/\n") (" :not_hl\n") ("\n") (" # restore any reset codes replaced above\n") (" s/^0/") (${ VSub_Name ESC) ("[0m/\n") ) } ] redirects: [ (Redir op_id: Redir_GreatAnd fd: 1 arg_word: {(4)} spids: [1331] ) ] ) ] negated: False ) terminator: ) ] redirects: [(Redir op_id:Redir_GreatAnd fd:3 arg_word:{(1)} spids:[1337])] spids: [1069] ) ] ) left_token: spids: [1068 1339] ) } spids: [1067] ) ] spids: [1067] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:sed_status) op: Equal rhs: {($ VSub_QMark "$?")} spids: [1342] ) ] spids: [1342] ) (AndOr children: [ (C {(test)} {($ VSub_Name "$ls_status")} {(KW_Bang "!") (Lit_Other "=")} {(0)}) (AndOr children: [ (C {(exit)} {($ VSub_Name "$ls_status")}) (C {(exit)} {($ VSub_Name "$sed_status")}) ] op_id: Op_DPipe ) ] op_id: Op_DAmp ) ] )