|
21 | 21 |
|
22 | 22 | logger = logging.getLogger(__name__) |
23 | 23 |
|
| 24 | +config_dir = os.path.expanduser('~/.tmuxp/') |
| 25 | +cwd_dir = os.getcwd() + '/' |
| 26 | + |
24 | 27 |
|
25 | 28 | def query_yes_no(question, default="yes"): |
26 | 29 | """Ask a yes/no question via raw_input() and return their answer. |
@@ -96,15 +99,10 @@ def build_workspace(config_file, args): |
96 | 99 | sconfig = config.expand(sconfig) |
97 | 100 | sconfig = config.trickle(sconfig) |
98 | 101 |
|
99 | | - t = Server() |
100 | | - |
101 | | - if args.socket_name: |
102 | | - print('socket_name %s' % args.socket_name) |
103 | | - t.socket_name = args.socket_name |
104 | | - |
105 | | - if args.socket_path: |
106 | | - print('socket_path %s' % args.socket_path) |
107 | | - t.socket_path = args.socket_path |
| 102 | + t = Server( |
| 103 | + socket_name=args.socket_name, |
| 104 | + socket_path=args.socket_path |
| 105 | + ) |
108 | 106 |
|
109 | 107 | try: |
110 | 108 | builder = WorkspaceBuilder(sconf=sconfig, server=t) |
@@ -139,10 +137,7 @@ def build_workspace(config_file, args): |
139 | 137 | return |
140 | 138 |
|
141 | 139 |
|
142 | | -def main(): |
143 | | - |
144 | | - config_dir = os.path.expanduser('~/.tmuxp/') |
145 | | - cwd_dir = os.getcwd() + '/' |
| 140 | +def cli_parser(): |
146 | 141 |
|
147 | 142 | parser = argparse.ArgumentParser( |
148 | 143 | description='''\ |
@@ -183,6 +178,12 @@ def main(): |
183 | 178 | parser.add_argument('--log-level', dest='log_level', default='INFO', |
184 | 179 | help='Log level') |
185 | 180 |
|
| 181 | + return parser |
| 182 | + |
| 183 | +def main(): |
| 184 | + |
| 185 | + parser = cli_parser() |
| 186 | + |
186 | 187 | args = parser.parse_args() |
187 | 188 |
|
188 | 189 | setupLogger(level=args.log_level.upper()) |
@@ -238,14 +239,32 @@ def main(): |
238 | 239 |
|
239 | 240 | def complete(cline, cpoint): |
240 | 241 |
|
241 | | - config_dir = os.path.expanduser('~/.tmuxp/') |
242 | | - cwd_dir = os.getcwd() + '/' |
| 242 | + parser = cli_parser() |
| 243 | + args = parser.parse_args() |
243 | 244 |
|
244 | 245 | commands = [] |
245 | 246 | commands += config.in_dir(config_dir) |
246 | 247 | commands += config.in_cwd() |
| 248 | + commands.extend(['attach', 'kill-session']) |
247 | 249 |
|
248 | 250 | ctext = cline.replace('tmuxp ', '') |
249 | 251 | commands = [c for c in commands if ctext in c] |
250 | 252 |
|
| 253 | + t = Server( |
| 254 | + socket_name=args.socket_name, |
| 255 | + socket_path=args.socket_path |
| 256 | + ) |
| 257 | + |
| 258 | + def session_complete(command, commands, ctext): |
| 259 | + if ctext.startswith(command + ' '): |
| 260 | + commands[:] = [] |
| 261 | + ctext_attach = ctext.replace(command + ' ', '') |
| 262 | + |
| 263 | + sessions = [s.get('session_name') for s in t._sessions] |
| 264 | + commands.extend([c for c in sessions if ctext_attach in c]) |
| 265 | + |
| 266 | + session_complete('attach', commands, ctext) |
| 267 | + session_complete('list-sessions', commands, ctext) |
| 268 | + session_complete('kill-session', commands, ctext) |
| 269 | + |
251 | 270 | print(' \n'.join(commands)) |
0 commit comments