summaryrefslogtreecommitdiffstats
path: root/client/powerline.sh
blob: ad278c28ce6b03654488262f19e37bdac806dc6b (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
#!/bin/sh

use_filesystem=1
darwin=
if test -n "$OSTYPE" ; then
	# OSTYPE variable is a shell feature. supported by bash and zsh, but not 
	# dash, busybox or (m)ksh.
	if test "${OSTYPE#linux}" '!=' "${OSTYPE}" ; then
		use_filesystem=
	elif test "${OSTYPE#darwin}" ; then
		darwin=1
	fi
elif command -v uname >/dev/null ; then
	if uname -o | grep -iqF linux ; then
		use_filesystem=
	elif uname -o | grep -iqF darwin ; then
		darwin=1
	fi
fi

if test "$1" = "--socket" ; then
	shift
	ADDRESS="$1"
	shift
else
	ADDRESS="powerline-ipc-${UID:-`id -u`}"
	test -n "$use_filesystem" && ADDRESS="/tmp/$ADDRESS"
fi

if test -n "$darwin" ; then
	ENV=genv
else
	ENV=env
fi

if test -z "$use_filesystem" ; then
	ADDRESS="abstract-client:$ADDRESS"
fi

# Warning: env -0 does not work in busybox. Consider switching to parsing 
# `set` output in this case
(
	printf '%x\0' "$#"
	for argv in "$@" ; do
		printf '%s\0' "$argv"
	done
	printf '%s\0' "$PWD"
	$ENV -0
) 2>/dev/null | socat -lf/dev/null -t 10 - "$ADDRESS"

if test $? -ne 0 ; then
	powerline-render "$@"
fi