-
Notifications
You must be signed in to change notification settings - Fork 0
/
.aliasrc-shell-settings
283 lines (235 loc) · 5.44 KB
/
.aliasrc-shell-settings
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
278
279
280
281
282
283
# vi: ft=zsh
DIR="$(dirname "$(readlink -f "$0")")"
alias pbc="pbcopy"
alias gd="git diff"
alias gdh="gd HEAD"
alias gds="gd --staged"
alias gs="git status"
alias hist="history"
alias l='ls -la | grep "^d" && ls -la | grep -v "^d"'
alias ll="ls -la"
alias s="source ~/.zshrc && hash -r && if type direnv > /dev/null; then direnv reload; fi"
alias yarn=__yarn
# functions
alias bunx=__bunx
alias mise-install=__mise-install
alias mise-update=__mise-update
alias cdf=__cdf
alias cdt=__cdt
alias dns=__dns
alias ff=__ff
alias fif=__fif
alias git-set-origin=__git-set-origin
alias git-vim-status=__git-vim-status
alias screen=__screen
alias ssh-keygen-secure=__ssh-keygen-secure
alias u=__u
# bash scripts
export BASH_SCRIPTS_PATH="$DIR/scripts"
export PATH="$BASH_SCRIPTS_PATH:$PATH"
# bash script aliases
for f in `find "$BASH_SCRIPTS_PATH" -type f -name "alias_*"`; do
cmd=`echo $f | sed -E 's#.*alias_(.*)#\1#'`
toeval="alias $cmd=\"$BASH_SCRIPTS_PATH/alias_$cmd\""
eval "$toeval"
done
# just helpful if I'm looking for the command and look under disk :)
alias disknnn="nnn"
if [ "$OS" = "darwin" ]; then
echo "macOS detected: loading $BASH_SCRIPTS_PATH/osx"
export PATH="$PATH:$BASH_SCRIPTS_PATH/osx"
fi
if [ "$OS" = "proxmox" ]; then
echo "proxmox detected: loading $BASH_SCRIPTS_PATH/proxmox"
export PATH="$PATH:$BASH_SCRIPTS_PATH/proxmox"
fi
# node scripts
__add_node_scripts_to_path() {
local nodedir="$DIR/scripts/node"
for f in `ls $nodedir`; do
local filename=$(basename "$nodedir/$f" .mjs)
alias $filename="$nodedir/$f"
done
}
__add_node_scripts_to_path
################################################################
# aliasing these to functions breaks functionality
cd() {
if [ $# -eq 1 -a -f "$@" ]; then
echo "file found, changing to parent directory"
cdf "$1"
return $?
fi
if [ "$1" != "-" -a ! -d "$@" ]; then
echo "no such directory: $@"
return 1
fi
builtin cd "$@" && echo "$OLDPWD --> $PWD"
}
__rmrf() {
SECONDS=0
echo "rm -rf $@"
local volume="$(df -P . | sed -n '$s/[^%]*%[[:blank:]]*//p')"
local tmp=$(mktemp)
local tmpFolder=$(basename $tmp)
local folders=("$@")
if [ $volume = "/" ]; then
local trash="/tmp/trash"
else
local trash="$volume/tmp/trash"
fi
mkdir -p $trash
if [ "$#" -eq 0 ]; then
echo "trash: $trash"
ls -la $trash
return 0;
fi
local trashfolder="$trash/$tmpFolder"
mkdir -p $trashfolder
echo "moving "$folders" to $trashfolder"
mv $folders $trashfolder
echo "emptying $trash in the background..."
__rmrfhelper() {
duration=$SECONDS
command rm -rf $trash
echo "$(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
}
{ __rmrfhelper & } 2>/dev/null
}
__rm() {
if [ "$1" = "-rf" ]; then
shift
__rmrf "$@"
return $?
fi
command rm "$@"
}
function findup() {
local needle="${1}"
local _DIR="${PWD}"
while [[ $PWD != '/' && ${PWD##*/} != 'httpdocs' ]]; do
if [[ -d "$needle" || -f "$needle" ]]; then
echo "${PWD}/${needle}"
builtin cd "${_DIR}"
return 0
fi
builtin cd ..
done
builtin cd "${_DIR}"
}
################################################################
__bunx() {
if exists bun; then
bun x "$@"
else
mise-install bun && bun x "$@"
fi
}
__mise-install() {
if [ -z $1 ]; then
echo "missing plugin name"
return
fi
mise plugin add "$1"
mise install "$1@latest"
mise global "$1@latest"
}
__mise-update() {
mise update
for tool in $(mise plugin list); do
mise install "${tool}" latest \
&& mise global "${tool}" latest \
&& echo "${tool} set globally"
done
}
__caff() {
if command -v caffeinate &> /dev/null
then
caffeinate -disu
else
echo "caffeinate not supported"
fi
}
__cdf() {
cd "$(dirname "$1")"
}
# cd to file or folder
__cdt() {
while [[ $PWD != '/' && `basename $PWD` != "$1" && ! -f "$1" ]]; do cd ..; done
}
__dns() {
domain="$1"
echo "[nameservers]"
dig +short "$domain" ns
echo "[a records]"
dig +short "$domain" a
echo "[cname records]"
dig +short "$domain" cname
echo "[txt records]"
dig +short "$domain" txt
echo "[mx records]"
dig +short "$domain" mx
echo "[aaaa records]"
dig +short "$domain" aaaa
echo "[srv records]"
dig +short "$domain" srv
}
# find file
__ff() {
local needle="${1:- }"
local grepopts="$2"
find . -iname "*$needle*" -type f | grep "$needle" $grepopts
}
# find in file
__fif() {
grep "$@" -r . | grep "$@"
}
__git-set-origin() {
local remote="${1:-origin}"
local currentbranch=$(git rev-parse --abbrev-ref HEAD)
local gitpath="$remote/$currentbranch"
echo "Setting upstream to \"$gitpath\""
git branch --set-upstream-to="$gitpath"
}
__git-vim-status() {
vim -p $(git status -s | sed -r 's#^(.*->)?[ARMU? ]+(.*)$#\2#')
}
__screen() {
if [[ ! $1 =~ ^- ]]; then
if [[ $1 == "ls" ]]; then
command screen -ls
return $?
fi
command screen -RR -S "$1"
return $?
fi
command screen "$@"
return $?
}
__ssh-keygen-secure() {
ssh-keygen -t ed25519 -a 100
}
__u() {
if exists brew; then
echo "updating brew"
brew update && brew upgrade
fi
if exists pacman; then
echo "updating pacman"
sudo pacman -Syu
fi
if exists apt; then
if apt -v &> /dev/null; then
echo "updating apt"
sudo apt update && sudo apt upgrade
fi
fi
if exists yum; then
echo "updating yum"
sudo yum update
fi
}
__yarn() {
echo "!!! use bun !!!"
return 1
}