summaryrefslogtreecommitdiff
path: root/.wmii/include.sh
blob: f4b29b367d3e8dfbd15fe20c727910719b4c712a (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash

if [ -z "$WMII_NAMESPACE" ]; then
    export WMII_NAMESPACE=`wmiir namespace`
fi
if [ -z "$WMII_DIR" ]; then
    export WMII_DIR=$WMII_NAMESPACE/mnt
fi

# a -- a work-around for buggy IO append in 9pfuse
# useing '|a' should be just like using '>>', but will work
# when 9pfuse decides to bug out.
a() {
	f="${1/#${WMII_DIR}/}"
	if [ "$f" = "$1" ]; then
		cat >> "$1"
	else
		if wmiir ls "$f" &>/dev/null; then
			wmiir write "$f"
		else
			wmiir create "$f"
		fi
	fi
}

# I like wmiir's setsid better than linux-utils'
setsid() { wmiir setsid "$@"; }

path_ls() {
	find -L `echo "$@"|sed 'y/:/ /'` -maxdepth 1 -type f -executable -printf '%f\n' 2>/dev/null| sort -u
}

path_which() {
	mypath=$1
	prog=$2
	which=`which which`
	PATH="$mypath" "$which" -- "$prog" 2>/dev/null
}


lstags() {
	ls $WMII_DIR/tag | sed '/^sel$/d'
}

scansection() {
	file=`path_which "$WMII_CONFPATH" wmiirc`
	sec=$1
	tmp=`mktemp`
	if [ -n "$sec" ]; then
		< "$file" sed -n "/^\s*$sec\s*()/,/##\s*End $sec/p" | sed '1d;$d'> $tmp
	else
		< "$file" sed "/\s*}\s*##\s*End\s/d" > $tmp
	fi
	< $tmp sed -n '/##/p'|sed -r 's/^\s*(.*)\)\s*## ?/\t\1\t/;s/\s*## ?//'
	rm $tmp
}

conffile() {
	echo "$HOME/.wmii/$@"
}

Action() {
	prog=`path_which "$WMII_CONFPATH" $1`; shift
	if [ -n "$prog" ]; then
		"$prog" "$@"
		return $?
	else
		return 1
	fi
}

connected_to_x_server() {
        xdpyinfo &>/dev/null
        return $?
}