Fix tmux cwd segment
Fixes #467 Still needs colors for cwd:current_folder, cwd and cwd:divider
This commit is contained in:
parent
a202072292
commit
26ad068265
|
@ -1,11 +1,17 @@
|
|||
_powerline_tmux_setenv() {
|
||||
if [[ -n "$TMUX" ]]; then
|
||||
tmux setenv TMUX_"$1"_$(tmux display -p "#D" | tr -d %) "$2"
|
||||
tmux setenv -g TMUX_"$1"_$(tmux display -p "#D" | tr -d %) "$2"
|
||||
tmux refresh -S
|
||||
fi
|
||||
}
|
||||
|
||||
POWERLINE_SAVED_PWD=
|
||||
|
||||
_powerline_tmux_set_pwd() {
|
||||
_powerline_tmux_setenv PWD "$PWD"
|
||||
if test "x$POWERLINE_SAVED_PWD" != "x$PWD" ; then
|
||||
POWERLINE_SAVED_PWD="$PWD"
|
||||
_powerline_tmux_setenv PWD "$PWD"
|
||||
fi
|
||||
}
|
||||
|
||||
_powerline_tmux_set_columns() {
|
||||
|
@ -18,6 +24,7 @@ _powerline_prompt() {
|
|||
eval $POWERLINE_OLD_PROMPT_COMMAND
|
||||
PS1="$(powerline shell left -r bash_prompt --last_exit_code=$last_exit_code)"
|
||||
_powerline_tmux_set_pwd
|
||||
return $last_exit_code
|
||||
}
|
||||
|
||||
trap "_powerline_tmux_set_columns" SIGWINCH
|
||||
|
|
|
@ -5,7 +5,7 @@ set -g status-fg colour231
|
|||
set -g status-bg colour234
|
||||
set -g status-left-length 20
|
||||
set -g status-left '#[fg=colour16,bg=colour254,bold] #S #[fg=colour254,bg=colour234,nobold]#(powerline tmux left)'
|
||||
set -g status-right '#(powerline tmux right)'
|
||||
set -g status-right '#(powerline tmux right -R pane_id=`tmux display -p "#D"`)'
|
||||
set -g status-right-length 150
|
||||
set -g window-status-format "#[fg=colour244,bg=colour234]#I #[fg=colour240] #[fg=colour249]#W "
|
||||
set -g window-status-current-format "#[fg=colour234,bg=colour31]#[fg=colour117,bg=colour31] #I #[fg=colour231,bold]#W #[fg=colour31,bg=colour234,nobold]"
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
_powerline_tmux_setenv() {
|
||||
emulate -L zsh
|
||||
if [[ -n "$TMUX" ]]; then
|
||||
tmux setenv TMUX_"$1"_$(tmux display -p "#D" | tr -d %) "$2"
|
||||
tmux setenv -g TMUX_"$1"_$(tmux display -p "#D" | tr -d %) "$2"
|
||||
tmux refresh -S
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,11 @@ def keyvaluesplit(s):
|
|||
raise ValueError('Option names must not start with `_\'')
|
||||
idx = s.index('=')
|
||||
o = s[:idx]
|
||||
val = json.loads(s[idx + 1:])
|
||||
rest = s[idx + 1:]
|
||||
if rest[0] in '"{[0193456789' or rest in ('null', 'true', 'false'):
|
||||
val = json.loads(s[idx + 1:])
|
||||
else:
|
||||
val = rest
|
||||
return (o, val)
|
||||
|
||||
|
||||
|
|
|
@ -40,5 +40,17 @@ class TmuxRenderer(Renderer):
|
|||
tmux_attr += ['nounderscore']
|
||||
return '#[' + ','.join(tmux_attr) + ']'
|
||||
|
||||
def get_segment_info(self, segment_info):
|
||||
r = self.segment_info.copy()
|
||||
if segment_info:
|
||||
r.update(segment_info)
|
||||
if 'pane_id' in r:
|
||||
print r['pane_id']
|
||||
print sorted(r['environ'].keys())
|
||||
varname = 'TMUX_PWD_' + r['pane_id'].lstrip('%')
|
||||
if varname in r['environ']:
|
||||
r['getcwd'] = lambda: r['environ'][varname]
|
||||
return r
|
||||
|
||||
|
||||
renderer = TmuxRenderer
|
||||
|
|
|
@ -53,6 +53,7 @@ def get_argparser(parser=None, *args, **kwargs):
|
|||
p.add_argument('-c', '--config', metavar='KEY.KEY=VALUE', action='append')
|
||||
p.add_argument('-t', '--theme_option', metavar='THEME.KEY.KEY=VALUE', action='append')
|
||||
p.add_argument('-p', '--config_path', metavar='PATH')
|
||||
p.add_argument('-R', '--renderer_arg', metavar='KEY="VAL"', type=lambda a: dict([parsedotval(a)]))
|
||||
return p
|
||||
|
||||
|
||||
|
|
|
@ -15,10 +15,13 @@ if __name__ == '__main__':
|
|||
args = get_argparser(description=__doc__).parse_args()
|
||||
finish_args(args)
|
||||
powerline = ShellPowerline(args, run_once=True)
|
||||
segment_info = {'args': args, 'environ': os.environ},
|
||||
if args.renderer_arg:
|
||||
segment_info.update(args.renderer_arg)
|
||||
rendered = powerline.render(
|
||||
width=args.width,
|
||||
side=args.side,
|
||||
segment_info={'args': args, 'environ': os.environ},
|
||||
segment_info=segment_info,
|
||||
)
|
||||
try:
|
||||
sys.stdout.write(rendered)
|
||||
|
|
Loading…
Reference in New Issue