secret
Created

  • Download Gist
config
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# my i3 config (the interesting bitz)
font -*-terminus-*-*-*-*-12-*-*-*-*-*-*-*
 
client.focused #493f5a #493f5a #ffffff #575757
client.focused_inactive #493f5a #493f5a #ffffff #575757
client.unfocused #202020 #202020 #eeeeee #202020
client.urgent #ff0000 #ff0000 #ffffff #ff0000# finds out, if available)
 
bar {
status_command i3status
position bottom
workspace_buttons yes
font -*-terminus-*-*-*-*-12-*-*-*-*-*-*-*
 
colors {
background #222222
statusline #fda8dd
 
focused_workspace #222222 #c94053 #ffffff
active_workspace #493f5a #222222
inactive_workspace #493f5a #222222 #ffffff
urgent_workspace #ffffff #900000
}
}
dmenu_wrap.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
#!/usr/bin/env python
 
import msgpack
import operator
import os
import time
from subprocess import Popen, PIPE
 
 
env_homedir = os.environ['HOME']
env_path = os.environ['PATH']
 
db_file = os.path.join(env_homedir, '.prn.db')
 
def populate(paths, bc, mtimes):
# bc is a map of binaries and counts
# mtimes is a map of directories and mtimes
current = set(bc.keys())
seen = set()
 
for path in paths:
try:
filenames = os.listdir(path)
except OSError:
continue
seen.update(filenames)
 
mtime = int(os.stat(path).st_mtime)
if path in mtimes and mtime == mtimes[path]:
continue
 
mtimes[path] = mtime
for filename in filenames:
if filename not in bc:
full = os.path.join(path, filename)
if os.stat(full).st_mode & 0100:
bc[filename] = 0
 
for key in current - seen:
del(bc[key])
 
return bc, mtimes
 
def read_database():
if os.path.exists(db_file):
with open(db_file) as db_file_fh:
bc, mtimes = msgpack.load(db_file_fh)
else:
bc = {}
mtimes = {}
return populate(env_path.split(':'), bc, mtimes)
 
def write_database(bc, mtimes):
with open(db_file, 'w') as db_file_fh:
msgpack.dump([bc, mtimes], db_file_fh)
 
if __name__ == '__main__':
bc, mtimes = read_database()
#dmenu = Popen(['dmenu'], stdin=PIPE, stdout=PIPE)
dmenu = Popen([
'dmenu',
'-nb', '#493f5a',
'-nf', '#c94053',
'-sb', '#493f5a',
'-sf', '#fda8dd',
'-fn', '-*-terminus-*-*-*-*-12-*-*-*-*-*-*-*',
], stdin=PIPE, stdout=PIPE)
filenames = []
for _, filename in sorted((v, k) for k, v in bc.iteritems()):
filenames.append(filename)
output, _ = dmenu.communicate('\n'.join(filenames))
binfile = output.strip().split()[0]
if binfile:
bc[binfile] = -time.time()
write_database(bc, mtimes)
os.system(output)
i3status.conf
1 2 3 4 5 6
general {
colors = true
interval = 5
color_good = "#c94053"
color_bad = "#fda8dd"
}
screenshot.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
#!/usr/bin/env python
 
import base64
import json
import optparse
import os
import subprocess
import sys
import time
import urllib
import urllib2
 
BINARY = 'scrot'
HOME = os.environ['HOME']
 
CLIENT_ID = 'xxx'
CLIENT_SECRET = 'xxx'
 
DROPBOX_DIR = os.path.join(HOME, 'Dropbox/Public/screens/')
DROPBOX_URL_TEMPLATE = 'http://dl.dropbox.com/u/%s/screens/%s'
DROPBOX_UID = 'xxx'
 
def upload_file(filename):
with open(filename, 'rb') as fh:
contents = fh.read()
payload = urllib.urlencode((
('image', base64.b64encode(contents)),
('key', CLIENT_SECRET),
))
request = urllib2.Request('https://api.imgur.com/3/image', payload)
request.add_header('Authorization', 'Client-ID ' + CLIENT_ID)
try:
resp = urllib2.urlopen(request)
except urllib2.HTTPError, exc:
return False, 'Returned status: %s' % exc.code
except urllib2.URLError, exc:
return False, exc.reason
resp_data = resp.read()
try:
resp_json = json.loads(resp_data)
except ValueError:
return False, 'Error decoding response: %s' % resp_data
if resp_json['success']:
return True, resp_json['data']['link']
return False, 'Imgur failure: %s' % resp_data
 
def get_parser():
parser = optparse.OptionParser('Screenshot helper')
parser.add_option('-s', '--select', action='store_true', default=True,
dest='select', help='Select region to capture')
parser.add_option('-f', '--full', action='store_true', dest='full',
help='Capture entire screen')
parser.add_option('-c', '--current', action='store_true', dest='current',
help='Capture currently selected window')
parser.add_option('-d', '--delay', default=0, dest='delay', type='int',
help='Seconds to wait before capture')
parser.add_option('-p', '--public', action='store_true', dest='dropbox',
help='Store in dropbox public folder')
parser.add_option('-x', '--no-upload', action='store_false', default=True,
dest='upload', help='Do not upload to imgur')
parser.add_option('-k', '--keep-local', action='store_true', default=False,
dest='keep', help='Keep local copy after upload')
return parser
 
def get_scrot_command(filename, options):
args = [BINARY]
if options.current:
args.append('-u')
elif not options.full:
args.append('-s')
if options.delay:
args.append('-d %s' % options.delay)
args.append(dest)
return args
 
if __name__ == '__main__':
parser = get_parser()
options, args = parser.parse_args()
 
filename = 's%s.png' % time.time()
if options.dropbox:
dest = os.path.join(DROPBOX_DIR, filename)
else:
dest = os.path.join(HOME, 'tmp', filename)
 
if not options.current and not options.full:
print 'Select a region to capture...'
 
scrot_args = get_scrot_command(dest, options)
p = subprocess.Popen(scrot_args)
p.wait()
 
if options.dropbox:
print DROPBOX_URL_TEMPLATE % (DROPBOX_UID, filename)
 
if options.upload:
success, res = upload_file(dest)
if not success:
print 'Error uploading image: %s' % res
print 'Image stored in: %s' % dest
sys.exit(1)
else:
if not options.keep:
os.unlink(dest)
print res
else:
print dest

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.