-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrfdev
More file actions
executable file
·88 lines (74 loc) · 2.73 KB
/
rfdev
File metadata and controls
executable file
·88 lines (74 loc) · 2.73 KB
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
#!/bin/bash
session_name=$(basename "$0")
quit() {
if tmux has-session -t "${session_name}" 2>/dev/null; then
tmux kill-session -t "${session_name}"
else
echo no tmux session "${session_name}" found.
fi
}
tmux_select_window() {
echo xxx | tee /tmp/tmux-windows.log
local windows=$(tmux list-windows -a -F "#S:#I:#W" | sed 's/:/ /g') # List all tmux windows
echo "$windows" | tee /tmp/tmux-windows.log
local window=$(echo "$windows" | fzf --height=40% --reverse | tee /tmp/fzf-output.log | awk '{print $1 ":" $2}') # Use fzf to select a window
if [[ -n $window ]]; then
tmux select-window -t $window # Switch to the selected window
else
echo "No window selected or fzf failed" | tee /tmp/fzf-error.log
fi
}
export -f tmux_select_window
config() {
cat<<'CONFIG' > /tmp/"${session_name}".tmux.conf
set -g mouse on
unbind C-b
set-option -g prefix C-o
bind-key C-o send-prefix
bind-key / command-prompt -p 'Search for window:' 'choose-tree -w'
bind-key z run-shell "tmux list-windows -a -F '#S:#I' | fzf --height=40% --reverse | xargs tmux select-window -t"
bind ^ split-window -v
bind-key A command-prompt -I "#W" "rename-window '%%'"
bind-key o last-pane
unbind-key \"
bind-key \" list-windows
set -g status-interval 10
set -g status-right "L: #(cut -d ' ' -f 1-3 /proc/loadavg) | #([ -f /root/rapidfort/RF_SAAS ] && echo S || echo O) | %a %h-%d %H:%M"
CONFIG
}
create_windows() {
local windows=("cli" "platform" "common" "test" "log" "build")
local repos=("." "." "." "." "." ".")
# windows=("agg" "bac" "com" "doc" "facc" "fupl" "fro" "fun" "iso" "k8s" "pac" "cli" "plat" "rfp" "rfv" "run" "vul")
# repos=("aggregator" "backend" "common" "documentation" "file_access" "fileupload" "frontrow" "functional-tests" \
# "iso-master" "k8s-rf-monitor" "package-analyzer" "rapidfort" "rapidfort-platform" "rfpubsub" "rfvdb" "runner" "vulns-db")
for i in "${!windows[@]}"; do
if [ $i = 0 ]; then
tmux rename-window -t "${session_name}" "${windows[i]}"
tmux send-keys -t "${session_name}" "cd /root/rapidfort/${repos[i]}" C-m
else
tmux new-window -t "${session_name}" -n "${windows[i]}"
tmux send-keys -t "${session_name}":$i "cd /root/rapidfort/${repos[i]}" C-m
fi
done
}
start() {
if tmux has-session -t "${session_name}" 2>/dev/null; then
tmux attach-session -t "${session_name}"
else
config
tmux -f /tmp/"${session_name}".tmux.conf new-session -d -s "${session_name}"
create_windows
tmux attach-session -t "${session_name}"
fi
}
case $1 in
quit|q|exit|x)
echo "Exiting the "${session_name}" ..."
quit
exit 0
;;
*)
start
;;
esac