added docker_check.sh
This commit is contained in:
parent
32739dbdc3
commit
e75983ac02
7 changed files with 122 additions and 27 deletions
17
.github/workflows/test_script.yml
vendored
17
.github/workflows/test_script.yml
vendored
|
|
@ -41,6 +41,7 @@ jobs:
|
||||||
sudo apt-get install -y tmux
|
sudo apt-get install -y tmux
|
||||||
sudo apt-get install -y fd-find
|
sudo apt-get install -y fd-find
|
||||||
sudo apt-get install -y fzf
|
sudo apt-get install -y fzf
|
||||||
|
sudo apt-get install -y bats
|
||||||
|
|
||||||
- name: Set up tmux environment
|
- name: Set up tmux environment
|
||||||
run: |
|
run: |
|
||||||
|
|
@ -51,15 +52,13 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
python aactivator.py
|
python aactivator.py
|
||||||
|
|
||||||
# - name: Test tmux_sessionizer
|
- name: Test tmux_sessionizer
|
||||||
# run: |
|
run: |
|
||||||
# chmod +x tmux_sessionizer
|
bats tests/test_tmux_sessionizer.bats
|
||||||
# ./tmux_sessionizer
|
|
||||||
#
|
- name: Test tmux_windownizer
|
||||||
# - name: Test tmux_windownizer
|
run: |
|
||||||
# run: |
|
bats tests/test_tmux_windownizer.bats
|
||||||
# chmod +x tmux_windownizer
|
|
||||||
# ./tmux_windownizer
|
|
||||||
|
|
||||||
- name: Test setup_dev_environment.sh
|
- name: Test setup_dev_environment.sh
|
||||||
run: |
|
run: |
|
||||||
|
|
|
||||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
*.log
|
||||||
|
__pycache__*
|
||||||
39
docker_check.sh
Executable file
39
docker_check.sh
Executable file
|
|
@ -0,0 +1,39 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Function to start Docker if not running
|
||||||
|
start_docker() {
|
||||||
|
echo "Docker is not running. Starting Docker..."
|
||||||
|
open --background -a Docker
|
||||||
|
sleep 3 # Wait for Docker to start
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if Docker is installed
|
||||||
|
if ! command -v docker &> /dev/null; then
|
||||||
|
echo "Docker is not installed."
|
||||||
|
read -p "Do you want to install Docker using Homebrew? (y/n): " choice
|
||||||
|
if [ "$choice" == "y" ]; then
|
||||||
|
brew install --cask docker
|
||||||
|
echo "Docker has been installed. Please restart this script."
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "Docker is required to run this script. Exiting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if Docker is running
|
||||||
|
if [ "$(docker info >/dev/null 2>&1 && echo "running")" != "running" ]; then
|
||||||
|
start_docker
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if docker-compose is called
|
||||||
|
if [ "$1" == "docker-compose" ]; then
|
||||||
|
# If docker-compose is called, check if Docker is running again
|
||||||
|
if [ "$(docker info >/dev/null 2>&1 && echo "running")" != "running" ]; then
|
||||||
|
start_docker
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Run the provided command
|
||||||
|
"$@"
|
||||||
|
|
||||||
26
tests/test_tmux_sessionizer
Executable file
26
tests/test_tmux_sessionizer
Executable file
|
|
@ -0,0 +1,26 @@
|
||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
@test "Script creates a tmux session" {
|
||||||
|
TMP_DIR=$(mktemp -d)
|
||||||
|
ORIGINAL_SESSION=$(tmux display-message -p "#S")
|
||||||
|
SESSION_NAME="test_session"
|
||||||
|
|
||||||
|
# Run your script with predefined selection
|
||||||
|
run ./tmux_sessionizer "$TMP_DIR/$SESSION_NAME"
|
||||||
|
|
||||||
|
# Check if the script exited successfully
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
|
||||||
|
# Check if tmux session was created
|
||||||
|
run tmux has-session -t=$SESSION_NAME
|
||||||
|
|
||||||
|
# Check if the tmux session exists
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
|
||||||
|
# Return to the original session
|
||||||
|
tmux switch-client -n -t="$ORIGINAL_SESSION"
|
||||||
|
|
||||||
|
# Clean up
|
||||||
|
tmux kill-session -t="$SESSION_NAME"
|
||||||
|
rm -r "$TMP_DIR"
|
||||||
|
}
|
||||||
40
tests/test_tmux_windownizer
Executable file
40
tests/test_tmux_windownizer
Executable file
|
|
@ -0,0 +1,40 @@
|
||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
@test "Script creates a new tmux window with the correct branch name" {
|
||||||
|
BRANCH_NAME="test_branch"
|
||||||
|
SESSION_NAME="test_session"
|
||||||
|
|
||||||
|
# Check if the created session exists
|
||||||
|
run tmux has-session -t "$SESSION_NAME"
|
||||||
|
|
||||||
|
if [ "$status" -ne 0 ]; then
|
||||||
|
# Create a new tmux session if it doesn't exist
|
||||||
|
run tmux new-session -d -s "$SESSION_NAME"
|
||||||
|
# Check if the session was created successfully
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
|
||||||
|
# Switch into the new test session
|
||||||
|
if [ "$status" -eq 0 ]; then
|
||||||
|
run tmux switch-client -t "$SESSION_NAME"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Run your script with predefined branch name and session name
|
||||||
|
run ./tmux_windownizer "$BRANCH_NAME"
|
||||||
|
|
||||||
|
# Check if the script exited successfully
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
|
||||||
|
# Check if tmux window was created
|
||||||
|
run tmux list-windows -t="$SESSION_NAME" | grep "$BRANCH_NAME"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
|
||||||
|
# Remove the created tmux window
|
||||||
|
run tmux kill-window -t "$SESSION_NAME:$BRANCH_NAME"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
|
||||||
|
# Remove the test session
|
||||||
|
run tmux kill-session -t "$SESSION_NAME"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
}
|
||||||
|
|
@ -6,6 +6,8 @@ else
|
||||||
selected=$(fd -H --full-path '/' --min-depth 1 --max-depth 3 --type d | fzf)
|
selected=$(fd -H --full-path '/' --min-depth 1 --max-depth 3 --type d | fzf)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo $selected
|
||||||
|
|
||||||
if [[ -z $selected ]]; then
|
if [[ -z $selected ]]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,13 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Explicitly start tmux server
|
branch_name=$(basename $1)
|
||||||
tmux start-server
|
|
||||||
|
|
||||||
# Get the branch name without using 'basename'
|
|
||||||
branch_name=$(git rev-parse --abbrev-ref HEAD)
|
|
||||||
|
|
||||||
# Set up tmux
|
|
||||||
session_name=$(tmux display-message -p "#S")
|
session_name=$(tmux display-message -p "#S")
|
||||||
clean_name=$(echo "$branch_name" | tr "./" "__")
|
clean_name=$(echo $branch_name | tr "./" "__")
|
||||||
target="$session_name:$clean_name"
|
target="$session_name:$clean_name"
|
||||||
|
|
||||||
# Start tmux server if not already running
|
if ! tmux has-session -t $target 2> /dev/null; then
|
||||||
if [ -z "$(tmux list-sessions 2>/dev/null)" ]; then
|
tmux neww -dn $clean_name
|
||||||
sleep 1
|
|
||||||
tmux new-session -d -s "$session_name"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Create a new window if it doesn't exist
|
|
||||||
if [ -z "$(tmux list-windows -t "$session_name" | grep "$clean_name")" ]; then
|
|
||||||
tmux neww -dn "$clean_name"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
shift
|
shift
|
||||||
tmux send-keys -t "$target" "$*"
|
tmux send-keys -t $target "$*"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue