-
Notifications
You must be signed in to change notification settings - Fork 0
DevX Hacks
Here is a simple footnote[^1].
A footnote can also have multiple lines[^2].
[^1]: My reference.
[^2]: To add line breaks within a footnote, add 2 spaces to the end of a line.
This is a second line.
If you do not use an explicit workspace, VC Code will implicitly create one for you. From a DevX perspective its not nice when things happen implicitly.
Important
If you don't use a named workspace, but just go with VS Code's implied one — and you add a new folder to the workspace. Then VS Code will see that as a new and different workspace and as an undesired side effect all your current and historic chat sessions with Copilot and, and all open terminal prompts are gone.
From the Command Palette[^shortcut] in VS Code:
Workspaces:Save Workspace As... → `default.code-workspace``
[^shortcut]:
Tip
Command Palette shortcut
- Mac: ⬆⌘P (
shift+command+P) - Windows/Linux: ⬆^P (
shift+ctrl+P)
./default.code-space
{
"folders": [
{
"path": ".",
},
],
"settings": {},
}Command Palette
- Mac: ⬆⌘P (
shift+command+P) - Windows/Linux: ⬆^P (
shift+ctrl+P)
Dev Containers:Add Dev Container Configurations Files...
→ Add configuration to workspace → Ubuntu → noble → Select additional features to install → GitHub CLI (devcontainers) → Common Utilities (devcontainers) → Keep Defaults
The steps above will create .devcontainer/devcontainer.json
Command Palette
- Mac: ⬆⌘P (
shift+command+P) - Windows/Linux: ⬆^P (
shift+ctrl+P)
Dev Containers:Reopen in Container
Test:
lsb_release -a # Shows detailed distribution information (release, codename, etc.)Reopen in Container requires that your host system (your PC!) can host a Docker container. In short **Docker must be installed and set up right"
Prerequsite: Install Docker Desktop
We need a few extensions in addition to the features
- Git Graph (mhutchie)
- Better Git Line Blame (Mitchell Kember)
- GitHub Copilot Chat (GitHub)
Open up the Extensions panel
View → Extensions
- Mac: ⬆⌘X (
shift+command+X) - Windows/Linux: ⬆^X (
shift+ctrl+X)
Search for each extension one by one. When you find it:
- Right click and choose Add to devcontainer.json
👆 When you update the devcontainer.json file VS Code reminds you to rebuild the container, but don't do that — yet, add all three extensions first.
NOW, you should rebuild the container:
Command Palette
- Mac: ⬆⌘P (
shift+command+P) - Windows/Linux: ⬆^P (
shift+ctrl+P)
Dev Containers:Rebuild Container
We want to be able to talk to GitHub using the Command Line Interface (one fo the features we installed).
In the terminal run:
gh auth statusIt replies:
You are not logged into any GitHub hosts. To log in, run: gh auth loginSo, every time we start the container it needs to be authorized. That's boring!
Let's instead, once and for all authorize you host system (Your PC) and then let the container inherit that authorization.
At this point the terminal is running in the Dev Container, we need to get back in our local environment:
Command Palette
- Mac: ⬆⌘P (
shift+command+P) - Windows/Linux: ⬆^P (
shift+ctrl+P)
Dev Containers:Reopen Folder Locally
(VS Code is back on your PC, it sees that you have a devcontainer configured, and offers you to open it – do not do that yet)
In your terminal run:
gh auth status- Is the
ghcommand even valid on your system? - Are you logged in?
- If so, are you logged in with the
GH_TOKEN? - Do you have the right scopes (we need
projectscope in addition to the default scopes)
Let's take them one by one (skip each step if it's not a concern)
gh auth login --hostname github.com --scopes project --git-protocol https --webrunning gh auth status should show something similar to:
github.com
✓ Logged in to github.com account lakruzz (GH_TOKEN)
- Active account: true
- Git operations protocol: https
- Token: gho_************************************
- Token scopes: 'gist', 'project', 'read:org', 'repo', 'workflow'- You should use
GH_TOKENas login procedure - Token should start with
gho - Token scopes should mention
'project'
If that is not the case try:
gh auth logout
unset GITHUB_TOKENrun gh auth status again.
OK? If not run steps 1+2 again.
GOOD TO KNOW
What if you suspect, that someone stole your token, and you wanted to revoke or disable it?
- Go to https://github.com/settings/applications
- Find the OAuth application named "GitHub CLI"
- Click on the three dots and choose Revoke
Test it (come on ...its fun!):
- Revoke the token
- Run
gh auth statusand see that you are now rejected access - Set it up again
OK, so now your shell is logged in to GitHub. You want to capture this state, so that you do not have to do this every time you start your PC.
Let's go through how you do this in bash and zsh (If you use fish the steps are slightly different).
We do not want to store the token in bare text in any files, so we will encode it with base64 first.
On you local system determine your shell:
echo $SHELLIf bash your profile is in ~/.bash_profile
If zshyour profile is in ~/.zprofile
run
echo $GH_TOKEN
echo $GH_TOKEN | base64You'll see first the token (starting with gho) and then the base64 encoded token.
Find (or create) your profile file and add the following lines:
export _GH_TOKEN=<your-base64-encoded-token-here>
export GH_TOKEN=$(echo $_GH_TOKEN | base64 --decode)At this point. Start an new shell and run gh auth status
Open .devcontainer/devcontainer.json and add the following as a top-level key:
"remoteEnv": {
"GH_TOKEN": "${localEnv:GH_TOKEN}"
}Note that JSON is really picky in regards of commas, so dependant on wether you put this key before, after or in between existing keys, you'll nee a comma after, before or both - respectively.
At this point your devcontainer.json looks like this
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
{
"name": "Ubuntu",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/base:noble",
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {},
"ghcr.io/devcontainers/features/github-cli:1": {}
},
"customizations": {
"vscode": {
"extensions": [
"mhutchie.git-graph",
"mk12.better-git-line-blame",
"GitHub.copilot-chat"
]
}
},
"remoteEnv": {
"GH_TOKEN": "${localEnv:GH_TOKEN}"
}
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "uname -a",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}Now rebuild in the dev container:
Command Palette
- Mac: ⬆⌘P (
shift+command+P) - Windows/Linux: ⬆^P (
shift+ctrl+P)
Dev Containers:Rebuild and Reopen in Container
run gh auth status