-
Notifications
You must be signed in to change notification settings - Fork 0
/
.functions
executable file
·74 lines (62 loc) · 1.64 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
#!/usr/bin/env bash
# Starts the ssh agent with my private key if it exists
init_ssh() {
if [[ $0 == "-zh" ]] || [[ $0 == 'init_ssh' ]]; then
TEMP_SSH_KEY="$HOME/.ssh/dquist_rsa"
if [[ -f $TEMP_SSH_KEY ]]; then
export SSH_KEY="$TEMP_SSH_KEY"
FP=$(ssh-keygen -lf $SSH_KEY | awk '{print $2}')
ssh-add -l | grep -q $FP || ssh-add $SSH_KEY
fi
fi
}
# Some WSL-specific configuration
wsl_only() {
# Checks if running under WSL
# 'uname -v' will return the kernel version in the form of
# #379-Microsoft Wed Mar 06 19:16:00 PST 2019
if [[ $(uname -v | sed -rE 's/^#[0-9]{1,}-(\S+).+/\1/') == "Microsoft" ]]; then
alias pshell="powershell.exe"
alias cmd="cmd.exe"
export WSL=1
fi
}
# Creates a directory and moves into it
into() {
mkdir $1
cd $1
}
# Function for determining the size of a git repository
gsize() {
git gc
size=$(git count-objects -vH | grep size-pack | awk '{ print $2, $3 }' | xargs)
echo 'Repo size: $size'
}
# Common setup that applies to all environments
setup_common() {
init_ssh
wsl_only
umask 027
}
# Remaps ssh to automatically start a tmux session on the remote server
ssh () {
/usr/bin/ssh -t $@ "tmux attach || tmux new"
}
# Switches back to master after a branch has been remotely merged
gmerged() {
branch_name="$(git symbolic-ref --short HEAD)"
git fetch origin master:master
git checkout master
git fetch --all --prune
git branch -d "$branch_name"
}
gfix() {
git add .
git commit --amend --no-edit
git push -f
}
# Local additions - Don't edit below this line
if [[ -f ".functions.local" ]]; then
source ".functions.local"
fi
setup_common