mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-06 02:51:32 +01:00
modified: tools/install.sh
new file: workspace.code-workspace
This commit is contained in:
parent
16660252f4
commit
aaadaa53af
2 changed files with 109 additions and 52 deletions
157
tools/install.sh
157
tools/install.sh
|
|
@ -52,7 +52,6 @@ HOME="${HOME:-$(getent passwd $USER 2>/dev/null | cut -d: -f6)}"
|
||||||
# macOS does not have getent, but this works even if $HOME is unset
|
# macOS does not have getent, but this works even if $HOME is unset
|
||||||
HOME="${HOME:-$(eval echo ~$USER)}"
|
HOME="${HOME:-$(eval echo ~$USER)}"
|
||||||
|
|
||||||
|
|
||||||
# Track if $ZSH was provided
|
# Track if $ZSH was provided
|
||||||
custom_zsh=${ZSH:+yes}
|
custom_zsh=${ZSH:+yes}
|
||||||
|
|
||||||
|
|
@ -78,7 +77,6 @@ CHSH=${CHSH:-yes}
|
||||||
RUNZSH=${RUNZSH:-yes}
|
RUNZSH=${RUNZSH:-yes}
|
||||||
KEEP_ZSHRC=${KEEP_ZSHRC:-no}
|
KEEP_ZSHRC=${KEEP_ZSHRC:-no}
|
||||||
|
|
||||||
|
|
||||||
command_exists() {
|
command_exists() {
|
||||||
command -v "$@" >/dev/null 2>&1
|
command -v "$@" >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
@ -166,7 +164,7 @@ supports_hyperlinks() {
|
||||||
|
|
||||||
# If $TERM_PROGRAM is set, these terminals support hyperlinks
|
# If $TERM_PROGRAM is set, these terminals support hyperlinks
|
||||||
case "$TERM_PROGRAM" in
|
case "$TERM_PROGRAM" in
|
||||||
Hyper|iTerm.app|terminology|WezTerm) return 0 ;;
|
Hyper | iTerm.app | terminology | WezTerm) return 0 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# kitty supports hyperlinks
|
# kitty supports hyperlinks
|
||||||
|
|
@ -192,15 +190,15 @@ supports_hyperlinks() {
|
||||||
# Source: https://gist.github.com/XVilka/8346728
|
# Source: https://gist.github.com/XVilka/8346728
|
||||||
supports_truecolor() {
|
supports_truecolor() {
|
||||||
case "$COLORTERM" in
|
case "$COLORTERM" in
|
||||||
truecolor|24bit) return 0 ;;
|
truecolor | 24bit) return 0 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "$TERM" in
|
case "$TERM" in
|
||||||
iterm |\
|
iterm | \
|
||||||
tmux-truecolor |\
|
tmux-truecolor | \
|
||||||
linux-truecolor |\
|
linux-truecolor | \
|
||||||
xterm-truecolor |\
|
xterm-truecolor | \
|
||||||
screen-truecolor) return 0 ;;
|
screen-truecolor) return 0 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
@ -215,7 +213,7 @@ fmt_link() {
|
||||||
|
|
||||||
case "$3" in
|
case "$3" in
|
||||||
--text) printf '%s\n' "$1" ;;
|
--text) printf '%s\n' "$1" ;;
|
||||||
--url|*) fmt_underline "$2" ;;
|
--url | *) fmt_underline "$2" ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -298,17 +296,17 @@ setup_ohmyzsh() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Manual clone with git config options to support git < v1.7.2
|
# Manual clone with git config options to support git < v1.7.2
|
||||||
git init --quiet "$ZSH" && cd "$ZSH" \
|
git init --quiet "$ZSH" && cd "$ZSH" &&
|
||||||
&& git config core.eol lf \
|
git config core.eol lf &&
|
||||||
&& git config core.autocrlf false \
|
git config core.autocrlf false &&
|
||||||
&& git config fsck.zeroPaddedFilemode ignore \
|
git config fsck.zeroPaddedFilemode ignore &&
|
||||||
&& git config fetch.fsck.zeroPaddedFilemode ignore \
|
git config fetch.fsck.zeroPaddedFilemode ignore &&
|
||||||
&& git config receive.fsck.zeroPaddedFilemode ignore \
|
git config receive.fsck.zeroPaddedFilemode ignore &&
|
||||||
&& git config oh-my-zsh.remote origin \
|
git config oh-my-zsh.remote origin &&
|
||||||
&& git config oh-my-zsh.branch "$BRANCH" \
|
git config oh-my-zsh.branch "$BRANCH" &&
|
||||||
&& git remote add origin "$REMOTE" \
|
git remote add origin "$REMOTE" &&
|
||||||
&& git fetch --depth=1 origin \
|
git fetch --depth=1 origin &&
|
||||||
&& git checkout -b "$BRANCH" "origin/$BRANCH" || {
|
git checkout -b "$BRANCH" "origin/$BRANCH" || {
|
||||||
[ ! -d "$ZSH" ] || {
|
[ ! -d "$ZSH" ] || {
|
||||||
cd -
|
cd -
|
||||||
rm -rf "$ZSH" 2>/dev/null
|
rm -rf "$ZSH" 2>/dev/null
|
||||||
|
|
@ -323,15 +321,11 @@ setup_ohmyzsh() {
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_zshrc() {
|
setup_zshrc() {
|
||||||
# Keep most recent old .zshrc at .zshrc.pre-oh-my-zsh, and older ones
|
|
||||||
# with datestamp of installation that moved them aside, so we never actually
|
|
||||||
# destroy a user's original zshrc
|
|
||||||
echo "${FMT_BLUE}Looking for an existing zsh config...${FMT_RESET}"
|
echo "${FMT_BLUE}Looking for an existing zsh config...${FMT_RESET}"
|
||||||
|
|
||||||
# Must use this exact name so uninstall.sh can find it
|
# Must use exact name so uninstall.sh can find it
|
||||||
OLD_ZSHRC="$zdot/.zshrc.pre-oh-my-zsh"
|
OLD_ZSHRC="$zdot/.zshrc.pre-oh-my-zsh"
|
||||||
if [ -f "$zdot/.zshrc" ] || [ -h "$zdot/.zshrc" ]; then
|
if [ -f "$zdot/.zshrc" ] || [ -h "$zdot/.zshrc" ]; then
|
||||||
# Skip this if the user doesn't want to replace an existing .zshrc
|
|
||||||
if [ "$KEEP_ZSHRC" = yes ]; then
|
if [ "$KEEP_ZSHRC" = yes ]; then
|
||||||
echo "${FMT_YELLOW}Found ${zdot}/.zshrc.${FMT_RESET} ${FMT_GREEN}Keeping...${FMT_RESET}"
|
echo "${FMT_YELLOW}Found ${zdot}/.zshrc.${FMT_RESET} ${FMT_GREEN}Keeping...${FMT_RESET}"
|
||||||
return
|
return
|
||||||
|
|
@ -352,17 +346,64 @@ setup_zshrc() {
|
||||||
mv "$zdot/.zshrc" "$OLD_ZSHRC"
|
mv "$zdot/.zshrc" "$OLD_ZSHRC"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "${FMT_GREEN}Using the Oh My Zsh template file and adding it to $zdot/.zshrc.${FMT_RESET}"
|
echo "${FMT_GREEN}Creating a new zsh config file...${FMT_RESET}"
|
||||||
|
|
||||||
# Modify $ZSH variable in .zshrc directory to use the literal $ZDOTDIR or $HOME
|
cat >"$zdot/.zshrc" <<'EOF'
|
||||||
omz="$ZSH"
|
#!/bin/zsh
|
||||||
if [ -n "$ZDOTDIR" ] && [ "$ZDOTDIR" != "$HOME" ]; then
|
# Set common environment variables
|
||||||
omz=$(echo "$omz" | sed "s|^$ZDOTDIR/|\$ZDOTDIR/|")
|
export ZSH_THEME="half-life"
|
||||||
fi
|
export HYPHEN_INSENSITIVE="true"
|
||||||
omz=$(echo "$omz" | sed "s|^$HOME/|\$HOME/|")
|
export ENABLE_CORRECTION="true"
|
||||||
|
export COMPLETION_WAITING_DOTS="true"
|
||||||
|
export HIST_STAMPS="dd/mm/yyyy"
|
||||||
|
export ARCHFLAGS="-arch x86_64"
|
||||||
|
|
||||||
sed "s|^export ZSH=.*$|export ZSH=\"${omz}\"|" "$ZSH/templates/zshrc.zsh-template" > "$zdot/.zshrc-omztemp"
|
# Set pyenv root and ensure pyenv is in the PATH
|
||||||
mv -f "$zdot/.zshrc-omztemp" "$zdot/.zshrc"
|
export PYENV_ROOT="$HOME/.pyenv"
|
||||||
|
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
|
||||||
|
|
||||||
|
# Function to source a file if it exists
|
||||||
|
source_if_exists() {
|
||||||
|
[[ -f "$1" ]] && source "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Initialize pyenv and pyenv-virtualenv if they are installed
|
||||||
|
eval "$(pyenv init --path)"
|
||||||
|
eval "$(pyenv virtualenv-init -)"
|
||||||
|
|
||||||
|
# Load Oh My Zsh script based on user type
|
||||||
|
load_oh_my_zsh_for_user_type() {
|
||||||
|
local zsh_dir="${1:-$HOME/.oh-my-zsh}"
|
||||||
|
export ZSH="$zsh_dir"
|
||||||
|
source_if_exists "${ZSH}/oh-my-zsh.sh"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Configuration for root and regular users
|
||||||
|
if [[ $EUID -eq 0 ]]; then
|
||||||
|
# Root-specific settings
|
||||||
|
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH"
|
||||||
|
export LANG="ru_UA.UTF-8"
|
||||||
|
load_oh_my_zsh_for_user_type "/root/.oh-my-zsh"
|
||||||
|
else
|
||||||
|
# Regular user settings
|
||||||
|
export PATH="$HOME/.local/bin:$PATH"
|
||||||
|
export LANG="en_US.UTF-8"
|
||||||
|
load_oh_my_zsh_for_user_type
|
||||||
|
source_if_exists "$HOME/.bash_aliases"
|
||||||
|
source_if_exists "$HOME/.bash_exports"
|
||||||
|
source_if_exists "$HOME/.zsh_plugins"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Initialize nodenv if it is installed
|
||||||
|
if command -v nodenv >/dev/null; then
|
||||||
|
eval "$(nodenv init -)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Initialize NVM (Node Version Manager) if it is installed
|
||||||
|
export NVM_DIR="${XDG_CONFIG_HOME:-$HOME/.nvm}"
|
||||||
|
[[ -s "$NVM_DIR/nvm.sh" ]] && . "$NVM_DIR/nvm.sh"
|
||||||
|
[[ -s "$NVM_DIR/bash_completion" ]] && . "$NVM_DIR/bash_completion"
|
||||||
|
EOF
|
||||||
|
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
@ -394,15 +435,24 @@ EOF
|
||||||
"$FMT_YELLOW" "$FMT_RESET"
|
"$FMT_YELLOW" "$FMT_RESET"
|
||||||
read -r opt
|
read -r opt
|
||||||
case $opt in
|
case $opt in
|
||||||
y*|Y*|"") ;;
|
y* | Y* | "") ;;
|
||||||
n*|N*) echo "Shell change skipped."; return ;;
|
n* | N*)
|
||||||
*) echo "Invalid choice. Shell change skipped."; return ;;
|
echo "Shell change skipped."
|
||||||
|
return
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Invalid choice. Shell change skipped."
|
||||||
|
return
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Check if we're running on Termux
|
# Check if we're running on Termux
|
||||||
case "$PREFIX" in
|
case "$PREFIX" in
|
||||||
*com.termux*) termux=true; zsh=zsh ;;
|
*com.termux*)
|
||||||
*) termux=false ;;
|
termux=true
|
||||||
|
zsh=zsh
|
||||||
|
;;
|
||||||
|
*) termux=false ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ "$termux" != true ]; then
|
if [ "$termux" != true ]; then
|
||||||
|
|
@ -430,9 +480,9 @@ EOF
|
||||||
|
|
||||||
# We're going to change the default shell, so back up the current one
|
# We're going to change the default shell, so back up the current one
|
||||||
if [ -n "$SHELL" ]; then
|
if [ -n "$SHELL" ]; then
|
||||||
echo "$SHELL" > "$zdot/.shell.pre-oh-my-zsh"
|
echo "$SHELL" >"$zdot/.shell.pre-oh-my-zsh"
|
||||||
else
|
else
|
||||||
grep "^$USER:" /etc/passwd | awk -F: '{print $7}' > "$zdot/.shell.pre-oh-my-zsh"
|
grep "^$USER:" /etc/passwd | awk -F: '{print $7}' >"$zdot/.shell.pre-oh-my-zsh"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Changing your shell to $zsh..."
|
echo "Changing your shell to $zsh..."
|
||||||
|
|
@ -447,9 +497,9 @@ EOF
|
||||||
# be prompted for the password either way, so this shouldn't cause any issues.
|
# be prompted for the password either way, so this shouldn't cause any issues.
|
||||||
#
|
#
|
||||||
if user_can_sudo; then
|
if user_can_sudo; then
|
||||||
sudo -k chsh -s "$zsh" "$USER" # -k forces the password prompt
|
sudo -k chsh -s "$zsh" "$USER" # -k forces the password prompt
|
||||||
else
|
else
|
||||||
chsh -s "$zsh" "$USER" # run chsh normally
|
chsh -s "$zsh" "$USER" # run chsh normally
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if the shell change was successful
|
# Check if the shell change was successful
|
||||||
|
|
@ -465,11 +515,11 @@ EOF
|
||||||
|
|
||||||
# shellcheck disable=SC2183 # printf string has more %s than arguments ($FMT_RAINBOW expands to multiple arguments)
|
# shellcheck disable=SC2183 # printf string has more %s than arguments ($FMT_RAINBOW expands to multiple arguments)
|
||||||
print_success() {
|
print_success() {
|
||||||
printf '%s %s__ %s %s %s %s %s__ %s\n' $FMT_RAINBOW $FMT_RESET
|
printf '%s %s__ %s %s %s %s %s__ %s\n' $FMT_RAINBOW $FMT_RESET
|
||||||
printf '%s ____ %s/ /_ %s ____ ___ %s__ __ %s ____ %s_____%s/ /_ %s\n' $FMT_RAINBOW $FMT_RESET
|
printf '%s ____ %s/ /_ %s ____ ___ %s__ __ %s ____ %s_____%s/ /_ %s\n' $FMT_RAINBOW $FMT_RESET
|
||||||
printf '%s / __ \\%s/ __ \\ %s / __ `__ \\%s/ / / / %s /_ / %s/ ___/%s __ \\ %s\n' $FMT_RAINBOW $FMT_RESET
|
printf '%s / __ \\%s/ __ \\ %s / __ `__ \\%s/ / / / %s /_ / %s/ ___/%s __ \\ %s\n' $FMT_RAINBOW $FMT_RESET
|
||||||
printf '%s/ /_/ /%s / / / %s / / / / / /%s /_/ / %s / /_%s(__ )%s / / / %s\n' $FMT_RAINBOW $FMT_RESET
|
printf '%s/ /_/ /%s / / / %s / / / / / /%s /_/ / %s / /_%s(__ )%s / / / %s\n' $FMT_RAINBOW $FMT_RESET
|
||||||
printf '%s\\____/%s_/ /_/ %s /_/ /_/ /_/%s\\__, / %s /___/%s____/%s_/ /_/ %s\n' $FMT_RAINBOW $FMT_RESET
|
printf '%s\\____/%s_/ /_/ %s /_/ /_/ /_/%s\\__, / %s /___/%s____/%s_/ /_/ %s\n' $FMT_RAINBOW $FMT_RESET
|
||||||
printf '%s %s %s %s /____/ %s %s %s %s....is now installed!%s\n' $FMT_RAINBOW $FMT_GREEN $FMT_RESET
|
printf '%s %s %s %s /____/ %s %s %s %s....is now installed!%s\n' $FMT_RAINBOW $FMT_GREEN $FMT_RESET
|
||||||
printf '\n'
|
printf '\n'
|
||||||
printf '\n'
|
printf '\n'
|
||||||
|
|
@ -493,9 +543,12 @@ main() {
|
||||||
# Parse arguments
|
# Parse arguments
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
--unattended) RUNZSH=no; CHSH=no ;;
|
--unattended)
|
||||||
--skip-chsh) CHSH=no ;;
|
RUNZSH=no
|
||||||
--keep-zshrc) KEEP_ZSHRC=yes ;;
|
CHSH=no
|
||||||
|
;;
|
||||||
|
--skip-chsh) CHSH=no ;;
|
||||||
|
--keep-zshrc) KEEP_ZSHRC=yes ;;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
|
||||||
4
workspace.code-workspace
Normal file
4
workspace.code-workspace
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"folders": [],
|
||||||
|
"settings": {}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue