-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zshrc
217 lines (174 loc) · 4.02 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
207
208
209
210
211
212
213
214
215
216
#############
# oh-my-zsh #
#############
export ZSH="$HOME/.oh-my-zsh"
plugins=(
git
zsh-syntax-highlighting
sudo
gh
safe-paste
web-search
)
ZSH_WEB_SEARCH_ENGINES=(
yt "https://www.youtube.com/results?search_query="
crates "https://crates.io/search?q="
brave "https://search.brave.com/search?q="
)
source $ZSH/oh-my-zsh.sh
###########
# Aliases #
###########
# Aliases for modified commands
alias cp="cp -i"
alias mv="mv -i"
alias cat="bat"
alias c="clear"
alias x="exit"
# Program aliases
alias neofetch="fastfetch"
alias v="nvim"
alias ls="eza --color=always --git --icons=always"
alias open="xdg-open 2>/dev/null"
# File aliases
alias src="source $HOME/.zshrc"
alias zshrc="nvim $HOME/.zshrc"
# Machine specific aliases
alias update="sudo $HOME/scripts/update.sh"
alias notes="cd ~/notes/ && nvim ./index.norg"
alias chad="java -jar $HOME/JChad/JChad-client.jar"
alias raspi="ssh [email protected]"
#############
# Functions #
#############
# Remap cd to z and run ls after each cd
cd() {
if [ -n "$1" ]; then
z "$@" && ls
else
z ~ && ls
fi
}
# Extracts any archive(s)
extract() {
for archive in "$@"; do
if [ -f "$archive" ]; then
case $archive in
*.tar.bz2) tar xvjf $archive ;;
*.tar.gz) tar xvzf $archive ;;
*.bz2) bunzip2 $archive ;;
*.rar) rar x $archive ;;
*.gz) gunzip $archive ;;
*.tar) tar xvf $archive ;;
*.tbz2) tar xvjf $archive ;;
*.tgz) tar xvzf $archive ;;
*.zip) unzip $archive ;;
*.Z) uncompress $archive ;;
*.7z) 7z x $archive ;;
*) echo "don't know how to extract '$archive'..." ;;
esac
else
echo "'$archive' is not a valid file!"
fi
done
}
# Copy and go to the directory
cpg() {
if [ -d "$2" ]; then
cp "$1" "$2" && cd "$2"
else
cp "$1" "$2"
fi
}
# Move and go to the directory
mvg() {
if [ -d "$2" ]; then
mv "$1" "$2" && cd "$2"
else
mv "$1" "$2"
fi
}
# Create and go to the directory
mkdirg() {
mkdir -p "$1"
cd "$1"
}
# Goes up a specified number of directories (for example up 4)
up() {
local d=""
limit=$1
for ((i = 1; i <= limit; i++)); do
d=$d/..
done
d=$(echo $d | sed 's/^\///')
if [ -z "$d" ]; then
d=..
fi
cd $d
}
################
# PATH exports #
################
export PATH="$HOME/go/bin:$PATH"
export PATH="$HOME/scripts:$PATH"
export PATH="$HOME/.spicetify:$PATH"
##########################
# Exported env variables #
##########################
# Set default editor
if [[ -n $SSH_CONNECTION ]]; then
export EDITOR='vim'
else
export EDITOR='nvim'
fi
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
#################
# Shell options #
#################
# Check window size after each command and update LINES and COLUMNS values
# Not a thing in zsh
# setopt checkwinsize
# Share history across all sessions
setopt SHARE_HISTORY
# Avoid duplicate entries in history
setopt HIST_IGNORE_ALL_DUPS
# Append history rather than overwrite
setopt APPEND_HISTORY
# Correct minor typos in path names when changing directories
setopt CORRECT
# Extended globbing
setopt EXTENDED_GLOB
####################
# Startup commands #
####################
# Set the main session name
session_name="main"
# If the "NO_TMUX" variable is not set
if [[ -z "$NO_TMUX" ]]; then
tmux has-session -t $session_name 2>/dev/null
if [[ $? -ne 0 ]]; then
TMUX='' tmux new-session -d -s "$session_name"
fi
if [[ -z "$TMUX" ]]; then
tmux attach -t "$session_name"
else
tmux switch-client -t "$session_name"
fi
fi
# Add homebrew to path
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
# Initialize zoxide
eval "$(zoxide init zsh)"
# Initialize the prompt
eval "$(oh-my-posh init zsh --config ~/.config/oh-my-posh/themes/custom/zen_rose-pine.json)"
# Source cargo
. "$HOME/.cargo/env"
# Source Nix
if [ -e $HOME/.nix-profile/etc/profile.d/nix.sh ]; then . $HOME/.nix-profile/etc/profile.d/nix.sh; fi
# Run a neofetch
neofetch
###############
# Other stuff #
###############