<commit_before># Ruby-based configuration file for wmii.
=begin
  Copyright 2006, 2007 <NAME>

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
=end

$: << File.join(File.dirname(__FILE__), 'wmii-irb')
require 'wm'
include Wmii

require 'find'


############################################################################
# CONFIGURATION VARIABLES
############################################################################

MODKEY            = 'Mod1'
UP_KEY            = 't'
DOWN_KEY          = 'n'
LEFT_KEY          = 'h'
RIGHT_KEY         = 's'

MOD_PREFIX        = MODKEY + '-Control-'
MOD_FOCUS         = MOD_PREFIX
MOD_SEND          = MOD_PREFIX + 'm,'
MOD_SWAP          = MOD_PREFIX + 'w,'
MOD_ARRANGE       = MOD_PREFIX + 'z,'
MOD_GROUP         = MOD_PREFIX + 'g,'
MOD_MENU          = MOD_PREFIX
MOD_PROGRAM       = MOD_PREFIX

PRIMARY_CLICK     = 1
MIDDLE_CLICK      = 2
SECONDARY_CLICK   = 3

# Colors tuples are "<text> <background> <border>"
WMII_NORMCOLORS   = '#e0e0e0 #0a0a0a #202020'
WMII_FOCUSCOLORS  = '#ffffff #285577 #4c7899'
WMII_BACKGROUND   = '#333333'
WMII_FONT         = '-*-fixed-medium-r-normal-*-18-*-*-*-*-*-*-*'

WMII_MENU         = "dmenu -b -fn #{WMII_FONT.inspect} #{
                      %w[-nf -nb -sf -sb].zip(
                        WMII_NORMCOLORS.split[0,2] +
                        WMII_FOCUSCOLORS.split[0,2]
                      ).flatten!.map! {|s| s.inspect}.join(' ')
                    }"
WMII_TERM         = 'gnome-terminal'

# export WMII_* constants as environment variables
  self.class.constants.grep(/^WMII_/).each do |c|
    ENV[c] = self.class.const_get c
  end


############################################################################
# WM CONFIGURATION
############################################################################

fs.ctl << <<EOF
font #{WMII_FONT}
focuscolors #{WMII_FOCUSCOLORS}
normcolors #{WMII_NORMCOLORS}
grabmod #{MODKEY}
border 1
EOF


############################################################################
# COLUMN RULES
############################################################################

fs.colrules = <<EOF
/.*/ -> 58+42
EOF


############################################################################
# TAGGING RULES
############################################################################

fs.tagrules = <<EOF
/jEdit.*/ -> code
/Buddy List.*/ -> chat
/XChat.*/ -> chat
/.*thunderbird.*/ -> mail
/xconsole.*/ -> ~
/alsamixer.*/ -> ~
/QEMU.*/ -> ~
/XMMS.*/ -> ~
/Gimp.*/ -> gimp
/MPlayer.*/ -> ~
/.*/ -> !
/.*/ -> 1
EOF


############################################################################
# FUNCTIONS
############################################################################

# Shows a menu with the given items and returns the chosen item.
# If nothing was chosen, then *nil* is returned.
def show_menu *aChoices
  IO.popen(WMII_MENU, 'r+') do |menu|
    menu.puts aChoices
    menu.close_write

    choice = menu.read
    choice unless choice.empty?
  end
end

# Returns the names of programs present in the given directories.
def find_programs *aPaths
  aPaths.flatten!
  aPaths.map! {|p| File.expand_path p}
  list = []

  Find.find(*aPaths) do |f|
    if File.file? f and File.executable? f
      list << File.basename(f)
    end
  end

  list.uniq!
  list.sort!
  list
end


############################################################################
# MISC
############################################################################

PROGRAM_MENU = find_programs ENV['PATH'].squeeze(':').split(':')
ACTION_MENU = find_programs File.dirname(__FILE__)

system 'xsetroot -solid $WMII_BACKGROUND &'


############################################################################
# KEY BINDINGS
############################################################################

# Tag used for wmii-2 style client detaching.
DETACHED_TAG = '^'

SHORTCUTS = {

  ##########################################################################
  ## focusing / showing
  ##########################################################################

  # focus client at left
  MOD_FOCUS + LEFT_KEY => lambda do
    current_view.ctl << 'select left'
  end,

  # focus client at right
  MOD_FOCUS + RIGHT_KEY => lambda do
    current_view.ctl << 'select right'
  end,

  # focus client below
  MOD_FOCUS + DOWN_KEY => lambda do
    current_view.ctl << 'select down'
  end,

  # focus client above
  MOD_FOCUS + UP_KEY => lambda do
    current_view.ctl << 'select up'
  end,

  # toggle focus between floating area and the columns
  MOD_FOCUS + 'space' => lambda do
    current_view.ctl << 'select toggle'
  end,

  # apply equal-spacing layout to current column
  MOD_ARRANGE + 'w' => lambda do
    current_area.layout = :default
  end,

  # apply equal-spacing layout to all columns
  MOD_ARRANGE + 'Shift-w' => lambda do
    current_view.columns.each do |a|
      a.layout = :default<commit_msg>fix 'bad value' exceptions occur upon 'select ...' commands in an empty floating area<commit_after># Ruby-based configuration file for wmii.
=begin
  Copyright 2006, 2007 <NAME>

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
=end

$: << File.join(File.dirname(__FILE__), 'wmii-irb')
require 'wm'
include Wmii

require 'find'


############################################################################
# CONFIGURATION VARIABLES
############################################################################

MODKEY            = 'Mod1'
UP_KEY            = 't'
DOWN_KEY          = 'n'
LEFT_KEY          = 'h'
RIGHT_KEY         = 's'

MOD_PREFIX        = MODKEY + '-Control-'
MOD_FOCUS         = MOD_PREFIX
MOD_SEND          = MOD_PREFIX + 'm,'
MOD_SWAP          = MOD_PREFIX + 'w,'
MOD_ARRANGE       = MOD_PREFIX + 'z,'
MOD_GROUP         = MOD_PREFIX + 'g,'
MOD_MENU          = MOD_PREFIX
MOD_PROGRAM       = MOD_PREFIX

PRIMARY_CLICK     = 1
MIDDLE_CLICK      = 2
SECONDARY_CLICK   = 3

# Colors tuples are "<text> <background> <border>"
WMII_NORMCOLORS   = '#e0e0e0 #0a0a0a #202020'
WMII_FOCUSCOLORS  = '#ffffff #285577 #4c7899'
WMII_BACKGROUND   = '#333333'
WMII_FONT         = '-*-fixed-medium-r-normal-*-18-*-*-*-*-*-*-*'

WMII_MENU         = "dmenu -b -fn #{WMII_FONT.inspect} #{
                      %w[-nf -nb -sf -sb].zip(
                        WMII_NORMCOLORS.split[0,2] +
                        WMII_FOCUSCOLORS.split[0,2]
                      ).flatten!.map! {|s| s.inspect}.join(' ')
                    }"
WMII_TERM         = 'gnome-terminal'

# export WMII_* constants as environment variables
  self.class.constants.grep(/^WMII_/).each do |c|
    ENV[c] = self.class.const_get c
  end


############################################################################
# WM CONFIGURATION
############################################################################

fs.ctl << <<EOF
font #{WMII_FONT}
focuscolors #{WMII_FOCUSCOLORS}
normcolors #{WMII_NORMCOLORS}
grabmod #{MODKEY}
border 1
EOF


############################################################################
# COLUMN RULES
############################################################################

fs.colrules = <<EOF
/.*/ -> 58+42
EOF


############################################################################
# TAGGING RULES
############################################################################

fs.tagrules = <<EOF
/jEdit.*/ -> code
/Buddy List.*/ -> chat
/XChat.*/ -> chat
/.*thunderbird.*/ -> mail
/xconsole.*/ -> ~
/alsamixer.*/ -> ~
/QEMU.*/ -> ~
/XMMS.*/ -> ~
/Gimp.*/ -> gimp
/MPlayer.*/ -> ~
/.*/ -> !
/.*/ -> 1
EOF


############################################################################
# FUNCTIONS
############################################################################

# Shows a menu with the given items and returns the chosen item.
# If nothing was chosen, then *nil* is returned.
def show_menu *aChoices
  IO.popen(WMII_MENU, 'r+') do |menu|
    menu.puts aChoices
    menu.close_write

    choice = menu.read
    choice unless choice.empty?
  end
end

# Returns the names of programs present in the given directories.
def find_programs *aPaths
  aPaths.flatten!
  aPaths.map! {|p| File.expand_path p}
  list = []

  Find.find(*aPaths) do |f|
    if File.file? f and File.executable? f
      list << File.basename(f)
    end
  end

  list.uniq!
  list.sort!
  list
end


############################################################################
# MISC
############################################################################

PROGRAM_MENU = find_programs ENV['PATH'].squeeze(':').split(':')
ACTION_MENU = find_programs File.dirname(__FILE__)

system 'xsetroot -solid $WMII_BACKGROUND &'


############################################################################
# KEY BINDINGS
############################################################################

# Tag used for wmii-2 style client detaching.
DETACHED_TAG = '^'

SHORTCUTS = {

  ##########################################################################
  ## focusing / showing
  ##########################################################################

  # focus client at left
  MOD_FOCUS + LEFT_KEY => lambda do
    current_view.ctl << 'select left' rescue nil
  end,

  # focus client at right
  MOD_FOCUS + RIGHT_KEY => lambda do
    current_view.ctl << 'select right' rescue nil
  end,

  # focus client below
  MOD_FOCUS + DOWN_KEY => lambda do
    current_view.ctl << 'select down' rescue nil
  end,

  # focus client above
  MOD_FOCUS + UP_KEY => lambda do
    current_view.ctl << 'select up' rescue nil
  end,

  # toggle focus between floating area and the columns
  MOD_FOCUS + 'space' => lambda do
    current_view.ctl << 'select toggle'
  end,

  # apply equal-spacing layout to current column
  MOD_ARRANGE + 'w' => lambda do
    current_area.layout = :default
  end,

  # apply equal-spacing layout to all columns
  MOD_ARRANGE + 'Shift-w' => lambda do
    current_view.columns.each do |a|
      a.layout = :default
{'fraction_non_alphanumeric': 0.30645448079658605, 'fraction_numerical': 0.011735419630156473, 'mean_word_length': 3.6695724366957245, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5348961', 'n_tokens_mistral': 3448, 'n_tokens_neox': 3197, 'n_words': 919}