#!/usr/bin/env zsh eval "$_z4h_opt" local user=${(%):-%n} [[ -n $user && -r /etc/shells && $_z4h_exe == /* && -x $_z4h_exe && $user != cloudshell-user && -t 0 && -t 1 && -t 2 ]] || return 0 if [[ $OSTYPE == linux* ]]; then [[ -r /etc/passwd ]] || return 0 if (( ! $+commands[chsh] )); then [[ $+commands[sudo] == 1 || -w /etc ]] || return 0 fi local passwd passwd="$($Z4H/stickycache/no-chsh || return '_z4h_err()' local home=~ local zdotdir=${${${(q)ZDOTDIR}/#${(q)home}/'~'}//\%/%%} print -Pr -- "Won't ask again unless %U\$Z4H/stickycache/no-chsh%u is deleted." return 1 fi [[ $choice == $'\n' ]] && continue if [[ $choice != (y|Y) ]]; then print -Pr -- '%F{3}z4h%f: invalid choice: '${(q-)choice//\%/%%} continue fi error=1 print if [[ -z $my_shell ]]; then print -Pr -- "Adding %F{2}${_z4h_exe//\%/%%}%f to %U/etc/shells%u." local precmd=(command) [[ -w /etc/shells ]] || precmd+=(sudo) $precmd tee -a /etc/shells >/dev/null <<<$_z4h_exe || continue my_shell=$_z4h_exe (( $#precmd == 1 )) || print fi print -Pr -- "Changing login shell to %F{2}${my_shell//\%/%%}%f." if (( $+commands[chsh] )); then command chsh -s $my_shell || continue else local MATCH MBEGIN MEND local p=("${(@)${(@f)passwd}/#%(#m)$user:*/${MATCH%:*}:$my_shell}") if [[ ${(F)p} == $passwd ]]; then print -Pru2 -- '%F{3}z4h%f: %F{1}internal error%f' return '_z4h_err()' fi local precmd=(command) [[ -w /etc ]] || precmd+=(sudo) $precmd tee -- /etc/passwd.bak.$$ >/dev/null <<<${(F)p} || continue $precmd mv -f -- /etc/passwd.bak.$$ /etc/passwd || continue fi print -Pr -- "Changed login shell of %F{3}${user//\%/%%}%f to %F{2}${my_shell//\%/%%}%f." print return 0 done ) ) && export SHELL=${my_shell:-$_z4h_exe}