-
Notifications
You must be signed in to change notification settings - Fork 8
/
zshrc
206 lines (162 loc) · 5.49 KB
/
zshrc
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# Allow directory stacks
setopt AUTO_PUSHD # Push the old directory onto a stack
setopt PUSHD_MINUS # Swap the directory stack ordering
# Autocompletion
fpath=(~/.zsh/completion $fpath)
zstyle ':completion:*' completer _expand _complete _ignored _correct
autoload -U bashcompinit
bashcompinit
autoload -U compinit
compinit
# Set zsh history file length
HISTFILE=~/.zsh_history
HISTSIZE=1000
SAVEHIST=1000
export PS1="%~ \$ "
# If not running interactively, don't do anything
[ -z "$PROMPT" ] && return
# Enable color support for ls and grep
if which dircolors &> /dev/null ; then
eval $(dircolors -b)
alias ls='ls -1 --color=auto'
alias grep='grep --color=auto'
else
alias ls='ls -1'
fi
# Replace git with hub if found
if which hub &> /dev/null ; then
function git(){ hub "$@" }
fi
alias gt='cd $(git rev-parse --show-toplevel)'
alias '$'='' # Copy-pasting commands with '$ ' in front still works
# copy & paste commands
alias "copy=xclip -sel clipboard"
alias "paste=xclip -o"
# Do not wait for full input before showing output in less
[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"
# Setup python-launcher to use pyenv default version
export PY_PYTHON=$(head -n 1 $(pyenv root)/version | cut -d "." -f 1,2)
alias mshell='docker-compose exec --user="$(id -u):$(id -g)" django python manage.py shell'
function mrun(){
cat "$@" | docker exec --user="$(id -u):$(id -g)" -i $(docker-compose ps -q django) python manage.py shell
}
alias mtest='docker-compose exec test pytest'
alias mexec='docker-compose exec django'
alias mmanage='docker-compose exec --user="$(id -u):$(id -g)" django python manage.py'
alias web='python -m webbrowser'
alias open=xdg-open
alias cvim='vim -c "call ToggleFancyFeatures()"'
# Setup python-launcher to use startup file
export PYTHONSTARTUP=$HOME/.startup.py
venv() {
local venv_name
local dir_name=$(basename "$PWD")
local uv_args=()
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
-*)
uv_args+=("$1")
if [[ "$2" != -* && -n "$2" ]]; then
uv_args+=("$2")
shift
fi
;;
*)
venv_name="$1"
;;
esac
shift
done
# If no venv_name was provided, use the directory name
if [[ -z "$venv_name" ]]; then
venv_name="$dir_name"
fi
# Check if .envrc already exists
if [ -f .envrc ]; then
echo "Error: .envrc already exists" >&2
return 1
fi
# Create venv using uv with parsed arguments
if ! uv venv --python-preference=system --seed --prompt "${uv_args[@]}" "$venv_name"; then
echo "Error: Failed to create venv" >&2
return 1
fi
# Create .envrc
echo "layout python" > .envrc
# Append to ~/.projects
echo "${venv_name} = ${PWD}" >> ~/.projects
# Allow direnv to immediately activate the virtual environment
direnv allow
}
PROJECTS_FILE=$HOME/.projects
workon() {
local project_name="$1"
local project_dir
# Check for projects config file
if [[ ! -f "$PROJECTS_FILE" ]]; then
echo "Error: $PROJECTS_FILE not found" >&2
return 1
fi
# Get the project directory for the given project name
project_dir=$(grep -E "^$project_name\s*=" "$PROJECTS_FILE" | sed 's/^[^=]*=\s*//')
# Ensure a project directory was found
if [[ -z "$project_dir" ]]; then
echo "Error: Project '$project_name' not found in $PROJECTS_FILE" >&2
return 1
fi
# Ensure the project directory exists
if [[ ! -d "$project_dir" ]]; then
echo "Error: Directory $project_dir does not exist" >&2
return 1
fi
# Change directories
cd "$project_dir"
}
# Completion for workon:
_complete_workon() {
projects=(${(f)"$(cat $PROJECTS_FILE | cut -f -1 -d ' ')"})
_arguments '*:projects:($projects)'
}
compdef _complete_workon workon
# Use virtualenvwrapper only for tmux sessions that set VIRTUALENV env variable
if [[ -d "$HOME/.virtualenvs" && "$VIRTUALENV" != "" ]]; then
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=$HOME/.local/pipx/venvs/virtualenvwrapper/bin/python
source virtualenvwrapper_lazy.sh
# Seems slightly faster than "workon $VIRTUALENV"
. "$WORKON_HOME/$VIRTUALENV/bin/activate"
fi
set -o emacs
export EDITOR=vim # Use vim as default text editor
stty -ixon
export LC_TIME="C" # Use 24 hour time
export NODE_PATH=$NODE_PATH:/home/trey/.nvm/v0.10.35/lib/node_modules
# Use fnm, which is like nvm but doesn't slow cause a slow shell load time
FNM_PATH="/home/trey/.local/share/fnm"
if [ -d "$FNM_PATH" ]; then
export PATH="/home/trey/.local/share/fnm:$PATH"
eval "`fnm env`"
fi
# Add Cabal to path
export PATH="$HOME/.cabal/bin:$PATH"
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
# Use local node_modules versions of packages
export PATH="./node_modules/.bin:$PATH"
[[ -s "$HOME/.avn/bin/avn.sh" ]] && source "$HOME/.avn/bin/avn.sh" # load avn
# Set directory colors for solarized light
eval `dircolors ~/.dotfiles/dircolors.ansi-light`
# Setup direnv
eval "$(direnv hook zsh)"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
setopt PROMPT_SUBST
# Add direnv-activated venv to prompt
show_virtual_env() {
if [[ -n "$VIRTUAL_ENV_PROMPT" && -n "$DIRENV_DIR" ]]; then
echo "($(basename $VIRTUAL_ENV_PROMPT)) "
fi
}
PS1='$(show_virtual_env)'$PS1
export DIRENV_LOG_FORMAT=
eval "$(starship init zsh)"