-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions
More file actions
225 lines (179 loc) · 3.54 KB
/
functions
File metadata and controls
225 lines (179 loc) · 3.54 KB
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
##
# Custom Functions
##################
tes() {
[[ $@ ]]; echo $?
}
teso() {
test $@; echo $?
}
jgrep() {
cat $1 | jq $2
}
cvim() {
cd $1 && vim
}
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
vd() {
cd $1; vim
}
npmrepo() {
npm info $1 repository.url
}
npmclone() {
npmrepo $1 | xargs git clone
}
npmopen() {
npmrepo $1 | sed "s/.git$//" | sed "s/git:/https:/" | xargs open
}
npmsummary() {
npm info $1 version repository.url
}
pjgrep() {
cat package.json | jq .$1
}
openl() {
open http://localhost:$1
}
gitdelremotebranch() {
git branch -D $1; git push origin :$1
}
gitdelremotetag() {
git push origin :refs/tag/$1
}
gitsub() {
git subtree $1 --prefix $2 $3 master $4
}
gsapply() {
git stash apply stash@{$1}
}
gdep() {
git diff $1 -- . ':(exclude)package-lock.json'
}
ftpgetall() {
# ftp://username:password@host/dir
wget -r ftp://$1@$2/$3
}
ctagsproj() {
if [ -d ./.git/ ] ; then
ctags -R -f ./.git/.tags
else
ctags -R -f .tags
fi
}
visnip() {
vi $1.snippets
}
# Check which process is listening to what port no
# $ lport 8008
port() {
lsof -i :$1
}
kport() {
port $1 | awk 'FNR==2 { print $2 }'| xargs kill -9 && port $1
}
agmatch() {
ag $1 -G $2 $3 $4
}
dmenvset() {
eval "$(docker-machine env $1)"
}
bbwatch() {
babel --presets es2015,react --watch $1 --out-dir $2
}
bbwatch5() {
babel --watch $1 --out-dir $2
}
browsersyncfiles() {
echo $1
browser-sync start --server --files="$1"
}
browsersyncproxy() {
if [[ $2 =~ [0-9]+ ]]; then
browser-sync start --proxy "$1:$2" --files "$3"
else
browser-sync start --proxy "$1" --files "$2"
fi
}
nmod() {
cd node_modules/$1
}
bbuser() {
output=$(npm run user $1 2>&1)
echo "$output"
echo "$output" | grep User: | awk '{print $2}' | sed 's/,$//' | pbcopy
}
addprettier() {
yarn add eslint prettier eslint-plugin-prettier eslint-config-prettier babel-eslint --dev
printf '{\n "parser": "babel-eslint",\n "plugins": ["prettier"],\n "rules": {\n "prettier/prettier": "error"\n }\n}' > .eslintrc
printf '{\n "semi": false,\n "singleQuote": true\n}' > .prettierrc
}
# find
fname() {
find . -name "$1"
}
fdir() {
find . -type d -name "$1"
}
ffile() {
# find . -type f -name "$1"
aglg $1
}
b64() {
echo "$1" | base64 | pbcopy
pbpaste
}
b64d() {
echo "$1" | base64 -d | jsonpp | pbcopy
pbpaste
}
agfrm() {
agf $1 | xargs rm
}
jwtd() {
sed 's/\./\n/g' <<< $(cut -d. -f1,2 <<< $1) | base64 --decode | jq
}
jwtd1() {
sed 's/\./\n/g' <<< $(cut -d. -f1,2 <<< $1) | base64 --decode
}
node_switch() {
# Ensure Node.js and nvm are installed
if ! command -v node &> /dev/null; then
return 1
fi
if ! command -v nvm &> /dev/null; then
return 1
fi
# Get Node major version (e.g., "v18.17.0" → 18)
local node_major=$(node -v | sed -E 's/v([0-9]+).*/\1/')
if [ "$node_major" -lt 20 ]; then
nvm use stable
echo 'Upgrade node to stable version'
fi
}
# Claude
clp() {
claude -p '${@:2}'
}
if [ -f ~/.aliases.local ]; then
. ~/.aliases.local
fi