-
Notifications
You must be signed in to change notification settings - Fork 17
/
zshrc
187 lines (161 loc) · 4.87 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
# History
HISTSIZE=10000
SAVEHIST=10000
HISTFILE=~/.local/share/history/histfile
setopt appendhistory
setopt inc_append_history
setopt hist_ignore_all_dups
# Colors
autoload -U colors && colors
# Key bindings
bindkey -e
bindkey ';5D' backward-word # ctrl+left
bindkey ';5C' forward-word # ctrl+right
# Completion
zstyle :compinstall filename '/home/ai/.zshrc'
autoload -Uz compinit
compinit
# Zsh plugins
if [[ -d ~/.local/share/zsh/zsh-syntax-highlighting/ ]]; then
source ~/.local/share/zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
fi
if [[ -d ~/.local/share/zsh/zsh-history-substring-search/ ]]; then
source ~/.local/share/zsh/zsh-history-substring-search/zsh-history-substring-search.zsh
fi
if [[ -d ~/.local/share/zsh/zsh-autosuggestions/ ]]; then
source ~/.local/share/zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
fi
if [[ -d ~/.local/share/zsh/pnpm-shell-completion/ ]]; then
source ~/.local/share/zsh/pnpm-shell-completion/pnpm-shell-completion.plugin.zsh
fi
# Local binaries
export PATH="~/.local/bin/:$PATH"
# Prompt
if command -v starship > /dev/null 2>&1; then
eval "$(starship init zsh)"
elif [ -f ~/.local/bin/starship ]; then
eval "$(~/.local/bin/starship init zsh)"
fi
# Rip Grep
export RIPGREP_CONFIG_PATH=~/.ripgreprc
# Console editor
export EDITOR=micro
# Fix Bat in light console
export BAT_THEME=ansi
# Aliases
alias g='git'
alias ..='cd ..'
alias l='eza --all'
alias ll='eza --long --all --git'
if command -v bat > /dev/null 2>&1; then
alias cat='bat'
fi
if command -v eza > /dev/null 2>&1; then
alias ls='eza'
fi
alias r='dev node --disable-warning=ExperimentalWarning --run'
alias t='dev node --disable-warning=ExperimentalWarning --run test'
alias n='pnpm '
alias pui='pnpm update --interactive --latest -r --include-workspace-root'
alias pu='pnpm update -r --include-workspace-root'
alias pui1='pnpm update --interactive --latest'
alias pu1='pnpm update'
export NODE_COMPILE_CACHE=~/.cache/node
if [ -n "$container" ]; then
alias dev='command'
else
# Run commands in container
export PATH="/home/ai/.local/share/node/node_modules/.bin/:$PATH"
function devcontainer_root() {
local dir=$PWD
while [ "$dir" != "/" ]; do
if [[ -f "$dir/.devcontainer.json" ]] || [[ -d "$dir/.devcontainer" ]]; then
echo $dir
return
fi
dir=$(dirname "$dir")
done
echo "No .devcontainer.json or .devcontainer/ found" >&2
return 1
}
function devcontainer_config() {
if [[ -f "$1/.devcontainer/podman/devcontainer.json" ]]; then
echo "$1/.devcontainer/podman/devcontainer.json"
elif [[ -f "$1/.devcontainer/devcontainer.json" ]]; then
echo "$1/.devcontainer/devcontainer.json"
else
echo "$1/.devcontainer.json"
fi
}
function dev () {
local root=$(devcontainer_root)
if [ "$root" = "" ]; then
return 1
fi
local config=$(devcontainer_config $root)
if [ "$PWD" = "$root" ]; then
if [ -z "$1" ]; then
devcontainer exec --docker-path podman \
--workspace-folder $root --config $config \
zsh
else
devcontainer exec --docker-path podman \
--workspace-folder $root --config $config \
zsh -ic "$*"
fi
else
local reldir="${PWD#$root/}"
if [ -z "$1" ]; then
devcontainer exec --docker-path podman \
--workspace-folder $root --config $config \
zsh -c "cd $reldir; exec zsh"
else
devcontainer exec --docker-path podman \
--workspace-folder $root --config $config \
zsh -ic "cd $reldir && $*"
fi
fi
}
function devup () {
local root=$(devcontainer_root)
if [ "$root" = "" ]; then
return 1
fi
devcontainer up --docker-path podman \
--dotfiles-repository https://github.com/ai/environment.git \
--dotfiles-install-command devcontainer/install-dotfiles \
--workspace-folder $root --config $(devcontainer_config $root)
}
alias devdown='podman kill --all'
alias pnpm='dev pnpm'
alias node='dev node'
alias isolate="\
cp ~/Dev/environment/devcontainer/devcontainer.json ./.devcontainer.json \
&& echo '.devcontainer.json' >> .git/info/exclude"
# Disable git hooks
function chpwd() {
if /usr/bin/git rev-parse --git-dir > /dev/null 2>&1; then
if [[ -n "$(/usr/bin/git config --local --get core.hooksPath)" ]]; then
echo -e "\e[33mGit hooks was disabled\e[0m"
fi
fi
}
chpwd
export GIT_CONFIG_PARAMETERS="'core.hooksPath=/dev/null'"
# Fast way to Dev projects
if [ -d ~/Dev ]; then
cdpath=(. ~/Dev)
fi
# VS Code
export ELECTRON_TRASH=gio
alias e='code .'
# Development
alias release=~/Dev/environment/bin/release
alias p='dev pnpm clean-publish --temp-dir .npm-release --without-publish \
&& cd .npm-release \
&& npm publish \
&& cd .. \
&& rm -R .npm-release'
# Google Cloud
alias gcloud='sudo --user gcloud gcloud'
fi