]> git.phdru.name Git - dotfiles.git/blob - bin/browser-stack.py
Feat(recode-filenames-recursive): Allow to omit parameters
[dotfiles.git] / bin / browser-stack.py
1 #! /usr/bin/env python
2
3 from __future__ import print_function
4 import sys, os
5 from browser_stack import get_stack, save_stack
6
7 command = sys.argv[1]
8 if command.startswith('--'):
9     command = command[2:]
10
11 stack = get_stack()
12
13 if command in ('get', 'peek', 'print'):
14     if stack: print(stack[0], end='')
15     sys.exit()
16 elif command in ('list', 'list-all'):
17     if stack: print(''.join(stack), end='')
18     sys.exit()
19
20 browser = os.path.basename(sys.argv[2]) + '\n'
21 if browser in stack:
22     # With 'push' this prevents duplicates
23     stack.remove(browser)
24
25 if command == 'push':
26     stack.insert(0, browser)
27 elif command == 'pop':
28     pass # The browser was already removed
29 else:
30     raise ValueError('Unknown command "%s"' % command)
31
32 save_stack(stack)