-
Notifications
You must be signed in to change notification settings - Fork 0
/
.aliases
executable file
·258 lines (206 loc) · 8.33 KB
/
.aliases
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
# Suggestions from StackOverflow:
# 1. functions and aliasses should go in ~/.bashrc and ~/.bash_profile or ~/.profile should source ~/.bashrc
# 2. sourcing one from the other makes life much easier. For safety, I have my .bash_profile check first, like this: if [ -f ~/.bashrc ]; then . ~/.bashrc; fi
# imported from sample file
# From http://hayne.net/MacDev/Bash/aliases.bash
#echo Sourcing .aliases
#-----------------
# Directory / list
#-----------------
alias la='ls -aO'
alias ll='ls -aOlh'
alias lt='ls -lt'
lll () { ls -aOlh "$@" | less ; }
# ls long with acl's
#lll () { ls -aOle "$@" | less ; }
# ls for resources MacOS fork
lsr () { ls -lh "$@"/..namedfork/rsrc ; }
#--------------
# Folder / Path
#-------------
alias md=mkdir
alias showpath='echo "$PATH" | tr ":" "\n" | nl'
#--------
# Aliases
#--------
# showa: to remind yourself of an alias (given some part of it)
showa () { grep -i -a1 $@ ~/.aliases | grep -v '^\s*$' ; }
# sourcea: to source this file (to make changes active after editing)
alias sourcea='source ~/.aliases'
#----------------
# Command history
#----------------
alias h=history 1
# history (paged)
hh () { history 1 "$@" | less ; }
# grep in command history
#hgrep () { grep -i "$1" ~/.zsh_history ; }
alias hgrep='history 1 | grep -i'
#--------------------------
# File & folder management:
#--------------------------
# ls long format
#ll () { ls -aOl "$@" | less ; }
# ls long with acl's
#lll () { ls -aOle "$@" | less ; }
# ls with time
#lt () { ls -lt "$@" | less ; }
# ls for resources fork
#lsr () { ls -l "$@"/..namedfork/rsrc ; }
#-----------
# Searching:
#-----------
# ff: to find a file under the current directory
ff () { find . -name "$@" ; }
# ffs: to find a file whose name starts with a given string
ffs () { find . -name "$@"'*' ; }
# ffe: to find a file whose name ends with a given string
ffe () { find . -name '*'"$@" ; }
# -----------
# Development
# -----------
alias killdoc='killall -KILL Dock'
alias python=python3
node-18() { brew unlink node ; brew unlink node@20 ; brew link --overwrite node@18 ; node --version ; }
node-20() { brew unlink node ; brew unlink node@18 ; brew link --overwrite node@20 ; node --version ; }
node-latest() { brew unlink node@18 ; brew unlink node@20 ; brew link --overwrite node ; node --version ; }
python-311() { alias python3 >/dev/null 2>&1 || if [[ $(uname -m) == 'arm64' ]]; then
alias python3=/opt/homebrew/bin/python3.11 ; export npm_config_python=/opt/homebrew/bin/python3.11
else
alias python3=/usr/local/bin/python3.11 ; export npm_config_python=/usr/local/bin/python3.11
fi; eval 'python3 --version' ; }
python-312() { alias python3 >/dev/null 2>&1 && unalias python3 ; unset npm_config_python ; eval 'python3 --version' ; }
alias py=python3
# ------------------------
# Mac OS & iOS Development
# ------------------------
# Change Mac terminal name
term() { echo -n -e "\033]0;$@\007" ; }
# Objective-C / NIB searches
gr() { grep --line-number --recursive --include=*.{m,h,xib} "$1" * ; }
gri() { grep --line-number --recursive --ignore-case --include=*.{m,h,xib} "$1" * ; }
xcode () { open /Applications/Xcode.app "$@" ; }
sim () { open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app ; }
# --------------------
# KDiff diff and merge
# --------------------
kdiff3() { open "/Applications/kdiff3.app" "$@" ; }
# kdiff two files
kd () { open -a kdiff3 --args "$PWD/$1" "$PWD/$2"; }
# kdiff merge two files to using a .merged output file
km () { open -a kdiff3 --args "$PWD/$1" "$PWD/$2" --output "$(PWD)/$1.merged"; }
# kdiff merge two files in place (overwrites first file)
kdm () { open -a kdiff3 --args "$PWD/$1" "$PWD/$2" --output "$(PWD)/$1"; }
# -------------
# Convert Video
# -------------
convert-video() {
video_name="${1%.*}"
source_file="${1}"
destination_file="${video_name}".mp4
# Check if source_file exists
if [ ! -f "${source_file}" ]; then
echo "Error: Source file '${source_file}' does not exist."
exit 1
fi
echo Converting "${source_file}" to "${destination_file}"
ffmpeg -i "${source_file}" -vcodec h264 -acodec aac "${destination_file}"
}
# ------
# docker
# ------
#alias docker-sha="docker images --no-trunc --quiet"
docker-sha() { docker inspect "$1" | jq '"Image: "+.[0].Id, "Repository: "+.[0].RepoDigests[0]' ; }
docker-ls() {
format_args="{{.Repository}}:{{.Tag}}\t{{.CreatedAt}}\t{{.ID}}\t{{.Size}}"
if [ -n "$1" ]; then
result=$(docker image ls --format "${format_args}")
for term in "$@"; do
result=$(echo "$result" | grep "$term")
done
echo "$result"
else
docker image ls --format "${format_args}"
fi
}
docker-run() { docker run --rm --interactive --tty --entrypoint "sh" --user root "$1" ; }
docker-os() { docker run --rm --interactive --tty --entrypoint "sh" --user root "$1" -c "grep ^ID= /etc/os-release | cut -c 4-" ; }
docker-exec() { docker exec --interactive --tty $1 sh ; }
# ----------
# Encryption
# ----------
encryption_extension="encrypted"
encrypt() {
# Prompt for password
IFS= read -rs 'password?Please enter a password: '
echo
# make sure we don't encrypt the same file twice
seen_files=()
# walk through the files and encrypt them
for pattern in "$@"; do
for file in ${pattern}; do
# space are needed in the comparison to avoid matching substrings
if [[ ! " ${seen_files[*]} " =~ " ${file} " ]]; then
# skip files that already end with .encrypted
if [[ "${file}" == *.${encryption_extension} ]]; then
echo "Skipping ${file} as it already ends with .${encryption_extension}"
continue
fi
# create the encrypted file name
encrypted_name="${file}.${encryption_extension}"
echo "Encrypting ${file} to ${encrypted_name}"
# remove the encrypted file if it exists
if [ -f "${encrypted_name}" ]; then
rm "${encrypted_name}"
fi
# encrypt the file
if ! openssl aes-256-cbc -in "${file}" -out "${encrypted_name}" -pass pass:"${password}"; then
echo "Error encrypting ${file}"
[ -f "${encrypted_name}" ] && rm "${encrypted_name}"
fi
# add the file to the seen files
seen_files+=("${file}")
fi
done
done
}
decrypt() {
# Prompt for password
IFS= read -rs 'password?Please enter a password: '
echo
# make sure we don't decrypt the same file twice
seen_files=()
# walk through the files and decrypt them
for pattern in "$@"; do
for file in ${pattern}; do
# space are needed in the comparison to avoid matching substrings
if [[ ! " ${seen_files[*]} " =~ " ${file} " ]]; then
# ensure the file ends with encryption_extension
if [[ ! "${file}" == *.${encryption_extension} ]]; then
echo "${file} does not end with .${encryption_extension}"
else
# decrypt the file
decrypted_name="${file%.$encryption_extension}"
# remove the decrypted file if it exists
if [ -f "${decrypted_name}" ]; then
rm "${decrypted_name}"
fi
echo "Decrypting ${file} to ${decrypted_name}"
if ! openssl aes-256-cbc -d -in "${file}" -out "${decrypted_name}" -pass pass:"${password}"; then
echo "Error decrypting ${file}"
[ -f "${decrypted_name}" ] && rm "${decrypted_name}"
fi
fi
seen_files+=("${file}")
fi
done
done
}
# ---------
# Optum/UHG
# ---------
if test -f ~/team/Docker/Scripts/prisma.sh; then alias prisma='~/team/Docker/Scripts/prisma.sh'; fi
if test -f ~/team/Docker/Scripts/xray.sh; then alias xray='~/team/Docker/Scripts/xray.sh'; fi
if test -f ~/team/Docker/Scripts/container-extract.sh; then alias container-extract='~/team/Docker/Scripts/container-extract.sh'; fi
if test -f ~/team/Docker/Scripts/image-extract.sh; then alias image-extract='~/team/Docker/Scripts/image-extract.sh'; fi
if test -f ~/team/scripts/ghcp-usage.sh; then alias ghcp='pushd ~/team/scripts; ./ghcp-usage.sh; popd'; fi