-
Notifications
You must be signed in to change notification settings - Fork 0
/
.functions
62 lines (55 loc) · 1.41 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
# Super useful Docker container oneshots.
# Usage: dockrun, or dockrun [centos7|fedora27|debian9|debian8|ubuntu1404|etc.]
dockrun() {
docker run -it geerlingguy/docker-"${1:-ubuntu1604}"-ansible /bin/bash
}
# Enter a running Docker container.
function denter() {
if [[ ! "$1" ]]; then
echo "You must supply a container ID or name."
return 0
fi
docker exec -it $1 bash
return 0
}
# Delete a given line number in the known_hosts file.
knownrm() {
re='^[0-9]+$'
if ! [[ $1 =~ $re ]]; then
echo "error: line number missing" >&2
else
sed -i '' "$1d" ~/.ssh/known_hosts
fi
}
# Git upstream branch syncer.
# Usage: gsync master (checks out master, pull upstream, push origin).
function gsync() {
if [[ ! "$1" ]]; then
echo "You must supply a branch."
return 0
fi
BRANCHES=$(git branch --list $1)
if [ ! "$BRANCHES" ]; then
echo "Branch $1 does not exist."
return 0
fi
git checkout "$1" &&
git pull upstream "$1" &&
git push origin "$1"
}
# Ask for confirmation when 'prod' is in a command string.
#prod_command_trap () {
# if [[ $BASH_COMMAND == *prod* ]]
# then
# read -p "Are you sure you want to run this command on prod [Y/n]? " -n 1 -r
# if [[ $REPLY =~ ^[Yy]$ ]]
# then
# echo -e "\nRunning command \"$BASH_COMMAND\" \n"
# else
# echo -e "\nCommand was not run.\n"
# return 1
# fi
# fi
#}
#shopt -s extdebug
#trap prod_command_trap DEBUG