dgy
/
hexagons
Archived
1
0
Fork 0
This repository has been archived on 2021-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
hexagons/.zshrc

328 lines
9.8 KiB
Bash
Raw Normal View History

# -*- mode: shell-script -*-
# vim:ft=zsh
# Profiling Tools {{{
PROFILE_STARTUP=false
if [[ "$PROFILE_STARTUP" == true ]]; then
zmodload zsh/zprof
# http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html
PS4=$'%D{%M%S%.} %N:%i> '
exec 3>&2 2>$HOME/startlog.$$
setopt xtrace prompt_subst
fi
# }}}
# Install Functions {{{
MODULES_DIR="$HOME/.config/zsh"
UPDATE_INTERVAL=5
function _net_test() {
netflag="/tmp/network_down"
touch $netflag
if [[ -n "$(curl -s --max-time 4 -I http://example.com | grep 200)" ]]; then
command rm $netflag >/dev/null
return 0
elif [[ -a $netflag ]]; then
return 1
elif [[ -z "$(curl -s --max-time 4 -I http://example.com | grep 200)" ]]; then
echo "NO NETWORK"
tput bel
touch $netflag
return 1
else
command rm $netflag >/dev/null
return 0
fi
}
function _update() {
if [[ -z $UPDATE_INTERVAL ]];
then
UPDATE_INTERVAL=30
fi
if [[ ! -a $MODULES_DIR/$1/.updatetime ]];
then
echo 0 > "$MODULES_DIR/$1/.updatetime"
fi
day=$((24 * 60 * 60 ))
gap=$(( $UPDATE_INTERVAL * $day ))
diff="$(( $(date +'%s') - $(cat $MODULES_DIR/$1/.updatetime) ))"
if [[ $diff -gt $gap ]]; then
(
_net_test
if [[ $? -eq 1 ]]; then
return
fi
echo "$2"
builtin cd "$MODULES_DIR/$1/" && git pull --rebase
echo "\n"
)
date +'%s' > "$MODULES_DIR/$1/.updatetime"
fi
}
function _get_clone_url() {
if [[ $1 =~ '^(git@|https)' ]]; then
cloneurl="$1"
if [[ $2 -eq 1 ]]; then
if [[ $1 =~ '.*github.*' ]]; then
cloneurl="https://github.com/$location"
fi
if [[ $1 =~ '.*gitlab.*' ]]; then
cloneurl="https://gitlab.com/$location"
fi
fi
else
cloneurl="git@github.com:$1"
if [[ $2 -eq 1 ]]; then
cloneurl="https://github.com/$1"
fi
fi
}
function _get_clone_dest() {
if [[ $1 =~ '^(git@|https)' ]]; then
tillcolon=("${(@s/:/)1}")
if [[ $tillcolon[1] = 'https' ]]; then
atslashes=("${(@s#/#)tillcolon}")
location="$atslashes[-2]/$atslashes[-1]"
else
location="$tillcolon[-1]"
fi
else
location=$1
fi
}
function source_or_install() {
_get_clone_dest "$2"
if [[ $HTTPS_CLONE -eq 1 ]]; then
_get_clone_url "$2" 1
else
_get_clone_url "$2"
fi
if [[ ! -d "$MODULES_DIR" ]]; then
mkdir -p "$MODULES_DIR"
fi
if [[ -a $1 ]] then;
source $1
else
_net_test
if [[ $? -eq 1 ]]; then
echo "oops"
return
fi
git clone --depth 3 "$cloneurl" "$MODULES_DIR/$location"
find $MODULES_DIR -type d -delete 2>/dev/null
if [[ ! -d $MODULES_DIR/$location ]]; then
echo "nothing cloned"
export HTTPS_CLONE=1
fi
date +'%s' > "$MODULES_DIR/$location/.updatetime"
echo "\n"
fi
_update $location
unset location
unset cloneurl
}
function force_updates() {
(
builtin cd $MODULES_DIR
find ./ -type f -name '.updatetime' -delete
source $HOME/.zshrc
)
}
2018-07-21 04:46:57 +00:00
# }}}
# Set Options For General Runtime {{{
source $MODULES_DIR/dotfiles.zsh
2018-07-04 19:27:13 +00:00
# Load the prompt system and completion system and initilize them
autoload -Uz compinit promptinit
# 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
promptinit
# Load colors
autoload -U colors && colors
# Use case-insensitve globbing.
unsetopt CASE_GLOB
# glob dotfiles as well
setopt GLOBDOTS
# Automatically change directory if a directory is entered
setopt autocd
setopt extendedglob
# Smart URLs
autoload -Uz url-quote-magic
zle -N self-insert url-quote-magic
# General
# Allow brace character class list expansion.
setopt BRACE_CCL
# Combine zero-length punctuation characters (accents) with the base character.
setopt COMBINING_CHARS
# Allow 'Henry''s Garage' instead of 'Henry'\''s Garage'.
setopt RC_QUOTES
# Jobs
# List jobs in the long format by default.
setopt LONG_LIST_JOBS
# Attempt to resume existing job before creating a new process.
setopt AUTO_RESUME
# Report status of background jobs immediately.
setopt NOTIFY
# Don't run all background jobs at a lower priority.
unsetopt BG_NICE
# Don't kill jobs on shell exit.
unsetopt HUP
# Don't report on jobs when shell exit.
unsetopt CHECK_JOBS
setopt rm_star_wait
setopt list_types
# turn on corrections
setopt correct
# Disable some shell keyboard shortcuts
stty -ixon > /dev/null 2>/dev/null
# }}}
# Completion {{{
# Complete from both ends of a word.
setopt COMPLETE_IN_WORD
# Move cursor to the end of a completed word.
setopt ALWAYS_TO_END
# Perform path search even on command names with slashes.
setopt PATH_DIRS
# Show completion menu on a successive tab press.
setopt AUTO_MENU
# Automatically list choices on ambiguous completion.
setopt AUTO_LIST
# If completed parameter is a directory, add a trailing slash.
setopt AUTO_PARAM_SLASH
setopt NO_COMPLETE_ALIASES
# Do not autoselect the first completion entry.
setopt MENU_COMPLETE
# Disable start/stop characters in shell editor.
unsetopt FLOW_CONTROL
setopt MARK_DIRS
2018-07-04 19:27:13 +00:00
zstyle ':completion:*' menu select=1
zstyle ':completion:*:matches' group 'yes'
zstyle ':completion:*:options' description 'yes'
zstyle ':completion:*:options' auto-description '%d'
zstyle ':completion:*:corrections' format $'\n %F{green}--- %d (errors: %e) ---%f'
zstyle ':completion:*:descriptions' format $'\n %F{yellow}--- %d ---%f'
zstyle ':completion:*:messages' format $'\n %F{purple}--- %d ---%f'
zstyle ':completion:*:warnings' format $'\n %F{red}-- No Matches Found --%f'
zstyle ':completion:*:default' list-prompt '%S%M matches%s'
zstyle ':completion:*:default' select-prompt ' --- Match %M %P ---'
zstyle ':completion:*' format $'\n %F{yellow}--- %d ---%f'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' verbose yes
zstyle ':completion::complete:*' use-cache on
zstyle ':completion::complete:*' cache-path "$HOME/.zcompcache"
zstyle ':completion:*' list-colors $LS_COLORS
2018-07-04 19:27:13 +00:00
zstyle ':completion:*:processes' command 'ps -au $USER -o pid,stat,%cpu,%mem,cputime,command'
zstyle ':completion:*:killall:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
zstyle ':completion:*:processes-names' command 'ps c -u ${USER} -o command | uniq'
zstyle ':completion:*:manuals' separate-sections true
zstyle ':completion:*:manuals.(^1*)' insert-sections true
zstyle ':completion:*:man:*' menu yes select
zstyle ':completion:*:parameters' list-colors '=*=34'
zstyle ':completion:*:commands' list-colors '=*=32'
2018-07-04 19:27:13 +00:00
zstyle ':completion:*:builtins' list-colors '=*=1;38;5;142'
zstyle ':completion:*:aliases' list-colors '=*=2;38;5;120'
zstyle ':completion:*:options' list-colors '=^(-- *)=34'
zstyle ':completion:*' list-separator "--"
2018-08-23 19:00:30 +00:00
zstyle ':completion:*:default' list-colors '=(#b)*(-- *)=36=33' '=*=36'
zstyle ':completion::*:kill:*:*' command 'ps xf -U $USER -o pid,%cpu,cmd'
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
zstyle ':completion:*:functions' ignored-patterns '(_*|pre(cmd|exec))'
zstyle ':completion:*' rehash true
# }}}
# History {{{
export HISTIGNORE="ls:cd:cd -:pwd:exit:date:* --help"
HISTFILE="$MODULES_DIR/histfile"
HISTSIZE=1000
SAVEHIST=1000
setopt appendhistory notify
unsetopt beep extendedglob nomatch
# Treat the '!' character specially during expansion.
setopt BANG_HIST
# Write to the history file immediately, not when the shell exits.
setopt INC_APPEND_HISTORY
# Share history between all sessions.
setopt SHARE_HISTORY
# Expire a duplicate event first when trimming history.
setopt HIST_EXPIRE_DUPS_FIRST
# Do not record an event that was just recorded again.
setopt HIST_IGNORE_DUPS
# Delete an old recorded event if a new event is a duplicate.
setopt HIST_IGNORE_ALL_DUPS
# Do not display a previously found event.
setopt HIST_FIND_NO_DUPS
# Do not record an event starting with a space.
setopt HIST_IGNORE_SPACE
# Do not write a duplicate event to the history file.
setopt HIST_SAVE_NO_DUPS
# Do not execute immediately upon history expansion.
setopt HIST_VERIFY
# Show timestamp in history
setopt EXTENDED_HISTORY
# }}}
# All Other Packages {{{
source_or_install "$MODULES_DIR/agkozak/agkozak-zsh-prompt/agkozak-zsh-prompt.plugin.zsh" agkozak/agkozak-zsh-prompt
AGKOZAK_BLANK_LINES=1
AGKOZAK_CUSTOM_SYMBOLS=( '⇣⇡' '⇣' '⇡' '+' 'x' '!' '>' '?' )
AGKOZAK_CUSTOM_PROMPT='%(?..%B%F{red}(%?%)%f%b )'
AGKOZAK_CUSTOM_PROMPT+=$'%B%F{blue}%2v%f%b '
AGKOZAK_CUSTOM_PROMPT+='%F{green}%(4V.:.%(!.%#.$))%f '
AGKOZAK_PROMPT_DIRTRIM=0
source /usr/share/zsh/plugins/zsh-autopair/autopair.zsh
source /usr/share/LS_COLORS/dircolors.sh
source $MODULES_DIR/up.plugin.zsh
2019-04-14 15:53:12 +00:00
source $MODULES_DIR/k.sh
source_or_install "$MODULES_DIR/zsh-users/zsh-completions/zsh-completions.plugin.zsh" zsh-users/zsh-completions
if [[ -d /usr/share/fzf ]]; then
source /usr/share/fzf/key-bindings.zsh
source /usr/share/fzf/completion.zsh
fi
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source /usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh
source $MODULES_DIR/keys.zsh
source $MODULES_DIR/extras.zsh
source $MODULES_DIR/fzf.zsh
source $MODULES_DIR/transmission.zsh
source $MODULES_DIR/aliases.plugin.zsh
source $MODULES_DIR/omg.zsh
# }}}
# End Profiling Script {{{
if [[ "$PROFILE_STARTUP" == true ]]; then
unsetopt xtrace
exec 2>&3 3>&-
zprof > ~/zshprofile
fi
# }}}
# vim:foldmethod=marker:foldlevel=0