-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions
73 lines (62 loc) · 1.82 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
#!/bin/bash
### Shell Functions ###
# grep the value of an img tag's src attribute
function imggrep() {
grep -Po "(?<=src\=([\"'])).*?\.(?:png|jpg|gif).*?(?=\1)" # Get img sources from HTML
}
# last 5 most recently modified files in cwd
function lastmod() {
find . -not -path '*/\.*' -type f -printf '%T@ %TY-%Tm-%Td %TH:%TM:%.2TS %p\n' | sort -nr | head -n 5 | cut -f2- -d" "
}
# print process info of any zombies
function zombiehunt() {
ps alx | awk 'NR==1 || $10~/[zZ]/'
}
# print datetime in a format suitable for naming files
function file_date() {
date +"%G-%m-%d-%H-%M"
}
# dump SI db schemas / namespaces to localhost
#function rdsdump() {
#date_time=$(file_date)
#dump_file="$HOME"/rds-dumps/"$1"-"$date_time".dump
#psql -d searchinfluence -c "DROP SCHEMA $1 CASCADE;";
#pg_dump -h rds -U $(whoami) -n $1 -d searchinfluence -C -f "$dump_file" -F d
#pg_restore --no-acl --no-owner -c -d searchinfluence "$dump_file" | pv
#}
# run rubocop on files modified inbetween HEAD and commit-SHA
function rubocopdiff() {
sha="$1"
if [[ -z $sha ]] ; then
echo "[-] rubocopdiff needs a commit hash as an argument"
else
git diff --name-only HEAD "$sha" | grep '\.rb' | xargs rubocop -f s -a
fi
}
# cd "hook" to source .env files
function cd() {
builtin cd $1
project_dir=$(pwd);
if [[ -f $project_dir/.env ]]; then
. $project_dir/.env;
echo "[!] Sourcing the .env file for $project_dir";
fi
}
# get changes in a single commit
function git_changes() {
git diff "$1"^ "$1"
}
# heroku
function heroku_restore() {
heroku pg:backups:capture
heroku pg:backups:download
pg_restore --verbose --clean --no-acl --no-owner -h localhost -d $1 latest.dump
rm -rf latest.dump
}
function heroku_psql() {
if [[ $1 -eq '' ]] ; then
echo 'Please specify the remote'
else
heroku pg:psql -r $1
fi
}