# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth:erasedups

# append to the history file, don't overwrite it
shopt -s histappend cmdhist lithist

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=100000
HISTFILESIZE=500000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar

blue="\033[0;34m"
nocolor="\033[0m"

day=$(date +%A)
case $day in
    Monday)
        hari="Senin"
        ;;
    Tuesday)
        hari="Selasa"
        ;;
    Wednesday)
        hari="Rabu"
        ;;
    Thursday)
        hari="Kamis"
        ;;
    Friday)
        hari="Jum'at"
        ;;
    Saturday)
        hari="Sabtu"
        ;;
    Sunday)
        hari="Ahad"
        ;;
    *)
        hari="Tidak diketahui"
        ;;
esac

month=$(date +%B)
case $month in
    January)
        bulan="Januari"
        ;;
    February)
        bulan="Februari"
        ;;
    March)
        bulan="Maret"
        ;;
    April)
        bulan="April"
        ;;
    May)
        bulan="Mei"
        ;;
    June)
        bulan="Juni"
        ;;
    July)
        bulan="Juli"
        ;;
	August)
		bulan="Agustus"
		;;
	September)
		bulan="September"
		;;
	October)
		bulan="Oktober"
		;;
	November)
		bulan="November"
		;;
	December)
		bulan="Desember"
		;;
    *)
        bulan="Tidak diketahui"
        ;;
esac

#PS1='\[\e[38;5;160m\][\[\e[38;5;39m\]\D{%A, %d %B %Y}\[\e[0;1m\] - \[\e[38;5;184m\]\t\[\e[0;38;5;160m\]]\[\e[0m\]'

#HISTTIMEFORMAT=`echo -e ${blue}[${hari}, %d ${bulan} %Y - %T] $nocolor `
HISTTIMEFORMAT=`echo -e "\e[38;5;160m[\e[38;5;39m${hari}, %d ${bulan} %Y \e[0;1m - \e[38;5;184m %T\e[0;38;5;160m]\e[0m " `
HISTIGNORE="ls:ll:pwd:bg:fg:history:tree"

# make less more friendly for non-text input files, see lesspipe(1)
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
	# We have color support; assume it's compliant with Ecma-48
	# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
	# a case would tend to support setf rather than setaf.)
	color_prompt=yes
    else
	color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls -lah --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    #alias grep='grep --color=auto'
    #alias fgrep='fgrep --color=auto'
    #alias egrep='egrep --color=auto'
fi

# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# some more ls aliases
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'
alias sudo="sudo "
alias ls="ls -lah --color=auto"
alias treeall="tree -ugsh --du"

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

##-----------------------------------------------------
## synth-shell-prompt.sh
if [ -f /home/$USER/.config/shell-prompt.sh ] && [ -n "$( echo $- | grep i )" ]; then
	source /home/$USER/.config/shell-prompt.sh
	else
	wget https://gist.darto.id/dartokloning/def50cb1b3024c3b8683960c873caf34/download/HEAD/shell-prompt.sh -P /home/$USER/.config
	source /home/$USER/.config/shell-prompt.sh
fi

if [ -f /usr/bin/vivid ]; then
#export LS_COLORS="$(vivid generate snazzy)"

##---------------------------------------------------------
## change LS_COLORS with random theme generated by vivid
##---------------------------------------------------------

# Define the list of items
themes=("alabaster_dark" "ayu" "catppuccin-frappe" "catppuccin-latte" "dracula" "iceberg-dark" "jellybeans" "lava" "molokai" "nord" "one-dark" "one-light" "rose-pine" "rose-pine-dawn" "snazzy" "solarized-dark" "tokyonight-moon" "zenburn")

# Get the current date in YYYYMMDD format
current_date=$(date +%Y%m%d)

# Use the date as a seed for the random number generator
RANDOM=$current_date

# Get a random index based on the number of items
random_index=$((RANDOM % ${#themes[@]}))
theme_now=${themes[$random_index]}

export LS_COLORS="$(vivid generate $theme_now)"

else

wget https://github.com/sharkdp/vivid/releases/download/v0.10.1/vivid_0.10.1_amd64.deb
sudo dpkg -i vivid_0.10.1_amd64.deb
rm vivid_0.10.1_amd64.deb
source /home/$USER/.bashrc

fi

if command -v neowofetch >/dev/null 2>&1; then
    # echo "Command exists"
    neowofetch
else
    # echo "Command not found"
    mkdir -p /home/$USER/.config/neowofetch
    wget -P /home/$USER/.config/neowofetch https://gist.darto.id/dartokloning/3282d7ef65f549d6a893501d509cfbeb/download/HEAD/config.conf
    sudo apt install -y neowofetch
fi
