-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaliases.zsh
255 lines (206 loc) · 7.58 KB
/
aliases.zsh
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
# Load some .env secreets
DIR=$( cd ~/.dotfiles && pwd )
source "$DIR/.env"
# General
alias cls="clear"
alias size="du -k -a | sort -n"
alias iip="ipconfig getifaddr en0"
alias eip="curl icanhazip.com"
alias reload=". ~/.zshrc && echo 'ZSH config reloaded from ~/.zshrc'"
alias prev="cd -"
# Work
alias gw="./gradlew"
alias dr="./debug/run"
alias bdw="npm run build.dev.watch"
alias rebuild="git submodule update && ./gradlew stopAll && ./gradlew clean packageDebug --parallel && ln -s ${PROJECTS_DIRECTORY}/curity-web-ui/dist/dev ${PROJECTS_DIRECTORY}/idsvr/dist/etc/admin-webui"
alias rebuildrf="git submodule update && ./gradlew stopAll && rm -rf ${PROJECTS_DIRECTORY}/idsvr/dist && ./gradlew packageDebug --parallel && ln -s ${PROJECTS_DIRECTORY}/curity-web-ui/dist/dev ${PROJECTS_DIRECTORY}/idsvr/dist/etc/admin-webui"
alias resym="ln -s ${PROJECTS_DIRECTORY}/curity-web-ui/dist/dev ${PROJECTS_DIRECTORY}/idsvr/dist/etc/admin-webui"
alias resymprod="ln -s ${PROJECTS_DIRECTORY}/curity-web-ui/dist/prod ${PROJECTS_DIRECTORY}/idsvr/dist/etc/admin-webui"
# Java
# The openjdk@X is keg-only; we need to create a symbolic link so that the macOS java wrapper can find it.
# https://docs.brew.sh/FAQ#what-does-keg-only-mean
# Switch Java versions
function java17() {
export JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk-17.jdk/Contents/Home
export PATH="$JAVA_HOME/bin:$PATH"
}
function java21() {
export JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk-21.jdk/Contents/Home
export PATH="$JAVA_HOME/bin:$PATH"
}
# Git log
alias gl="git log --all --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
# Git log today
alias glt="git log --no-merges --since="6am" --pretty=oneline --abbrev-commit"
# Git log this week
alias glw="git shortlog --all --no-merges --author $(git config user.email) --since "1 week ago""
# Git status
alias gs="git status -s"
# Copy current git branch name to clipboard
alias gb="git branch | grep '^\*' | cut -d' ' -f2 | pbcopy"
# Check total git commits across all branches
alias gt="git rev-list --all --count"
# Total git branches
alias gbt="git branch | wc -l"
# Number of commits per author on all branches
alias gct="git shortlog -s -n --all --no-merges --since='1 Jan, 2019'"
# Show files changes, insertions and deletions in one line
alias gshort="git diff --shortstat | sed '/^\s*$/d'"
# Show size of the current changed files in git status
alias gst="git_status_size"
git_status_size(){
git status --porcelain | awk '{print $2}' | xargs ls -hl | sort -r -h | awk '{print $5 "\t" $9}'
}
# Git language in English
alias git="LANG=en_US.UTF.8 git"
# Docker
alias dockerkill='docker kill $(docker ps -q)'
alias dockerdelete='docker rm $(docker ps -a -q)'
alias dockerdeleteimages='docker rmi $(docker images -q)'
alias dockerstop='docker stop $(docker ps -a -q)'
alias dki='docker images'
alias dup='docker compose up'
alias dus='docker compose stop'
alias dud='docker compose down'
# Launch dev standup on Zoom
function sdev() {
clear
echo "Launching Zoom..."
open "zoommtg://zoom.us/join?action=join&confno=${ZOOM_DEV_STANDUP_CONF_NO}&pwd=${ZOOM_DEV_STANDUP_PASSWORD}"
}
# Launch PMe/Marketing standup on Zoom
function spme() {
clear
echo "Launching Zoom..."
open "zoommtg://zoom.us/join?action=join&confno=${ZOOM_PME_STANDUP_CONF_NO}&pwd=${ZOOM_PME_STANDUP_PASSWORD}"
}
# Git Standup
function gitStandup() {
local days=$1
if [[ -z $days ]]; then
echo "Usage: git_standup <number of days>"
return 1
fi
cd "${PROJECTS_DIRECTORY}"
git standup -a "Urban Sandén" -m 5 -w "$days" -s
}
# Open in VS Code
function code {
if [[ $# = 0 ]]
then
open -a "Visual Studio Code"
else
local argPath="$1"
[[ $1 = /* ]] && argPath="$1" || argPath="$PWD/${1#./}"
open -a "Visual Studio Code" "$argPath"
fi
}
# Create a directory an cd into the new directory at once
function take() {
mkdir $1 && cd $_
}
# Show whats running on port X
function port() {
lsof -nP -iTCP:"$1"
}
# Kill processes at a given port
function killport() {
echo '🚨 Killing all processes at port' $1
lsof -ti tcp:$1 | xargs kill
}
# Merge two images side by side
# then open in Preview (for fast annotations etc)
# Usage example: mont 1.jpg 2.jpg
function mergex() {
convert +append "$1" "$2" merged.jpg;
# open -a Preview merged.jpg
open -a CleanShot\ X/ merged.jpg
}
# Merge two images on top of eachother
# then open in Preview or CleanShotX (for fast annotations etc)
# Usage example: mont 1.jpg 2.jpg
function mergey() {
convert -append "$1" "$2" merged.jpg;
# open -a Preview ~/desktop/merged.jpg
open -a CleanShot\ X/ merged.jpg
}
# Collage of all images in the current folder
function montageall() {
montage -background '#f2f2f2' -geometry 1280x -tile 4x4 -border 80 -bordercolor white *.jpg merged.jpg
open -a Preview merged.jpg
}
# Annotate two images with "Before" and "After". Then merge two images side by side. Upload to Cloudinary if upload flag passed
# Usage example: amont 1.jpg 2.jpg upload
function amont() {
# I store my screenshots on the desktop, so start here
cd ~/desktop
if [ "$4" = 'annotate' ]
then
# Annotate adding the Before/After text if annotate flag is passed
convert "$1" -undercolor white -pointsize 66 -fill red -gravity Northwest -annotate 0 'Before' "$1"
convert "$2" -undercolor white -pointsize 66 -fill "#78BE21" -gravity Northwest -annotate 0 'After' "$2"
fi
# Merge the two images side by side, open the image in Preview
# montage -background '#f2f2f2' -geometry 1280x720+0+0 1.jpg 2.jpg merged.jpg;
convert -background "#6e768f" 2.jpg +append \( 1.jpg \) -append -resize 1600x1600 result.jpg
# Open in Preview
open -a Preview ~/desktop/result.jpg
# Upload to CDN if upload flag passed
if [ "$3" = 'upload' ]
then
DIR=$( cd ~/.dotfiles && pwd )
source "$DIR/.env"
CLOUDINARY_URL=$(echo "$CLOUDINARY_URL")
# Upload to Cloudinary and then copy the HTTPS image link to clipboard (using the cld uploader)
cld uploader upload ~/desktop/result.jpg | jq -r '.secure_url' | pbcopy
fi
}
# Check weather using "weather Cityname"
weather() {
city="$1"
if [ -z "$city" ]; then
city="Lidköping"
fi
eval "curl http://wttr.in/${city}"
}
# Check size of files
# Handy to check bundle sizes, built assets etc.
# Pass in a file path ex. sz path/to/file.css
function sz() {
du -d 1 -h "$1" | cut -f1
}
function szgzip() {
gzip -c "$1" | wc -c | awk '{$1/=1024;printf "%.2fK\n",$1}'
}
# Convert mp4 to GIF with ffmpeg
# Usage: togif "validation.mp4" "output" 25 1.5
togif() {
# Required arguments
input_file="$1"
output_file="$2"
# Optional arguments with default values
framerate="${3:-30}"
pts="${4:-2}"
ffmpeg -i "$input_file" -vf "setpts=PTS/$pts,fps=$framerate,scale=1520:-1:flags=lanczos" -c:v pam -f image2pipe - \
| convert -delay 5 - -loop 0 -layers optimize "$output_file.gif"
}
# Activate/deactivate ./git/hooks/prepare-commit-msg hook
togglePrepareCommitHook() {
hook_path=".git/hooks/prepare-commit-msg"
backup_path=".git/hooks/prepare-commit-msg-BAK"
if [ -f "$hook_path" ]; then
if [ -f "$backup_path" ]; then
echo "Error: Backup file already exists. Aborting."
return 1
fi
mv "$hook_path" "$backup_path"
echo "Prepare-commit-msg hook deactivated."
else
if [ ! -f "$backup_path" ]; then
echo "Error: No backup file found. Aborting."
return 1
fi
mv "$backup_path" "$hook_path"
echo "Prepare-commit-msg hook activated."
fi
}