Skip to content

Commit

Permalink
[release] version: 4.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kamontat committed Aug 10, 2020
1 parent fa41f8d commit ccc5820
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 39 deletions.
59 changes: 29 additions & 30 deletions .zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export MYZS_USER="$USER"
# Copy path you would like to go, the start shell will try to cd to that path automatically
export MYZS_SETTINGS_AUTO_OPEN_PATH=true

# add trigger event to cd command to check .myzs-setup file
export MYZS_SETTINGS_AUTOLOAD_SETUP_LOCAL=false

# start command; this will run after exit init.sh
export MYZS_START_COMMAND=""
# start command arguments
Expand All @@ -32,36 +35,38 @@ export MYZS_TYPE="FULLY"
export MYZS_ROOT="$HOME/.myzs"

export MYZS_LOADING_MODULES=(
"app/android.sh"
"app/docker.sh"
# "app/fzf.sh"
"app/history.sh"
"app/kube.sh"
"app/myzs.sh"
"app/tmux.sh"
"app/wireshark.sh"
"app/asdf.sh"
"app/flutter.sh"
"app/go.sh"
"app/iterm.sh"
"app/macgpg.sh"
"app/thefuck.sh"
# "app/android.sh"
# "app/docker.sh"
# "app/fzf.sh"
# "app/history.sh"
# "app/kube.sh"
# "app/tmux.sh"
# "app/wireshark.sh"
# "app/asdf.sh"
# "app/flutter.sh"
# "app/go.sh"
# "app/iterm.sh"
# "app/macgpg.sh"
# "app/thefuck.sh"
# "app/travis.sh"
"app/yarn.sh"
"alias/agoda.sh"
"alias/docker.sh"
"alias/fuck.sh"
# "app/yarn.sh"
"alias/initial.sh"
"alias/myzs.sh"
# "alias/agoda.sh"
# "alias/docker.sh"
# "alias/fuck.sh"
"alias/git.sh"
"alias/mac.sh"
"alias/shell.sh"
"alias/vim.sh"
"alias/coreutils.sh"
# "alias/vim.sh"
# "alias/coreutils.sh"
"alias/editor.sh"
"alias/generator.sh"
"alias/github.sh"
"alias/neofetch.sh"
"alias/short.sh"
"alias/yarn.sh"
# "alias/generator.sh"
# "alias/github.sh"
# "alias/neofetch.sh"
# "alias/short.sh"
# "alias/yarn.sh"
)

################################
Expand Down Expand Up @@ -128,9 +133,3 @@ fi
################################
# Appending by user or scripts #
################################

# The next line updates PATH for the Google Cloud SDK.
if [ -f '/usr/local/bin/google-cloud-sdk/path.zsh.inc' ]; then . '/usr/local/bin/google-cloud-sdk/path.zsh.inc'; fi

# The next line enables shell command completion for gcloud.
if [ -f '/usr/local/bin/google-cloud-sdk/completion.zsh.inc' ]; then . '/usr/local/bin/google-cloud-sdk/completion.zsh.inc'; fi
26 changes: 21 additions & 5 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export __MYZS_ZPLUG="${ZPLUG_HOME:-${__MYZS_ROOT}/zplug}"

export __MYZS_USER="${MYZS_USER:-$USER}"
export __MYZS_OWNER="Kamontat Chantrachirathumrong"
export __MYZS_VERSION="4.6.0"
export __MYZS_VERSION="4.7.0"
export __MYZS_SINCE="21 Apr 2018"
export __MYZS_LAST_UPDATED="11 Aug 2020"
export __MYZS_LAST_UPDATED="10 Aug 2020"
export __MYZS_LICENSE="MIT"
export __MYZS_MODULES=()
export __MYZS_FULLY_MODULES=(
Expand All @@ -29,6 +29,8 @@ export __MYZS_FULLY_MODULES=(
"app/thefuck.sh"
"app/travis.sh"
"app/yarn.sh"
"alias/initial.sh"
"alias/myzs.sh"
"alias/agoda.sh"
"alias/docker.sh"
"alias/fuck.sh"
Expand All @@ -46,7 +48,15 @@ export __MYZS_FULLY_MODULES=(
)

export __MYZS_CHANGELOGS=(
"4.6.0" "11 Aug 2020"
"4.7.0" "10 Aug 2020"
" - reduce start time by loading only important modules
- add myzs-load / mload for load modules after initial finish
- alias all myzs-XXXXX command
- reduce start time from ~7 seconds to ~2 seconds
- add .myzs-setup file to automatic load when it present (configuable)
- manually load .myzs-setup file by run myzs-setup-local command
"
"4.6.0" "10 Aug 2020"
" - change logic to load modules
- remove exclude module variable
- add prefix to modules name
Expand Down Expand Up @@ -151,8 +161,12 @@ for __path in "${MYZS_LOADING_MODULES[@]}"; do
fullpath="${__MYZS_SOURCE_CODE}/${__path}"

# supported components
if [[ "${__MYZS_FULLY_MODULES[*]}" =~ $__path ]]; then
__myzs_load_module "${__path}" "$fullpath" || pg_mark_false "Cannot load $__path"
if __myzs__is_valid_module "$__path"; then
if __myzs_is_fully || [[ $__path =~ "alias" ]]; then
__myzs_load_module "${__path}" "$fullpath" || pg_mark_false "Cannot load $__path"
else
pg_mark_false "non-alias modules cannot autoload in TYPE=$__MYZS_TYPE"
fi
else
pg_mark_false "'$__path' not found in FULLY_COMPONENTS"
fi
Expand Down Expand Up @@ -208,4 +222,6 @@ if __myzs_is_fully; then
fi
fi

$MYZS_SETTINGS_AUTOLOAD_SETUP_LOCAL && myzs-setup-local

__myzs_cleanup
10 changes: 10 additions & 0 deletions src/alias/initial.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# shellcheck disable=SC1090,SC2148

__myzs_initial "$0"

if $MYZS_SETTINGS_AUTOLOAD_SETUP_LOCAL; then
cd_function() {
cd "$1" && myzs-setup-local
}
__myzs_alias_force "cd" "cd_function"
fi
12 changes: 12 additions & 0 deletions src/alias/myzs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# shellcheck disable=SC1090,SC2148

__myzs_initial "$0"

__myzs_alias "mupload" "myzs-upload"
__myzs_alias "mdownload" "myzs-download"

__myzs_alias "mlc" "myzs-list-changelogs"
__myzs_alias "mlm" "myzs-list-modules"

__myzs_alias "mload" "myzs-load"
__myzs_alias "mlocal" "myzs-setup-local"
29 changes: 28 additions & 1 deletion src/app/myzs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ myzs-list-modules() {
echo "# Modules"
echo

test -z "${__MYZS_MODULES[*]}" && echo "Cannot find any modules exist" && exit 2
! __myzs_is_string_exist "${__MYZS_MODULES[*]}" && echo "Cannot find any modules exist" && exit 2

local mod reg1 reg2 reg3 filename filepath filestatus raw raw1

Expand Down Expand Up @@ -96,3 +96,30 @@ myzs-list-modules() {
echo
printf 'Total %s modules\n' "${#__MYZS_MODULES[@]}"
}

# load modules
# param $1 - module name in src only
# $2 - string as 'debug' to print debug information
myzs-load() {
__myzs_initial "app/myzs.sh#myzs-load"

local name="$1" # fully_modules format
local debug="$2"

fullpath="${__MYZS_SOURCE_CODE}/${name}"

__myzs_is_string_exist "$debug" && echo "input name: $name"
__myzs_is_string_exist "$debug" && echo "input path: $fullpath"

if __myzs_load_module "$name" "$fullpath"; then
__myzs_is_string_exist "$debug" && echo "loaded"
fi
}

# run myzs load set file: $PWD/.myzs-setup
myzs-setup-local() {
__myzs_initial "app/myzs.sh#myzs-setup-local"

local fullpath="$PWD/.myzs-setup"
__myzs_load "local-setup" "$fullpath"
}
84 changes: 81 additions & 3 deletions src/utils/helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ __myzs_is_folder_exist() {
export __myzs_is_string_exist
__myzs_is_string_exist() {
if test -n "$1"; then
__myzs_debug "Checking string '$1': EXIST"
__myzs_debug "Checking string '${1:0:10}': EXIST"
return 0
else
__myzs_warn "Checking string '$1': EMPTY"
Expand Down Expand Up @@ -191,6 +191,11 @@ __myzs_is_mac() {
fi
}

export __myzs__remove_array_index
__myzs__remove_array_index() {
eval "$1=( \"\${$1[@]:0:$2}\" \"\${$1[@]:$(($2 + 1))}\" )"
}

# $1 => readable file name
# $2 => file path
export __myzs_load
Expand All @@ -201,13 +206,13 @@ __myzs_load() {
exitcode=$?
if [[ "$exitcode" != "0" ]]; then
__myzs_error "Cannot load ${_name} (${_path}) because source return $exitcode"
return 1
__myzs_failure
fi

__myzs_info "Loaded ${_name} (${_path}) to the system"
else
__myzs_warn "Cannot load ${_name} (${_path}) because file is missing"
return 1
__myzs_failure
fi
}

Expand All @@ -219,6 +224,14 @@ __myzs_load_module() {
export __MYZS__CURRENT_FILEPATH="$2"
export __MYZS__CURRENT_STATUS="unknown"

local index

index="$(__myzs__get_module_index "$__MYZS__CURRENT_FILENAME" "0")"
if [[ "${index}" != "-1" ]]; then
__myzs_info "load exist module $__MYZS__CURRENT_FILENAME at $index"
__myzs__remove_array_index "__MYZS_MODULES" "${index}"
fi

if __myzs_load "$__MYZS__CURRENT_FILENAME" "$__MYZS__CURRENT_FILEPATH"; then
__MYZS__CURRENT_STATUS="pass"
__MYZS_MODULES+=("{1{${__MYZS__CURRENT_FILENAME}}}{2{${__MYZS__CURRENT_FILEPATH}}}{3{$__MYZS__CURRENT_STATUS}}")
Expand Down Expand Up @@ -340,3 +353,68 @@ __myzs_is_plugin_installed() {
return 1
fi
}

export __myzs__is_valid_module
__myzs__is_valid_module() {
local input="$1"

! __myzs_is_string_exist "${input}" && echo "Cannot found input string" && __myzs_failure "2"
! __myzs_is_string_exist "${__MYZS_FULLY_MODULES[*]}" && echo "Cannot find any modules exist" && __myzs_failure "2"

if [[ "${__MYZS_FULLY_MODULES[*]}" =~ $input ]]; then
__myzs_complete
else
__myzs_failure
fi
}

export __myzs__get_module_index
__myzs__get_module_index() {
local input="$1"
local starter_index="${2:-1}"

! __myzs_is_string_exist "${input}" && __myzs_failure "2"
! __myzs_is_string_exist "${__MYZS_MODULES[*]}" && __myzs_failure "2"

local mod reg index result raw raw1

reg="\{3\{(pass|fail|skip)\}\}"

index="$starter_index"
for mod in "${__MYZS_MODULES[@]}"; do
if [[ $mod =~ $input ]]; then
result="$index"
echo "$result"
break
fi
((index++))
done

! __myzs_is_string_exist "$result" &&
echo "-1" &&
__myzs_failure "3"
}

export __myzs__get_module_status
__myzs__get_module_status() {
local input="$1"

! __myzs_is_string_exist "${input}" && __myzs_failure "2"
! __myzs_is_string_exist "${__MYZS_MODULES[*]}" && __myzs_failure "2"

local mod reg index result raw raw1

reg="\{3\{(pass|fail|skip)\}\}"

index="$(__myzs__get_module_index "$input")"
mod="${__MYZS_MODULES[$index]}"
if [[ $mod =~ $input ]]; then
raw="$(echo "$mod" | grep -Eoi "${reg}")"
raw1="${raw//\{3\{/}"
result="${raw1//\}\}/}"

echo "$result"
else
__myzs_failure "3"
fi
}

0 comments on commit ccc5820

Please sign in to comment.