From fb6becb80829e3c6321937c77018247b7feaf113 Mon Sep 17 00:00:00 2001 From: Kamontat Chantrachirathumrong Date: Wed, 25 Sep 2019 12:37:57 +0700 Subject: [PATCH] [release] version: 4.0.1 --- src/alias/mac.sh | 4 +- src/app/go.sh | 2 +- src/settings/zsh.sh | 195 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 195 insertions(+), 6 deletions(-) diff --git a/src/alias/mac.sh b/src/alias/mac.sh index 410fabb..4ad8551 100644 --- a/src/alias/mac.sh +++ b/src/alias/mac.sh @@ -10,10 +10,10 @@ if [ "$(uname -s)" = "Darwin" ] && __myzs_is_command_exist "osascript"; then clipboard="$(pbpaste)" # check is input is path - if is_string_exist "$1" && is_folder_exist "$1"; then + if __myzs_is_string_exist "$1" && __myzs_is_folder_exist "$1"; then echo "$1" | pbcopy # check is clipboard is path - elif ! is_folder_exist "$clipboard"; then + elif ! __myzs_is_folder_exist "$clipboard"; then pwd | pbcopy fi diff --git a/src/app/go.sh b/src/app/go.sh index b6dd55c..723fb6c 100644 --- a/src/app/go.sh +++ b/src/app/go.sh @@ -7,7 +7,7 @@ fi export GOPATH="${__GOPATH:-$HOME/Desktop/Personal/go}" if __myzs_is_command_exist "go"; then - __myzs_push_path "$GOPATH/bin" + __myzs_append_path "$GOPATH/bin" __myzs_fpath "$GOPATH/src/github.com/urfave/cli/autocomplete/zsh_autocomplete" fi diff --git a/src/settings/zsh.sh b/src/settings/zsh.sh index db3ef40..bcfc759 100644 --- a/src/settings/zsh.sh +++ b/src/settings/zsh.sh @@ -4,7 +4,196 @@ if [[ "$MYZS_DEBUG" == "true" ]]; then set -x # enable DEBUG MODE fi -unsetopt correct_all -unsetopt correct +emulate -L zsh +unsetopt CORRECT_ALL +unsetopt CORRECT -zstyle :prezto:load pmodule +# typeset -gU cdpath fpath mailpath path + +# zstyle :prezto:load pmodule + +export LESS='-F -g -i -M -R -S -w -X -z-4' + +# Set the Less input preprocessor. +# Try both `lesspipe` and `lesspipe.sh` as either might exist on a system. +if (( $#commands[(i)lesspipe(|.sh)] )); then + export LESSOPEN="| /usr/bin/env $commands[(i)lesspipe(|.sh)] %s 2>&-" +fi + +# +# History +# + +setopt BANG_HIST # Treat the '!' character specially during expansion. +setopt EXTENDED_HISTORY # Write the history file in the ':start:elapsed;command' format. +setopt SHARE_HISTORY # Share history between all sessions. +setopt HIST_EXPIRE_DUPS_FIRST # Expire a duplicate event first when trimming history. +setopt HIST_IGNORE_DUPS # Do not record an event that was just recorded again. +setopt HIST_IGNORE_ALL_DUPS # Delete an old recorded event if a new event is a duplicate. +setopt HIST_FIND_NO_DUPS # Do not display a previously found event. +setopt HIST_IGNORE_SPACE # Do not record an event starting with a space. +setopt HIST_SAVE_NO_DUPS # Do not write a duplicate event to the history file. +setopt HIST_VERIFY # Do not execute immediately upon history expansion. +setopt HIST_BEEP # Beep when accessing non-existent history. + +# +# Variables +# + +HISTFILE="${HISTFILE:-${ZDOTDIR:-$HOME}/.zhistory}" # The path to the history file. +HISTSIZE=10000 # The maximum number of events to save in the internal history. +SAVEHIST=10000 # The maximum number of events to save in the history file. + +# +# Aliases +# + +# Lists the ten most used commands. +alias history-stat="history 0 | awk '{print \$2}' | sort | uniq -c | sort -n -r | head" + +# +# Sets directory options and defines directory aliases. +# + +setopt AUTO_CD # Auto changes to a directory without typing cd. +setopt AUTO_PUSHD # Push the old directory onto the stack on cd. +setopt PUSHD_IGNORE_DUPS # Do not store duplicates in the stack. +setopt PUSHD_SILENT # Do not print the directory stack after pushd or popd. +setopt PUSHD_TO_HOME # Push to home directory when no argument is given. +setopt CDABLE_VARS # Change directory to a path stored in a variable. +setopt MULTIOS # Write to multiple descriptors. +setopt EXTENDED_GLOB # Use extended globbing syntax. +unsetopt CLOBBER # Do not overwrite existing files with > and >>. + # Use >! and >>! to bypass. + +autoload -Uz bracketed-paste-url-magic +zle -N bracketed-paste bracketed-paste-url-magic + +setopt COMBINING_CHARS # Combine zero-length punctuation characters (accents) + # with the base character. +setopt INTERACTIVE_COMMENTS # Enable comments in interactive shell. +setopt RC_QUOTES # Allow 'Henry''s Garage' instead of 'Henry'\''s Garage'. +unsetopt MAIL_WARNING # Don't print a warning message if a mail file has been accessed. + +setopt LONG_LIST_JOBS # List jobs in the long format by default. +setopt AUTO_RESUME # Attempt to resume existing job before creating a new process. +setopt NOTIFY # Report status of background jobs immediately. +unsetopt BG_NICE # Don't run all background jobs at a lower priority. +unsetopt HUP # Don't kill jobs on shell exit. +unsetopt CHECK_JOBS # Don't report on jobs when shell exit. + +# +# Completion +# + +setopt COMPLETE_IN_WORD # Complete from both ends of a word. +setopt ALWAYS_TO_END # Move cursor to the end of a completed word. +setopt PATH_DIRS # Perform path search even on command names with slashes. +setopt AUTO_MENU # Show completion menu on a successive tab press. +setopt AUTO_LIST # Automatically list choices on ambiguous completion. +setopt AUTO_PARAM_SLASH # If completed parameter is a directory, add a trailing slash. +setopt EXTENDED_GLOB # Needed for file modification glob modifiers with compinit +unsetopt MENU_COMPLETE # Do not autoselect the first completion entry. +unsetopt FLOW_CONTROL # Disable start/stop characters in shell editor. + +# Load and initialize the completion system ignoring insecure directories with a +# cache time of 20 hours, so it should almost always regenerate the first time a +# shell is opened each day. +autoload -Uz compinit +_comp_files=(${ZDOTDIR:-$HOME}/.zcompdump(Nm-20)) +if (( $#_comp_files )); then + compinit -i -C +else + compinit -i +fi +unset _comp_files + +# Use caching to make completion for commands such as dpkg and apt usable. +zstyle ':completion::complete:*' use-cache on +zstyle ':completion::complete:*' cache-path "${ZDOTDIR:-$HOME}/.zcompcache" + +# Case-insensitive (all), partial-word, and then substring completion. +zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' +unsetopt CASE_GLOB + +# Group matches and describe. +zstyle ':completion:*:*:*:*:*' menu select +zstyle ':completion:*:matches' group 'yes' +zstyle ':completion:*:options' description 'yes' +zstyle ':completion:*:options' auto-description '%d' +zstyle ':completion:*:corrections' format ' %F{green}-- %d (errors: %e) --%f' +zstyle ':completion:*:descriptions' format ' %F{yellow}-- %d --%f' +zstyle ':completion:*:messages' format ' %F{purple} -- %d --%f' +zstyle ':completion:*:warnings' format ' %F{red}-- no matches found --%f' +zstyle ':completion:*:default' list-prompt '%S%M matches%s' +zstyle ':completion:*' format ' %F{yellow}-- %d --%f' +zstyle ':completion:*' group-name '' +zstyle ':completion:*' verbose yes + +# Fuzzy match mistyped completions. +zstyle ':completion:*' completer _complete _match _approximate +zstyle ':completion:*:match:*' original only +zstyle ':completion:*:approximate:*' max-errors 1 numeric + +# Increase the number of errors based on the length of the typed word. But make +# sure to cap (at 7) the max-errors to avoid hanging. +zstyle -e ':completion:*:approximate:*' max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3>7?7:($#PREFIX+$#SUFFIX)/3))numeric)' + +# Don't complete unavailable commands. +zstyle ':completion:*:functions' ignored-patterns '(_*|pre(cmd|exec))' + +# Array completion element sorting. +zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters + +# Directories +zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} +zstyle ':completion:*:*:cd:*' tag-order local-directories directory-stack path-directories +zstyle ':completion:*:*:cd:*:directory-stack' menu yes select +zstyle ':completion:*:-tilde-:*' group-order 'named-directories' 'path-directories' 'users' 'expand' +zstyle ':completion:*' squeeze-slashes true + +# History +zstyle ':completion:*:history-words' stop yes +zstyle ':completion:*:history-words' remove-all-dups yes +zstyle ':completion:*:history-words' list false +zstyle ':completion:*:history-words' menu yes + +# Environment Variables +zstyle ':completion::*:(-command-|export):*' fake-parameters ${${${_comps[(I)-value-*]#*,}%%,*}:#-*-} + +zstyle -e ':completion:*:hosts' hosts 'reply=( + ${=${=${=${${(f)"$(cat {/etc/ssh/ssh_,~/.ssh/}known_hosts(|2)(N) 2> /dev/null)"}%%[#| ]*}//\]:[0-9]*/ }//,/ }//\[/ } + ${=${(f)"$(cat /etc/hosts(|)(N) <<(ypcat hosts 2> /dev/null))"}%%(\#${_etc_host_ignores:+|${(j:|:)~_etc_host_ignores}})*} + ${=${${${${(@M)${(f)"$(cat ~/.ssh/config 2> /dev/null)"}:#Host *}#Host }:#*\**}:#*\?*}} +)' + +# Don't complete uninteresting users... +zstyle ':completion:*:*:*:users' ignored-patterns \ + adm amanda apache avahi beaglidx bin cacti canna clamav daemon \ + dbus distcache dovecot fax ftp games gdm gkrellmd gopher \ + hacluster haldaemon halt hsqldb ident junkbust ldap lp mail \ + mailman mailnull mldonkey mysql nagios \ + named netdump news nfsnobody nobody nscd ntp nut nx openvpn \ + operator pcap postfix postgres privoxy pulse pvm quagga radvd \ + rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs '_*' + +zstyle '*' single-ignored show + +# Ignore multiple entries. +zstyle ':completion:*:(rm|kill|diff):*' ignore-line other +zstyle ':completion:*:rm:*' file-patterns '*:all-files' + +# Kill +zstyle ':completion:*:*:*:*:processes' command 'ps -u $LOGNAME -o pid,user,command -w' +zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;36=0=01' +zstyle ':completion:*:*:kill:*' menu yes select +zstyle ':completion:*:*:kill:*' force-list always +zstyle ':completion:*:*:kill:*' insert-ids single + +# SSH/SCP/RSYNC +zstyle ':completion:*:(ssh|scp|rsync):*' tag-order 'hosts:-host:host hosts:-domain:domain hosts:-ipaddr:ip\ address *' +zstyle ':completion:*:(scp|rsync):*' group-order users files all-files hosts-domain hosts-host hosts-ipaddr +zstyle ':completion:*:ssh:*' group-order users hosts-domain hosts-host users hosts-ipaddr +zstyle ':completion:*:(ssh|scp|rsync):*:hosts-host' ignored-patterns '*(.|:)*' loopback ip6-loopback localhost ip6-localhost broadcasthost +zstyle ':completion:*:(ssh|scp|rsync):*:hosts-domain' ignored-patterns '<->.<->.<->.<->' '^[-[:alnum:]]##(.[-[:alnum:]]##)##' '*@*' +zstyle ':completion:*:(ssh|scp|rsync):*:hosts-ipaddr' ignored-patterns '^(<->.<->.<->.<->|(|::)([[:xdigit:].]##:(#c,2))##(|%*))' '127.0.0.<->' '255.255.255.255' '::1' 'fe80::*'