Chris Siebenmann
2012-02-12 07:32:41 UTC
As a followup to asking about how to do this a while back on the
mailing list (and then asking a related question more recently), I'm
sharing with the list how I have put this together.
The goal: allow me to select terminal windows from the keyboard in a
manner similar to searching for text in a browser: hit a key, start
typing a window name, and have some form of autocompletion. I don't
feel the need to do anything clever if several terminal windows have
the same name and I pick it; which window gets selected can be random.
The tools you'll need in addition to FVWM:
- xwininfo for getting window information. I think this is pretty
standard to have installed.
- dmenu, http://tools.suckless.org/dmenu/, for handling the general
selection process.
I have made a patch for dmenu that adds shell-like partial
autocompletion, which is very useful for this and which my scripts
assume:
http://lists.suckless.org/dev/1202/10851.html
I have a core driver script that I call 'term-front':
#!/bin/sh
# Keyboard selection of terminal windows with completion based on window
# name, via dmenu.
# dmenu will appear at the bottom of the screen.
# Generate a list of unique names of terminal windows.
genwins() {
xwininfo -root -tree |
egrep ': \([^)]* "(XTerm|Gnome-terminal|9term)"\) [0-9]' |
awk '{print $2}' | sed -e 's/^"//' -e 's/":$//' | sort -u
}
# run dmenu to get the answer; exit if dmenu aborted.
win=$(genwins | dmenu -b -P -p win -t) || exit 1
# pass the selected window to my ToWindow function in FVWM.
echo "Function ToWindow \"$win\"" | FvwmCommand -c
exit 0
(You may want to customize what font dmenu uses with '-fn ...'. My
actual script runs a frontend script for dmenu that sets the font
and my preferred dmenu colours; I omitted it here for simplicity.)
In my FVWM config file I have the following relevant bits (in addition
to starting the FvwmCommandS module as part of FVWM startup, so that
FvwmCommand works):
# Invoke terminal selection (ie term-front) via F4.
# Stealing F4 may not be to everyone's tastes; customize to suit.
Key F4 A N Exec exec term-front
# Aggregate all terminal windows together by turning on State 2 for them.
Style "XTerm" State 2
Style "Gnome-terminal" State 2
Style "9term" State 2
# Assist function for window selection via the keyboard.
# Only matches terminal windows (ie windows with State 2 on).
# Invoked as 'Function ToWindow "whatever"'.
# - if the current window is $0, do nothing
# - if there is no window $0, do nothing.
# - otherwise deiconfy, focus, raise, and warp pointer to window.
DestroyFunc ToWindow
AddToFunc ToWindow
+ I Current (State 2, "$0") Break
+ I Next (State 2, "$0") ToWindow2
DestroyFunc ToWindow2
AddToFunc ToWindow2
+ I Iconify False
+ I Focus
+ I Raise
+ I WarpToWindow 80 20
A longer writeup of this with more blathering can be found at:
http://utcc.utoronto.ca/~cks/space/blog/unix/FvwmKeyboardWindows
http://utcc.utoronto.ca/~cks/space/blog/unix/FvwmStatesUndertood
You should read both (if you read them at all) because the second
contains a valuable improvement after I finally understood States
right. I have to thank Thomas Adam for finally getting some important
stuff about States through my evidently thick skull.
- cks
mailing list (and then asking a related question more recently), I'm
sharing with the list how I have put this together.
The goal: allow me to select terminal windows from the keyboard in a
manner similar to searching for text in a browser: hit a key, start
typing a window name, and have some form of autocompletion. I don't
feel the need to do anything clever if several terminal windows have
the same name and I pick it; which window gets selected can be random.
The tools you'll need in addition to FVWM:
- xwininfo for getting window information. I think this is pretty
standard to have installed.
- dmenu, http://tools.suckless.org/dmenu/, for handling the general
selection process.
I have made a patch for dmenu that adds shell-like partial
autocompletion, which is very useful for this and which my scripts
assume:
http://lists.suckless.org/dev/1202/10851.html
I have a core driver script that I call 'term-front':
#!/bin/sh
# Keyboard selection of terminal windows with completion based on window
# name, via dmenu.
# dmenu will appear at the bottom of the screen.
# Generate a list of unique names of terminal windows.
genwins() {
xwininfo -root -tree |
egrep ': \([^)]* "(XTerm|Gnome-terminal|9term)"\) [0-9]' |
awk '{print $2}' | sed -e 's/^"//' -e 's/":$//' | sort -u
}
# run dmenu to get the answer; exit if dmenu aborted.
win=$(genwins | dmenu -b -P -p win -t) || exit 1
# pass the selected window to my ToWindow function in FVWM.
echo "Function ToWindow \"$win\"" | FvwmCommand -c
exit 0
(You may want to customize what font dmenu uses with '-fn ...'. My
actual script runs a frontend script for dmenu that sets the font
and my preferred dmenu colours; I omitted it here for simplicity.)
In my FVWM config file I have the following relevant bits (in addition
to starting the FvwmCommandS module as part of FVWM startup, so that
FvwmCommand works):
# Invoke terminal selection (ie term-front) via F4.
# Stealing F4 may not be to everyone's tastes; customize to suit.
Key F4 A N Exec exec term-front
# Aggregate all terminal windows together by turning on State 2 for them.
Style "XTerm" State 2
Style "Gnome-terminal" State 2
Style "9term" State 2
# Assist function for window selection via the keyboard.
# Only matches terminal windows (ie windows with State 2 on).
# Invoked as 'Function ToWindow "whatever"'.
# - if the current window is $0, do nothing
# - if there is no window $0, do nothing.
# - otherwise deiconfy, focus, raise, and warp pointer to window.
DestroyFunc ToWindow
AddToFunc ToWindow
+ I Current (State 2, "$0") Break
+ I Next (State 2, "$0") ToWindow2
DestroyFunc ToWindow2
AddToFunc ToWindow2
+ I Iconify False
+ I Focus
+ I Raise
+ I WarpToWindow 80 20
A longer writeup of this with more blathering can be found at:
http://utcc.utoronto.ca/~cks/space/blog/unix/FvwmKeyboardWindows
http://utcc.utoronto.ca/~cks/space/blog/unix/FvwmStatesUndertood
You should read both (if you read them at all) because the second
contains a valuable improvement after I finally understood States
right. I have to thank Thomas Adam for finally getting some important
stuff about States through my evidently thick skull.
- cks