summaryrefslogtreecommitdiffstats
path: root/powerline/bindings/rc/powerline.rc
blob: b2d6538f85f1118d140b04a3fa259ce23bf9d069 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
fn _powerline_sigwinch {
	_POWERLINE_COLUMNS = `{
		stty size | cut -d' ' -f2
	}
	_powerline_tmux_setenv COLUMNS $_POWERLINE_COLUMNS
}
fn _powerline_update_pwd {
	_POWERLINE_NEW_PWD = `{pwd}
	if (test $^_POWERLINE_NEW_PWD '=' $^_POWERLINE_SAVED_PWD) {
		_POWERLINE_SAVED_PWD = $_POWERLINE_NEW_PWD
		_powerline_tmux_setenv PWD $_POWERLINE_SAVED_PWD
	}
}
fn _powerline_continuation_prompt {
	_powerline_prompt --renderer-arg 'local_theme=continuation' $*
}
fn _powerline_prompt {
	$POWERLINE_COMMAND $POWERLINE_COMMAND_ARGS shell aboveleft -r.readline --last-pipe-status $^_POWERLINE_STATUS --last-exit-code $_POWERLINE_STATUS($#_POWERLINE_STATUS) --jobnum $_POWERLINE_JOBNUM --renderer-arg 'client_id='$pid $*
}
fn _powerline_set_prompt {
	_POWERLINE_STATUS = ( $status )
	_POWERLINE_JOBNUM = $#apids
	prompt = (``() {
		_powerline_prompt
	} ``() {
		_powerline_continuation_prompt
	})
	_powerline_update_pwd
}

fn _powerline_common_setup {
	fn sigwinch {
		_powerline_sigwinch
	}
	_powerline_sigwinch
	_POWERLINE_SAVED_PWD = ''
}

fn _powerline_tmux_pane {
	if (test -n $TMUX_PANE) {
		echo $TMUX_PANE | tr -d ' %'
	} else {
		TMUX=$_POWERLINE_TMUX tmux display -p '#D' | tr -d ' %'
	}
}

fn _powerline_tmux_setenv {
}

if (test -z $POWERLINE_CONFIG_COMMAND) {
	if (which powerline-config >/dev/null) {
		POWERLINE_CONFIG_COMMAND = powerline-config
	} else {
		echo powerline-config executable not found, unable to proceed >[2=1]
	}
}
if (test -n $POWERLINE_CONFIG_COMMAND) {
	if ($POWERLINE_CONFIG_COMMAND shell --shell rcsh uses prompt) {
		if (test -n $POWERLINE_COMMAND_ARGS) {
			# Perform splitting
			POWERLINE_COMMAND_ARGS=( `{echo $POWERLINE_COMMAND_ARGS} )
		}
		fn prompt {
			_powerline_set_prompt
		}
		if (test -z $POWERLINE_SHELL_CONTINUATION$POWERLINE_RCSH_CONTINUATION) {
			_POWERLINE_STATUS = 0
			_POWERLINE_JOBNUM = 0
			_POWERLINE_CONTINUATION = `{
				_powerline_continuation_prompt
			}
			fn _powerline_continuation_prompt {
				echo -n $_POWERLINE_CONTINUATION
			}
		}
		_powerline_common_setup
	}
	if (test -n $TMUX) {
		if ($POWERLINE_CONFIG_COMMAND shell --shell rcsh uses tmux) {
			_POWERLINE_TMUX=$TMUX
			fn _powerline_tmux_setenv {
				if (test -n $2) {
					TMUX=$_POWERLINE_TMUX tmux setenv -g TMUX_$1^_`{
						_powerline_tmux_pane
					} $2
				}
			}
			_powerline_common_setup
		}
	}
}
# vim: ft=rcshell