diff --git a/Dockerfile b/Dockerfile index 442f70e..1f4fa25 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,10 @@ ADD test/run_tests.sh run_tests.sh ADD test/run_tests.fish run_tests.fish ADD examples examples RUN mkdir -p .config/fish && touch .config/fish/config.fish -RUN chown -R $USERNAME:$USERNAME .zshrc examples run_tests.fish run_tests.sh .bashrc .config + +# Set up test Deskfile +RUN mkdir -p example-project && cp examples/hello.sh example-project/Deskfile + +RUN chown -R $USERNAME:$USERNAME .zshrc example-project examples run_tests.fish run_tests.sh .bashrc .config USER $USERNAME diff --git a/README.md b/README.md index d3f4a07..cd5f9d9 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ There are no dependencies other than `bash`. Desk is explicitly tested with `bas `zsh`, and `fish`. ```sh -◲ desk 0.4.1 +◲ desk 0.5.0 Usage: @@ -44,8 +44,10 @@ Usage: Initialize desk configuration. desk (list|ls) List all desks along with a description. - desk (.|go) [shell-args...] - Activate a desk. Extra arguments are passed onto shell. + desk (.|go) [ [shell-args...]] + Activate a desk. Extra arguments are passed onto shell. If called with + no arguments, look for a Deskfile in the current directory. If not a + recognized desk, try as a path to directory containing a Deskfile. desk run Run a command within a desk's environment then exit. Think '$SHELL -c'. desk edit [desk-name] @@ -95,9 +97,9 @@ $ desk tf desk for doing work on a terraform repo - set_aws_env - Set up AWS env variables: - plan - Run `terraform plan` with proper AWS var config - apply - Run `terraform apply` with proper AWS var config + set_aws_env Set up AWS env variables: + plan Run `terraform plan` with proper AWS var config + apply Run `terraform apply` with proper AWS var config ``` Basically, desk just associates a shell script (`name.sh`) with a name. When @@ -179,7 +181,23 @@ Desk does pay attention to certain kinds of comments, though. - *alias and function docs*: if the line above an alias or function is a comment, it will be used as documentation. + +### Deskfiles +Deskfiles are just shell scripts at the root of a project directory that +adhere to the conventions above. These can be put into version control to +formalize and ease common development tasks like running tests or doing +local builds. + +For example, if we have some directory or repository called `myproject`, if +we create `myproject/Deskfile`, we'll be able to do any of the following: +```sh +$ desk go /path/to/myproject/ +$ desk go /path/to/myproject/Deskfile +myproject/ $ desk go . +myproject/ $ desk go +``` + ### Sharing deskfiles across computers Of course, the desk config directory (by default `~/.desks`) can be a symlink diff --git a/desk b/desk index ada70f2..8f25232 100755 --- a/desk +++ b/desk @@ -3,12 +3,13 @@ PREFIX="${DESK_DIR:-$HOME/.desk}" DESKS="${DESK_DESKS_DIR:-$PREFIX/desks}" +DESKFILE_NAME=Deskfile ## Commands cmd_version() { - echo "◲ desk 0.4.1" + echo "◲ desk 0.5.0" } @@ -25,8 +26,10 @@ Usage: Initialize desk configuration. $PROGRAM (list|ls) List all desks along with a description. - $PROGRAM (.|go) [shell-args...] - Activate a desk. Extra arguments are passed onto shell. + $PROGRAM (.|go) [ [shell-args...]] + Activate a desk. Extra arguments are passed onto shell. If called with + no arguments, look for a Deskfile in the current directory. If not a + recognized desk, try as a path to directory containing a Deskfile. $PROGRAM run Run a command within a desk's environment then exit. Think '\$SHELL -c'. $PROGRAM edit [desk-name] @@ -90,9 +93,34 @@ cmd_init() { cmd_go() { + # TODESK ($1) may either be + # + # - the name of a desk in $DESKS/ + # - a path to a Deskfile + # - a directory containing a Deskfile + # - empty -> `./Deskfile` + # local TODESK="$1" local DESKEXT=$(get_deskfile_extension) - local DESKPATH="$(find "${DESKS}/" -name "${TODESK}${DESKEXT}")" + local DESKPATH="$(find "${DESKS}/" -name "${TODESK}${DESKEXT}" 2>/dev/null)" + + local POSSIBLE_DESKFILE_DIR="${TODESK%$DESKFILE_NAME}" + if [ -z "$POSSIBLE_DESKFILE_DIR" ]; then + POSSIBLE_DESKFILE_DIR="." + fi + + # If nothing could be found in $DESKS/, check to see if this is a path to + # a Deskfile. + if [[ -z "$DESKPATH" && -d "$POSSIBLE_DESKFILE_DIR" ]]; then + if [ ! -f "${POSSIBLE_DESKFILE_DIR}/${DESKFILE_NAME}" ]; then + echo "No Deskfile found in '${POSSIBLE_DESKFILE_DIR}'" + exit 1 + fi + + local REALPATH=$( cd $POSSIBLE_DESKFILE_DIR && pwd ) + DESKPATH="${REALPATH}/${DESKFILE_NAME}" + TODESK=$(basename "$REALPATH") + fi # Shift desk name so we can forward on all arguments to the shell. shift; @@ -165,8 +193,6 @@ cmd_current() { fi local DESKPATH=$DESK_ENV - local DESK_NAME=${DESKPATH##*/} - local DESK_NAME=${DESK_NAME%.*} local CALLABLES=$(get_callables "$DESKPATH") local AUTO_ALIGN len longest out diff --git a/test/run_tests.sh b/test/run_tests.sh index b99f628..263b6e1 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -129,4 +129,34 @@ RAN=$(desk run hello 'hi j') echo "$RAN" | grep 'hi, j!' >/dev/null ensure $? "Run in desk 'hello' didn't work with hi function" +## `desk go` + +RAN=$(desk go example-project/Deskfile -c 'desk ; exit') +echo "$RAN" | grep "example-project - simple desk that says hello" >/dev/null +ensure $? "Deskfile invocation didn't work (example-project/)" +echo "$RAN" | grep -E "hi\s+" >/dev/null +ensure $? "Deskfile invocation didn't work (example-project/)" +echo "$RAN" | grep -E "howdy\s+" >/dev/null +ensure $? "Deskfile invocation didn't work (example-project/)" + +RAN=$(desk go example-project/ -c 'desk ; exit') +echo "$RAN" | grep "example-project - simple desk that says hello" >/dev/null +ensure $? "Deskfile invocation didn't work (example-project/)" +echo "$RAN" | grep -E "hi\s+" >/dev/null +ensure $? "Deskfile invocation didn't work (example-project/)" +echo "$RAN" | grep -E "howdy\s+" >/dev/null +ensure $? "Deskfile invocation didn't work (example-project/)" + +pushd example-project + +RAN=$(desk go . -c 'desk ; exit') +echo "$RAN" | grep "example-project - simple desk that says hello" >/dev/null +ensure $? "Deskfile invocation didn't work (./)" +echo "$RAN" | grep -E "hi\s+" >/dev/null +ensure $? "Deskfile invocation didn't work (example-project/)" +echo "$RAN" | grep -E "howdy\s+" >/dev/null +ensure $? "Deskfile invocation didn't work (example-project/)" + +popd + echo "tests pass."