Skip to content

Instantly share code, notes, and snippets.

@geemoo
Forked from bartman/NOTES
Last active August 29, 2015 14:17
Show Gist options
  • Save geemoo/540ec09654c534637dbb to your computer and use it in GitHub Desktop.
Save geemoo/540ec09654c534637dbb to your computer and use it in GitHub Desktop.
#!/bin/bash
gnome-screensaver&
xsetroot -solid '#101010' &
brightness 100
xset b off
xrandr --output DP1 --primary
# This file has been auto-generated by i3-config-wizard(1).
# It will not be overwritten, so edit it as you like.
#
# Should you change your keyboard layout somewhen, delete
# this file and re-run i3-config-wizard(1).
#
# i3 config file (v4)
#
# Please see http://i3wm.org/docs/userguide.html for a complete reference!
set $mod Mod1
set $mod2 Mod4
# Font for window titles. Will also be used by the bar unless a different font
# is used in the bar {} block below. ISO 10646 = Unicode
#font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
font -windows-proggytiny-medium-r-normal--10-80-96-96-c-60-iso8859-1
# The font above is very space-efficient, that is, it looks good, sharp and
# clear in small sizes. However, if you need a lot of unicode glyphs or
# right-to-left text rendering, you should instead use pango for rendering and
# chose an xft font, such as:
# font xft:DejaVu Sans Mono 10
# Use Mouse+$mod to drag floating windows to their wanted position
floating_modifier $mod
# start a terminal
bindsym $mod+Return exec i3-sensible-terminal
# kill focused window
bindsym $mod+Shift+q kill
# start dmenu (a program launcher)
bindsym $mod+p exec dmenu_run
# change focus
bindsym $mod+h focus left
bindsym $mod+j focus down
bindsym $mod+k focus up
bindsym $mod+l focus right
# alternatively, you can use the cursor keys:
#bindsym $mod+Left focus left
#bindsym $mod+Down focus down
#bindsym $mod+Up focus up
#bindsym $mod+Right focus right
# move focused window
bindsym $mod+Shift+h move left
bindsym $mod+Shift+j move down
bindsym $mod+Shift+k move up
bindsym $mod+Shift+l move right
# find a window
bindsym $mod+f exec ~/.i3/get_window_list.py | dmenu -b | ~/.i3/focus_window_named.py
# split in horizontal orientation
bindsym $mod+semicolon split h
# split in vertical orientation
bindsym $mod+v split v
# enter fullscreen mode for the focused container
bindsym $mod+Shift+f fullscreen
# change container layout (stacked, tabbed, toggle split)
bindsym $mod+s layout stacking
bindsym $mod+w layout tabbed
bindsym $mod+e layout toggle split
# toggle tiling / floating
bindsym $mod+Shift+space floating toggle
# change focus between tiling / floating windows
bindsym $mod+space focus mode_toggle
# focus the parent container
bindsym $mod+Shift+a focus parent
bindsym $mod+Shift+d focus child
# switch to workspace
bindsym $mod2+1 workspace 1
bindsym $mod2+2 workspace 2
bindsym $mod2+3 workspace 3
bindsym $mod2+4 workspace 4
bindsym $mod2+5 workspace 5
bindsym $mod2+6 workspace 6
bindsym $mod2+7 workspace 7
bindsym $mod2+8 workspace 8
bindsym $mod2+9 workspace 9
bindsym $mod2+0 workspace 10
# move focused container to workspace
bindsym $mod2+Shift+1 move container to workspace 1
bindsym $mod2+Shift+2 move container to workspace 2
bindsym $mod2+Shift+3 move container to workspace 3
bindsym $mod2+Shift+4 move container to workspace 4
bindsym $mod2+Shift+5 move container to workspace 5
bindsym $mod2+Shift+6 move container to workspace 6
bindsym $mod2+Shift+7 move container to workspace 7
bindsym $mod2+Shift+8 move container to workspace 8
bindsym $mod2+Shift+9 move container to workspace 9
bindsym $mod2+Shift+0 move container to workspace 10
# $ for n ( {a..z} ) echo "bindsym \$mod2+$n exec ~/.i3/go_to_workspace.py $n"
bindsym $mod2+a exec ~/.i3/go_to_workspace.py a
bindsym $mod2+b exec ~/.i3/go_to_workspace.py b
bindsym $mod2+c exec ~/.i3/go_to_workspace.py c
bindsym $mod2+d exec ~/.i3/go_to_workspace.py d
bindsym $mod2+e exec ~/.i3/go_to_workspace.py e
bindsym $mod2+f exec ~/.i3/go_to_workspace.py f
bindsym $mod2+g exec ~/.i3/go_to_workspace.py g
bindsym $mod2+h exec ~/.i3/go_to_workspace.py h
bindsym $mod2+i exec ~/.i3/go_to_workspace.py i
bindsym $mod2+j exec ~/.i3/go_to_workspace.py j
bindsym $mod2+k exec ~/.i3/go_to_workspace.py k
bindsym $mod2+l exec ~/.i3/go_to_workspace.py l
bindsym $mod2+m exec ~/.i3/go_to_workspace.py m
bindsym $mod2+n exec ~/.i3/go_to_workspace.py n
bindsym $mod2+o exec ~/.i3/go_to_workspace.py o
bindsym $mod2+p exec ~/.i3/go_to_workspace.py p
bindsym $mod2+q exec ~/.i3/go_to_workspace.py q
bindsym $mod2+r exec ~/.i3/go_to_workspace.py r
bindsym $mod2+s exec ~/.i3/go_to_workspace.py s
bindsym $mod2+t exec ~/.i3/go_to_workspace.py t
bindsym $mod2+u exec ~/.i3/go_to_workspace.py u
bindsym $mod2+v exec ~/.i3/go_to_workspace.py v
bindsym $mod2+w exec ~/.i3/go_to_workspace.py w
bindsym $mod2+x exec ~/.i3/go_to_workspace.py x
bindsym $mod2+y exec ~/.i3/go_to_workspace.py y
bindsym $mod2+z exec ~/.i3/go_to_workspace.py z
bindsym $mod+r workspace back_and_forth
bindsym $mod+comma workspace prev
bindsym $mod+period workspace next
#bindsym $mod+less workspace to output left
#bindsym $mod+greater workspace to output right
bindsym $mod+Shift+comma exec 'i3-left'
bindsym $mod+Shift+period exec 'i3-right'
# http://www.blog.kaiserapps.com/2014/02/my-killer-i3-setup.html
# http://www.blog.kaiserapps.com/2014/02/dynamic-tagging-in-i3.html
# https://gist.github.com/benkaiser/8822222
bindsym $mod+t exec ~/.i3/get_workspace_options.py | dmenu -b | ~/.i3/go_to_workspace.py
bindsym $mod+Shift+t exec ~/.i3/get_workspace_options.py | dmenu -b | ~/.i3/move_to_workspace.py
# reload the configuration file
bindsym $mod+Shift+c reload
# restart i3 inplace (preserves your layout/session, can be used to upgrade i3)
bindsym $mod+Control+Shift+r restart
# exit i3 (logs you out of your X session)
bindsym $mod+Shift+e exec "i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -b 'Yes, exit i3' 'i3-msg exit'"
## Colors
## class border background text
client.focused #9966CC #9966CC #000000
client.focused_inactive #333333 #333333 #999999
client.unfocused #333333 #333333 #999999
client.urgent #FF0000 #8C5665 #999999
#bar.focused #DA6F00 #000000 #999999
#bar.unfocused #333333 #000000 #999999
#bar.urgent #FF0000 #000000 #999999
workspace 1 output LVDS1
workspace 2 output LVDS1
workspace 9 output DP1
workspace "10: www" output DP1
bindsym $mod+b border toggle
#for_window [class="^Google-chrome$"] border pixel
for_window [title="Google Chrome$"] border pixel
bindsym XF86AudioLowerVolume exec aumix -v -5
bindsym XF86AudioRaiseVolume exec aumix -v +5
#bindsym XF86AudioMute exec aumix ...
bindsym XF86MonBrightnessUp exec brightness +10
bindsym XF86MonBrightnessDown exec brightness -10
# resize window (you can also use the mouse for that)
mode "resize" {
# These bindings trigger as soon as you enter the resize mode
# Pressing left will shrink the window’s width.
# Pressing right will grow the window’s width.
# Pressing up will shrink the window’s height.
# Pressing down will grow the window’s height.
bindsym h resize shrink width 5 px or 5 ppt
bindsym j resize grow height 5 px or 5 ppt
bindsym k resize shrink height 5 px or 5 ppt
bindsym l resize grow width 5 px or 5 ppt
# same bindings, but for the arrow keys
#bindsym Left resize shrink width 10 px or 10 ppt
#bindsym Down resize grow height 10 px or 10 ppt
#bindsym Up resize shrink height 10 px or 10 ppt
#bindsym Right resize grow width 10 px or 10 ppt
# back to normal: Enter or Escape
bindsym Return mode "default"
bindsym Escape mode "default"
}
bindsym $mod+Shift+s mode "resize"
mode "(s)leep (h)ybernate (p)owersave (r)estart shut(d)own" {
bindsym s exec sudo pm-suspend; mode "default"
bindsym h exec sudo pm-hibernate; mode "default"
bindsym p exec sudo pm-powersave; mode "default"
bindsym d exec sudo 'shutdown -h now'; mode "default"
bindsym r exec sudo 'shutdown -r now'; mode "default"
bindsym Return mode "default"
bindsym Escape mode "default"
}
bindsym $mod+Shift+n mode "(s)leep (h)ybernate (p)owersave (r)estart shut(d)own"
# Start i3bar to display a workspace bar (plus the system information i3status
# finds out, if available)
bar {
mode dock
status_command i3status --config ~/.i3/i3status.conf
strip_workspace_numbers yes
tray_output primary
verbose yes
}
#!/usr/bin/python3
import json
import re
import subprocess
import sys
I3MSG = 'i3-msg'
#I3MSG = '/usr/bin/i3-msg'
windows = []
def get_pattern():
return str(sys.stdin.readlines()[0]).strip()
def get_tree():
test = subprocess.Popen(["i3-msg","-t","get_tree"], stdout=subprocess.PIPE)
output = test.communicate()[0]
return json.loads(output.decode())
def walk_tree(tree):
if tree['window']:
#print("+ "+tree['name'])
windows.append({
'name': tree['name'],
'id': str(tree['id']),
'focused': tree['focused']
})
if len(tree['nodes']) > 0:
for node in tree['nodes']:
walk_tree(node)
def filter_windows(pattern):
found = list(filter(lambda x: re.search(pattern, x['name']), windows))
if len(found) > 0:
return found
found = list(filter(lambda x: re.search(pattern, x['name'], flags=re.IGNORECASE), windows))
if len(found) > 0:
return found
print("# no match '%s'"%str(pattern))
sys.exit()
def main():
pattern = get_pattern()
#print(" pattern '"+str(pattern)+"'")
tree = get_tree()
walk_tree(tree)
#print(" windows "+str(windows))
#print(" ...size "+str(len(windows)))
focused = False
#focused = filter(lambda x: x['focused'], windows)
#print(" focused "+str(focused))
#if len(focused) == 1:
# focused = focused[0]
#else:
# focused = False
filteredWindows = filter_windows(pattern)
#print(" filteredWindows "+str(filteredWindows))
#print(" ...size "+str(len(filteredWindows)))
if len(filteredWindows) == 0:
sys.exit()
print("# matched %u windows"%len(filteredWindows))
nextWindow = False
try:
if not focused:
raise ValueError
nextIndex = filteredWindows.index(focused) + 1
if nextIndex == len(filteredWindows):
raise ValueError
else:
nextWindow = filteredWindows[nextIndex]
except ValueError:
nextWindow = filteredWindows[0]
con_id = nextWindow['id']
subprocess.call([I3MSG, '[con_id=' + con_id + ']', 'focus'])
if __name__ == '__main__':
main()
#!/usr/bin/python3
import subprocess
import json
windows = []
def walk_tree(tree):
if tree['window']:
#print(tree['window'])
print(" %s"%tree['window_properties']['title'])
windows.append({'window': str(tree['window']),
'focused': tree['focused']})
if len(tree['nodes']) > 0:
for node in tree['nodes']:
walk_tree(node)
test = subprocess.Popen(["i3-msg","-t","get_tree"], stdout=subprocess.PIPE)
output = test.communicate()[0]
data = json.loads(output.decode())
walk_tree(data)
#!/usr/bin/python3
import subprocess
import json
test = subprocess.Popen(["i3-msg","-t","get_workspaces"], stdout=subprocess.PIPE)
output = test.communicate()[0]
data = json.loads(output.decode())
#def ws_cmp(a,b):
# return a['name'] < b['name']
#data = sorted(data, cmp=ws_cmp)
data = sorted(data, key=lambda k: k['name'])
for i in data:
print(i['name'])
#!/usr/bin/python3
import subprocess
import json
import sys
if len(sys.argv) > 1:
req = sys.argv[1]
test = subprocess.Popen(["i3-msg","-t","get_workspaces"], stdout=subprocess.PIPE)
output = test.communicate()[0]
workspaces = json.loads(output.decode())
names = map(lambda i: i['name'], workspaces)
names = sorted(names)
names = list(filter(lambda i: req in i, names))
current = list(filter(lambda i: i['focused'], workspaces))
current = current[0]['name']
try:
found = names.index(current)
names = names[found+1:] + names[0:found]
except ValueError:
pass
name = names[0]
else:
name = sys.stdin.readlines()[0]
test = subprocess.Popen(["i3-msg","workspace "+name], stdout=subprocess.PIPE)
# i3status configuration file.
# see "man i3status" for documentation.
# It is important that this file is edited as UTF-8.
# The following line should contain a sharp s:
# ß
# If the above line is not correctly displayed, fix your editor first!
general {
colors = true
interval = 5
}
order += "ipv6"
order += "disk /"
order += "run_watch DHCP"
order += "run_watch VPN"
order += "wireless wlan0"
order += "ethernet eth0"
order += "battery 0"
order += "load"
order += "tztime local"
wireless wlan0 {
format_up = "W: (%quality at %essid) %ip"
format_down = "W: down"
}
ethernet eth0 {
# if you use %speed, i3status requires root privileges
format_up = "E: %ip (%speed)"
format_down = "E: down"
}
battery 0 {
format = "%status %percentage %remaining"
}
run_watch DHCP {
pidfile = "/var/run/dhclient*.pid"
}
run_watch VPN {
pidfile = "/var/run/vpnc/pid"
}
#time local {
# format = "%Y-%m-%d %H:%M:%S"
#}
load {
format = "%1min"
}
disk "/" {
format = "%avail"
}
#!/usr/bin/python3
import subprocess
import sys
data = sys.stdin.readlines()[0]
test = subprocess.Popen(["i3-msg","move container to workspace "+data], stdout=subprocess.PIPE)
#!/usr/bin/python3
#
# https://faq.i3wm.org/question/2473/run-or-focus-in-i3/
#
# I use it in my configuration like this:
#
# bindsym F1 exec python ~/.i3/scripts/next_window.py "Chrome$" google-chrome
# bindsym F2 exec python ~/.i3/scripts/next_window.py "Sublime Text 2$" sublime-text
#
# The first parameter is a regex to match the window title. The second
# parameter is the application to launch if no active window is found.
import json
import re
import subprocess
import sys
I3MSG = '/usr/bin/i3-msg'
windows = []
def parse_args():
if len(sys.argv) == 3:
return (sys.argv[1], sys.argv[2])
else:
sys.exit('Must provide 2 arguments.')
def get_tree():
process = subprocess.Popen([I3MSG, "-t", "get_tree"], stdout=subprocess.PIPE)
tree = str(process.communicate()[0])
process.stdout.close()
return json.loads(tree)
def walk_tree(tree):
if tree['window']:
windows.append({
'name': tree['name'],
'id': str(tree['id']),
'focused': tree['focused']
})
if len(tree['nodes']) > 0:
for node in tree['nodes']:
walk_tree(node)
def main():
pattern, command = parse_args()
tree = get_tree()
walk_tree(tree)
focused = filter(lambda x: x['focused'], windows)
if len(focused) == 1:
focused = focused[0]
else:
focused = False
filteredWindows = filter(lambda x: re.search(pattern, x['name']), windows)
if len(filteredWindows) == 0:
subprocess.call([I3MSG, 'exec', '--no-startup-id', command])
else:
nextWindow = False
try:
if not focused:
raise ValueError
nextIndex = filteredWindows.index(focused) + 1
if nextIndex == len(filteredWindows):
raise ValueError
else:
nextWindow = filteredWindows[nextIndex]
except ValueError:
nextWindow = filteredWindows[0]
con_id = nextWindow['id']
subprocess.call([I3MSG, '[con_id=' + con_id + ']', 'focus'])
if __name__ == '__main__':
main()
#!/bin/bash
killall i3bar
i3bar --bar_id=bar-0 --socket=$( i3 --get-socketpath )
#!/usr/bin/python3
#
# https://faq.i3wm.org/question/2473/run-or-focus-in-i3/
#
# I wanted something that's similar to awesome's RoR. That is, matching by
# class and cycling through matching windows. gustavnikolaj's solution matches
# by window title, which I didn't want, so I wrote this (the walk_tree function
# is from his script).
#
# Save it in e.g. ~.i3/runorfocus.py. To use it, just call the script (first
# argument is the class to match, the second argument is the program to launch
# if no matching window is found):
#
# bindsym $mod+w exec python ~/.i3/runorfocus.py "Firefox" firefox
#
# Note that you need xdotool to use the script.
import json
import subprocess
import sys
def get_output(cmd):
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
out = process.communicate()[0].decode()
process.stdout.close()
return out
def get_tree():
cmd = ["i3-msg", "-t", "get_tree"]
return json.loads(get_output(cmd))
def get_matching_class():
cmd = ["xdotool", "search", "--class", sys.argv[1]]
return get_output(cmd).split('\n')
windows = []
def walk_tree(tree):
if tree['window']:
windows.append({'window': str(tree['window']),
'focused': tree['focused']})
if len(tree['nodes']) > 0:
for node in tree['nodes']:
walk_tree(node)
def get_matches():
matches = []
tree = get_tree()
check = get_matching_class()
walk_tree(tree)
for window in windows:
for winid in check:
if window['window'] == winid:
matches.append(window)
return matches
def main():
matches = get_matches()
# Sort the list by window IDs
matches = [(match['window'], match) for match in matches]
matches.sort()
matches = [match for (key, match) in matches]
# Iterate over the matches to find the first focused one, then focus the
# next one.
for ind, match in enumerate(matches):
if match['focused'] == True:
subprocess.call(["i3-msg", "[id=%s] focus" % matches[(ind+1)%len(matches)]['window']])
return
# No focused match was found, so focus the first one
if len(matches) > 0:
subprocess.call(["i3-msg", "[id=%s] focus" % matches[0]['window']])
return
# No matches found, launch program
subprocess.call(["i3-msg", "exec", "--no-startup-id", sys.argv[2]])
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment