chore: fix devcontainer setup

This commit is contained in:
Jan De Dobbeleer 2021-11-26 12:02:28 +01:00 committed by Jan De Dobbeleer
parent 09df670e07
commit d31a24c654
5 changed files with 22 additions and 35 deletions

View file

@ -18,42 +18,32 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get install -y --no-install-recommends \ && apt-get install -y --no-install-recommends \
fish \ fish \
powershell \ powershell \
tmux \
&& apt-get clean && apt-get clean
# Deploy latest stable oh-my-posh as a starting point: ARG USERNAME=vscode
RUN pwsh -Command Install-Module oh-my-posh -Scope AllUsers -Force && \
chmod 777 -R /usr/local/share/powershell
# If you recompile the prompt in the devcontainer you may overwrite the executables at:
# /usr/local/share/powershell/Modules/oh-my-posh/<version>/bin/
# Deploy symlink of binary under /usr/bin/oh-my-posh for convenience access from non-Powershell shells: # Download the oh-my-posh binary
RUN export ARCH=`uname -m`;\ RUN mkdir /home/${USERNAME}/bin; \
export ARCH=`uname -m`;\
if [[ "$ARCH" -eq "aarch64" ]]; then \ if [[ "$ARCH" -eq "aarch64" ]]; then \
export POSH_BIN="$(find /usr/local/share/powershell/Modules/oh-my-posh/*/bin/posh-linux-arm64)";\ export POSH_BIN="posh-linux-arm64";\
elif [[ "$ARCH" -eq "armv7l" ]]; then \ elif [[ "$ARCH" -eq "armv7l" ]]; then \
export POSH_BIN="$(find /usr/local/share/powershell/Modules/oh-my-posh/*/bin/posh-linux-arm)";\ export POSH_BIN="posh-linux-arm";\
else \ else \
export POSH_BIN="$(find /usr/local/share/powershell/Modules/oh-my-posh/*/bin/posh-linux-amd64)";\ export POSH_BIN="posh-linux-amd64";\
fi;\ fi;\
ln -sf $POSH_BIN /usr/bin/oh-my-posh wget https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/${POSH_BIN} -O /home/${USERNAME}/bin/oh-my-posh; \
chmod +x /home/${USERNAME}/bin/oh-my-posh; \
chown ${USERNAME}: /home/${USERNAME}/bin;
# NOTE: devcontainers are Linux-only at this time but when # NOTE: devcontainers are Linux-only at this time but when
# Windows or Darwin is supported someone will need to improve # Windows or Darwin is supported someone will need to improve
# the code logic above. # the code logic above.
# Deploy all latest oh-my-posh themes at devcontainer build time: # add the oh-my-posh path to the PATH variable
ARG USERNAME=vscode ENV PATH "$PATH:${USERNAME}/bin"
ARG POSHTHEMES_ROOT=/home/${USERNAME}/.poshthemes
ENV POSHTHEMES_ROOT=${POSHTHEMES_ROOT}
RUN mkdir -m=777 -p ${POSHTHEMES_ROOT} && \
wget https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/themes.zip -O ${POSHTHEMES_ROOT}/themes.zip && \
unzip ${POSHTHEMES_ROOT}/themes.zip -d ${POSHTHEMES_ROOT} && \
chmod 777 ${POSHTHEMES_ROOT}/*.json && \
rm ${POSHTHEMES_ROOT}/themes.zip
# Can be used to override the devcontainer prompt default theme: # Can be used to override the devcontainer prompt default theme:
ARG DEFAULT_POSH_THEME=jandedobbeleer ENV POSH_THEME="/workspaces/oh-my-posh/themes/jandedobbeleer.omp.json"
ENV DEFAULT_POSH_THEME=${DEFAULT_POSH_THEME}
# Deploy oh-my-posh prompt to Powershell: # Deploy oh-my-posh prompt to Powershell:
COPY Microsoft.PowerShell_profile.ps1 /home/${USERNAME}/.config/powershell/Microsoft.PowerShell_profile.ps1 COPY Microsoft.PowerShell_profile.ps1 /home/${USERNAME}/.config/powershell/Microsoft.PowerShell_profile.ps1
@ -67,11 +57,10 @@ RUN chmod 777 -R /home/${USERNAME}/.config
# Override vscode's own Bash prompt with oh-my-posh: # Override vscode's own Bash prompt with oh-my-posh:
RUN sed -i 's/^__bash_prompt$/#&/' /home/${USERNAME}/.bashrc && \ RUN sed -i 's/^__bash_prompt$/#&/' /home/${USERNAME}/.bashrc && \
echo "eval \"\$(oh-my-posh --init --shell bash --config ${POSHTHEMES_ROOT}/${DEFAULT_POSH_THEME}.omp.json)\"" >> /home/${USERNAME}/.bashrc echo "eval \"\$(oh-my-posh --init --shell bash --config $POSH_THEME)\"" >> /home/${USERNAME}/.bashrc
# Override vscode's own ZSH prompt with oh-my-posh: # Override vscode's own ZSH prompt with oh-my-posh:
RUN sed -i 's/^source \$ZSH/oh-my-zsh.sh$/# source \$ZSH/oh-my-zsh.sh&/' /home/${USERNAME}/.zshrc && \ RUN echo "eval \"\$(oh-my-posh --init --shell zsh --config $POSH_THEME)\"" >> /home/${USERNAME}/.zshrc
echo "eval \"\$(oh-my-posh --init --shell zsh --config ${POSHTHEMES_ROOT}/${DEFAULT_POSH_THEME}.omp.json)\"" >> /home/${USERNAME}/.zshrc
# Set container timezone: # Set container timezone:
ARG TZ="UTC" ARG TZ="UTC"

View file

@ -1,5 +1,3 @@
# Activate oh-my-posh prompt: oh-my-posh --init --shell pwsh --config $env:POSH_THEME | Invoke-Expression
Import-Module oh-my-posh
Set-PoshPrompt -Theme ${env:POSHTHEMES_ROOT}/${env:DEFAULT_POSH_THEME}.omp.json
# NOTE: You can override the above env vars from the devcontainer.json "args" under the "build" key. # NOTE: You can override the above env var from the devcontainer.json "args" under the "build" key.

View file

@ -1,4 +1,4 @@
# Activate oh-my-posh prompt: # Activate oh-my-posh prompt:
oh-my-posh --init --shell fish --config $POSHTHEMES_ROOT/$DEFAULT_POSH_THEME.omp.json | source oh-my-posh --init --shell fish --config $POSH_THEME | source
# NOTE: You can override the above env vars from the devcontainer.json "args" under the "build" key. # NOTE: You can override the above env vars from the devcontainer.json "args" under the "build" key.

View file

@ -12,7 +12,7 @@
// Options: // Options:
"DEFAULT_POSH_THEME": "jandedobbeleer", "POSH_THEME": "/workspaces/oh-my-posh/themes/jandedobbeleer.omp.json",
// Override me with your own timezone: // Override me with your own timezone:
"TZ": "UTC", "TZ": "UTC",

6
.vscode/tasks.json vendored
View file

@ -21,7 +21,7 @@
{ {
"type": "shell", "type": "shell",
"command": "go", "command": "go",
"label": "devcontainer: build omp", "label": "devcontainer: rebuild oh-my-posh",
"options": { "options": {
"cwd": "${workspaceRoot}/src", "cwd": "${workspaceRoot}/src",
"shell": { "shell": {
@ -31,13 +31,13 @@
"statusbar": { "statusbar": {
"hide": false, "hide": false,
"color": "#22C1D6", "color": "#22C1D6",
"label": "$(beaker) devcontainer: build omp", "label": "$(beaker) devcontainer: rebuild oh-my-posh",
"tooltip": "Compiles *oh-my-posh* from this repo while **overwriting** your preinstalled stable release." "tooltip": "Compiles *oh-my-posh* from this repo while **overwriting** your preinstalled stable release."
} }
}, },
"group": "build", "group": "build",
"problemMatcher": "$go", "problemMatcher": "$go",
"args": ["build", "-v", "-o", "`readlink", "/usr/bin/oh-my-posh`"] "args": ["build", "-v", "-o", "/home/vscode/bin/oh-my-posh", "-ldflags", "\"-X 'main.Version=development-$(git --no-pager log -1 --pretty=%h-%B)'\""]
}, },
{ {
"label": "golangci-lint - docker", "label": "golangci-lint - docker",