Skip to main content
added 85 characters in body
Source Link
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);
    prtecho "";
    case $filetype in 
        "")
            prtecho "llt: $1: not found" 1>&2;
            return 1
        ;;
        *alias*)
            prt-underlineecho "Alias";
            alias "$1" | awk '{sub(/^alias /, ""); print}';
            prtecho ""
        ;;&
        *function*)
            prt-underlineecho "Shell Function";
            declare -f "$1";
            prtecho ""
        ;;&
        *builtin*)
            prt-underlineecho "Shell Builtin";
            prtecho ""
        ;;&
        *keyword*)
            prt-underlineecho "Shell Reserved Word";
            prtecho ""
        ;;&
        *file*)
            prt-underlineecho "File";
            for fn in $(type -ap $1);
            do
                stat $fn | awk 'NR==1{sub(/^  File: /, ""); print}';
            done
        ;;
    esac
}

On my Mac, llt ls outputs:

Alias
ls='/usr/local/bin/eza'

File
/usr/local/gnubin/ls -> /usr/local/Cellar/coreutils/9.6/libexec/gnubin//ls
/bin/ls

The initial printf will create a one liner based on the type -ta $1 ie aliasfilefile Each test of the case statement 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

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

This is my take on what you are asking for:

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

On my Mac, llt ls outputs:

Alias
ls='/usr/local/bin/eza'

File
/usr/local/gnubin/ls -> /usr/local/Cellar/coreutils/9.6/libexec/gnubin//ls
/bin/ls

The initial printf will create a one liner based on the type -ta $1 ie aliasfilefile Each test of the case statement 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.

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

Source Link
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