Skip to content

Commit

Permalink
[feature] Add more features
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamontat Chantrachirathumrong committed Sep 3, 2018
1 parent 2a01765 commit 8c848a5
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 109 deletions.
129 changes: 37 additions & 92 deletions .zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,36 @@ source "${MYZS_LIB}/progress.sh"
pg_start
source "${MYZS_LIB}/lazyload.sh"

pg_mark "Load require libraries"
pg_mark "Fetches required 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 "Setup alias"
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 "Setup libraries"
source "${MYZS_SRC}/default.library.sh" || pg_mark_false "Loading default library"

pg_mark "Setup completions"
source "${MYZS_SRC}/default.completion.sh" || pg_mark_false "Loading default completion"

pg_mark "Setup work location"
source "${MYZS_SRC}/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}/zgen.zsh"
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 'emacs'
zgen prezto prompt theme 'steeef'
zgen prezto editor key-bindings 'vi'
zgen prezto editor 'dot-expansion' 'yes'

# zgen prezto prompt theme 'spaceship'

zgen prezto autosuggestions color 'yes'
zgen prezto 'autosuggestions:color' found 'fg=8'

# 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'

zgen prezto 'syntax-highlighting' color 'yes'
zgen prezto 'syntax-highlighting' highlighters 'main' 'brackets' 'pattern' 'line' 'cursor' 'root'

zgen prezto

Expand All @@ -65,6 +67,8 @@ 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
Expand All @@ -75,85 +79,26 @@ else
pg_mark_false "Zgen not found"
fi

pg_stop

# SECONDS=0

# export MYZS_ROOT="${HOME}/.myzs"
# export MYZS_SRC="${HOME}/.myzs/src"

# export MYZS_GLOBAL="${MYZS_ROOT}/global"
pg_mark "Customize zgen plugin"
source "${MYZS_SRC}/custom.zgen.plugin.zsh"

# export MYZS_SETTING="${MYZS_GLOBAL}/settings"
# export MYZS_LIB="${MYZS_GLOBAL}/lib"

# export MYZS_CUSTOM="${MYZS_ROOT}/custom.lib"

# export MYZS_TEMP_FOLDER="/tmp/myzs"
# mkdir $MYZS_TEMP_FOLDER &>/dev/null

# _myzs_is_integer() {
# [[ $1 =~ ^[0-9]+$ ]] 2>/dev/null && return 0 || return 1
# }

# throw() {
# printf '%s\n' "$1" >&2 && _myzs_is_integer "$2" && return "$2"
# return 0
# }

# _myzs__load() {
# local file="$1" # temp

# ! [ -f "$file" ] && _myzs_print_error_tofile "status" "file" "${file} NOT EXIST!"

# if source "$file"; then
# _myzs_print_log_tostd "load" "file" "${file}"
# return 0
# else
# _myzs_print_error_tostd "load" "file" "${file} (code=$?)"
# return 1
# fi
# }

# _myzs_loop_load() {
# local exit_code=0
# for f in $1/[0-9]*; do
# _myzs__load "$f" || ((exit_code++))
# done

# return $exit_code
# }

# _myzs_load() {
# local folder="$1"
# ! test -d "$folder" && throw "$folder Not EXIST!" && return 5
# _myzs_loop_load "$folder"
# }

# _myzs_raw_load() {
# local folder="$1"
# ! test -d "$folder" && echo "CANNOT load $folder" && return 199
# _myzs_loop_load "$folder"
# }

# _myzs_raw_load "$MYZS_LIB"
pg_mark "Setup alias"
source "${MYZS_SRC}/default.alias.sh" || pg_mark_false "Loading default alias"
source "${MYZS_SRC}/custom.alias.sh" || pg_mark_false "Loading custom alias"

# _myzs_print_log_seperate_tostd "setting"
# _myzs_raw_load "$MYZS_SETTING"
pg_mark "Setup libraries"
source "${MYZS_SRC}/default.library.sh" || pg_mark_false "Loading default library"

# _myzs_print_log_seperate_tostd "global"
# _myzs_load "$MYZS_GLOBAL"
pg_mark "Setup completions"
source "${MYZS_SRC}/default.completion.sh" || pg_mark_false "Loading default completion"

# _myzs_print_log_seperate_tostd "custom"
# _myzs_load "$MYZS_CUSTOM"
pg_mark "Setup work location"
source "${MYZS_SRC}/location.sh" || pg_mark_false "Loading location cli"

# _myzs_print_log_seperate_tostd "main"
# _myzs_load "$MYZS_SRC"
pg_mark "Setup prompt theme"
source "${MYZS_SRC}/theme.sh" || pg_mark_false "Loading theme configuration"

# duration=$SECONDS
# min="$((duration / 60))"
# sec="$((duration % 60))"
pg_mark "Customize Zsh setting"
source "${MYZS_SRC}/custom.setting.zsh" || pg_mark_false "Setting zsh setting"

# _myzs_print_log_seperate_tostd
# _myzs_print_log_tostd "status" "time" "$min minutes $sec seconds elapsed"
# _myzs_print_log_tofile "status" "time" "$min minutes $sec seconds elapsed"
pg_stop
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@
1. [prezto](https://github.com/sorin-ionescu/prezto) => Instantly Awesome Zsh
2. [powerlevel9k](https://github.com/bhilburn/powerlevel9k) => A theme for ZSH
3. [zgen](https://github.com/tarjoilija/zgen) => A lightweight plugin manager for Zsh

## Usage

1. Change your config in [constants.sh](./lib/constrants.sh)
2. Change your setting in [variable.sh](./src/custom.variable.sh)
8 changes: 0 additions & 8 deletions lib/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,3 @@
if is_command_exist "git" && ! is_folder_exist "${HOME}/.zgen"; then
git clone "https://github.com/tarjoilija/zgen.git" "${HOME}/.zgen" &>/dev/null
fi

wd_name="${HOME}/.zgen/mfaerevaag/wd-master"
if is_command_exist "git" && ! is_folder_exist "$wd_name"; then
mkdir "$wd_name" &>/dev/null
git clone "https://github.com/mfaerevaag/wd.git" "$wd_name" &>/dev/null

cp "${wd_name}/wd.1" "/usr/share/man/man1/wd.1"
fi
4 changes: 4 additions & 0 deletions src/custom.setting.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# shellcheck disable=SC1090,SC2148

unsetopt correct_all
unsetopt correct
2 changes: 2 additions & 0 deletions src/custom.variable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ export EDITOR='code-insiders'

export KEYTIMEOUT=1

export GOPATH="$HOME/Desktop/Projects/go"

set -o vi
29 changes: 29 additions & 0 deletions src/custom.zgen.plugin.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# shellcheck disable=SC1090,SC2148

wd_name="${HOME}/.zgen/mfaerevaag/wd-master"
if is_command_exist "git" && ! is_folder_exist "$wd_name"; then
mkdir "$wd_name" &>/dev/null
git clone "https://github.com/mfaerevaag/wd.git" "$wd_name" &>/dev/null

cp "${wd_name}/wd.1" "/usr/share/man/man1/wd.1"
fi

# contrib="${HOME}/.zgen/sorin-ionescu/prezto-master/contrib"
# if ! is_folder_exist "$contrib"; then
# git clone https://github.com/belak/prezto-contrib "$contrib"
# cd contrib || exit 1
# git submodule init
# git submodule update
# fi

spaceship_url="https://github.com/denysdovhan/spaceship-prompt.git"
spaceship_location="${HOME}/.zgen/sorin-ionescu/prezto-master/modules/prompt/external/spaceship"

if ! is_folder_exist "$spaceship_location"; then
git clone "$spaceship_url" "$spaceship_location" &>/dev/null
ln -s "${spaceship_location}/spaceship.zsh-theme" ~/.zprezto/modules/prompt/functions/prompt_spaceship_setup
fi

if is_file_exist "${spaceship_location}/spaceship.zsh-theme"; then
prompt spaceship
fi
1 change: 1 addition & 0 deletions src/default.alias.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ fi

if is_command_exist "code" || is_command_exist "code-insiders"; then
alias newcode='code --new-window'
alias ncode='code --new-window'
alias ccode='code --reuse-window'
fi

Expand Down
12 changes: 8 additions & 4 deletions src/default.completion.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# shellcheck disable=SC1090,SC2148

if is_command_exist "kubectl"; then
source <(kubectl completion zsh)
fi

gcloud_path='/usr/local/etc/google-cloud-sdk/path.zsh.inc'
if is_file_exist "$gcloud_path"; then
source "$gcloud_path"
Expand All @@ -14,6 +10,14 @@ if is_file_exist "$gcloud_completion"; then
source "$gcloud_completion"
fi

if is_command_exist "kubectl"; then
source <(kubectl completion zsh)
fi

if is_file_exist "$GO_ZSH_COMPLETE" || is_folder_exist "$GO_ZSH_COMPLETE"; then
fpath=("${fpath[@]}" "$GO_ZSH_COMPLETE")
fi

if is_string_exist "$ZGEN_DIR"; then
fpath=("${fpath[@]}" "$ZGEN_DIR")
fi
4 changes: 1 addition & 3 deletions src/default.variable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ if is_folder_exist "$HOME/Library/Android/sdk"; then
export PATH="$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools" # android path
fi

if is_command_exist "go" && is_folder_exist "$HOME/Documents/go"; then
export GOPATH="$HOME/Documents/go"
if is_command_exist "go"; then
export PATH="$PATH:$GOPATH/bin" # go lang

export GO_ZSH_COMPLETE="$GOPATH/src/github.com/urfave/cli/autocomplete/zsh_autocomplete"
fi

Expand Down
6 changes: 4 additions & 2 deletions src/zgen.zsh → src/default.zgen.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

export ZGEN_FORCE_SAVE=false

export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=246'
export ZGEN_RESET_ON_CHANGE=("${HOME}/.zshrc")

# https://github.com/hlissner/zsh-autopair#zgen--prezto-compatibility
export AUTOPAIR_INHIBIT_INIT=1

export ZGEN_PREZTO_PLUGIN_LIST=(
# "contrib-prompt"
"syntax-highlighting"
"environment"
"gnu-utility"
"autosuggestions"
Expand All @@ -21,6 +22,8 @@ export ZGEN_PREZTO_PLUGIN_LIST=(
"homebrew"
"osx"
"utility"
"completion"
"prompt"
)

export ZGEN_PLUGIN_LIST=(
Expand All @@ -29,7 +32,6 @@ export ZGEN_PLUGIN_LIST=(
"djui/alias-tips"
"supercrabtree/k"
"unixorn/autoupdate-zgen"
"zsh-users/zsh-syntax-highlighting"
"wbingli/zsh-wakatime"
"hlissner/zsh-autopair"
)
49 changes: 49 additions & 0 deletions src/theme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# shellcheck disable=SC1090,SC2148

# init promt theme

SPACESHIP_PROMPT_ORDER=(
time
user
host
hg
package
node
ruby
elixir
xcode
swift
golang
php
rust
julia
docker
aws
venv
conda
pyenv
dotnet
ember
line_sep
dir
git
exec_time
line_sep
battery
exit_code
char
)

SPACESHIP_RPROMPT_ORDER=(
jobs
)

SPACESHIP_PROMPT_FIRST_PREFIX_SHOW=true

SPACESHIP_TIME_SHOW=true
SPACESHIP_TIME_FORMAT="%D{%d-%m-%Y %H.%M.%S}"
SPACESHIP_BATTERY_SHOW=always

SPACESHIP_EXIT_CODE_SHOW=true
SPACESHIP_EXEC_TIME_SHOW=true
SPACESHIP_EXEC_TIME_ELAPSED=1

0 comments on commit 8c848a5

Please sign in to comment.