Skip to content

Commit 5e1c654

Browse files
committed
feat(powerlevel10k): add devcontainer feature for install powerlevel10k
1 parent 538b0e2 commit 5e1c654

File tree

10 files changed

+251
-0
lines changed

10 files changed

+251
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# powerlevel10k devcontainer feature
2+
3+
This feature will install, activate and config powerlevel10k theme for oh my zsh
4+
5+
![Screenshot](https://github.com/ebizbase/dev-infras/raw/main/devcontainer-features/powerlevel10k/screenshot.png)
6+
7+
## Example Usage
8+
9+
With default config. The result is like the screenshot above. The default config are pretty minimal. We don’t need to know the current user since it’s already specified in devcontainer.json. But one important thing is that the git branch and state will be set up.
10+
11+
```json
12+
"features": {
13+
"ghcr.io/ebizbase/devcontainer-features/powerlevel10k:0": {}
14+
}
15+
```
16+
17+
You can define custom config file
18+
19+
```json
20+
"features": {
21+
"ghcr.io/ebizbase/devcontainer-features/powerlevel10k:0": {
22+
"config": "https://github.com/romkatv/powerlevel10k/blob/master/config/p10k-lean-8colors.zsh"
23+
}
24+
}
25+
```
26+
27+
## Options
28+
29+
| Options Id | Description | Type | Default |
30+
| ------------------------ | ----------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------ |
31+
| config | Powerlevel10k configuration file url | string | https://raw.githubusercontent.com/ebizbase/dev-infras/refs/heads/main/devcontainer-features/powerlevel10k/p10k.zsh |
32+
| version | Powerlevel10k version | string | "latest" |
33+
| deletePreinstalledThemes | Should delete pre installed themes or not | boolean | false |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Config for Powerlevel10k with minimalism prompt style. Type `p10k configure` to generate
2+
# your own config based on it.
3+
4+
'builtin' 'local' '-a' 'p10k_config_opts'
5+
[[ ! -o 'aliases' ]] || p10k_config_opts+=('aliases')
6+
[[ ! -o 'sh_glob' ]] || p10k_config_opts+=('sh_glob')
7+
[[ ! -o 'no_brace_expand' ]] || p10k_config_opts+=('no_brace_expand')
8+
'builtin' 'setopt' 'no_aliases' 'no_sh_glob' 'brace_expand'
9+
10+
() {
11+
emulate -L zsh -o extended_glob
12+
13+
unset -m '(POWERLEVEL9K_*|DEFAULT_USER)~POWERLEVEL9K_GITSTATUS_DIR'
14+
15+
# Zsh >= 5.1 is required.
16+
[[ $ZSH_VERSION == (5.<1->*|<6->.*) ]] || return
17+
typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir vcs)
18+
typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
19+
typeset -g POWERLEVEL9K_SHORTEN_STRATEGY=truncate_to_last
20+
typeset -g POWERLEVEL9K_DISABLE_HOT_RELOAD=true
21+
(( ! $+functions[p10k] )) || p10k reload
22+
}
23+
24+
typeset -g POWERLEVEL9K_CONFIG_FILE=${${(%):-%x}:a}
25+
(( ${#p10k_config_opts} )) && setopt ${p10k_config_opts[@]}
26+
'builtin' 'unset' 'p10k_config_opts'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "powerlevel10k",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "devcontainer-features/powerlevel10k/src",
5+
"projectType": "application",
6+
"tags": [],
7+
"targets": {
8+
"test": {
9+
"executor": "nx:run-commands",
10+
"options": {
11+
"command": "devcontainer features test --skip-autogenerated -p devcontainer-features/powerlevel10k -f powerlevel10k -i mcr.microsoft.com/devcontainers/base:ubuntu"
12+
}
13+
},
14+
"publish": {
15+
"executor": "nx:run-commands",
16+
"options": {
17+
"command": "devcontainer features publish devcontainer-features/powerlevel10k/src/powerlevel10k --registry ghcr.io --namespace=ebizbase/devcontainer-features",
18+
"parallel": false
19+
}
20+
},
21+
"version": {
22+
"executor": "@jscutlery/semver:version",
23+
"options": {
24+
"preset": "angular"
25+
}
26+
}
27+
}
28+
}
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"id": "powerlevel10k",
3+
"version": "0.0.4",
4+
"name": "powerlevel10k setup and activate",
5+
"documentationURL": "https://github.com/ebizbase/dev-infras/tree/main/devcontainer-features/powerlevel10k/README.md",
6+
"description": "Setup and activate powerlevel10k devcontainer feature",
7+
"options": {
8+
"config": {
9+
"type": "string",
10+
"default": "https://raw.githubusercontent.com/ebizbase/dev-infras/refs/heads/main/devcontainer-features/powerlevel10k/p10k.zsh",
11+
"description": "Powerlevel10k configuration file url"
12+
},
13+
"version": {
14+
"type": "string",
15+
"default": "latest",
16+
"description": "Powerlevel10k version"
17+
},
18+
"deletePreinstalledThemes": {
19+
"type": "boolean",
20+
"default": false,
21+
"description": "Should delete pre installed themes or not"
22+
},
23+
"debug": {
24+
"type": "boolean",
25+
"default": false,
26+
"description": "Enable debug mode (Internal use)"
27+
}
28+
},
29+
"dependsOn": {
30+
"ghcr.io/devcontainers/features/common-utils": {}
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
# trunk-ignore-all(shellcheck/SC2312)
4+
set -e
5+
6+
CONFIG=${CONFIG:-'https://raw.githubusercontent.com/ebizbase/dev-infras/refs/heads/main/devcontainer-features/powerlevel10k/p10k.zsh'}
7+
VERSION=${VERSION:-'latest'}
8+
DELETE_PREINSTALL_THEMES=${DELETEPREINSTALLEDTHEMES:-false}
9+
DEBUG=${DEBUG:-false}
10+
11+
debug() {
12+
if [[ ${DEBUG} == true ]]; then
13+
echo "$1" >>/tmp/powerlevel10k.log
14+
fi
15+
}
16+
17+
if [[ -n ${_REMOTE_USER_HOME} ]]; then
18+
USER_HOME="${_REMOTE_USER_HOME}"
19+
elif [[ ${_REMOTE_USER} == "root" ]]; then
20+
USER_HOME="/root"
21+
# Check if user already has a home directory other than /home/${USERNAME}
22+
elif [[ "/home/${_REMOTE_USER}" != $(getent passwd "${_REMOTE_USER}" | cut -d: -f6) ]]; then
23+
USER_HOME=$(getent passwd "${_REMOTE_USER}" | cut -d: -f6)
24+
else
25+
USER_HOME="/home/${_REMOTE_USER}"
26+
fi
27+
28+
if [[ ${VERSION} == "latest" ]]; then
29+
VERSION=$(curl --silent "https://api.github.com/repos/romkatv/powerlevel10k/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/')
30+
fi
31+
32+
debug "==============================="
33+
debug "VERSION: ${VERSION}"
34+
debug "CONFIG: ${CONFIG}"
35+
debug "REMOTE_USER: ${_REMOTE_USER}"
36+
debug "USER_HOME: ${USER_HOME}"
37+
debug "==============================="
38+
39+
if [[ ${DELETE_PREINSTALL_THEMES} == true ]]; then
40+
debug "Deleting other themes"
41+
rm -rf "${USER_HOME}"/.oh-my-zsh/themes/*
42+
fi
43+
44+
curl -L https://github.com/romkatv/powerlevel10k/archive/refs/tags/v"${VERSION}".zip -o /tmp/powerlevel10k.zip
45+
unzip /tmp/powerlevel10k.zip -d /tmp
46+
cp -r /tmp/powerlevel10k-"${VERSION}" "${USER_HOME}"/.oh-my-zsh/custom/themes/powerlevel10k
47+
rm -rf /tmp/powerlevel10k.zip /tmp/powerlevel10k-"${VERSION}"
48+
sed -i 's/ZSH_THEME=".*"/ZSH_THEME="powerlevel10k\/powerlevel10k"/g' "${USER_HOME}/.zshrc"
49+
echo 'source ~/.oh-my-zsh/custom/themes/powerlevel10k/powerlevel10k.zsh-theme' >>"${USER_HOME}/.zshrc"
50+
echo '[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh' >>"${USER_HOME}/.zshrc"
51+
52+
curl -L "${CONFIG}" -o "${USER_HOME}/.p10k.zsh"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
# trunk-ignore-all(shellcheck/SC2312)
3+
4+
set -e
5+
6+
source dev-container-features-test-lib
7+
8+
check "LOG" cat /tmp/powerlevel10k.log
9+
check "checking active omz theme" grep -v '^#' ~/.zshrc | grep 'ZSH_THEME=".*"' | awk -F'[""]' '{print $2}' | grep -q 'powerlevel10k/powerlevel10k'
10+
check "powerlevel10k config file should exist" test -f ~/.p10k.zsh
11+
check "powerlevel10k config file should contain '8-color lean prompt style' string in first line" head -n 1 ~/.p10k.zsh | grep -q '8-color lean prompt style'
12+
check "should source powerlevel10k theme" grep -q 'source ~/.oh-my-zsh/custom/themes/powerlevel10k/powerlevel10k.zsh-theme' ~/.zshrc
13+
check "should source config if exists" grep -q '[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh' ~/.zshrc
14+
check "powerlevel10k should installed" test -f ~/.oh-my-zsh/custom/themes/powerlevel10k/powerlevel10k.zsh-theme
15+
16+
reportResults
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
# trunk-ignore-all(shellcheck/SC2312)
3+
4+
set -e
5+
6+
source dev-container-features-test-lib
7+
8+
check "LOG" cat /tmp/powerlevel10k.log
9+
check "active theme should be powerlevel10k" grep -v '^#' ~/.zshrc | grep 'ZSH_THEME=".*"' | awk -F'[""]' '{print $2}' | grep -q 'powerlevel10k/powerlevel10k'
10+
check "powerlevel10k config file should exist" test -f ~/.p10k.zsh
11+
check "powerlevel10k config file should contain 'classic powerline prompt style' string in first line" head -n 1 ~/.p10k.zsh | grep -q 'classic powerline prompt style'
12+
check "should source powerlevel10k theme" grep -q 'source ~/.oh-my-zsh/custom/themes/powerlevel10k/powerlevel10k.zsh-theme' ~/.zshrc
13+
check "should source config if exists" grep -q '[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh' ~/.zshrc
14+
check "powerlevel10k should installed" test -f ~/.oh-my-zsh/custom/themes/powerlevel10k/powerlevel10k.zsh-theme
15+
16+
reportResults
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
# trunk-ignore-all(shellcheck/SC2312)
3+
4+
set -e
5+
6+
source dev-container-features-test-lib
7+
8+
check "LOG" cat /tmp/powerlevel10k.log
9+
check "active theme should be powerlevel10k" grep -v '^#' ~/.zshrc | grep 'ZSH_THEME=".*"' | awk -F'[""]' '{print $2}' | grep -q 'powerlevel10k/powerlevel10k'
10+
check "powerlevel10k config file should exist" test -f ~/.p10k.zsh
11+
check "powerlevel10k config file should contain 'classic powerline prompt style' string in first line" head -n 1 ~/.p10k.zsh | grep -q 'classic powerline prompt style'
12+
check "should source powerlevel10k theme" grep -q 'source ~/.oh-my-zsh/custom/themes/powerlevel10k/powerlevel10k.zsh-theme' ~/.zshrc
13+
check "should source config if exists" grep -q '[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh' ~/.zshrc
14+
check "powerlevel10k should installed" test -f ~/.oh-my-zsh/custom/themes/powerlevel10k/powerlevel10k.zsh-theme
15+
check "all pre installed omz themes should be deleted" ls -l ~/.oh-my-zsh/themes | grep -c ^d | grep -q '0' || exit 1
16+
17+
reportResults
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"default": {
3+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
4+
"remoteUser": "vscode",
5+
"features": {
6+
"powerlevel10k": {
7+
"debug": true
8+
}
9+
}
10+
},
11+
"8color": {
12+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
13+
"remoteUser": "root",
14+
"features": {
15+
"powerlevel10k": {
16+
"config": "https://github.com/romkatv/powerlevel10k/blob/master/config/p10k-lean-8colors.zsh",
17+
"debug": true
18+
}
19+
}
20+
},
21+
"delete": {
22+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
23+
"remoteUser": "root",
24+
"features": {
25+
"powerlevel10k": {
26+
"debug": true,
27+
"deleteOtherThemes": true
28+
}
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)