Skip to main content
1 of 2
rr0ss0rr
  • 366
  • 2
  • 6

This is my take on what you are asking for:

llt () 
{ 
    [[ -n $1 ]] || return 1;
    printf -v filetype '%s' $(type -ta $1);
    prt "";
    case $filetype in 
        "")
            prt "llt: $1: not found" 1>&2;
            return 1
        ;;
        *alias*)
            prt-underline "Alias";
            alias "$1" | awk '{sub(/^alias /, ""); print}';
            prt ""
        ;;&
        *function*)
            prt-underline "Shell Function";
            declare -f "$1";
            prt ""
        ;;&
        *builtin*)
            prt-underline "Shell Builtin";
            prt ""
        ;;&
        *keyword*)
            prt-underline "Shell Reserved Word";
            prt ""
        ;;&
        *file*)
            prt-underline "File";
            for fn in $(type -ap $1);
            do
                stat $fn | awk 'NR==1{sub(/^  File: /, ""); print}';
            done
        ;;
    esac
}

The initial printf will create a one liner based on the type -ta $1 ie aliasfilefile Each test of the case will perform the test and the ;;& tells the case statement to continue onto the next test (so the example will hit the alias test and the file test. You can use printf instead of my prt* functions

Forgot to mention if the command is an alias or function, I output the contents of that alias or function

rr0ss0rr
  • 366
  • 2
  • 6