Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ mlh docker in web
# Select container [1-3]: 1
```

> **💡 Note:** Usually, you don't need `sudo` for `mlh docker in`. If your user is in the `docker` group, you can run it directly. If you need to use `sudo`, use: `sudo env "PATH=$PATH" mlh docker in <pattern>` or `sudo "$HOME/.local/bin/mlh" docker in <pattern>`

---

### 📦 `linux` - Container Management
Expand Down
45 changes: 45 additions & 0 deletions get-mlh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,49 @@ ensure_local_bin_on_path() {
grep -Fq "$line" "$PROFILE" 2>/dev/null || echo "$line" >>"$PROFILE"
}

cleanup_unnecessary_files() {
green "Cleaning up unnecessary files…"

# List of files/directories to remove (user doesn't need these)
# NOTE: .git is NOT removed - it's needed for git pull/update functionality
local cleanup_items=(
"tests"
"CLAUDE.md"
"docs/BOOKMARK_ALIAS_GUIDE.md"
"docs/BOOKMARK_QUICK_REFERENCE.md"
"docs/RELEASE_NOTES_v1.5.0.md"
"docs/RELEASE_NOTES_v1.5.1.md"
"docs/assets"
".github"
"TODO.md"
".gitignore"
)
Comment on lines +99 to +115

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid deleting .git in cleanup_unnecessary_files

The new cleanup routine removes the .git directory after cloning. download_repo relies on the presence of .git to decide between git pull and git clone; when the directory is deleted, rerunning get-mlh.sh will hit the git clone path even though ${INSTALL_DIR} already exists, causing fatal: destination path ... already exists and is not an empty directory and preventing updates. Users who reinstall will have to manually remove the install directory to recover. Consider keeping .git or adjusting the download logic to handle a non‑git install.

Useful? React with 👍 / 👎.


# Keep docs/config/mlh.conf.example (needed for setup.sh)
# Keep README.md (useful for users)
# Keep LICENSE (required)
# Keep .git (needed for git pull/update functionality)

for item in "${cleanup_items[@]}"; do
local item_path="${INSTALL_DIR}/${item}"
if [ -e "$item_path" ]; then
rm -rf "$item_path"
echo " Removed: $item"
fi
done

# Clean up docs directory if it's now empty (except config/)
if [ -d "${INSTALL_DIR}/docs" ]; then
# Check if docs only contains config/ directory
local docs_contents
docs_contents=$(find "${INSTALL_DIR}/docs" -mindepth 1 -maxdepth 1 ! -name "config" | wc -l)
if [ "$docs_contents" -eq 0 ]; then
# Keep docs/config, but we can leave docs/ as is since it only has config/
:
fi
fi
}

run_repo_setup() {
green "Running repository setup…"
chmod +x "${INSTALL_DIR}/setup.sh" || true
Expand All @@ -105,6 +148,8 @@ run_repo_setup() {
main() {
green "Installing ${REPO_NAME} into ${INSTALL_DIR}"
download_repo
# Cleanup unnecessary files (both git and tarball methods include development files)
cleanup_unnecessary_files
ensure_local_bin_on_path
run_repo_setup
green "Done. Try:"
Expand Down
20 changes: 15 additions & 5 deletions plugins/mlh-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,18 @@ case "$COMMAND" in
;;
in)
# Check if docker is available (only for actual commands)
# Try to find docker in common locations if not in PATH (for sudo usage)
if ! command -v docker >/dev/null 2>&1; then
die "Docker is not installed or not in PATH"
# Check common docker locations
if [ -x "/usr/bin/docker" ]; then
DOCKER_CMD="/usr/bin/docker"
elif [ -x "/usr/local/bin/docker" ]; then
DOCKER_CMD="/usr/local/bin/docker"
else
die "Docker is not installed or not in PATH"
fi
else
DOCKER_CMD="docker"
fi

# Enter container by pattern
Expand All @@ -77,7 +87,7 @@ in)
PATTERN="$1"

# Find matching containers (running only)
mapfile -t CONTAINERS < <(docker ps --format "{{.ID}}|{{.Names}}" | grep -i "$PATTERN" || true)
mapfile -t CONTAINERS < <("$DOCKER_CMD" ps --format "{{.ID}}|{{.Names}}" | grep -i "$PATTERN" || true)

if [ ${#CONTAINERS[@]} -eq 0 ]; then
die "No running containers found matching pattern: $PATTERN"
Expand All @@ -88,7 +98,7 @@ in)
CONTAINER_ID="${CONTAINERS[0]%%|*}"
CONTAINER_NAME="${CONTAINERS[0]##*|}"
echo "Entering container: $CONTAINER_NAME"
exec docker exec -it "$CONTAINER_ID" bash
exec "$DOCKER_CMD" exec -it "$CONTAINER_ID" bash
else
# Multiple matches - show menu
echo "Multiple containers found matching '$PATTERN':"
Expand All @@ -98,7 +108,7 @@ in)
CONTAINER_NAME="${CONTAINERS[$i]##*|}"
CONTAINER_ID="${CONTAINERS[$i]%%|*}"
# Get container image and status
CONTAINER_INFO=$(docker ps --filter "id=$CONTAINER_ID" --format "{{.Image}} | {{.Status}}" | head -1)
CONTAINER_INFO=$("$DOCKER_CMD" ps --filter "id=$CONTAINER_ID" --format "{{.Image}} | {{.Status}}" | head -1)
echo " $((i + 1)). $CONTAINER_NAME ($CONTAINER_INFO)"
done

Expand All @@ -117,7 +127,7 @@ in)

echo ""
echo "Entering container: $CONTAINER_NAME"
exec docker exec -it "$CONTAINER_ID" bash
exec "$DOCKER_CMD" exec -it "$CONTAINER_ID" bash
fi
;;
*)
Expand Down
Loading