<commit_before>#!/usr/bin/env zsh
#
# Author: <NAME>, <EMAIL>
# https://github.com/denysdovhan/spaceship-zsh-theme

# Source ~/.zshrc because we need oh-my-zsh variables
source "$HOME/.zshrc"

# ------------------------------------------------------------------------------
# HELPERS
# Useful functions for common tasks
# ------------------------------------------------------------------------------

# Check if program exists
# USAGE:
#   exists <program>
exists() {
  command -v $1 >/dev/null 2>&1
}

# Paint text in color
# USAGE:
#   paint <color> [text...]
paint() {
  echo "$fg[$1]${@:2}$reset_color"
}

# Logging functions.
# USAGE:
#   log|error|success [text...]
log()     {        paint 'cyan'  "SPACESHIP: $*"        }
error()   { echo ; paint 'red'   "SPACESHIP: $*" ; echo }
success() { echo ; paint 'green' "SPACESHIP: $*" ; echo }

# ------------------------------------------------------------------------------
# VARIABLES
# Paths to important resources
# ------------------------------------------------------------------------------

URL='https://raw.githubusercontent.com/denysdovhan/spaceship-zsh-theme/master/spaceship.zsh'
SPACESHIP="$PWD/spaceship.zsh"
DIST="$ZSH_CUSTOM/themes/spaceship.zsh-theme"

# ------------------------------------------------------------------------------
# MAIN
# Checkings and installing process
# ------------------------------------------------------------------------------

# Should we download Spaceship form GitHub
if [ ! -f "$SPACESHIP" ]; then
  SPACESHIP=$(mktemp /tmp/spaceship.zsh.XXXXXX)
  log "Spaceship is not present in current directory"
  log "Temporary file is created: $SPACESHIP"

  if exists curl; then
    log "Downloading using curl:"
    curl "$URL" -o "$SPACESHIP" || error "Filed to load using curl!" ; exit 1
  elif exists wget; then
    log "Downloading using wget:"
    wget "$URL" -O "$SPACESHIP" || error "Filed to load using wget!" ; exit 1
  else
    # Exit with error
    error "curl and wget are unavailable!"
    exit 1
  fi
else
  log "Spaceship is present in current directory"
fi

# Choose Installation path

DIST="/usr/local/share/zsh/site-functions"
if [[ ! -w "$DIST" ]]; then
  log "Failed to symlink $SPACESHIP to $DIST, Using $HOME/.zfunctions"
  DIST="$HOME/.zfunctions"
  log  "Adding $DIST to fpath"
  echo 'fpath=( "'"$DIST"'" $fpath )' >> "$HOME/.zshrc"
fi

# Linking
log "Linking $SPACESHIP to $DIST..."
mkdir -p "$(dirname $DIST)"
ln -sf "$SPACESHIP" "$DIST"

# Add source command to ~/.zshrc
log "Sourcing Spacehsip in ~/.zshrc..."
echo '\n'                           >> "$HOME/.zshrc"
echo 'source "'"$DIST"'"'           >> "$HOME/.zshrc"

# Replace current theme to Spaceship
log 'Attempting to change $ZSH_THEME to "spaceship"...'
sed -i '' 's/ZSH_THEME=.*$/ZSH_THEME="spaceship"/g' "$HOME/.zshrc" \
  && success "Done! Please, reload your terminal." \
  || error "Cannot change theme in ~/.zshrc. Please, do it by yourself." \<commit_msg>Update npm install without oh-my-zsh<commit_after>#!/usr/bin/env zsh
#
# Author: <NAME>, denysdovhan.com
# https://github.com/denysdovhan/spaceship-zsh-theme

# Source ~/.zshrc
source "$HOME/.zshrc"

# ------------------------------------------------------------------------------
# HELPERS
# Useful functions for common tasks
# ------------------------------------------------------------------------------

# Check if program exists
# USAGE:
#   exists <program>
exists() {
  command -v $1 >/dev/null 2>&1
}

# Paint text in color
# USAGE:
#   paint <color> [text...]
paint() {
  echo "$fg[$1]${@:2}$reset_color"
}

# Logging functions.
# USAGE:
#   log|error|success [text...]
log()     { echo ; paint 'cyan'  "SPACESHIP: $*" }
error()   { echo ; paint 'red'   "SPACESHIP: $*" }
success() { echo ; paint 'green' "SPACESHIP: $*" ; echo }

# ------------------------------------------------------------------------------
# VARIABLES
# Paths to important resources
# ------------------------------------------------------------------------------

URL='https://raw.githubusercontent.com/denysdovhan/spaceship-zsh-theme/master/spaceship.zsh'
SPACESHIP="$PWD/spaceship.zsh"

# ------------------------------------------------------------------------------
# MAIN
# Checkings and installing process
# ------------------------------------------------------------------------------

# Should we download Spaceship form GitHub
if [ ! -f "$SPACESHIP" ]; then
  SPACESHIP=$(mktemp /tmp/spaceship.zsh.XXXXXX)
  log "Spaceship is not present in current directory"
  log "Temporary file is created: $SPACESHIP"

  if exists curl; then
    log "Downloading using curl:"
    curl "$URL" -o "$SPACESHIP" || error "Filed to load using curl!" ; exit 1
  elif exists wget; then
    log "Downloading using wget:"
    wget "$URL" -O "$SPACESHIP" || error "Filed to load using wget!" ; exit 1
  else
    # Exit with error
    error "curl and wget are unavailable!"
    exit 1
  fi
else
  log "Spaceship is present in current directory"
fi

# Choose Installation path

DIST="/usr/local/share/zsh/site-functions"
if [[ ! -w "$DIST" ]]; then
  log "Failed to symlink $SPACESHIP to $DIST, Using $HOME/.zfunctions"
  DIST="$HOME/.zfunctions"
  log  "Adding $DIST to fpath"
  echo 'fpath=( "'"$DIST"'" $fpath )' >> "$HOME/.zshrc"
fi

# Link prompt to fpath
log "Linking $SPACESHIP to $DIST/prompt_spaceship_setup..."
mkdir -p "$(dirname $DIST)"
ln -sf "$SPACESHIP" "$DIST/prompt_spaceship_setup"

local msg="
  autoload -U promptinit; promptinit
  prompt spaceship
  "

read -q "choice?Do you want to set prompt now (Y/n) ?
This will append the following to your .zshrc $msg"

if [[ $choice == "y" ]]; then
  echo 'autoload -U promptinit; promptinit' >> "$HOME/.zshrc"
  echo 'prompt spaceship'                   >> "$HOME/.zshrc"
  success "Done! Please, reload your terminal."
else
  error "Please manually update your .zshrc with the following"
  echo "$msg"
fi
{'fraction_non_alphanumeric': 0.2882392929979606, 'fraction_numerical': 0.002719238613188307, 'mean_word_length': 1.8707317073170733, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 26, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4955414', 'n_tokens_mistral': 1909, 'n_tokens_neox': 1802, 'n_words': 532}