File: wmanager-loop

package info (click to toggle)
wmanager 0.2.2-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 204 kB
  • sloc: cpp: 520; perl: 124; makefile: 99; sh: 83
file content (115 lines) | stat: -rw-r--r-- 2,810 bytes parent folder | download | duplicates (5)
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
#!/bin/sh -e

#  wmanager-loop -- loop running window managers chosen with wmanager
#  Copyright (C) 2000  Tommi Virtanen <tv@debian.org>
#  Copyright (C) 2008, 2009  Peter Pentchev <roam@ringlet.net>

#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.

#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.

#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# Search .wmanagerrc for the WM specified by the user
check_wm()
{
	local wm esc try

	# A directly specified executable file
	if [ -x "$1" ]; then
		echo "$1"
		return 0
	fi

	# No, we'll have to look through .wmanagerrc
	if [ ! -r "$RC" ]; then
		echo "Nonexistent or unreadable config file: $RC" 1>&2
		return 1
	fi

	if `expr "$1" : '.*[^A-Za-z0-9_/-]' > /dev/null`; then
		echo "Invalid characters in WM specification: $1" 1>&2
		return 1
	fi
	wm="$1"
	esc=`echo "$1" | sed -e 's@/@\\\\/@g'`

	# An exact match
	try=`awk -F= '$1 == "'$wm'" {print $2}' "$RC"`
	if [ -n "$try" ]; then
		echo "$try"
		return 0
	fi

	# An exact match for the program
	try=`awk -F= '$2 ~ /\/'"$esc"'$/ {print $2}' "$RC"`
	if [ -n "$try" ]; then
		set $try
		if [ "$#" -gt 1 ]; then
			echo "Ambiguous WM specification '$wm': $@" 1>&2
			return 1
		fi
		echo "$try"
		return 0
	fi

	# A WM starting with the specified string
	try=`awk -F= '$2 ~ /\/'"$esc"'[^\/]*$/ {print $2}' "$RC"`
	if [ -n "$try" ]; then
		set $try
		if [ "$#" -gt 1 ]; then
			echo "Ambiguous WM specification '$wm': $@" 1>&2
			return 1
		fi
		echo "$try"
		return 0
	fi

	# A WM ending with the specified string
	try=`awk -F= '$2 ~ /'"$esc"'$/ {print $2}' "$RC"`
	if [ -n "$try" ]; then
		set $try
		if [ "$#" -gt 1 ]; then
			echo "Ambiguous WM specification '$wm': $@" 1>&2
			return 1
		fi
		echo "$try"
		return 0
	fi

	echo "Invalid WM specification '$wm'" 1>&2
	return 1
}

RC="$HOME/.wmanagerrc"
if [ -n "$WM" ]; then
	WM=`check_wm "$WM"`
	[ -n "$WM" ] || exit 1
fi
if [ -z "$WM" ] && [ -r "$RC" ]; then
	WM="$(sed 's/^.*=//; q' "$RC")"
fi

if [ -z "$WMTERM" ]; then
	WMTERM='xterm'
	for prog in x-terminal-emulator urxvt rxvt xterm; do
		WMCMD=`which "$prog" || true`
		if [ -n "$WMCMD" ]; then
			WMTERM="$WMCMD"
			break
		fi
	done
fi

while [ "$WM" != "-1" ]; do
    ${WM:-"$WMTERM"} || true
    WM="$(wmanager "$@" || true)"
done