aboutsummaryrefslogtreecommitdiff
path: root/sh/shrc.d/lore.sh
blob: 2d7c0becc8c484848c66de11c3fca177afa401d2 (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
# Pipe ls(1) output through PAGER; mostly to preserve coloring interactively
# through less(1), but it'll work fine with plain ls(1) and more(1)
lore() {

    # Add --color=always if the terminal has at least 8 colors; we have to add
    # "always" to coax ls(1) into emitting colors even though it can tell its
    # stdout isn't a terminal but a pager
    [ -e "$HOME"/.cache/ls/color ] &&
    [ "$({ tput colors || tput Co ; } 2>/dev/null)" -ge 8 ] &&
        set -- --color=always "$@"

    # Prefer -A/--almost-all (exclude "." and "..") if available
    if [ -e "$HOME"/.cache/ls/almost-all ] ; then
        set -- -Al "$@"
    else
        set -- -al "$@"
    fi

    # Run whatever `ls` gives us; it might be our function wrapper; that's OK
    ls "$@" |

    # Run the appropriate pager; if it's less(1), we can tack on -R (though my
    # ~/.lesskey does this anyway)
    case $PAGER in
        less) "$PAGER" -R ;;
        *) "$PAGER" ;;
    esac
}