]> git.phdru.name Git - dotfiles.git/blob - bin/browser_stack.py
.xinitrc: calculate geometry for `xclock`
[dotfiles.git] / bin / browser_stack.py
1
2 import os, shutil
3 browser_stack = os.path.expanduser('~/.cache/browser-stack')
4
5 def get_stack():
6     try:
7         with open(browser_stack, 'rU') as stack_file:
8             return stack_file.readlines()
9     except IOError: # No such file
10         return []
11
12 def save_stack(stack):
13     os.umask(0o066) # octal -rw-------
14     with open(browser_stack+'.tmp', 'w') as stack_file:
15         stack_file.writelines(stack)
16     shutil.copy(browser_stack+'.tmp', browser_stack)
17     os.remove(browser_stack+'.tmp')
18
19 def set_current_browser():
20     stack = get_stack()
21     if stack:
22         os.environ['BROWSER'] = stack[0].strip()