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