-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zshrc
219 lines (174 loc) · 5.82 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
# This file depends on eight packages installed from the Brewfile:
# argc asdf direnv pure zsh-autocomplete zsh-autopair zsh-autosuggestions zsh-syntax-highlighting
# If the `brew` command exists
if type brew &>/dev/null; then
# Read in the files installed by Homebrew
# asdf version manager
source $(brew --prefix)/opt/asdf/libexec/asdf.sh
# direnv (automatically loads/unloads environment variables)
eval "$(direnv hook zsh)"
# zsh-autocomplete extension (automatically displays completions for commands in real-time)
source $(brew --prefix)/share/zsh-autocomplete/zsh-autocomplete.plugin.zsh
# zsh-autopair extension (automatically inserts matching brackets, quotes, etc.)
source $(brew --prefix)/share/zsh-autopair/autopair.zsh
# zsh-autosuggestions extension (suggests previously typed command lines from history)
source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh
# zsh pure extension (aesthetically pleasing terminal prompt)
autoload promptinit
promptinit
prompt pure
# zsh-syntax-highlighting extension (syntax highlighting in real-time while typing)
source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
fi
# You must manually create a link from the .argc folder in this repo to $HOME/.argc or this will fail
if [ -d "$HOME/.argc" ]; then
# Store the name of each completion shell script in an array
argc_scripts=($(ls -p -1 "$ARGC_COMPLETIONS_ROOT/completions" | sed -n 's/\.sh$//p'))
source <(argc --argc-completions zsh $argc_scripts)
fi
# The following obscure line customizes colors of the text in the zsh autocompletion menu using zstyle's pattern matching syntax:
# =(#b): Pattern matches follow.
# *: Matches command names or options before --.
# (-- *): Matches --, a space, and the description text after the space.
# =color1=color2: color2 is applied to the matched pattern, color1 to everything else. 35=magenta, 90=light gray.
# Adapted from online examples. See https://github.com/ohmyzsh/ohmyzsh/issues/9728#issuecomment-1025890246 and https://superuser.com/a/1200812.
zstyle ':completion:*' list-colors '=(#b)*(-- *)=35=90'
# Add paths for Perl
eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib=$HOME/perl5)"
# The following are useful functions or aliases for command-line use
# Remove error messages when searching for manual pages
alias man='/usr/bin/man 2>/dev/null'
# Open a Homebrew package in your browser
bh() {
brew home $@
}
# Open a Rust package in a browser
cb() {
open "https://crates.io/crates/${1}"
}
# Delete a line from the zsh history file
del() {
# Delete the line by its line number
sed -i '' $1d ~/.zsh_history
}
# Example usage:
# open_github_file "cncf/cnf-testbed examples/use_case/external-packet-filtering-on-k8s-nsm-on-packet/README.md"
# Load the Google Cloud SDK – it's too bloated to load everytime the shell starts
gcloud() {
# Check if Google Cloud SDK is installed
if [ -d "$(brew --prefix)/share/google-cloud-sdk" ]; then
# Source the SDK components
source "$(brew --prefix)/share/google-cloud-sdk/path.zsh.inc"
source "$(brew --prefix)/share/google-cloud-sdk/completion.zsh.inc"
# Remove the function definition after it's called once
unset -f gcloud
# Proceed with the original gcloud command
command gcloud "$@"
else
echo "Google Cloud SDK is not installed."
fi
}
# Open GitHub files in a browser
# Usage: ghcb <repo1> <file_path1> <repo2> <file_path2> ...
ghcb() {
while [ "$#" -gt 0 ]; do
repo=$1
file_path=$2
# Determine default branch (main or master)
default_branch="main"
if curl --head --silent --fail "https://github.com/$repo/tree/master" >/dev/null; then
default_branch="master"
fi
# Construct URL to the file on GitHub
url="https://github.com/$repo/blob/$default_branch/$file_path"
# Shift to the next pair of arguments
shift 2
echo "$url"
done | xargs -n 1 -P 8 open
}
ghgv() {
gh gist view $@
}
ghge() {
gh gist edit $@
}
# Open GitHub issues in a browser
# Usage: ghib <owner/repo> <issue1> <issue2> ...
ghib() {
repo=$1
shift # This shifts the positional parameters down by one, which deletes the first argument in $@
for issue in "$@"; do
# Remove preceding '#' if it exists and construct the URL
clean_issue=${issue#\#}
echo "https://github.com/$repo/issues/$clean_issue"
done | xargs -n 1 -P 8 open
}
# Open a GitHub repository in the browser
ghrb() {
xargs -n 1 -P 8 hub browse <<<$@
}
# Clone a GitHub repo
ghrc() {
gh repo clone $@
}
# Search GitHub code
ghsc() {
gh search code $@
}
# Search GitHub issues
ghsi() {
gh search issues $@
}
# Search for GitHub issues matching the search terms, and open them all in a browser
# Usage: ghissueb <owner/repo> <search terms>
ghsib() {
repo=$1
# Shift the positional parameters down by one, which deletes the first argument in $@
shift
gh search issues -R $repo $@ | awk '{ print $2 }' | xargs -P 8 -I {} gh issue view -R $repo {} -w
}
# Search GitHub pull requests
ghspr() {
gh search prs $@
}
# Search for GitHub repos
ghsr() {
gh search repos $@
}
# Search for GitHub repos and open each result in a browser
ghsrb() {
gh search repos $@ | awk '{print $1}' | xargs -n 1 -P 8 hub browse
}
# Open the website of a Git repo
gito() {
git-open $@
}
# Update local Git repos
gu() {
gitup -c -t 2
}
alias gitu=gu
# Install .pkg files
ins() {
for pkg in "$@"; do
sudo installer -pkg "$pkg" -target /
done
}
# List an npm package's dependencies
npmdeps() {
npm view $1 dependencies
}
# Order files in the current directory by their name
ord() {
counter=1
for file in $(ls | sort); do
new_file_name=$(printf "%02d-%s" "$counter" "${file#*-}")
mv "$file" "$new_file_name"
((counter++))
done
}
# Sign a macOS app bundle
prep() {
sudo xattr -r -d com.apple.quarantine "$1"
sudo codesign --force --deep --sign - "$1"
}