diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index b62641ee..a65bfcb1 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -8,16 +8,74 @@ FROM mcr.microsoft.com/vscode/devcontainers/go:0-${VARIANT} ARG NODE_VERSION="none" RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi -# Download the Microsoft repository GPG keys -RUN wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb -# Register the Microsoft repository GPG keys -RUN dpkg -i packages-microsoft-prod.deb +# Download and register the Microsoft repository GPG keys +RUN wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb && \ + dpkg -i packages-microsoft-prod.deb && \ + rm -f packages-microsoft-prod.deb # [Optional] Uncomment this section to install additional OS packages. RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ - && apt-get install -y --no-install-recommends fish\ - && apt-get install -y --no-install-recommends powershell + && apt-get install -y --no-install-recommends \ + fish \ + powershell \ + tmux \ + && apt-get clean +# Deploy latest stable oh-my-posh as a starting point: +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//bin/ + +# Deploy symlink of binary under /usr/bin/oh-my-posh for convenience access from non-Powershell shells: +RUN export ARCH=`uname -m`;\ + if [[ "$ARCH" -eq "aarch64" ]]; then \ + export POSH_BIN="$(find /usr/local/share/powershell/Modules/oh-my-posh/*/bin/posh-linux-arm64)";\ + elif [[ "$ARCH" -eq "armv7l" ]]; then \ + export POSH_BIN="$(find /usr/local/share/powershell/Modules/oh-my-posh/*/bin/posh-linux-arm)";\ + else \ + export POSH_BIN="$(find /usr/local/share/powershell/Modules/oh-my-posh/*/bin/posh-linux-amd64)";\ + fi;\ + ln -sf $POSH_BIN /usr/bin/oh-my-posh +# NOTE: devcontainers are Linux-only at this time but when +# Windows or Darwin is supported someone will need to improve +# the code logic above. + +# Deploy all latest oh-my-posh themes at devcontainer build time: +ARG USERNAME=vscode +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: +ARG DEFAULT_POSH_THEME=jandedobbeleer +ENV DEFAULT_POSH_THEME=${DEFAULT_POSH_THEME} + +# Deploy oh-my-posh prompt to Powershell: +COPY Microsoft.PowerShell_profile.ps1 /home/${USERNAME}/.config/powershell/Microsoft.PowerShell_profile.ps1 + +# Deploy oh-my-posh prompt to Fish: +COPY config.fish /home/${USERNAME}/.config/fish/config.fish + +# Everything runs as root during build time, so we want +# to make sure the vscode user can edit these paths too: +RUN chmod 777 -R /home/${USERNAME}/.config + +# Override vscode's own Bash prompt with oh-my-posh: +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 + +# 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 && \ + echo "eval \"\$(oh-my-posh --init --shell zsh --config ${POSHTHEMES_ROOT}/${DEFAULT_POSH_THEME}.omp.json)\"" >> /home/${USERNAME}/.zshrc + +# Set container timezone: +ARG TZ="UTC" +RUN ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime # [Optional] Uncomment the next line to use go get to install anything else you need # RUN go get -x github.com/JanDeDobbeleer/battery diff --git a/.devcontainer/Microsoft.PowerShell_profile.ps1 b/.devcontainer/Microsoft.PowerShell_profile.ps1 new file mode 100644 index 00000000..7c6e6088 --- /dev/null +++ b/.devcontainer/Microsoft.PowerShell_profile.ps1 @@ -0,0 +1,5 @@ +# Activate oh-my-posh prompt: +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. diff --git a/.devcontainer/config.fish b/.devcontainer/config.fish new file mode 100644 index 00000000..974dae10 --- /dev/null +++ b/.devcontainer/config.fish @@ -0,0 +1,4 @@ +# Activate oh-my-posh prompt: +oh-my-posh --init --shell fish --config $POSHTHEMES_ROOT/$DEFAULT_POSH_THEME.omp.json | source + +# NOTE: You can override the above env vars from the devcontainer.json "args" under the "build" key. diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index cc31ea0f..227da7ac 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,7 +1,7 @@ // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: // https://github.com/microsoft/vscode-dev-containers/tree/v0.177.0/containers/go { - "name": "Go", + "name": "oh-my-posh", "build": { "dockerfile": "Dockerfile", "args": { @@ -9,7 +9,16 @@ // Append -bullseye or -buster to pin to an OS version. // Use -bullseye variants on local arm64/Apple Silicon. "VARIANT": "1.17-bullseye", - // Options + + // Options: + + "DEFAULT_POSH_THEME": "jandedobbeleer", + + // Override me with your own timezone: + "TZ": "UTC", + // Use one of the "TZ database name" entries from: + // https://en.wikipedia.org/wiki/List_of_tz_database_time_zones + "NODE_VERSION": "lts/*" } }, @@ -43,19 +52,22 @@ "terminal.integrated.defaultProfile.linux": "pwsh", "terminal.integrated.defaultProfile.windows": "pwsh", "terminal.integrated.defaultProfile.osx": "pwsh", + "tasks.statusbar.default.hide": true }, // Add the IDs of extensions you want installed when the container is created. "extensions": [ + "actboy168.tasks", "eamodio.gitlens", - "github.vscode-pull-request-github", - "esbenp.prettier-vscode", - "davidanson.vscode-markdownlint", - "yzhang.markdown-all-in-one", "bungcip.better-toml", - "redhat.vscode-yaml", + "davidanson.vscode-markdownlint", + "editorconfig.editorconfig", + "esbenp.prettier-vscode", + "github.vscode-pull-request-github", "golang.go", - "ms-vscode.powershell" + "ms-vscode.powershell", + "redhat.vscode-yaml", + "yzhang.markdown-all-in-one" ], // Use 'forwardPorts' to make a list of ports inside the container available locally. diff --git a/.vscode/tasks.json b/.vscode/tasks.json index f6f9a4f8..b8f3cd71 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -17,6 +17,27 @@ }, "problemMatcher": "$go", "args": ["build", "-v"] + }, + { + "type": "shell", + "command": "go", + "label": "devcontainer: build omp", + "options": { + "cwd": "${workspaceRoot}/src", + "shell": { + "executable": "bash", + "args": ["-c"] + }, + "statusbar": { + "hide": false, + "color" : "#22C1D6", + "label" : "$(beaker) devcontainer: build omp", + "tooltip": "Compiles *oh-my-posh* from this repo while **overwriting** your preinstalled stable release." + } + }, + "group": "build", + "problemMatcher": "$go", + "args": ["build", "-v", "-o", "`readlink", "/usr/bin/oh-my-posh`"] } ] } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 910f5df6..673e5e81 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,6 +14,42 @@ can be a good starting point. or core functionality. 4. Pull Requests are merged once all checks pass and a project maintainer has approved it. +## Codespaces / Devcontainer Development Environment + +Arguably the easiest way to contribute anything is to use our prepared development environment. + +We have a `.devcontainer/devcontainer.json` file, meaning we are compatible with: + +- [Github Codespaces][codespaces], or +- the [Visual Studio Code Remote - Containers][devcontainer-ext] extension. + +This Linux environment includes all shells supported by oh-my-posh, including Bash, ZSH, +Fish and PowerShell, the latter of which is the default. + +### Configuring Devcontainer's Timezone & Theme + +1. Open the `.devcontainer/devcontainer.json` file and in the "*build*" section modify: + + - `TZ`: with [your own timezone][timezones] + - `DEFAULT_POSH_THEME`: with [your preferred theme][themes] + +2. Summon the Command Panel (Ctrl+Shift+P) and select `Codespaces: Rebuild Container` + to rebuild your devcontainer. (This should take just a few seconds.) + +### Recompiling oh-my-posh within + +The devcontainer definition preinstalls the latest stable oh-my-posh release at build time. + +To overwrite the installation's version inside the running devcontainer, you may use the +VSCode *task* `devcontainer: build omp` to rebuild your oh-my-posh with that of +your running repository's state. (You might see a button for this in your statusbar.) + +If the compile succeeds, `oh-my-posh --version` should reply: +`development` + +Should you somehow mess up your devcontainer's OMP install catastrophically, remember that +if you do `Codespaces: Rebuild Container` again, you'll be back to the latest stable release. + ## Code of Conduct ### Our Pledge @@ -33,23 +69,23 @@ diverse, inclusive, and healthy community. Examples of behavior that contributes to a positive environment for the project include: -* Demonstrating empathy and kindness toward other people -* Being respectful of differing opinions, viewpoints, and experiences -* Giving and gracefully accepting constructive feedback -* Accepting responsibility and apologizing to those affected by our mistakes, +- Demonstrating empathy and kindness toward other people +- Being respectful of differing opinions, viewpoints, and experiences +- Giving and gracefully accepting constructive feedback +- Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience -* Focusing on what is best not just for us as individuals, but for the +- Focusing on what is best not just for us as individuals, but for the project Examples of unacceptable behavior include: -* The use of sexualized language or imagery, and sexual attention or +- The use of sexualized language or imagery, and sexual attention or advances of any kind -* Trolling, insulting or derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or email +- Trolling, insulting or derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or email address, without their explicit permission -* Other conduct which could reasonably be considered inappropriate in a +- Other conduct which could reasonably be considered inappropriate in a professional setting ### Enforcement Responsibilities @@ -142,3 +178,7 @@ enforcement ladder](https://github.com/mozilla/diversity). [homepage]: https://www.contributor-covenant.org [conduct]: mailto:conduct@ohmyposh.dev [coc]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html +[codespaces]: https://github.com/features/codespaces +[devcontainer-ext]: https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers +[timezones]: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones +[themes]: https://ohmyposh.dev/docs/themes