-
Notifications
You must be signed in to change notification settings - Fork 0
/
.functions
127 lines (109 loc) · 2.77 KB
/
.functions
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
#!/bin/bash
function c() {
if [ -f "$PWD/bin/rails" ]; then
bin/rails console "$@"
else
ansi --bold --red "Ain't no rails app here"
fi
}
# Copy w/ progress
cp_p () {
rsync -WavP --human-readable --progress $1 $2
}
function dev() {
if [ -f "$PWD/Procfile.local" ]; then
bin/foreman start -f Procfile.local
elif [ -f "$PWD/bin/dev" ]; then
bin/dev "$@"
else
ansi --bold --red "No bin/dev script or Procfile.local is present in this directory"
fi
}
function dotfiles() {
cd ~/dotfiles
code ~/dotfiles
}
# echo all args then call them
# https://stackoverflow.com/a/12240862
function echo-then-run() {
ansi --bold --white-intense "$*" ; "$@" ;
}
# find shorthand
# https://github.com/paulirish/dotfiles/blob/master/.functions#L9-L12
function f() {
find . -name "$1" 2>&1 | grep -v 'Permission denied'
}
# https://github.com/ryanwood/dotfiles/blob/d25fff3f5bb22cfaee4aea7eb8aa122621b8b7f7/zsh/functions/g
#
# No arguments: `git status`
# With arguments: acts like `git`
function g() {
if [[ $# -gt 0 ]]; then
git "$@"
else
git status -sb
fi
}
# See here: https://stackoverflow.com/questions/10610327/delete-all-local-git-branches/26152574#26152574
function git-delete-merged-branches() {
for mergedBranch in $(git for-each-ref --format '%(refname:short)' --merged HEAD refs/heads/)
do
if [[ "$mergedBranch" == "main" || "$mergedBranch" == "master" ]]; then
# If it matches, skip this iteration
continue
fi
git branch -d ${mergedBranch}
done
}
function ip() {
curl -s ipinfo.io/$1 | jq
echo ''
}
# https://stackoverflow.com/a/30029855
listening() {
if [ $# -eq 0 ]; then
sudo lsof -iTCP -sTCP:LISTEN -n -P
elif [ $# -eq 1 ]; then
sudo lsof -iTCP -sTCP:LISTEN -n -P | grep -i --color $1
else
echo "Usage: listening [pattern]"
fi
}
function ruby-server() {
dir=${1:="."}
ruby -run -e httpd $dir -p 5000
}
# http://www.red56.uk/2017/03/26/running-rubocop-on-changed-files/
function run-rubocop-for-changed-files() {
git ls-files -m | xargs ls -1 2>/dev/null | grep '\.rb$' | xargs bundle exec rubocop -a --force-exclusion
}
function s() {
if [ -f "$PWD/bin/rails" ]; then
bin/rails s "$@"
else
ansi --bold --red "Ain't no rails app here"
fi
}
function srb() {
if [ -f "$PWD/bin/standardrb" ]; then
bin/standardrb "$@"
else
ansi --bold --red "Ain't no standardrb here"
fi
}
function t() {
if [ -f "$PWD/bin/rspec" ]; then
bin/rspec "$@"
else
ansi --bold --red "Ain't no rspec here"
fi
}
# whois a domain or a URL
function whois() {
local domain=$(echo "$1" | awk -F/ '{print $3}') # get domain from URL
if [ -z $domain ] ; then
domain=$1
fi
echo "Getting whois record for: $domain …"
/usr/bin/whois -h whois.internic.net $domain | sed '/NOTICE:/q'
}