diff --git a/desk b/desk index 8f25232..0442767 100755 --- a/desk +++ b/desk @@ -185,7 +185,7 @@ cmd_list() { # Usage: desk [options] # Description: List the current desk and any associated aliases. If no desk is being used, display available desks -# --no-format: Use ' - ' to separate alias/function names from their descriptions +# --no-format: Use ' - ' to separate alias/export/function names from their descriptions cmd_current() { if [ -z "$DESK_ENV" ]; then printf "No desk activated.\n\n%s" "$(cmd_list)" @@ -214,7 +214,7 @@ cmd_current() { (( len > longest )) && longest=$len local DOCLINE=$( grep -B 1 -E \ - "^(alias ${NAME}=|(function )?${NAME}( )?\()|function $NAME" "$DESKPATH" \ + "^(alias ${NAME}=|export ${NAME}=|(function )?${NAME}( )?\()|function $NAME" "$DESKPATH" \ | grep "#") if [ -z "$DOCLINE" ]; then @@ -262,11 +262,12 @@ echo_description() { echo "${descline##*Description: }" } -# Echo a list of aliases and functions for a given desk +# Echo a list of aliases, exports, and functions for a given desk get_callables() { local DESKPATH=$1 - grep -E "^(alias |(function )?${FNAME_CHARS}+ ?\()|function $NAME" "$DESKPATH" \ + grep -E "^(alias |export |(function )?${FNAME_CHARS}+ ?\()|function $NAME" "$DESKPATH" \ | sed 's/alias \([^= ]*\)=.*/\1/' \ + | sed 's/export \([^= ]*\)=.*/\1/' \ | sed -E "s/(function )?(${FNAME_CHARS}+) ?\(\).*/\2/" \ | sed -E "s/function (${FNAME_CHARS}+).*/\1/" } diff --git a/examples/hello.sh b/examples/hello.sh index 9083a8f..b7ce5ae 100644 --- a/examples/hello.sh +++ b/examples/hello.sh @@ -9,3 +9,6 @@ hi() { # Use if you're from Texas. alias howdy="echo howdy y\'all" +# Why should I always type my name +export MyName="James" + diff --git a/test/run_tests.sh b/test/run_tests.sh index 4013e9e..a2c531e 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -121,6 +121,12 @@ ensure $? "Desk current terraform missing apply" echo "$CURRENT" | grep 'config - Set up terraform config: ' >/dev/null ensure $? "Desk current terraform missing config" +# testing for exported variables +CURRENT=$(DESK_ENV=$HOME/.desk/desks/hello.sh desk) +echo "$CURRENT" | grep 'MyName Why should I always type my name' >/dev/null +ensure $? "Desk current hello missing exported environment variable" + + RAN=$(desk run hello 'howdy james!') echo "$RAN" | grep 'howdy y'"'"'all james!' >/dev/null ensure $? "Run in desk 'hello' didn't work with howdy alias" @@ -129,6 +135,10 @@ RAN=$(desk run hello 'hi j') echo "$RAN" | grep 'hi, j!' >/dev/null ensure $? "Run in desk 'hello' didn't work with hi function" +RAN=$(desk run hello 'echo $MyName') +echo "$RAN" | grep 'James' >/dev/null +ensure $? "Run in desk 'hello' didn't work with MyName exported variable" + ## `desk go` RAN=$(desk go example-project/Deskfile -c 'desk ; exit')