Skip to content

Commit b1957e2

Browse files
author
Yuriy Bezsonov
committed
update base shell
1 parent c4d6e46 commit b1957e2

3 files changed

Lines changed: 166 additions & 2 deletions

File tree

infra/scripts/ide/base.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ install_kubernetes_tools() {
195195
mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$PATH:$HOME/bin
196196
echo "export PATH=\$PATH:\$HOME/bin" | sudo tee -a /etc/profile.d/workshop.sh >/dev/null
197197
kubectl completion bash >> ~/.bash_completion
198-
echo "alias k=kubectl" | sudo tee -a /etc/profile.d/workshop.sh >/dev/null
199-
echo "complete -F __start_kubectl k" >> ~/.bashrc
200198

201199
log_info "Installing Helm ${HELM_VERSION}..."
202200
retry_critical "Helm ${HELM_VERSION}" "curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 && chmod 700 get_helm.sh && ./get_helm.sh --version v${HELM_VERSION}"
@@ -262,4 +260,11 @@ log_info "Configuring AWS CLI default region..."
262260
source /etc/profile.d/workshop.sh
263261
aws configure set default.region ${AWS_REGION}
264262

263+
# Shell UX setup (zsh + oh-my-zsh + powerlevel10k + fzf)
264+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
265+
if [ -f "${SCRIPT_DIR}/shell.sh" ]; then
266+
log_info "Setting up shell environment..."
267+
sudo -u ec2-user bash "${SCRIPT_DIR}/shell.sh"
268+
fi
269+
265270
log_info "Base development tools setup completed successfully at $(date)"

infra/scripts/ide/p10k.zsh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Instant prompt - makes prompt appear instantly while zsh loads
2+
typeset -g POWERLEVEL9K_INSTANT_PROMPT=quiet
3+
4+
# Left prompt: directory, git status, prompt symbol
5+
typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir vcs newline prompt_char)
6+
7+
# Right prompt: status, duration, jobs, k8s context, aws profile, time
8+
typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status command_execution_time background_jobs kubecontext aws time newline)
9+
10+
# Visual style
11+
typeset -g POWERLEVEL9K_MODE=powerline
12+
typeset -g POWERLEVEL9K_PROMPT_ADD_NEWLINE=true
13+
typeset -g POWERLEVEL9K_LEFT_SEGMENT_SEPARATOR='\uE0B0'
14+
typeset -g POWERLEVEL9K_RIGHT_SEGMENT_SEPARATOR='\uE0B2'
15+
typeset -g POWERLEVEL9K_LEFT_SUBSEGMENT_SEPARATOR='\uE0B1'
16+
typeset -g POWERLEVEL9K_RIGHT_SUBSEGMENT_SEPARATOR='\uE0B3'
17+
typeset -g POWERLEVEL9K_MULTILINE_FIRST_PROMPT_SUFFIX='%240F─╮'
18+
typeset -g POWERLEVEL9K_MULTILINE_NEWLINE_PROMPT_SUFFIX='%240F─┤'
19+
typeset -g POWERLEVEL9K_MULTILINE_LAST_PROMPT_SUFFIX='%240F─╯'
20+
21+
# Prompt char: green on success, red on error
22+
typeset -g POWERLEVEL9K_PROMPT_CHAR_BACKGROUND=
23+
typeset -g POWERLEVEL9K_PROMPT_CHAR_OK_{VIINS,VICMD,VIVIS,VIOWR}_FOREGROUND=76
24+
typeset -g POWERLEVEL9K_PROMPT_CHAR_ERROR_{VIINS,VICMD,VIVIS,VIOWR}_FOREGROUND=196
25+
typeset -g POWERLEVEL9K_PROMPT_CHAR_{OK,ERROR}_VIINS_CONTENT_EXPANSION=''
26+
27+
# Directory
28+
typeset -g POWERLEVEL9K_DIR_BACKGROUND=4
29+
typeset -g POWERLEVEL9K_DIR_FOREGROUND=254
30+
typeset -g POWERLEVEL9K_SHORTEN_STRATEGY=truncate_to_unique
31+
typeset -g POWERLEVEL9K_DIR_MAX_LENGTH=80
32+
33+
# Git status: green=clean, yellow=modified, red=conflicts
34+
typeset -g POWERLEVEL9K_VCS_CLEAN_BACKGROUND=2
35+
typeset -g POWERLEVEL9K_VCS_MODIFIED_BACKGROUND=3
36+
typeset -g POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND=2
37+
typeset -g POWERLEVEL9K_VCS_CONFLICTED_BACKGROUND=1
38+
typeset -g POWERLEVEL9K_VCS_BACKENDS=(git)
39+
40+
# Command execution time: show if > 3 seconds
41+
typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=3
42+
typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=0
43+
typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_FOREGROUND=0
44+
typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_BACKGROUND=3
45+
46+
# Kubernetes context: show only when using k8s commands
47+
typeset -g POWERLEVEL9K_KUBECONTEXT_SHOW_ON_COMMAND='kubectl|helm|kubens|kubectx|k9s|k'
48+
typeset -g POWERLEVEL9K_KUBECONTEXT_FOREGROUND=7
49+
typeset -g POWERLEVEL9K_KUBECONTEXT_BACKGROUND=5
50+
51+
# AWS profile: show only when using aws commands
52+
typeset -g POWERLEVEL9K_AWS_SHOW_ON_COMMAND='aws|terraform|cdk|sam'
53+
typeset -g POWERLEVEL9K_AWS_FOREGROUND=7
54+
typeset -g POWERLEVEL9K_AWS_BACKGROUND=208
55+
56+
# Time: 24-hour format
57+
typeset -g POWERLEVEL9K_TIME_FOREGROUND=0
58+
typeset -g POWERLEVEL9K_TIME_BACKGROUND=7
59+
typeset -g POWERLEVEL9K_TIME_FORMAT='%D{%H:%M}'
60+
61+
# Status: show only on error
62+
typeset -g POWERLEVEL9K_STATUS_OK=false
63+
typeset -g POWERLEVEL9K_STATUS_ERROR=true
64+
typeset -g POWERLEVEL9K_STATUS_ERROR_FOREGROUND=7
65+
typeset -g POWERLEVEL9K_STATUS_ERROR_BACKGROUND=1
66+
67+
# Background jobs
68+
typeset -g POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE=false
69+
typeset -g POWERLEVEL9K_BACKGROUND_JOBS_FOREGROUND=6
70+
typeset -g POWERLEVEL9K_BACKGROUND_JOBS_BACKGROUND=0

infra/scripts/ide/shell.sh

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# =============================================================================
5+
# Shell UX Setup (zsh + oh-my-zsh + powerlevel10k + fzf)
6+
# =============================================================================
7+
8+
log_info() {
9+
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1"
10+
}
11+
12+
log_info "Installing zsh and dependencies..."
13+
sudo dnf install -y -q zsh util-linux-user >/dev/null
14+
15+
log_info "Setting zsh as default shell..."
16+
sudo chsh -s /bin/zsh ec2-user
17+
18+
log_info "Installing oh-my-zsh..."
19+
rm -rf ~/.oh-my-zsh
20+
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
21+
22+
log_info "Installing Powerlevel10k theme..."
23+
git clone --depth=1 -q https://github.com/romkatv/powerlevel10k.git ~/.oh-my-zsh/custom/themes/powerlevel10k
24+
25+
log_info "Installing zsh plugins..."
26+
git clone --depth=1 -q https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
27+
git clone --depth=1 -q https://github.com/zsh-users/zsh-syntax-highlighting ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
28+
29+
log_info "Installing fzf..."
30+
rm -rf ~/.fzf
31+
git clone --depth=1 -q https://github.com/junegunn/fzf.git ~/.fzf
32+
~/.fzf/install --all --no-bash --no-fish >/dev/null
33+
34+
log_info "Creating .zshrc..."
35+
cat > ~/.zshrc << 'EOF'
36+
# Powerlevel10k instant prompt
37+
typeset -g POWERLEVEL9K_INSTANT_PROMPT=quiet
38+
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
39+
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
40+
fi
41+
42+
export ZSH=$HOME/.oh-my-zsh
43+
ZSH_THEME="powerlevel10k/powerlevel10k"
44+
DISABLE_UPDATE_PROMPT="true"
45+
DISABLE_UNTRACKED_FILES_DIRTY="true"
46+
47+
plugins=(git docker kubectl zsh-syntax-highlighting zsh-autosuggestions)
48+
49+
source $ZSH/oh-my-zsh.sh
50+
51+
# fzf integration
52+
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
53+
54+
# Powerlevel10k config
55+
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
56+
57+
# Source workshop env vars (must be before kubectl completion)
58+
[ -f /etc/profile.d/workshop.sh ] && source /etc/profile.d/workshop.sh
59+
60+
# Basic aliases
61+
alias ll='ls -la'
62+
alias k=kubectl
63+
alias code=/usr/lib/code-server/bin/code-server
64+
65+
# kubectl completion
66+
source <(kubectl completion zsh)
67+
compdef k=kubectl
68+
69+
# Source user-specific env vars from bashrc.d
70+
if [ -d ~/.bashrc.d ]; then
71+
for rc in ~/.bashrc.d/*; do
72+
[ -f "$rc" ] && . "$rc"
73+
done
74+
fi
75+
EOF
76+
77+
log_info "Copying .p10k.zsh..."
78+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
79+
cp "${SCRIPT_DIR}/p10k.zsh" ~/.p10k.zsh
80+
81+
log_info "Configuring code-server to use zsh..."
82+
if [ -f ~/.local/share/code-server/User/settings.json ]; then
83+
# Add zsh as default terminal if settings.json exists
84+
jq '. + {"terminal.integrated.defaultProfile.linux": "zsh"}' \
85+
~/.local/share/code-server/User/settings.json > /tmp/settings.json \
86+
&& mv /tmp/settings.json ~/.local/share/code-server/User/settings.json
87+
fi
88+
89+
log_info "Shell setup completed successfully"

0 commit comments

Comments
 (0)