alias ls=ls --color=auto
alias grep=grep --color=auto
alias egrep=egrep --color=auto

function progress {
    # Pulls the read progress of a Linux pid via /proc/$pid/fdinfo (only runs on Linux)

    if { ${os}=="linux" } then {
        #params -> [ 1 ] -> set pid
        $1 -> set pid
        
        g <!null> /proc/$pid/fd/* -> regexp <!null> (f,/proc/[0-9]+/fd/([0-9]+)) -> foreach <!null> fd {
            trypipe <!null> {
                open /proc/$pid/fdinfo/$fd -> cast yaml -> [ pos ] -> set pos
                readlink: /proc/$pid/fd/$fd -> set file
                du -b $file -> [ :0 ] -> set int size
                if { = size > 0 } then {
                    = ($pos/$size)*100 -> set int percent
                    out "$percent% ($pos/$size) $file"
                }
            }
        }
    }
}

autocomplete set progress {
    [{
        "DynamicDesc": ({
            ps -A -o pid,cmd --no-headers -> set ps
            map { $ps[:0] } { $ps -> regexp 'f/^[ 0-9]+ (.*)$' }
        }),
        "ListView": true
    }]
}

config set shell stop-status-func {
    progress $PID
}

if { or { $WSLENV } { $WSL_DISTRO_NAME } } then {
    trypipe {
        mount \
            -> regexp (m/[A-Z]:\\/) -> [:2] \
            -> cast str -> format json \
            -> config: set wsl windows-mounts true
    }
}