From 9846e7f47afc9660a5eb3af7af618a138d907058 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Fri, 10 Jun 2016 14:48:05 +0200 Subject: [PATCH] Shell: Make typex work on multiple arguments --- .shell.d/funs_rc | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/.shell.d/funs_rc b/.shell.d/funs_rc index 17bff928..adcaef1c 100644 --- a/.shell.d/funs_rc +++ b/.shell.d/funs_rc @@ -145,20 +145,25 @@ echokeymap () { ## Extended info typex () { - local xpath - if [ $# -ne 1 ] || ! command -v "$1" >/dev/null 2>&1; then - echo "Provide an existing command as parameter." + local xpath cmd + + if [ $# -lt 1 ]; then + echo >&2 "Provide an existing command as parameter." return fi - if [ -z "$(command -v "$1" 2>/dev/null | grep ^/)" ]; then - type "$1" - return - fi - - xpath="$(type $1 | cut -d' ' -f3)" - ls -l "$xpath" - file "$xpath" | cut -d':' -f2 | cut -b 2- + for i; do + cmd="$(command -v "$i" 2>/dev/null)" + if [ $? -ne 0 ]; then + echo "$i does not exist." + elif [ -z "$(echo "$cmd" | grep ^/)" ]; then + type "$i" + else + xpath="$(type $1 | cut -d' ' -f3)" + ls -l "$xpath" + file "$xpath" | cut -d':' -f2 | cut -b 2- + fi + done } # Automatically change the directory in shell after closing ranger.