Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
leahneukirchen committed Mar 20, 2011
1 parent e7967e5 commit e58e854
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
22 changes: 22 additions & 0 deletions b
@@ -0,0 +1,22 @@
#!/bin/sh
# b - trivial commandline browser

STORE="/tmp/b-$HOSTNAME.$USER"

case "$TERM" in
9term|win) PAGER=cat;;
*) PAGER=less; LESS=-FX;;
esac

case "$1" in
[0-9]*)
$0 "$(awk '/^References/,0' <$STORE |
N=$1 awk '$1 == ENVIRON["N"] { print $2 }')";;
*/*|*.*)
lynx --dump "$1" | tee $STORE | $PAGER;;
?*)
$0 "http://www.google.com/search?ie=utf-8&oe=utf-8&q=$*";;
*)
# empty
$PAGER $STORE 2>/dev/null
esac
13 changes: 13 additions & 0 deletions base
@@ -0,0 +1,13 @@
#!/usr/bin/env ruby
# base - convert between bases

abort "usage: base NUMBERS..." if ARGV.empty?

ARGV.each { |s|
begin
n = Integer(s)
puts "%s = %08b %d 0%o 0x%x" % [s, n, n, n, n]
rescue ArgumentError
warn "base: invalid number '#{s}'"
end
}
11 changes: 11 additions & 0 deletions hyp
@@ -0,0 +1,11 @@
#!/bin/sh
# hyp - look up hyphenation on wiktionary

case "$1" in
-??) lang=$1; shift;;
esac

for word; do
curl -s http://${lang:-de}.wiktionary.org/wiki/$word | grep -Po '[^\s>]+·[^\s,<]+' | head -1 | sed 's/·/\\-/g'
done

78 changes: 78 additions & 0 deletions randrmove
@@ -0,0 +1,78 @@
#!/usr/bin/env ruby -s
# randrmove [-rp] [CRTC...] - cycle windows between xrandr "screens"
# By default, cycle left-to-right.
# -r to reverse the order
# -p to try to keep proportions screen layout
# Needs xrandr, xdotool, xwininfo.

# TODO:
# * fix negative offsets
# * resize windows?
# * base proportions on smallest distance to margin

cycle = ARGV

screens = {}

minfo = `xdotool getmouselocation`
mx = minfo[/x:(\d+)/, 1].to_i
my = minfo[/y:(\d+)/, 1].to_i

`xrandr --current`.each_line { |line|
fields = line.split
if fields[1] == "connected"
screens[fields[0]] = fields[2].split(/[x+]/).map { |n| n.to_i }
end
}

if cycle.empty?
cycle = screens.sort_by { |_, (_, _, sx, sy)| [sx,sy] }.map { |s, _| s }
end

cycle.reverse! if $r

abort "unknown screens: #{cycle-screens.keys}" unless (cycle-screens.keys).empty?

`xdotool search --name --onlyvisible .`.each_line { |windowid|
windowid.chomp!
winfo = `xwininfo -id #{windowid}`

info = []
["Absolute upper-left X", "Absolute upper-left Y", "Width", "Depth"].each { |f|
info << winfo[/#{f}: *(\d+)/, 1].to_i
}

x, y, w, h = *info

# find screen where window occupies most space
screen = screens.sort_by { |_, (sw, sh, sx, sy)|
[0, [sx+sw, x+w].min - [sx, x].max].max *
[0, [sy+sh, y+h].min - [sy, y].max].max
}.first.first

target = cycle[(cycle.index(screen)+1) % cycle.size] rescue screen

next if screen == target

sw,sh,sx,sy = screens[screen]
tw,th,tx,ty = screens[target]

if $p
# *(sw.to_f/tw)).to_i
puts "windowmove #{windowid} #{(sx+(x-tx)*(sw.to_f/tw)).to_i} #{(sy+(y-ty)*(sw.to_f/tw)).to_i} # #{sx-tx} #{sy-ty}"
else
puts "windowmove #{windowid} #{x+sx-tx} #{y+sy-ty} # #{sx-tx} #{sy-ty}"
end
}

mscreen = screens.sort_by { |_, (sw, sh, sx, sy)|
[0, [sx+sw, mx+1].min - [sx, mx].max].max *
[0, [sy+sh, my+1].min - [sy, my].max].max
}.first.first

mtarget = cycle[(cycle.index(mscreen)+1) % cycle.size] rescue exit

_,_,sx,sy = screens[mscreen]
_,_,tx,ty = screens[mtarget]

puts "mousemove #{mx+sx-tx} #{my+sy-ty} # #{sx-tx} #{sy-ty}"

0 comments on commit e58e854

Please sign in to comment.