Skip to content

Commit

Permalink
Merge pull request #60 from cfont/features/display_exports
Browse files Browse the repository at this point in the history
Fixes #56 adding support for displaying exported environment variables in deskfiles
  • Loading branch information
jamesob committed Mar 19, 2016
2 parents 824fc4b + 2e00f5c commit 4cab6dd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
9 changes: 5 additions & 4 deletions desk
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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/"
}
Expand Down
3 changes: 3 additions & 0 deletions examples/hello.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

10 changes: 10 additions & 0 deletions test/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ ensure $? "Desk current terraform missing apply"
echo "$CURRENT" | grep 'config - Set up terraform config: <config_key>' >/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"
Expand All @@ -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')
Expand Down

0 comments on commit 4cab6dd

Please sign in to comment.