-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrofi-docker.sh
More file actions
executable file
·53 lines (46 loc) · 1.61 KB
/
rofi-docker.sh
File metadata and controls
executable file
·53 lines (46 loc) · 1.61 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
#!/usr/bin/bash
#Set default terminal emulator
TERMINAL_APP=alacritty
CUSTOM_SCRIPTS_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )/custom"
function execInTerminal {
$TERMINAL_APP -e $SHELL -c "$1"
}
function getExtraActions {
local custom_scripts=""
if [ -d "$CUSTOM_SCRIPTS_DIR/$1" ]; then
for file in "$CUSTOM_SCRIPTS_DIR/$1"/*
do
custom_scripts="$custom_scripts\n$(basename $file)"
done
fi
echo $custom_scripts
}
selected_container=$(docker ps --format "table {{.ID}}:\t[{{.Image}}]\t{{.Names}}" | sed '1d' | rofi -p "Running containers " -dmenu)
container_options_attach="Attach"
container_options_stop="Stop"
container_options_logs="Logs"
container_options_restart="Restart"
if [[ ! -z $selected_container ]]; then
container_id=$(echo $selected_container | cut -d':' -f 1)
container_name=$(echo $selected_container | cut -d ' ' -f 3)
selected_action=$(echo -e "$container_options_attach\n$container_options_logs\n$container_options_restart\n$container_options_stop$(getExtraActions $container_name)" | rofi -dmenu -selected-row 0)
case $selected_action in
$container_options_attach)
execInTerminal "docker exec -it ${container_id} /bin/sh"
;;
$container_options_restart)
msg=$(docker restart $container_id)
rofi -e "Message from the docker: $msg"
;;
$container_options_logs)
execInTerminal "docker logs -f ${container_id}"
;;
$container_options_stop)
msg=$(docker stop $container_id)
rofi -e "Message from the docker: $msg"
;;
*)
bash "$CUSTOM_SCRIPTS_DIR/$container_name/$selected_action" $container_name
;;
esac
fi