From e14543a4bcdb118e835091af697af2ea618b25c7 Mon Sep 17 00:00:00 2001 From: Travis Swicegood Date: Tue, 15 May 2012 10:26:03 -0500 Subject: [PATCH] fix typeset_functions typeset_functions relies on a hack to determine the shell it is running under. this hack fails on some versions of bash. if the $SHELL variable is set, prefer that instead. fix bug in draft() --- lib/composure.sh | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/composure.sh b/lib/composure.sh index 8ca66d6..beaf13a 100644 --- a/lib/composure.sh +++ b/lib/composure.sh @@ -145,13 +145,19 @@ typeset_functions () # unfortunately, there does not seem to be a easy, portable way to list just the # names of the defined shell functions... - # here's a hack I modified from a StackOverflow post: - # we loop over the ps listing for the current process ($$), and print the last column (CMD) - # stripping any leading hyphens bash sometimes throws in there - - typeset x ans - typeset this=$(for x in $(ps -p $$); do ans=$x; done; printf "%s\n" $ans | sed 's/^-*//') - typeset shell=$(basename $this) # e.g. /bin/bash => bash + # first, determine our shell: + typeset shell + if [ -n "$SHELL" ]; then + shell=$(basename $SHELL) # we assume this is set correctly! + else + # we'll have to try harder + # here's a hack I modified from a StackOverflow post: + # we loop over the ps listing for the current process ($$), and print the last column (CMD) + # stripping any leading hyphens bash sometimes throws in there + typeset x ans + typeset this=$(for x in $(ps -p $$); do ans=$x; done; printf "%s\n" $ans | sed 's/^-*//') + typeset shell=$(basename $this) # e.g. /bin/bash => bash + fi case "$shell" in bash) typeset -F | awk '{print $3}' @@ -229,7 +235,7 @@ draft () fi # aliases bind tighter than function names, disallow them - if [ -n "$(type -a $func | grep 'is.*alias')" ]; then + if [ -n "$(type -a $func 2>/dev/null | grep 'is.*alias')" ]; then printf '%s\n' "sorry, $(type -a $func). please choose another name." return fi -- 2.17.1