diff --git a/Dockerfile b/Dockerfile index 1f4fa25..6585a0d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,40 @@ -FROM ubuntu:14.04 -MAINTAINER desk +FROM ubuntu:jammy + +SHELL ["/bin/bash", "-o", "pipefail", "-c"] +ENV DEBIAN_FRONTEND=noninteractive ENV USERNAME desktester RUN adduser --disabled-password --gecos "" desktester -RUN apt-get update && apt-get install -y vim expect zsh fish + +RUN set -eux; \ + \ + apt-get update -y; \ + apt-get install -y \ + vim \ + expect \ + zsh \ + fish \ + ; \ + apt-get clean; \ + rm -f /var/lib/apt/lists/*_* WORKDIR /home/$USERNAME/ -ADD desk /usr/local/bin/desk -ADD test/zshrc .zshrc -ADD test/bashrc .bashrc -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 -# Set up test Deskfile -RUN mkdir -p example-project && cp examples/hello.sh example-project/Deskfile +COPY desk /usr/local/bin/desk +COPY test/zshrc .zshrc +COPY test/bashrc .bashrc +COPY test/run_tests.sh run_tests.sh +COPY test/run_tests.fish run_tests.fish +COPY examples examples -RUN chown -R $USERNAME:$USERNAME .zshrc example-project examples run_tests.fish run_tests.sh .bashrc .config +RUN set -eux; \ + \ + mkdir -p .config/fish; \ + touch .config/fish/config.fish; \ + # Set up test Deskfile \ + mkdir -p example-project; \ + cp examples/hello.sh example-project/Deskfile; \ + \ + chown -R $USERNAME:$USERNAME .zshrc example-project examples run_tests.fish run_tests.sh .bashrc .config USER $USERNAME diff --git a/desk b/desk index d8b5fb2..63e1920 100755 --- a/desk +++ b/desk @@ -30,6 +30,11 @@ Usage: 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 load [] + Display the commands needed to load a desk into the current 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. Normal usage: eval \$($PROGRAM load ) $PROGRAM run '' $PROGRAM run ... Run a command within a desk's environment then exit. In the first form @@ -103,27 +108,10 @@ cmd_go() { # - a directory containing a Deskfile # - empty -> `./Deskfile` # - local TODESK="$1" - local DESKEXT=$(get_deskfile_extension) - 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 + local RESULT="$(get_desk_name_and_path $1)" + local TODESK="${RESULT%:*}" + local DESKPATH="${RESULT#*:}" # Shift desk name so we can forward on all arguments to the shell. shift; @@ -138,6 +126,30 @@ cmd_go() { } +cmd_load() { + # 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 RESULT="$(get_desk_name_and_path $1)" + local TODESK="${RESULT%:*}" + local DESKPATH="${RESULT#*:}" + + # Shift desk name so we can forward on all arguments to the shell. + shift; + + if [ -z "$DESKPATH" ]; then + echo "Desk $TODESK (${TODESK}${DESKEXT}) not found in $DESKS" + exit 1 + else + echo "export DESK_NAME=\"${TODESK}\"; export DESK_ENV=\"${DESKPATH}\"; source \${DESK_ENV}" + fi +} + cmd_run() { local TODESK="$1" shift; @@ -324,6 +336,32 @@ print_aligned() { }' } +get_desk_name_and_path() { + local TODESK="$1" + local DESKEXT=$(get_deskfile_extension) + 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 + >&2 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 + + echo "${TODESK}:${DESKPATH}" +} + PROGRAM="${0##*/}" @@ -333,6 +371,7 @@ case "$1" in version|--version) shift; cmd_version "$@" ;; ls|list) shift; cmd_list "$@" ;; go|.) shift; cmd_go "$@" ;; + load) shift; cmd_load "$@" ;; run) shift; cmd_run "$@" ;; edit) shift; cmd_edit "$@" ;; *) cmd_current "$@" ;; diff --git a/test/run_tests.sh b/test/run_tests.sh index 08ea9b1..4e9ca0a 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -161,7 +161,7 @@ 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 +pushd example-project >/dev/null RAN=$(desk go . -c 'desk ; exit') echo "$RAN" | grep "example-project - simple desk that says hello" >/dev/null @@ -171,6 +171,20 @@ 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 +popd >/dev/null + +## `desk load` + +pushd example-project >/dev/null + +RAN=$($SHELL -c 'eval $(desk load); desk; exit') +echo "$RAN" | grep "example-project - simple desk that says hello" >/dev/null +ensure $? "Deskfile load didn't work (./)" +echo "$RAN" | grep -E "hi\s+" >/dev/null +ensure $? "Deskfile load didn't work (example-project/)" +echo "$RAN" | grep -E "howdy\s+" >/dev/null +ensure $? "Deskfile load didn't work (example-project/)" + +popd >/dev/null echo "tests pass."