-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfoorc
118 lines (97 loc) · 2.67 KB
/
foorc
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
# vim: filetype=bash
alias vim="nvim"
tm() {
# Get the current directory name
session_name=$(basename "$PWD")
# Check if a tmux session with the current directory name exists
if tmux has-session -t "$session_name" 2>/dev/null; then
# If it exists, attach to the session
tmux attach-session -t "$session_name"
else
# If it doesn't exist, create a new session with that name
tmux new-session -s "$session_name"
fi
}
sshz_hosts() {
echo $(cat ~/.ssh/config* | grep 'Host ' | grep -v '*' | sed 's/^Host //' | fzf)
}
sshz() {
endpoint=$(sshz_hosts)
echo $endpoint
ssh $endpoint
}
sshz_install() {
if [ -f $1 ]; then
key=$1
endpoint=$(sshz_hosts)
echo $key
echo $endpoint
ssh-copy-id -i $key $endpoint
else
echo "Please specify a key file as your argument"
return
fi
}
sshz_install() {
if [ -n "$1" ] && [ -f $1 ]; then
key=$1
endpoint=$(sshz_hosts)
echo $key
echo $endpoint
ssh-copy-id -i $key $endpoint
else
echo "Please specify a key file as your argument"
return
fi
}
sshz_remove() {
if [ -n "$1" ] && [ -f $1 ]; then
key=$1
endpoint=$(sshz_hosts)
echo $key
echo $endpoint
KEY_ESCAPED=$(printf "$(cat $key)\n" | sed -e 's/[\/&]/\\&/g')
echo $ESCAPED_REPLACE
echo "BEFORE"
ssh $endpoint "cat .ssh/authorized_keys" | sed "s/$KEY_ESCAPED//g"
echo "HERE WE GO"
ssh $endpoint "cat .ssh/authorized_keys" | sed "s/$KEY_ESCAPED//g"
else
echo "Please specify a key file as your argument"
return
fi
}
# Remote all branches that aren't main
git_prune() {
# Ensure you are in a git repository
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "Error: This is not a Git repository."
return
fi
# Check if on the main branch
current_branch=$(git branch --show-current)
if [ "$current_branch" != "main" ]; then
echo "Switching to the main branch..."
git checkout main || { echo "Failed to switch to the main branch."; return; }
fi
# Fetch and prune remote-tracking branches
echo "Fetching and pruning local branches..."
git fetch --prune
# List all local branches except 'main'
branches_to_delete=$(git branch --list | grep -v "^\* main$" | grep -v "main$")
if [ -z "$branches_to_delete" ]; then
echo "No local branches to delete."
return
fi
# Confirm deletion
echo "The following local branches will be deleted:"
echo "$branches_to_delete"
echo -n "Are you sure? (y/N): "
read confirmation
if [[ "$confirmation" =~ ^[Yy]$ ]]; then
echo "$branches_to_delete" | xargs git branch -D
echo "Deleted the branches."
else
echo "Operation canceled."
fi
}