Skip to content

Commit

Permalink
[refactor] Update files and some folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamontat Chantrachirathumrong committed Sep 5, 2018
1 parent bf314cb commit 060a49b
Show file tree
Hide file tree
Showing 20 changed files with 270 additions and 169 deletions.
99 changes: 53 additions & 46 deletions .zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,52 @@ ROOT="${HOME}/.zshrc"
ROOT="$(dirname "$ROOT")"

export MYZS_ROOT="$ROOT"
export MYZS_CON="${MYZS_ROOT}/const"
export MYZS_LIB="${MYZS_ROOT}/lib"
export MYZS_SRC="${MYZS_ROOT}/src"

source "${MYZS_LIB}/constrants.sh"
source "${MYZS_LIB}/helper.sh"
export MYZS_DEFAULT="${MYZS_SRC}/default"
export MYZS_PERSONAL="${MYZS_SRC}/personal"

source "${MYZS_SRC}/default.variable.sh"
# progress libraries
source "${MYZS_LIB}/progress.sh"

pg_start
source "${MYZS_LIB}/lazyload.sh"
source "${MYZS_CON}/default.sh"

pg_mark "Fetches required library"
pg_mark "Libraries" "Load helper method"
source "${MYZS_LIB}/helper.sh" || pg_mark_false "Loading helper file"
source "${MYZS_LIB}/lazyload.sh" || pg_mark_false "Loading lazyload library"
source "${MYZS_LIB}/setup.sh" || pg_mark_false "Loading setup file"

pg_mark "Setup variables"
source "${MYZS_SRC}/custom.variable.sh" || pg_mark_false "Setting custom variable"
pg_mark "Libraries" "Load work CLI"
source "${MYZS_LIB}/location.sh" || pg_mark_false "Loading location cli"

pg_mark "Setup zgen"
if is_string_exist "$ZGEN_HOME" && is_file_exist "${ZGEN_HOME}/zgen.zsh"; then
source "${MYZS_SRC}/default.zgen.plugin.zsh"
source "${ZGEN_HOME}/zgen.zsh"

if ! zgen saved || $ZGEN_FORCE_SAVE; then
# prezto options
zgen prezto editor key-bindings 'vi'
zgen prezto editor 'dot-expansion' 'yes'
pg_mark "Default" "Setup Zsh var"
source "${MYZS_DEFAULT}/variable.sh" || pg_mark_false "Loading default variable"

# zgen prezto prompt theme 'spaceship'
pg_mark "Personal" "Setup Zsh var"
source "${MYZS_PERSONAL}/variable.sh" || pg_mark_false "Loading personal variable"

zgen prezto autosuggestions color 'yes'
zgen prezto 'autosuggestions:color' found 'fg=8'
pg_mark "Default" "Setup ZGEN setting"
source "${MYZS_DEFAULT}/zgen.setting.sh" || pg_mark_false "Setting custom zgen variable"

# zgen prezto 'tmux:iterm' integrate 'yes'

zgen prezto terminal 'auto-title' 'yes'
zgen prezto 'terminal:window-title' format '%n@%m: %s'
zgen prezto 'terminal:tab-title' format '%m: %s'
zgen prezto 'terminal:multiplexer-title' format '%s'
pg_mark "Default" "Setup ZGEN plugin"
if is_string_exist "$ZGEN_HOME" && is_file_exist "${ZGEN_HOME}/zgen.zsh"; then
source "${MYZS_DEFAULT}/zgen.plugin.sh"
source "${MYZS_DEFAULT}/zgen.prezto-setting.sh"
source "${ZGEN_HOME}/zgen.zsh"

zgen prezto 'syntax-highlighting' color 'yes'
zgen prezto 'syntax-highlighting' highlighters 'main' 'brackets' 'pattern' 'line' 'cursor' 'root'
if ! zgen saved || $ZGEN_FORCE_SAVE; then
setup=()
for setting in "${ZGEN_PREZTO_SETTING_LIST[@]}"; do
if [[ "$setting" == "_END_" ]]; then
zgen prezto "${setup[@]}"
setup=()
else
setup+=("$setting")
fi
done

zgen prezto

Expand All @@ -67,39 +71,42 @@ if is_string_exist "$ZGEN_HOME" && is_file_exist "${ZGEN_HOME}/zgen.zsh"; then
zgen load "$plugin"
done

# zgen load denysdovhan/spaceship-prompt

# generate the init script from plugins above
zgen save
fi

# https://github.com/hlissner/zsh-autopair#zgen--prezto-compatibility
autopair-init
else
pg_mark_false "Zgen not found"
fi

pg_mark "Customize zgen plugin"
source "${MYZS_SRC}/custom.zgen.plugin.zsh"
pg_mark "POST" "Setup ZGEN plugin"
source "${MYZS_DEFAULT}/zgen.plugin-post.sh" || pg_mark_false "Setting (POST) zgen plugin"

pg_mark "Setup alias"
eval "$(thefuck --alias)" # setup thefuck
source "${MYZS_SRC}/default.alias.sh" || pg_mark_false "Loading default alias"
source "${MYZS_SRC}/custom.alias.sh" || pg_mark_false "Loading custom alias"
pg_mark "Default" "Setup Zsh setting"
source "${MYZS_DEFAULT}/setting.sh" || pg_mark_false "Setting Zsh"

pg_mark "Setup libraries"
source "${MYZS_SRC}/default.library.sh" || pg_mark_false "Loading default library"
pg_mark "Default" "Setup alias"
source "${MYZS_DEFAULT}/alias.sh" || pg_mark_false "Loading alias"

pg_mark "Setup completions"
source "${MYZS_SRC}/default.completion.sh" || pg_mark_false "Loading default completion"
pg_mark "Default" "Setup libraries"
source "${MYZS_DEFAULT}/library.sh" || pg_mark_false "Sourcing library"

pg_mark "Setup work location"
source "${MYZS_SRC}/location.sh" || pg_mark_false "Loading location cli"
pg_mark "Default" "Setup completions"
source "${MYZS_DEFAULT}/completion.sh" || pg_mark_false "Loading zsh completion"

pg_mark "Default" "Editor setting"
source "${MYZS_DEFAULT}/editor.sh" || pg_mark_false "Loading editor setting"

pg_mark "Language" "Setup ruby rbenv"
if is_command_exist "rbenv"; then
eval "$(rbenv init -)"
fi

pg_mark "Setup prompt theme"
source "${MYZS_SRC}/theme.sh" || pg_mark_false "Loading theme configuration"
pg_mark "Personal" "Setup prompt theme"
source "${MYZS_PERSONAL}/theme.sh" || pg_mark_false "Loading theme configuration"

pg_mark "Customize Zsh setting"
source "${MYZS_SRC}/custom.setting.zsh" || pg_mark_false "Setting zsh setting"
pg_mark "Personal" "Setup alias"
source "${MYZS_PERSONAL}/alias.sh" || pg_mark_false "Loading custom alias"

pg_stop
7 changes: 5 additions & 2 deletions lib/constrants.sh → const/default.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# shellcheck disable=SC1090,SC2148

export PG_SHOW_PERF_INFO=true
export PG_SHOW_PERF_INFO=false
export PG_FORMAT_TIME=true

export WORK_ROOT="$HOME/Desktop"
Expand All @@ -9,4 +9,7 @@ export WORKSPACE_NAME="Workspaces"
export PROJECT_NAME="Projects"
export LAB_NAME="Labs"

export NOTE_NAME="Notes"
export REFERENCE_NAME="Documents"

export NOTE_NAME="${REFERENCE_NAME}/Notes"
export TODO_NAME="${REFERENCE_NAME}/Todos"
9 changes: 6 additions & 3 deletions lib/helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ export to_work_root
to_work_root() {
local path
path="$(get_work_root "$1")"
if is_folder_exist "$path"; then
if ! is_folder_exist "$path"; then
mkdir -p "$path"
fi

cd "$path" || exit 1

cd "$path" || {
echo "$path" &&
return 1
}
}
8 changes: 4 additions & 4 deletions src/location.sh → lib/location.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ rcd() {

wcd() {
if is_string_exist "$WORKSPACE_NAME"; then
rcd "$WORKSPACE_NAME"
rcd "${WORKSPACE_NAME}/$1"
fi
}

pcd() {
if is_string_exist "$PROJECT_NAME"; then
rcd "$PROJECT_NAME"
rcd "${PROJECT_NAME}/$1"
fi
}

lcd() {
if is_string_exist "$LAB_NAME"; then
rcd "$LAB_NAME"
rcd "${LAB_NAME}/$1"
fi
}

ncd() {
if is_string_exist "$NOTE_NAME"; then
rcd "$NOTE_NAME"
rcd "${NOTE_NAME}/$1"
fi
}
78 changes: 59 additions & 19 deletions lib/progress.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# shellcheck disable=SC1090,SC2148

# Theme setting
export PG_RED="\033[1;31m"
export PG_GREEN="\033[1;32m"
export PG_YELLOW="\033[1;33m"
export PG_RESET="\033[0m"

# Progress setting
export PG_STYLE="shark"

export MESSAGE_LENGTH=35
export PG_PROCESS_COUNT=1

sec() {
Expand All @@ -22,64 +27,99 @@ conv_time() {
printf '%0dm:%0ds:%0dms' $((ms / 60000)) $((ms % 60000/1000)) $((ms % 1000))
}

format_message() {
local title="$1"
shift
local message="$*"
printf "(%-10s) %s" "$title" "$message"
}

_message() {
local color symbol raw_time dur message

color="$1"
symbol="$2"
raw_time="$3"
shift 3

dur="$(conv_time "${raw_time}")"
message="$*"

printf "${color}[%s]${PG_RESET} %-${MESSAGE_LENGTH}s done in ${PG_YELLOW}%s${PG_RESET}." "$symbol" "$message" "$dur"
}

show_message_by() {
if $1; then
completed_message "$2" "$3"
else
failure_message "$2" "$3"
fi
echo
}

completed_message() {
local dur="$1"
shift
local message="$*"

_message "$PG_GREEN" "+" "$dur" "$message"
}

failure_message() {
local dur="$1"
shift
local message="$*"

_message "$PG_RED" "-" "$dur" "$message"
}

export PG_START_TIME
PG_START_TIME="$(sec)"

export PG_PREV_TIME
PG_PREV_TIME="$(sec)"

export PG_PREV_MSG
PG_PREV_MSG="Starting shell"
PG_PREV_MSG=$(format_message "Start" "Initialization")

export PG_PREV_STATE
PG_PREV_STATE=true

pg_start() {
"${MYZS_LIB}/revolver" -s 'dots' start "${PG_GREEN}Booting up shell. Please Wait..."
"${MYZS_LIB}/revolver" -s "$PG_STYLE" start "${PG_GREEN}Initialization shell. Please Wait..."
}

pg_mark() {
TIME=$(($(sec) - PG_PREV_TIME))

"${MYZS_LIB}/revolver" update "${PG_GREEN}$1.."
"${MYZS_LIB}/revolver" -s "$PG_STYLE" update "${PG_GREEN}$2.."

if "$PG_SHOW_PERF_INFO"; then
$PG_PREV_STATE &&
printf "${PG_GREEN}[+]${PG_RESET} %-25s done in ${PG_YELLOW}%s${PG_RESET}." "${PG_PREV_MSG}" "$(conv_time "${TIME}")" ||
printf "${PG_RED}[-]${PG_RESET} %-25s error in ${PG_YELLOW}%s${PG_RESET}." "${PG_PREV_MSG}" "$(conv_time "${TIME}")"
echo
show_message_by "$PG_PREV_STATE" "$TIME" "$PG_PREV_MSG"
fi

PG_PREV_TIME=$(sec)
PG_PREV_MSG=$1
PG_PREV_MSG=$(format_message "$@")
PG_PREV_STATE=true
((PG_PROCESS_COUNT++))
}

pg_mark_false() {
PG_PREV_STATE=false
PG_PREV_MSG=$1
PG_PREV_MSG=$(format_message "Error" "$1")
}

pg_stop() {
TIME=$(($(sec) - PG_PREV_TIME))

if "$PG_SHOW_PERF_INFO"; then
$PG_PREV_STATE &&
printf "${PG_GREEN}[+]${PG_RESET} %-25s done in ${PG_YELLOW}%s${PG_RESET}." "${PG_PREV_MSG}" "$(conv_time "${TIME}")" ||
printf "${PG_RED}[-]${PG_RESET} %-25s error in ${PG_YELLOW}%s${PG_RESET}." "${PG_PREV_MSG}" "$(conv_time "${TIME}")"
echo
show_message_by "$PG_PREV_STATE" "$TIME" "$PG_PREV_MSG"
fi

"${MYZS_LIB}/revolver" stop

TIME=$(($(sec) - PG_START_TIME))

printf "${PG_GREEN}[+]${PG_RESET} %-25s done in ${PG_YELLOW}%s${PG_RESET}." "Initialization ($PG_PROCESS_COUNT tasks)" "$(conv_time "${TIME}")"
printf "${PG_GREEN}[+]${PG_RESET} %-${MESSAGE_LENGTH}s in ${PG_YELLOW}%s${PG_RESET}." "$(format_message "Completed" "Initialization $PG_PROCESS_COUNT tasks")" "$(conv_time "${TIME}")"
echo
}

export is_command_exist
is_command_exist() {
command -v "$1" &>/dev/null
}
16 changes: 0 additions & 16 deletions src/custom.variable.sh

This file was deleted.

Loading

0 comments on commit 060a49b

Please sign in to comment.