Coverage for src/lcdoc/lp_session.py: 76.81%

Shortcuts on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

204 statements  

1import os lp|task_runner.md

2import sys lp|task_runner.md

3import time lp|task_runner.md

4from functools import partial as p lp|task_runner.md

5 

6from lcdoc import lp lp|task_runner.md

7from lcdoc.tools import write_file lp|task_runner.md

8 

9env = os.environ lp|task_runner.md

10wait = time.sleep lp|task_runner.md

11now = time.time lp|task_runner.md

12exists = lp.exists lp|task_runner.md

13I = lp.I lp|task_runner.md

14L = lp.L lp|task_runner.md

15 

16dbg = lp.dbg lp|task_runner.md

17 

18is_lprunner = lp.is_lprunner lp|task_runner.md

19 

20 

21def tmux_ver_check(checked=[0]): lp|task_runner.md

22 """tmux -H only from 3.0""" 

23 if checked[0]: lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.md

24 return lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.md

25 msg = 'Please install tmux, version >= 3.0' lp|features/lp/examples.md

26 t = os.popen('tmux -V').read().replace(' ', '') lp|features/lp/examples.md

27 if not t or 'tmux2' in t or 'tmux1' in t: 27 ↛ 28line 27 didn't jump to line 28, because the condition on line 27 was never truelp|features/lp/examples.md

28 lp.app.die(msg) 

29 checked[0] = 1 lp|features/lp/examples.md

30 

31 

32def init_prompt(n, kw): lp|task_runner.md

33 """run before each command""" 

34 if not is_lprunner[0]: 34 ↛ 37line 34 didn't jump to line 37, because the condition on line 34 was never falselp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

35 lp.sprun('tmux send-keys -R -t %s:1' % n) # -R reset terminal state lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

36 lp.sprun('tmux clear-history -t %s:1' % n) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

37 lp.sprun("tmux send-keys -t %s:1 '' Enter" % n) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

38 t0 = now() lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

39 p = prompt(kw) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

40 while now() - t0 < 2: 40 ↛ 47line 40 didn't jump to line 47, because the condition on line 40 was never falselp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

41 res = lp.sprun('tmux capture-pane -epJS -1000000 -t %s:1' % n) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

42 r = res.decode('utf-8').rstrip() lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

43 if r and (r.endswith(p) or r[-1] in {'#', '$'}): 43 ↛ 45line 43 didn't jump to line 45, because the condition on line 43 was never falselp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

44 return lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

45 dbg('waiting for prompt...', have=r, want=p) 

46 wait(0.1) 

47 raise Exception('No Prompt; Have so far: %s' % r) 

48 

49 

50def get_cwd(session_name): lp|task_runner.md

51 res = srun_in_tmux('echo "::$(pwd)::"', session_name=session_name) 

52 res = res.rsplit('::')[-2] 

53 assert os.path.exists(res) 

54 return res 

55 

56 

57def get(session_name, **kw): lp|task_runner.md

58 """ 

59 Starts tmux if not running and delivers a srun_in_tmux function, 

60 parametrized for that session. 

61 """ 

62 s = '\n' + os.popen('tmux ls').read() lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

63 if not '\n%s:' % session_name in s: lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

64 create(session_name, kw) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.md

65 if is_lprunner[0]: 65 ↛ 67line 65 didn't jump to line 67, because the condition on line 65 was never truelp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

66 global lprunner 

67 from lcdoc import lprunner 

68 

69 lprunner.show_tmux(session_name) 

70 

71 res = p(srun_in_tmux, session_name=session_name) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

72 return res lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

73 

74 

75# :docs:configure_tmux_base_index_1 

76def configure_tmux_base_index_1(session_name): lp|task_runner.md

77 """ 

78 Seems everybody really using it has 1 (on normal keyboards 0 is far away) 

79 and its a hard to detect or change, especially when the messed with it outside of 

80 our control.  

81 

82 On clean systems it will be just missing or: the user / runner does not care. 

83 

84 => Lets create it - when it is NOT present, so that we can have automatic CI/CD. 

85 While for a normal user (who is using it) we fail if not configured correctly. 

86 """ 

87 fn = env.get('HOME', '') + '/.tmux.conf' 

88 if exists(fn): 

89 return 

90 

91 lp.app.warning('!!! Writing %s to set base index to 1 !!' % fn) 

92 r = [ 

93 'set-option -g base-index 1', 

94 'set-window-option -g pane-base-index 1', 

95 '', 

96 ] 

97 write_file(fn, '\n'.join(r)) 

98 lp.sprun('tmux source-file "%s"' % fn) 

99 wait(0.5) 

100 tmux_kill_session(session_name) 

101 wait(0.5) 

102 tmux_start(session_name) 

103 wait(0.5) 

104 

105 

106# :docs:configure_tmux_base_index_1 

107 

108 

109def prompt(kw): lp|task_runner.md

110 return kw.get('prompt', '$') lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

111 

112 

113def tmux_start(session_name): lp|task_runner.md

114 # path is set new. bash (if executing user's shell is fish we'd be screwed) 

115 s = session_name lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.md

116 lp.sprun('export SHELL=/bin/bash; export p="$PATH"; tmux new -s %s -d' % s) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.md

117 

118 

119def create(session_name, kw): lp|task_runner.md

120 # new session: 

121 tmux_ver_check() lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.md

122 s = session_name lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.md

123 tmux_start(s) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.md

124 # all lp vars into the session, maybe of use: 

125 lp_env = ['%s="%s"' % (i, env[i]) for i in env if i[:3] in ('LP_', 'lp_')] lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.md

126 lp_env = ' '.join(lp_env) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.md

127 a = 'tmux send-keys -t %(session)s:1 \'export PATH="$p" PS1="%(prompt)s " ' lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.md

128 a += "%(lp_env)s' Enter" lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.md

129 

130 b = {'prompt': prompt(kw), 'session': s, 'lp_env': lp_env} lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.md

131 for try_nr in (1, 2): 131 ↛ 147line 131 didn't jump to line 147, because the loop on line 131 didn't completelp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.md

132 try: lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.md

133 lp.sprun(a % b) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.md

134 # the reset in init prompt needs thate time before 

135 # otherwise you have the command 2 times in 

136 time.sleep(0.2) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.md

137 break lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.md

138 except Exception as ex: 

139 if try_nr == 1: 

140 configure_tmux_base_index_1(session_name) 

141 continue 

142 

143 msg = 'tmux session start failed. Do you have tmux, configured with' 

144 msg += 'base index 1? 0 is default but will NOT work!!' 

145 raise Exception(msg) 

146 

147 init_prompt(s, kw) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.md

148 if kw.get('root'): 148 ↛ 149line 148 didn't jump to line 149, because the condition on line 148 was never truelp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.md

149 lp.sprun('tmux send-keys -t %s "sudo bash" Enter' % s) 

150 wait(0.1) 

151 

152 

153def handle_cwd_pre_post(cpp_mode, spec, session_name, timeout=1, **kw): lp|task_runner.md

154 t = {'cwd': 'cd "%s"', 'pre': '%s', 'post': '%s'}[cpp_mode] lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

155 cmd = spec.get(cpp_mode) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

156 if cmd: lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

157 cmd = t % cmd lp|features/lp/parameters.mdlp|features/lp/parameters.md

158 sn = session_name lp|features/lp/parameters.mdlp|features/lp/parameters.md

159 srun_in_tmux(cmd, session_name=sn, timeout=0.1) lp|features/lp/parameters.mdlp|features/lp/parameters.md

160 

161 

162def srun(cmds, session_name, **kw): lp|task_runner.md

163 S = get(session_name, **kw) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

164 if kw.get('with_paths'): 164 ↛ 165line 164 didn't jump to line 165, because the condition on line 164 was never truelp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

165 for e in 'PATH', 'PYTHONPATH': 

166 S('export %s="%s"' % (e, os.environ.get(e, '')), **kw) 

167 h = handle_cwd_pre_post lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

168 [h(k, kw, session_name, **kw) for k in ('cwd', 'pre')] lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

169 res = [{'cmd': cmd, 'res': S(cmd, **kw)} for cmd in lp.to_list(cmds)] lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

170 h('post', kw, session_name, **kw) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

171 res = [i for i in res if not i.get('res') == 'silent'] # sleeps removed lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

172 if kw.get('kill_session'): lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

173 tmux_kill_session(session_name) lp|features/lp/parameters.md

174 return res lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

175 

176 

177def srun_in_tmux(cmd, session_name, expect=None, timeout=1, **kw): lp|task_runner.md

178 n = session_name lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

179 

180 # TODO: clean up 

181 assert_ = None lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

182 silent = kw.get('silent') lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

183 # undocumented 

184 wait_after = kw.get('wait_after') lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

185 

186 do_post = None lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

187 if isinstance(cmd, dict): lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

188 h = handle_cwd_pre_post lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

189 [h(k, cmd, session_name, **kw) for k in ('cwd', 'pre')] lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

190 if 'post' in cmd: lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

191 do_post = p(h, 'post', cmd, session_name, **kw) lp|features/lp/parameters.md

192 

193 # fmt:off 

194 timeout = cmd.get('timeout', timeout) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

195 expect = cmd.get('expect', expect) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

196 assert_ = cmd.get('asserts') or cmd.get('assert', assert_) # asserts:deprecated lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

197 silent = cmd.get('silent', silent) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

198 wait_after = cmd.get('wait_after', wait_after) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

199 cmd = cmd.get('cmd') # if not given: only produce output lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

200 # fmt:on 

201 

202 if cmd.startswith('wait '): 202 ↛ 203line 202 didn't jump to line 203, because the condition on line 202 was never truelp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

203 time.sleep(float(cmd.split()[1])) 

204 return 'silent' 

205 

206 sk = 'send-keys:' lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

207 if cmd.startswith('send-keys:'): lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

208 cmd = cmd.split('#', 1)[0] lp|features/lp/parameters.md

209 lp.spresc('tmux send-keys -t %s:1 %s' % (n, cmd.split(sk, 1)[1].strip())) lp|features/lp/parameters.md

210 # at ci seen delays after C-c: 

211 wait(0.1) lp|features/lp/parameters.md

212 return 'silent' lp|features/lp/parameters.md

213 

214 expect_echo_out_cmd = '' lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

215 is_multiline = '\n' in cmd lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

216 if expect is None: lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

217 # we do NOT fail on exit codes, just want to know if the command completed, 

218 # by scraping the tmux output for a string: 

219 # if you want the first send set -e 

220 sep = '\n' if (is_multiline or ' # ' in cmd) else ';' lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

221 # here docs can't have ';echo -n... at last line: 

222 # not match on the issuing cmd 

223 expect_echo_out_cmd = sep + 'echo -n ax_; echo -n done' lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

224 cmd += expect_echo_out_cmd lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

225 expect = 'ax_done' lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

226 

227 if expect is False: lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

228 expectb = b'des soid ned bassian - we want timeout' lp|features/lp/parameters.md

229 else: 

230 expectb = expect.encode('utf-8') lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

231 if cmd: 231 ↛ 250line 231 didn't jump to line 250, because the condition on line 231 was never falselp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

232 init_prompt(n, kw) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

233 # send the sequence as hex (-H): 

234 if is_lprunner[0]: 234 ↛ 235line 234 didn't jump to line 235, because the condition on line 234 was never truelp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

235 lprunner.confirm(cmd) 

236 seq = ' '.join([hex(ord(b))[2:] for b in cmd]) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

237 seq += ' a' lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

238 # if is_multiline: 

239 # breakpoint() # FIXME BREAKPOINT 

240 # for line in cmd.splitlines(): 

241 # spresc("tmux send-keys -t %s:1 '%s' Enter" % (n, line)) 

242 # else: 

243 # spresc("tmux send-keys -t %s:1 '%s' Enter" % (n, cmd)) 

244 _ = expect_echo_out_cmd lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

245 _ = cmd if not _ else cmd.split(_, 1)[0] + L(_) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

246 symb = '💻' lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

247 lp.nfo(symb, tmux=' ' + _) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

248 lp.spresc('tmux send-keys -t %s:1 -H %s' % (n, seq)) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

249 

250 t0 = now() lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

251 wait_dt = 0.1 lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

252 last_msg = 0 lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

253 max_wait = 2 lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

254 

255 while True: lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

256 res = lp.sprun('tmux capture-pane -epJS -1000000 -t %s:1' % n) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

257 dbg(res) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

258 if expectb in res: lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

259 break lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

260 dt = now() - t0 lp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.md

261 if dt > timeout: lp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.md

262 if expect is False: 262 ↛ 265line 262 didn't jump to line 265, because the condition on line 262 was never falselp|features/lp/parameters.md

263 # wanted then: 

264 break lp|features/lp/parameters.md

265 raise Exception( 

266 'Command %s: Timeout (> %s sec) expecting "%s"' 

267 % (cmd, timeout, expectb.decode('utf-8')) 

268 ) 

269 

270 if now() - last_msg > 5: 270 ↛ 273line 270 didn't jump to line 273, because the condition on line 270 was never falselp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.md

271 dbg('%ss[%s] Inspect: tmux att -t %s' % (round(dt, 1), timeout, n)) lp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.md

272 lst_msg = now() lp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.md

273 wait(wait_dt) # fast first lp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.md

274 wait_dt = min(timeout / 10.0, max_wait) lp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.md

275 max_wait = min(5, max_wait + 2) lp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.md

276 

277 res = res.decode('utf-8') lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

278 if expect_echo_out_cmd: lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

279 # when expect was given we include it (expect="Ready to accept Connections") 

280 # expect_echo_out_cmd is empty then 

281 res = res.split(expect, 1)[0].strip() lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

282 a = expect_echo_out_cmd lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

283 a = a[1:] if a.startswith('\n') else a # when \n is the sep we won't see it lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

284 res = res.replace(a, '') lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

285 else: 

286 # the tmux window contains a lot of white space after the last output when 

287 # short cmd 

288 res = res.strip() lp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.md

289 if wait_after: 289 ↛ 290line 289 didn't jump to line 290, because the condition on line 289 was never truelp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

290 time.sleep(float(wait_after)) 

291 lp.check_assert(assert_, res) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

292 dbg('Have tmux result:', res='\n' + res) lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

293 if do_post: lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

294 do_post() lp|features/lp/parameters.md

295 return res if not silent else 'silent' lp|features/lp/bash/sessions.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/sessions.mdlp|features/lp/syntax.mdlp|features/lp/syntax.mdlp|features/lp/tips.md

296 

297 

298def find_output_range(res, between, ls=b'\n'): lp|task_runner.md

299 """default: parse out last range in res between begin and end of between""" 

300 # todo: regex 

301 pre, post = res.rsplit(between[0], 1) 

302 r = pre.rsplit(ls, 1)[-1] + between[0] 

303 body, post = post.split(between[1], 1) 

304 r += body 

305 r += between[1] + post.split(ls, 1)[0] 

306 return r 

307 

308 

309def tmux_kill_session(session_name): lp|task_runner.md

310 os.system('tmux kill-session -t %s' % session_name) lp|features/lp/examples.mdlp|features/lp/parameters.mdlp|features/lp/parameters.mdlp|features/lp/sessions.mdlp|features/lp/syntax.md