-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash_functions
More file actions
87 lines (75 loc) · 1.68 KB
/
Copy pathbash_functions
File metadata and controls
87 lines (75 loc) · 1.68 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
#!/bin/bash
# utility
check() {
ps aux | rg $1
}
replace() {
replaced="$1"; shift
replace_with="$1"; shift
files=($(rg -l "$replaced"))
for file in $files
do
sed -i '' "s/$replaced/$replace_with/" "$file"
done
}
# nvim
vl() {
_now=$(date +%Y-%m-%d:%H:%M:%S)
_file="nvim-log-$_now.log"
nvim $1 -V9$_file
}
brewupdate() {
brew update
for package in $(brew outdated)
do
print -n "Do you want to upgrade and cleanup $(tput bold)${package}$(tput sgr0)? $(tput setaf 1)[y/n]$(tput sgr0) "
read answer
case "${answer}" in
[y])
brew upgrade $package && brew cleanup $package ;;
[n])
echo "passed on updating $(tput bold)${package}$(tput sgr0)" ;;
esac
done
}
# git
gitfco() {
if [[ $(git branch | rg -c $1) == 1 ]]; then git branch | rg $1 | xargs git co; else git br | rg $1; fi
}
git_delete_old_branches() {
for branch in $(git br | rg months | cut -d ' ' -f1)
do
case "$1" in
--dry)
echo "Locally Deleting ${branch}"
;;
*)
echo "Locally $(git branch -D ${branch})"
;;
esac
done
}
# Docker
drmc() {
all_containers=($(docker ps -a --format '{{.ID}}'))
docker stop "${all_containers[@]}"
docker rm "${all_containers[@]}"
}
dsac() {
all_containers=($(docker ps -a --format '{{.ID}}'))
docker stop "${all_containers[@]}"
}
dstc() {
all_containers=($(docker ps -a --format '{{.ID}}'))
docker start "${all_containers[@]}"
}
drmi() {
all_images=($(docker images -a --format '{{.ID}}'))
docker rmi "${all_images[@]}"
}
denter() {
docker exec -it "${1}" /bin/bash
}
drmc_by_img() {
docker rm $(docker stop $(docker ps -a -q --filter ancestor=$1 --format="{{.ID}}"))
}