dotfiles

<-- duh.
git clone https://hhvn.uk/dotfiles
git clone git://hhvn.uk/dotfiles
Log | Files | Refs | Submodules | LICENSE

main (1463B)


      1 #!/bin/rc
      2 
      3 . $home/.config/bspwm/conf
      4 
      5 # variables {{{
      6 monitors = `{bspc query -M --names}
      7 desktops = `{bspc query -D --names}
      8 report   = `:$nl{bspc wm -g | sed 's/^W//'}
      9 # }}}
     10 
     11 # utility functions {{{
     12 fn cmd {
     13 	cmds = ($cmds $*)
     14 }
     15 
     16 fn die {
     17 	printf 'error: %s\n' $1 >[1=2]
     18 	exit 1
     19 }
     20 
     21 fn lshift {
     22 	_lshift=$* *=$$1 {
     23 		shift $_lshift(2)
     24 		$_lshift(1)=$*
     25 	}
     26 }
     27 # }}}
     28 
     29 cmd configure_monitors #{{{
     30 fn configure_monitors {
     31 	dunused = ()
     32 	mmain = ()
     33 
     34 	for (m in $c_monpriority) {
     35 		if (~ $m $monitors) {
     36 			mmain = $m
     37 			break
     38 		}
     39 	}
     40 
     41 	if (~ $mmain ())
     42 		mmain = $monitors(1)
     43 
     44 	for (d in $c_desktops) {
     45 		d = `' '$nl{echo $d}
     46 		m = $d(1)
     47 		lshift d
     48 
     49 		if (! ~ $m $monitors) {
     50 			dunused = ($dunused $d)
     51 		} else if (~ $m $mmain) {
     52 			dmain = $d
     53 		} else {
     54 			assign_desktops $m $d
     55 		}
     56 	}
     57 
     58 	dmain = `$nl{echo $dunused $dmain | tr ' ' '\n' | sort -n}
     59 
     60 	assign_desktops $mmain $dmain
     61 
     62 	# Delete the automatically created desktops
     63 	for (m in $monitors) {
     64 		bspc desktop Desktop -r
     65 	} >[2]/dev/null
     66 }
     67 # }}}
     68 cmd assign_desktops #{{{
     69 fn assign_desktops {
     70 	if (~ $2 ())
     71 		die 'usage: <monitor> desktops'
     72 
     73 	m = $1
     74 	shift
     75 	d = $*
     76 
     77 	for (d in $d) {
     78 		if (~ $d $desktops) {
     79 			bspc desktop $d -m $m
     80 		} else {
     81 			bspc monitor $m -a $d
     82 		}
     83 	}
     84 }
     85 #}}}
     86 cmd main #{{{
     87 fn main {
     88 	cd `$nl{dirname $0}
     89 	for (c in $cmds) {
     90 		ln -s main `$nl{echo $c | tr '_' '-'}
     91 	}
     92 }
     93 # }}}
     94 
     95 cmd = `$nl{basename $0 | tr '-' '_'}
     96 if (~ $cmd $cmds) {
     97 	$cmd $*
     98 } else {
     99 	echo 'Unrecognized command: ' ^ $cmd
    100 }