Skip to content

Axonasif/add_ext_recommendation #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
# Dotfiles auto open (dot).code-workspace file
# Dotfiles Multi-Repository Workspace

This is a hack to auto open the available .code-workspace file in VS Code Web or Desktop
This dotfiles setup automatically creates a VS Code workspace that includes multiple repositories, allowing you to work with several related projects simultaneously in a single workspace.

## How it works

When you start a new Gitpod workspace, the `install.sh` script:

1. **Configures additional repositories**: You can specify multiple GitHub repositories in the `additional_repos` array
2. **Clones repositories**: Automatically clones the specified repositories as siblings to your main dotfiles repository
3. **Creates dynamic workspace**: Generates a temporary `.code-workspace` file that includes all repositories as folders
4. **Opens multi-repo workspace**: Opens VS Code with all repositories accessible in a single workspace

## Quickstart

1. Fork this repository to your own account ([direct link](https://github.com/gitpod-samples/dotfiles.open_code_workspace/fork))
2. Go to https://gitpod.io/user/preferences and scroll down. (You may replace `gitpod.io` with your own instance domain)
3. Copy your forked repo link and set it as **Dotfiles - Repository URL** and click on `Save`.
4. Create new workspace to see in action.
2. Edit the `install.sh` file and modify the `additional_repos` array to include your desired repositories:
```bash
local additional_repos=(
"https://github.com/your-username/repo1"
"https://github.com/your-username/repo2"
# Add more repositories as needed
)
```
3. Go to https://gitpod.io/user/preferences and scroll down. (You may replace `gitpod.io` with your own instance domain)
4. Copy your forked repo link and set it as **Dotfiles - Repository URL** and click on `Save`.
5. Create new workspace to see in action.

## Customization

Expand Down
2 changes: 2 additions & 0 deletions debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
gitpod_evars="${!GITPOD_*}" gp_evars="${!GP_*}"; for k in ${gitpod_evars:-} ${gp_evars:-}; do dargs+=(-e "${k}"); done; docker run "${dargs[@]}" --net=host --rm -v $PWD:/home/gitpod/.dotfiles -v /workspace:/workspace -v /ide:/ide -v /usr/bin/gp:/usr/bin/gp:ro -v /.supervisor:/.supervisor -v /var/run/docker.sock:/var/run/docker.sock --privileged -it gitpod/workspace-full bash -c 'trap "echo -e \"=== Run \033[1;32mexit\033[0m command to leave debug workspace\"; exec bash -li" EXIT ERR; echo "PROMPT_COMMAND=\"echo -n \\\"[debug-workspace] \\\"; \$PROMPT_COMMAND\"" >> $HOME/.bashrc; eval "$(gp env -e)"; dot_path="${HOME}/.dotfiles"; for s in install setup bootstrap; do if p="${dot_path}/${s}" && test -x "${p}" || p="${p}.sh" && test -x "${p}"; then set +m; "$p"; set -m; exit; fi; done; while read -r file; do rf_path="${file#"${dot_path}"/}"; target_file="${HOME}/${rf_path}"; target_dir="${target_file%/*}"; if test ! -d "$target_dir"; then mkdir -p "$target_dir"; fi; ln -sf "$file" "$target_file"; done < <(find "${dot_path}" -type f);'
57 changes: 49 additions & 8 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,51 @@
#!/usr/bin/env bash
set -eux
(
if grep -q 'supervisor' /proc/1/cmdline; then {
gp ports await 23000 1>/dev/null
cd "${GITPOD_REPO_ROOT}"
code_wss=(*.code-workspace)
code -r "${DOTFILES_CODE_WORKSPACE:-${code_wss[-1]}}"
} fi
) & disown

function add_folder_path() {
printf '\t\t{ "path": "%s" },\n' "${1}"
}

function main() {
# Configure your addtional repos here
local additional_repos=(
"https://github.com/axonasif/test"
"https://github.com/axonasif/gearlock"
)

###### No need to modify any logic below
###### We can make the below non-blocking but then the IDE window may surprise the user
local repo_root="${GITPOD_REPO_ROOT}"
local workspaces_root=${repo_root%/*}
local code_ws; code_ws="$(
printf '%s\n' \
'{' \
' "folders": ['

add_folder_path "${repo_root}"
for repo_url in "${additional_repos[@]}"; do {
local repo_clone_path="${workspaces_root}/${repo_url##*/}"
if test ! -e "${repo_clone_path}/.git"; then {
git clone --depth 1 "${repo_url}" "${repo_clone_path}" 1>&2
} fi
add_folder_path "${repo_clone_path}"
} done

printf '%s\n' \
' ],' \
' "settings": { "extensions": { "recommendations": [ "PKief.material-icon-theme" ] } }' \
'}'
)"

local ephemeral_code_ws_file=/tmp/multi-repo.code-workspace
printf '%s\n' "${code_ws}" > "${ephemeral_code_ws_file}"

(
if grep -q 'supervisor' /proc/1/cmdline; then {
gp ports await 23000 1>/dev/null
cd "${workspaces_root}"
code -r "${ephemeral_code_ws_file}"
} fi
) & disown
}

main "$@"
8 changes: 0 additions & 8 deletions test.code-workspace

This file was deleted.

8 changes: 0 additions & 8 deletions test2.code-workspace

This file was deleted.