about summary refs log tree commit diff
path: root/contrib/lrls
blob: 2d41447b1c1daaff35786069ba929b7b27ea0083 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh
# lrls - lr with GNU ls style output
#
# Usage (Bash, Zsh):
#
#     # Clear any system-level aliases:
#     unalias ls la ll 2>/dev/null
#     alias ls='lslr -A'
#     alias la='lslr'
#     alias ll='lslr -lh'

use_strip=1
check_depth=1

if [ -t 1 ]; then
    use_color=1
    use_column=1
fi

while getopts :01ABC:DFGHLQPST:UWXde:f:lho:st:x opt; do
    case $opt in
    # If we're not entering directories:
    # - Avoid depth check so directory names aren't skipped entirely.
    # - Avoid strip so directory names aren't replaced with dots.
    d)  unset check_depth
        unset use_strip
        ;;
    # Avoid git column for long lr output.
    l)  unset use_column
        ;;
    esac
done

# If more than one path is given as an arg, strip can produce ambiguous output
# for multi-segment paths (and has no effect on single-segment paths).
if [ "$#" -gt "$OPTIND" ]; then
    unset use_strip
fi

lr -1 \
    ${use_color:+-GG} \
    ${use_strip:+-s} \
    ${check_depth:+-t '!type == d || depth > 0'} \
    "$@" | {
        if [ -n "$use_column" ]; then
            git column --mode=dense --pad=2
        else
            cat
        fi;
    }