From 18196f78fb35689984fb6d15b567b1e432da1fd6 Mon Sep 17 00:00:00 2001 From: Ryan Schlesinger Date: Wed, 25 Jan 2017 09:09:50 -0800 Subject: [PATCH 1/6] Add load command --- desk | 75 ++++++++++++++++++++++++++++++++++------------- test/run_tests.sh | 14 +++++++++ 2 files changed, 69 insertions(+), 20 deletions(-) diff --git a/desk b/desk index d8b5fb2..e8c335b 100755 --- a/desk +++ b/desk @@ -103,27 +103,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 +121,31 @@ 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}" + echo "export DESK_ENV=${DESKPATH}" + fi +} + cmd_run() { local TODESK="$1" shift; @@ -324,6 +332,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 + 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 +367,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..f14f8c7 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -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 + +## `desk load` + +pushd example-project + +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 echo "tests pass." From 5ba73a39414a204542661b3c0cd4ff6297ce90b2 Mon Sep 17 00:00:00 2001 From: Ryan Schlesinger Date: Wed, 25 Jan 2017 10:19:15 -0800 Subject: [PATCH 2/6] Send error to stderr --- desk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/desk b/desk index e8c335b..c8fc150 100755 --- a/desk +++ b/desk @@ -346,7 +346,7 @@ get_desk_name_and_path() { # 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}'" + >&2 echo "No Deskfile found in '${POSSIBLE_DESKFILE_DIR}'" exit 1 fi From cff7aabea8417d603697df4567b4173e54fde4aa Mon Sep 17 00:00:00 2001 From: Ryan Schlesinger Date: Wed, 25 Jan 2017 10:19:30 -0800 Subject: [PATCH 3/6] Add usage --- desk | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/desk b/desk index c8fc150..ccae03c 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 From 6544859aa0c3dba07213c05c636973928ac31635 Mon Sep 17 00:00:00 2001 From: Ryan Schlesinger Date: Wed, 8 Feb 2017 08:38:54 -0800 Subject: [PATCH 4/6] load now sources desk_env --- desk | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/desk b/desk index ccae03c..63e1920 100755 --- a/desk +++ b/desk @@ -146,8 +146,7 @@ cmd_load() { echo "Desk $TODESK (${TODESK}${DESKEXT}) not found in $DESKS" exit 1 else - echo "export DESK_NAME=${TODESK}" - echo "export DESK_ENV=${DESKPATH}" + echo "export DESK_NAME=\"${TODESK}\"; export DESK_ENV=\"${DESKPATH}\"; source \${DESK_ENV}" fi } From ace8f55ee28b96e0ea119c95d777c2c2b3885c0b Mon Sep 17 00:00:00 2001 From: Ryan Schlesinger Date: Thu, 7 Jul 2022 17:56:33 +0000 Subject: [PATCH 5/6] Update Dockerfile --- Dockerfile | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) 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 From 7c7ae87aa3c3c8f8b475012a9b7a935a6aac1d56 Mon Sep 17 00:00:00 2001 From: Ryan Schlesinger Date: Thu, 7 Jul 2022 17:56:47 +0000 Subject: [PATCH 6/6] Fix busted test and silence pushd/popd --- test/run_tests.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/run_tests.sh b/test/run_tests.sh index f14f8c7..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,13 +171,13 @@ 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 +pushd example-project >/dev/null -RAN=$($SHELL -c '$(eval desk load .); desk; exit') +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 @@ -185,6 +185,6 @@ 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 +popd >/dev/null echo "tests pass."