aboutsummaryrefslogtreecommitdiffstats
path: root/.zprofile-dtach
blob: 4571f944df96dc5ea31d3ebdf6e3bcc5b4dffb73 (plain)
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
if [[ -z "${DTACH_SUB}" ]]; then
{
	setopt NULL_GLOB

	while true; do
		set -- /tmp/dtach*
		if [[ "$#" -gt 0 ]]; then
			# session exists, so show the menu
			{
				while true; do
					set -- /tmp/dtach*
					if [[ "$#" -eq 0 ]]; then
						# logout if all sessions terminated
						clear
						logout
					fi

					# list sessions
					set -- /tmp/dtach*
					if [[ "$#" -gt 0 ]]; then
						ls /tmp/dtach* | sed 's/\/tmp\/dtach-//g'
					fi

					echo -n "> "
					read -A args
					case "${args[1]}" in
						"")
							break;
							;;

						q)
							break;
							;;

						*)
							DTACH_SUB=true dtach -A "/tmp/dtach-${args[1]}" -z zsh
							clear
							;;
					esac

				done
			}

			clear
			logout
		else
			# create the main session
			DTACH_SUB=true dtach -A /tmp/dtach-1 -z zsh
			clear
			set -- /tmp/dtach*
			if [[ "$#" -eq 0 ]]; then
				# logout if all sessions terminated
				clear
				logout
			fi
		fi
	done
}
fi