refactor(zsh): replace oh-my-zsh with a hand-rolled zprofile
Drops both git_deploy clones (ohmyzsh, zsh-autosuggestions), the chown action, the bw.zsh-theme, and the plugin directories. /etc/zsh/zprofile now embeds a compact prompt mirroring the old theme's colors (no git segment), sources zsh-autosuggestions from the new apt package, and binds prefix-history search on the arrow keys. Per-user ~/.zshrc is kept as a one-line marker so zsh-newuser-install doesn't fire when ckn logs in. Leftover /etc/zsh/oh-my-zsh/ trees aren't removed automatically — clean once with `bw run linux 'rm -rf /etc/zsh/oh-my-zsh'` after the next fleet-wide apply. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
9d59d65fa0
commit
f3122f3d0a
4 changed files with 40 additions and 118 deletions
|
|
@ -1,51 +0,0 @@
|
|||
function zsh_spwd {
|
||||
paths=(${(s:/:)PWD})
|
||||
|
||||
cur_path='/'
|
||||
cur_short_path='/'
|
||||
for directory in ${paths[@]}
|
||||
do
|
||||
cur_dir=''
|
||||
for (( i=0; i<${#directory}; i++ )); do
|
||||
cur_dir+="${directory:$i:1}"
|
||||
matching=("$cur_path"/"$cur_dir"*/)
|
||||
if [[ ${#matching[@]} -eq 1 ]]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
cur_short_path+="$cur_dir/"
|
||||
cur_path+="$directory/"
|
||||
done
|
||||
|
||||
printf %q "${cur_short_path: : -1}"
|
||||
echo
|
||||
}
|
||||
|
||||
function zsh_root_color {
|
||||
if test "$EUID" -eq 0
|
||||
then
|
||||
echo "%{$fg_bold[green]%}"
|
||||
else
|
||||
echo "%{$fg_bold[yellow]%}"
|
||||
fi
|
||||
}
|
||||
|
||||
function zsh_exitcode_color {
|
||||
echo "%(?:%{$fg_bold[green]%}:%{$fg_bold[red]%})"
|
||||
}
|
||||
|
||||
function zsh_hostname {
|
||||
if [ -z "$ZSH_HOSTNAME" ]
|
||||
then
|
||||
hostname -s
|
||||
else
|
||||
echo "$ZSH_HOSTNAME"
|
||||
fi
|
||||
}
|
||||
|
||||
PROMPT='$(zsh_root_color)$(whoami)%{$reset_color%}@$(zsh_exitcode_color)$(zsh_hostname) %{$fg[cyan]%}$(zsh_spwd)%{$reset_color%} $(git_prompt_info)'
|
||||
|
||||
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}"
|
||||
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
|
||||
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗"
|
||||
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"
|
||||
|
|
@ -1,22 +1,36 @@
|
|||
# /etc/zsh/zprofile: system-wide .zprofile file for zsh(1).
|
||||
#
|
||||
# This file is sourced only for login shells (i.e. shells
|
||||
# invoked with "-" as the first character of argv[0], and
|
||||
# shells invoked with the -l flag.)
|
||||
#
|
||||
# Global Order: zshenv, zprofile, zshrc, zlogin
|
||||
# /etc/zsh/zprofile — managed by ckn-bw bundles/zsh
|
||||
# Sourced for login shells only. SSH gives login shells; that's all we need.
|
||||
|
||||
setopt prompt_subst
|
||||
autoload -Uz colors && colors
|
||||
autoload -Uz compinit && compinit
|
||||
|
||||
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
|
||||
|
||||
# Mirrors the old bw.zsh-theme colors (sans git segment) plus a closing arrow:
|
||||
# user — bold, yellow normally, green as root
|
||||
# host — bold, green when last cmd succeeded, red otherwise
|
||||
# path — cyan (full path, ~ for $HOME)
|
||||
# ❯ — bold, same green/red as host
|
||||
PROMPT='%B%(!.%F{green}.%F{yellow})%n%f%b@%B%(?.%F{green}.%F{red})%m%f%b %F{cyan}%~%f %(?.%F{green}.%F{red})%B❯%b%f '
|
||||
|
||||
# Prefix-based history search on arrow keys
|
||||
autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
|
||||
zle -N up-line-or-beginning-search
|
||||
zle -N down-line-or-beginning-search
|
||||
bindkey '^[[A' up-line-or-beginning-search
|
||||
bindkey '^[[B' down-line-or-beginning-search
|
||||
bindkey '^[OA' up-line-or-beginning-search
|
||||
bindkey '^[OB' down-line-or-beginning-search
|
||||
|
||||
# Autosuggestions (apt-installed; guarded for minimal images)
|
||||
[[ -r /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh ]] \
|
||||
&& source /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh
|
||||
|
||||
# Server-only conveniences, carried over from the old zprofile
|
||||
alias s='sudo su - root -s /usr/bin/zsh'
|
||||
|
||||
function hhtop {
|
||||
hhtop() {
|
||||
mkdir -p ~/.config/htop
|
||||
cp /etc/htoprc.global ~/.config/htop/htoprc
|
||||
htop
|
||||
}
|
||||
|
||||
ZSH_THEME=bw
|
||||
DISABLE_AUTO_UPDATE=true
|
||||
plugins=(
|
||||
zsh-autosuggestions
|
||||
)
|
||||
source /etc/zsh/oh-my-zsh/oh-my-zsh.sh
|
||||
|
|
|
|||
|
|
@ -1,61 +1,19 @@
|
|||
from os.path import join
|
||||
|
||||
directories = {
|
||||
'/etc/zsh/oh-my-zsh': {},
|
||||
'/etc/zsh/oh-my-zsh/custom/plugins': {
|
||||
'mode': '0755',
|
||||
'needs': [
|
||||
f"git_deploy:/etc/zsh/oh-my-zsh",
|
||||
]
|
||||
},
|
||||
'/etc/zsh/oh-my-zsh/custom/plugins/zsh-autosuggestions': {
|
||||
'mode': '0755',
|
||||
'needs': [
|
||||
f"git_deploy:/etc/zsh/oh-my-zsh",
|
||||
]
|
||||
},
|
||||
}
|
||||
|
||||
git_deploy = {
|
||||
'/etc/zsh/oh-my-zsh': {
|
||||
'repo': 'https://github.com/ohmyzsh/ohmyzsh.git',
|
||||
'rev': 'master',
|
||||
},
|
||||
'/etc/zsh/oh-my-zsh/custom/plugins/zsh-autosuggestions': {
|
||||
'repo': 'https://github.com/zsh-users/zsh-autosuggestions.git',
|
||||
'rev': 'master',
|
||||
},
|
||||
}
|
||||
|
||||
files = {
|
||||
'/etc/zsh/zprofile': {
|
||||
'mode': '0755',
|
||||
},
|
||||
'/etc/zsh/oh-my-zsh/themes/bw.zsh-theme': {
|
||||
'mode': '0755',
|
||||
'needs': [
|
||||
f"git_deploy:/etc/zsh/oh-my-zsh",
|
||||
]
|
||||
},
|
||||
}
|
||||
|
||||
actions = {
|
||||
'chown_oh_my_zsh': {
|
||||
'command': 'chmod -R 755 /etc/zsh/oh-my-zsh',
|
||||
'triggered': True,
|
||||
'triggered_by': [
|
||||
"git_deploy:/etc/zsh/oh-my-zsh",
|
||||
"git_deploy:/etc/zsh/oh-my-zsh/custom/plugins/zsh-autosuggestions",
|
||||
"file:/etc/zsh/zprofile",
|
||||
"file:/etc/zsh/oh-my-zsh/themes/bw.zsh-theme",
|
||||
],
|
||||
'mode': '0644',
|
||||
},
|
||||
}
|
||||
|
||||
# Empty stub in each zsh user's home. zsh-newuser-install fires on login
|
||||
# when none of ~/.{zshrc,zshenv,zprofile,zlogin} exists, and the real
|
||||
# config lives in /etc/zsh/zprofile — so we keep a one-line marker file
|
||||
# here to suppress the new-user wizard.
|
||||
for name, user_config in node.metadata.get('users').items():
|
||||
if user_config.get('shell', None) == '/usr/bin/zsh':
|
||||
files[join(user_config['home'], '.zshrc')] = {
|
||||
'owner': name,
|
||||
'group': name,
|
||||
'content': '# bw managed',
|
||||
'content': '# bw managed; real config in /etc/zsh/zprofile\n',
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ defaults = {
|
|||
'apt': {
|
||||
'packages': {
|
||||
'zsh': {},
|
||||
'zsh-autosuggestions': {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue