-
Notifications
You must be signed in to change notification settings - Fork 0
/
zshrc
277 lines (227 loc) 路 7.18 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# Zsh configuration file
#
# This file contains various aliases, functions, and configurations to enhance the
# Zsh shell experience. It includes support for iTerm2 shell integration, custom
# 'cd' command, Git shortcuts, Neovim setup, macOS clipboard utilities, and more.
#
# Table of Contents:
# 1. iTerm2 Shell Integration
# 2. Custom 'cd' command
# 3. Git commit and push function
# 4. Directory navigation aliases
# 5. 'lsd' for directory listings
# 6. Neovim shortcuts
# 7. Git command shortcuts
# 8. Default editor
# 9. macOS clipboard utilities
# 10. Neovim file search using 'find' and 'fzf'
# 11. Python alias
# 12. Java Home configuration
# 13. .NET Core SDK tools
# 14. Conda initialization
# 15. GitHub Copilot CLI wrapper functions
# 16. Zsh plugins (syntax highlighting, autosuggestions)
# 17. 'thefuck' alias
# 18. fzf key bindings and fuzzy completion
#
# Requirements:
# - iTerm2 (for shell integration)
# - 'lsd' command (for enhanced directory listings)
# - Neovim (for text editing)
# - 'fzf' command (for file searching)
# - Java 17 (for Java development)
# - .NET Core SDK (for .NET development)
# - Anaconda (for Python development)
# - GitHub CLI (for GitHub Copilot CLI wrapper functions)
# - Zsh plugins: zsh-syntax-highlighting, zsh-autosuggestions
# - 'thefuck' command (for correcting previous console commands)
# ESLINT CONFIG
export PATH="$PATH:$(npm get prefix)/bin"
# iTerm2 Shell Integration
test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
# Custom 'cd' command: automatically runs 'ls' after 'cd'
cd() {
builtin cd "$@" && lsd
}
# Directory navigation aliases
alias ..='cd ..'
alias ...='cd ../../'
alias ....='cd ../../../'
# Use 'lsd' for directory listings
alias ls='lsd'
alias ll='ls -lAh'
# Neovim shortcuts
alias nv='nvim'
alias vi='nvim'
alias vim='nvim'
# Quick access to Neovim config directory
alias nvconfig='cd ~/.config/nvim/'
# Quick access to .zshrc
alias zshrc='nvim ~/.zshrc'
# Git command shortcuts
alias gi='git init'
alias gs='git status'
alias ga='git add'
alias gc='git commit -m'
alias gp='git push'
alias gpl='git pull'
alias gco='git checkout'
alias gb='git branch'
alias gba='git branch -a'
alias gd='git diff'
alias gl='git log'
# Git status, add, and commit with a single command
function gac() {
git status && git add . && git commit -m "$1"
}
# Git commit and push with a single command
function gcp() {
git commit -am "$1" && git push
}
# Open in web
alias openrepo='gh repo view --web'
# Set Neovim as default editor
export EDITOR='nvim'
# macOS clipboard utilities
alias ccp='pbcopy' # Copy command output to clipboard
alias pst='pbpaste' # Paste from clipboard to terminal
# Neovim file search using 'find' and 'fzf'
function nvf() {
nvim "$(find . -type f | fzf)"
}
# Example to copy file contents to clipboard (Usage: `ccat <filename>`)
alias ccat='cat <file> | pbcopy'
# Python = Python3
alias python='python3'
# Java Home configuration
export JAVA_HOME=$(/usr/libexec/java_home -v 17)
# Add .NET Core SDK tools
export DOTNET_ROOT=/Users/nathannguyen/.vscode-dotnet-sdk/.dotnet
export PATH="$PATH:/Users/nathannguyen/.dotnet/tools"
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/opt/anaconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/opt/anaconda3/etc/profile.d/conda.sh" ]; then
. "/opt/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/opt/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
# Zsh plugins
source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh
# 'thefuck' alias
eval $(thefuck --alias fk)
# Set up fzf key bindings and fuzzy completion
eval "$(fzf --zsh)"
# GitHub Copilot CLI wrapper functions
ghcs() {
FUNCNAME="$funcstack[1]"
TARGET="shell"
local GH_DEBUG="$GH_DEBUG"
read -r -d '' __USAGE <<-EOF
Wrapper around \`gh copilot suggest\` to suggest a command based on a natural language description of the desired output effort.
Supports executing suggested commands if applicable.
USAGE
$FUNCNAME [flags] <prompt>
FLAGS
-d, --debug Enable debugging
-h, --help Display help usage
-t, --target target Target for suggestion; must be shell, gh, git
default: "$TARGET"
EXAMPLES
- Guided experience
$ $FUNCNAME
- Git use cases
$ $FUNCNAME -t git "Undo the most recent local commits"
$ $FUNCNAME -t git "Clean up local branches"
$ $FUNCNAME -t git "Setup LFS for images"
- Working with the GitHub CLI in the terminal
$ $FUNCNAME -t gh "Create pull request"
$ $FUNCNAME -t gh "List pull requests waiting for my review"
$ $FUNCNAME -t gh "Summarize work I have done in issues and pull requests for promotion"
- General use cases
$ $FUNCNAME "Kill processes holding onto deleted files"
$ $FUNCNAME "Test whether there are SSL/TLS issues with github.com"
$ $FUNCNAME "Convert SVG to PNG and resize"
$ $FUNCNAME "Convert MOV to animated PNG"
EOF
local OPT OPTARG OPTIND
while getopts "dht:-:" OPT; do
if [ "$OPT" = "-" ]; then # long option: reformulate OPT and OPTARG
OPT="${OPTARG%%=*}" # extract long option name
OPTARG="${OPTARG#"$OPT"}" # extract long option argument (may be empty)
OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=`
fi
case "$OPT" in
debug | d)
GH_DEBUG=api
;;
help | h)
echo "$__USAGE"
return 0
;;
target | t)
TARGET="$OPTARG"
;;
esac
done
# shift so that $@, $1, etc. refer to the non-option arguments
shift "$((OPTIND-1))"
TMPFILE="$(mktemp -t gh-copilotXXX)"
trap 'rm -f "$TMPFILE"' EXIT
if GH_DEBUG="$GH_DEBUG" gh copilot suggest -t "$TARGET" "$@" --shell-out "$TMPFILE"; then
if [ -s "$TMPFILE" ]; then
FIXED_CMD="$(cat $TMPFILE)"
print -s "$FIXED_CMD"
echo
eval "$FIXED_CMD"
fi
else
return 1
fi
}
ghce() {
FUNCNAME="$funcstack[1]"
local GH_DEBUG="$GH_DEBUG"
read -r -d '' __USAGE <<-EOF
Wrapper around \`gh copilot explain\` to explain a given input command in natural language.
USAGE
$FUNCNAME [flags] <command>
FLAGS
-d, --debug Enable debugging
-h, --help Display help usage
EXAMPLES
# View disk usage, sorted by size
$ $FUNCNAME 'du -sh | sort -h'
# View git repository history as text graphical representation
$ $FUNCNAME 'git log --oneline --graph --decorate --all'
# Remove binary objects larger than 50 megabytes from git history
$ $FUNCNAME 'bfg --strip-blobs-bigger-than 50M'
EOF
local OPT OPTARG OPTIND
while getopts "dh-:" OPT; do
if [ "$OPT" = "-" ]; then # long option: reformulate OPT and OPTARG
OPT="${OPTARG%%=*}" # extract long option name
OPTARG="${OPTARG#"$OPT"}" # extract long option argument (may be empty)
OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=`
fi
case "$OPT" in
debug | d)
GH_DEBUG=api
;;
help | h)
echo "$__USAGE"
return 0
;;
esac
done
# shift so that $@, $1, etc. refer to the non-option arguments
shift "$((OPTIND-1))"
GH_DEBUG="$GH_DEBUG" gh copilot explain "$@"
}