Skip to content

Commit 9011739

Browse files
authored
feat(shell): add initial shell environment feature (zsh, oh-my-zsh, powerlevel10k) (#2)
* feat(shell): add initial shell environment feature (zsh, oh-my-zsh, powerlevel10k) * feat(shell): add initial shell environment feature (zsh, oh-my-zsh, powerlevel10k) * feat(shell): make shell environment installation cross-platform and production ready --- Signed-off-by: Jonatan Mata <jonmatum@gmail.com>
1 parent 8d8814f commit 9011739

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed

features/shell/feature.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"id": "shell",
3+
"version": "1.0.0",
4+
"name": "Shell Environment",
5+
"description": "Configurable shell with optional Zsh, Oh My Zsh, Powerlevel10k, autosuggestions, and syntax highlighting.",
6+
"options": {
7+
"installZsh": {
8+
"type": "boolean",
9+
"default": true,
10+
"description": "Install Zsh and set as default shell"
11+
},
12+
"ohMyZsh": {
13+
"type": "boolean",
14+
"default": true,
15+
"description": "Install Oh My Zsh framework"
16+
},
17+
"powerlevel10k": {
18+
"type": "boolean",
19+
"default": true,
20+
"description": "Install Powerlevel10k theme"
21+
},
22+
"autosuggestions": {
23+
"type": "boolean",
24+
"default": true,
25+
"description": "Enable zsh-autosuggestions"
26+
},
27+
"syntaxHighlighting": {
28+
"type": "boolean",
29+
"default": true,
30+
"description": "Enable zsh-syntax-highlighting"
31+
},
32+
"opinionated": {
33+
"type": "boolean",
34+
"default": false,
35+
"description": "Apply opinionated Zsh and Powerlevel10k settings"
36+
}
37+
},
38+
"entrypoint": "install.sh"
39+
}

features/shell/install.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
set -e
3+
4+
USERNAME="${_REMOTE_USER:-vscode}"
5+
USER_HOME="/home/$USERNAME"
6+
ZSHRC="$USER_HOME/.zshrc"
7+
OMZ_DIR="$USER_HOME/.oh-my-zsh"
8+
ZSH_CUSTOM="${OMZ_DIR}/custom"
9+
10+
# Options
11+
: "${INSTALLZSH:=true}"
12+
: "${OHMYZSH:=true}"
13+
: "${POWERLEVEL10K:=true}"
14+
: "${AUTOSUGGESTIONS:=true}"
15+
: "${SYNTAXHIGHLIGHTING:=true}"
16+
: "${AUTOSUGGESTHIGHLIGHT:=fg=8}"
17+
: "${OPINIONATED:=false}"
18+
19+
apt-get update
20+
21+
# Install Zsh if required
22+
if [[ "$INSTALLZSH" == "true" ]]; then
23+
if ! command -v zsh &>/dev/null; then
24+
echo "Installing Zsh..."
25+
apt-get install -y zsh
26+
fi
27+
chsh -s "$(which zsh)" "$USERNAME"
28+
fi
29+
30+
# Oh My Zsh setup
31+
if [[ "$OHMYZSH" == "true" ]]; then
32+
if [ ! -d "$OMZ_DIR" ]; then
33+
echo "Installing Oh My Zsh..."
34+
su - "$USERNAME" -c "sh -c \"\$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)\" --unattended"
35+
fi
36+
37+
grep -qxF 'export ZSH="$HOME/.oh-my-zsh"' "$ZSHRC" || echo 'export ZSH="$HOME/.oh-my-zsh"' >>"$ZSHRC"
38+
grep -qxF 'ZSH_THEME="robbyrussell"' "$ZSHRC" || echo 'ZSH_THEME="robbyrussell"' >>"$ZSHRC"
39+
fi
40+
41+
# Powerlevel10k theme
42+
if [[ "$POWERLEVEL10K" == "true" ]]; then
43+
THEME_DIR="${ZSH_CUSTOM}/themes/powerlevel10k"
44+
if [ ! -d "$THEME_DIR" ]; then
45+
echo "Installing Powerlevel10k..."
46+
su - "$USERNAME" -c "git clone --depth=1 https://github.com/romkatv/powerlevel10k.git $THEME_DIR"
47+
fi
48+
sed -i 's/^ZSH_THEME=.*/ZSH_THEME="powerlevel10k\/powerlevel10k"/' "$ZSHRC" || true
49+
50+
# 💡 Apply preconfigured .p10k.zsh only in opinionated mode
51+
if [[ "$OPINIONATED" == "true" ]]; then
52+
echo "Applying default Powerlevel10k configuration..."
53+
cp "$(dirname "$0")/assets/p10k.zsh" "$USER_HOME/.p10k.zsh"
54+
chown "$USERNAME:$USERNAME" "$USER_HOME/.p10k.zsh"
55+
grep -qxF '[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh' "$ZSHRC" || echo '[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh' >>"$ZSHRC"
56+
fi
57+
fi
58+
59+
# Autosuggestions plugin
60+
if [[ "$AUTOSUGGESTIONS" == "true" ]]; then
61+
PLUGIN_DIR="${ZSH_CUSTOM}/plugins/zsh-autosuggestions"
62+
if [ ! -d "$PLUGIN_DIR" ]; then
63+
echo "Installing zsh-autosuggestions..."
64+
su - "$USERNAME" -c "git clone https://github.com/zsh-users/zsh-autosuggestions $PLUGIN_DIR"
65+
fi
66+
grep -qxF "source ${PLUGIN_DIR}/zsh-autosuggestions.zsh" "$ZSHRC" || echo "source ${PLUGIN_DIR}/zsh-autosuggestions.zsh" >>"$ZSHRC"
67+
grep -qxF "ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='$AUTOSUGGESTHIGHLIGHT'" "$ZSHRC" || echo "ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='$AUTOSUGGESTHIGHLIGHT'" >>"$ZSHRC"
68+
fi
69+
70+
# Syntax Highlighting plugin
71+
if [[ "$SYNTAXHIGHLIGHTING" == "true" ]]; then
72+
PLUGIN_DIR="${ZSH_CUSTOM}/plugins/zsh-syntax-highlighting"
73+
if [ ! -d "$PLUGIN_DIR" ]; then
74+
echo "Installing zsh-syntax-highlighting..."
75+
su - "$USERNAME" -c "git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $PLUGIN_DIR"
76+
fi
77+
grep -qxF "source ${PLUGIN_DIR}/zsh-syntax-highlighting.zsh" "$ZSHRC" || echo "source ${PLUGIN_DIR}/zsh-syntax-highlighting.zsh" >>"$ZSHRC"
78+
fi
79+
80+
# Ownership
81+
chown -R "$USERNAME:$USERNAME" "$USER_HOME"
82+
echo "✅ Shell configuration complete for $USERNAME"
83+
[[ "$OPINIONATED" == "true" ]] && echo "(💡 opinionated Powerlevel10k config applied)"

0 commit comments

Comments
 (0)