Skip to content

Instantly share code, notes, and snippets.

@renttek
Created August 20, 2021 08:55
Show Gist options
  • Save renttek/556670e2716cfa0e1848c073f3e7d41a to your computer and use it in GitHub Desktop.
Save renttek/556670e2716cfa0e1848c073f3e7d41a to your computer and use it in GitHub Desktop.
#!/bin/zsh
if [ -z "${1}" ]
then
echo "No project name given"
exit 1
fi
WORKSPACE_DIRECTORY="${HOME}/workspace"
PROJECT_NAME="${1}"
PROJECT_DIRECTORY="${WORKSPACE_DIRECTORY}/${PROJECT_NAME}"
DOCKER_WINDOW_NAME="docker"
DOCKER_DIRECTORY="${PROJECT_DIRECTORY}/docker"
SOURCE_WINDOW_NAME="source"
SOURCE_DIRECTORY="${PROJECT_DIRECTORY}/htdocs"
[ -d "${PROJECT_DIRECTORY}" ] || { echo "Directory ${PROJECT_DIRECTORY} does not exist"; exit 2 }
[ -d "${DOCKER_DIRECTORY}" ] || { echo "Directory ${DOCKER_DIRECTORY} does not exist"; exit 2 }
[ -d "${SOURCE_DIRECTORY}" ] || { echo "Directory ${SOURCE_DIRECTORY} does not exist"; exit 2 }
tmux has-session -t "${PROJECT_NAME}" 2>/dev/null
if [ $? != 0 ]; then
tmux new-session -t "${PROJECT_NAME}" -c "${DOCKER_DIRECTORY}" -d
tmux rename-window "${DOCKER_WINDOW_NAME}"
tmux new-window -n "${SOURCE_WINDOW_NAME}" -c "/${SOURCE_DIRECTORY}"
fi
tmux attach-session -d -c "${PROJECT_DIRECTORY}" -t "${PROJECT_NAME}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment