modified: tools/install.sh

new file:   workspace.code-workspace
This commit is contained in:
seocringe 2024-02-22 02:24:07 +02:00
parent 16660252f4
commit aaadaa53af
2 changed files with 109 additions and 52 deletions

View file

@ -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
HOME="${HOME:-$(eval echo ~$USER)}"
# Track if $ZSH was provided
custom_zsh=${ZSH:+yes}
@ -78,7 +77,6 @@ CHSH=${CHSH:-yes}
RUNZSH=${RUNZSH:-yes}
KEEP_ZSHRC=${KEEP_ZSHRC:-no}
command_exists() {
command -v "$@" >/dev/null 2>&1
}
@ -166,7 +164,7 @@ supports_hyperlinks() {
# If $TERM_PROGRAM is set, these terminals support hyperlinks
case "$TERM_PROGRAM" in
Hyper|iTerm.app|terminology|WezTerm) return 0 ;;
Hyper | iTerm.app | terminology | WezTerm) return 0 ;;
esac
# kitty supports hyperlinks
@ -192,15 +190,15 @@ supports_hyperlinks() {
# Source: https://gist.github.com/XVilka/8346728
supports_truecolor() {
case "$COLORTERM" in
truecolor|24bit) return 0 ;;
truecolor | 24bit) return 0 ;;
esac
case "$TERM" in
iterm |\
tmux-truecolor |\
linux-truecolor |\
xterm-truecolor |\
screen-truecolor) return 0 ;;
iterm | \
tmux-truecolor | \
linux-truecolor | \
xterm-truecolor | \
screen-truecolor) return 0 ;;
esac
return 1
@ -215,7 +213,7 @@ fmt_link() {
case "$3" in
--text) printf '%s\n' "$1" ;;
--url|*) fmt_underline "$2" ;;
--url | *) fmt_underline "$2" ;;
esac
}
@ -298,17 +296,17 @@ setup_ohmyzsh() {
fi
# Manual clone with git config options to support git < v1.7.2
git init --quiet "$ZSH" && cd "$ZSH" \
&& git config core.eol lf \
&& git config core.autocrlf false \
&& git config fsck.zeroPaddedFilemode ignore \
&& git config fetch.fsck.zeroPaddedFilemode ignore \
&& git config receive.fsck.zeroPaddedFilemode ignore \
&& git config oh-my-zsh.remote origin \
&& git config oh-my-zsh.branch "$BRANCH" \
&& git remote add origin "$REMOTE" \
&& git fetch --depth=1 origin \
&& git checkout -b "$BRANCH" "origin/$BRANCH" || {
git init --quiet "$ZSH" && cd "$ZSH" &&
git config core.eol lf &&
git config core.autocrlf false &&
git config fsck.zeroPaddedFilemode ignore &&
git config fetch.fsck.zeroPaddedFilemode ignore &&
git config receive.fsck.zeroPaddedFilemode ignore &&
git config oh-my-zsh.remote origin &&
git config oh-my-zsh.branch "$BRANCH" &&
git remote add origin "$REMOTE" &&
git fetch --depth=1 origin &&
git checkout -b "$BRANCH" "origin/$BRANCH" || {
[ ! -d "$ZSH" ] || {
cd -
rm -rf "$ZSH" 2>/dev/null
@ -323,15 +321,11 @@ setup_ohmyzsh() {
}
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}"
# 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"
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
echo "${FMT_YELLOW}Found ${zdot}/.zshrc.${FMT_RESET} ${FMT_GREEN}Keeping...${FMT_RESET}"
return
@ -352,17 +346,64 @@ setup_zshrc() {
mv "$zdot/.zshrc" "$OLD_ZSHRC"
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
omz="$ZSH"
if [ -n "$ZDOTDIR" ] && [ "$ZDOTDIR" != "$HOME" ]; then
omz=$(echo "$omz" | sed "s|^$ZDOTDIR/|\$ZDOTDIR/|")
fi
omz=$(echo "$omz" | sed "s|^$HOME/|\$HOME/|")
cat >"$zdot/.zshrc" <<'EOF'
#!/bin/zsh
# Set common environment variables
export ZSH_THEME="half-life"
export HYPHEN_INSENSITIVE="true"
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"
mv -f "$zdot/.zshrc-omztemp" "$zdot/.zshrc"
# Set pyenv root and ensure pyenv is in the PATH
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
}
@ -394,15 +435,24 @@ EOF
"$FMT_YELLOW" "$FMT_RESET"
read -r opt
case $opt in
y*|Y*|"") ;;
n*|N*) echo "Shell change skipped."; return ;;
*) echo "Invalid choice. Shell change skipped."; return ;;
y* | Y* | "") ;;
n* | N*)
echo "Shell change skipped."
return
;;
*)
echo "Invalid choice. Shell change skipped."
return
;;
esac
# Check if we're running on Termux
case "$PREFIX" in
*com.termux*) termux=true; zsh=zsh ;;
*) termux=false ;;
*com.termux*)
termux=true
zsh=zsh
;;
*) termux=false ;;
esac
if [ "$termux" != true ]; then
@ -430,9 +480,9 @@ EOF
# We're going to change the default shell, so back up the current one
if [ -n "$SHELL" ]; then
echo "$SHELL" > "$zdot/.shell.pre-oh-my-zsh"
echo "$SHELL" >"$zdot/.shell.pre-oh-my-zsh"
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
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.
#
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
chsh -s "$zsh" "$USER" # run chsh normally
chsh -s "$zsh" "$USER" # run chsh normally
fi
# 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)
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 '\n'
printf '\n'
@ -493,9 +543,12 @@ main() {
# Parse arguments
while [ $# -gt 0 ]; do
case $1 in
--unattended) RUNZSH=no; CHSH=no ;;
--skip-chsh) CHSH=no ;;
--keep-zshrc) KEEP_ZSHRC=yes ;;
--unattended)
RUNZSH=no
CHSH=no
;;
--skip-chsh) CHSH=no ;;
--keep-zshrc) KEEP_ZSHRC=yes ;;
esac
shift
done

4
workspace.code-workspace Normal file
View file

@ -0,0 +1,4 @@
{
"folders": [],
"settings": {}
}