-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzshrc.sym
More file actions
108 lines (79 loc) · 3.06 KB
/
zshrc.sym
File metadata and controls
108 lines (79 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# ZSH Configs (run on login)
## Add to .zshrc: `source <absolute_path_to_zshenv.sym>`
## Find Current Script Directory
CUR_DIR=$(dirname "$0")
# Set Custom Prompt if oh-my-zsh isn't installed (to prevent bad looking prompt)
# --------
which omz 1> /dev/null
if [[ "$?" != "0" ]]; then
# need prompt expansion for running gitstatus
setopt PROMPT_SUBST
# start underline and add pwd
PS1="%U %d"
# add spaces based on width
PS1+="\`printf '%*s' \$(max 1 \$(( \$((\$(tput cols) - 5)) - \$( pwd | wc -m | grep -o '[0-9]\+') - \$(gitstatus | wc -m | grep -o '[0-9]\+') - $(whoami | wc -m | grep -o '[0-9]\+') - $(hostname | wc -m | grep -o '[0-9]\+')))) ''\`"
# add git status and stop underline
PS1+="\`gitstatus\`%u| "
# print user and hostname
PS1+="%n @ %m"$'\n'"|z =>"
export PS1
export PS2="|>"
fi
# Add to PATH
# ------------
## Add Personal Scripts to path
PATH=$PATH:$CUR_DIR/../scripts
## Add For Macports
PATH=$PATH:/opt/local/bin
# from nvm macport install:
if [[ -f /opt/local/share/nvm/init-nvm.sh ]]; then
source /opt/local/share/nvm/init-nvm.sh
fi
# Add Personal Aliases
# -------------------------------------
source $CUR_DIR/lib/alias_fs.zsh
source $CUR_DIR/lib/alias_proc.zsh
source $CUR_DIR/lib/alias_net.zsh
## only include OSX aliases on OSX machines
if [[ "$OSTYPE" == "darwin"* ]]; then
source $CUR_DIR/lib/alias_osx.zsh
fi
# Add Remind Script
# -------------------------------------
source $CUR_DIR/lib/_remind.zsh
# Config ZSH autocomplete to be better
# -----------------------------------
# Highlight the current autocomplete option
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
## Better SSH/Rsync/SCP Autocomplete
zstyle ':completion:*:(scp|rsync):*' tag-order ' hosts:-ipaddr:ip\ address hosts:-host:host files'
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-host' ignored-patterns '*(.|:)*' loopback ip6-loopback localhost ip6-localhost broadcasthost
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-ipaddr' ignored-patterns '^(<->.<->.<->.<->|(|::)([[:xdigit:].]##:(#c,2))##(|%*))' '127.0.0.<->' '255.255.255.255' '::1' 'fe80::*'
## Allow for autocomplete to be case insensitive
zstyle ':completion:*' matcher-list '' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' \
'+l:|?=** r:|?=**'
# Initialize the autocompletion
autoload -Uz compinit && compinit -i # use -i flag to ignore insecure directories
# Add Hook to ZSH to load node version from .nvmrc file if it exists on directory change
# -----------------------------
load-nvmrc() {
local node_version="$(nvm version)"
local nvmrc_path="$(nvm_find_nvmrc)"
if [ -n "$nvmrc_path" ]; then
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
if [ "$nvmrc_node_version" = "N/A" ]; then
nvm install
elif [ "$nvmrc_node_version" != "$node_version" ]; then
nvm use
fi
elif [ "$node_version" != "$(nvm version default)" ]; then
echo "Reverting to nvm default version"
nvm use default
fi
}
# Check for NVM (but hide output "1>")
if $(which nvm 1> /dev/null); then
autoload -U add-zsh-hook
add-zsh-hook chpwd load-nvmrc
load-nvmrc
fi