aboutsummaryrefslogtreecommitdiffstats
path: root/.zprofile-dtach
blob: b2256cb2b4fe0cd46e1625b46cbebd2aa52e145e (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 -- $tmpdir/dtach*
		if [[ "$#" -gt 0 ]]; then
			# session exists, so show the menu
			{
				while true; do
					set -- $tmpdir/dtach*
					if [[ "$#" -eq 0 ]]; then
						# logout if all sessions terminated
						clear
						logout
					fi

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

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

						q)
							break;
							;;

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

				done
			}

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