Administration
  Home arrow Administration arrow Page 4 - Customizing the User Environment in BS...
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ADMINISTRATION

Customizing the User Environment in BSD
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2006-12-07

    Table of Contents:
  • Customizing the User Environment in BSD
  • Hack 2: Useful tcsh Shell Con
  • Hack 3: Create Shell Bindings
  • Hack 4: Use Terminal and X Bindings

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Route your faxes to your email inbox. Private, secure fax numbers available from CallWave. Choose your fax number.

    Customizing the User Environment in BSD - Hack 4: Use Terminal and X Bindings
    (Page 4 of 4 )

    Take advantage of your terminal’s capabilities.

    It’s not just thetcshshell that is capable of understanding bindings. Your FreeBSD terminal provides thekbdcontrolcommand to map commands to your keyboard. Unfortunately, neither NetBSD nor OpenBSD offer this feature. You can, however, remap your keyboard under X, as described later.

    Creating Temporary Mappings

    Let’s start by experimenting with some temporary mappings. The syntax for mapping a command withkbdcontrolis as follows:

      kbdcontrol -f number "command"

    Table 1-2 lists the possible numbers, each with its associated key combination.

    Table 1-2. Key numbers

    Number

    Key combination

    1, 2, . . . 12

    F1, F2, . . . F12

    13, 14, . . . 24

    Shift+F1, Shift+F2, . . . Shift+F12

    25, 26, . . . 36

    Ctrl+F1, Ctrl+F2,. . . Ctrl+F12

    Table 1-2. Key numbers (continued)

    Number

    Key combination

    37, 38, . . . 48

    Shift+Ctrl+F1, Shift+Ctrl+F2, . . . Shift+Ctrl+F12

    49

    Home

    50

    Up arrow

    51

    Page Up

    52

    Numpad - (Num Lock off)

    53

    Left arrow (also works in editor)

    54

    Numpad 5 (without Num Lock)

    55

    Right arrow

    56

    Numpad + (without Num Lock)

    57

    End

    58

    Down arrow (affects c history)

    59

    Page Down

    60

    Ins

    61

    Del

    62

    Left GUI key (Windows icon next to left Ctrl)

    63

    Right GUI key (Windows icon next to right Alt)

    64

    Menu (menu icon next to right Ctrl)

    Those last three key combinations may or may not be present, depending upon your keyboard. My Logitech keyboard has a key with a Windows icon next to the left Ctrl key; that is the left GUI key. There’s another key with a Windows icon next to my right Alt key; this is the right GUI key. The next key to the right has an icon of a cursor pointing at a square containing lines; that is the Menu key.

    Now that we know the possible numbers, let’s maplynxto the Menu key:

      % kbdcontrol -f 64 "lynx"

    Note that the command must be contained within quotes and be in your path. (You could give an absolute path, but there’s a nasty limitation coming up soon.)

    If I now press the Menu key,lynxis typed to the terminal for me. I just need to press Enter to launch the browser. This may seem a bit tedious at first, but it is actually quite handy. It can save you from inadvertently launching the wrong application if you’re anything like me and tend to forget which commands you’ve mapped to which keys.

    Let’s see what happens if I modify that original mapping somewhat:

      % kbdcontrol -f 64 "lynx www.google.ca"
      kbdcontrol: function key string too long (18 > 16)

    When doing your own mappings, beware that the command and its arguments can’t exceed 16 characters. Other than that, you can pretty well map any command that strikes your fancy.

    Shell Bindings Versus Terminal Bindings

    Before going any further, I’d like to pause a bit and compare shell-specific bindings, which we saw in “Create Shell Bindings” [Hack #3], and the terminal-specific bindings we’re running across here.

    One advantage of usingkbdcontrol is that your custom bindings work in any terminal, regardless of the shell you happen to be using. A second advantage is that you can easily map to any key on your keyboard. Shell mappings can be complicated if you want to map them to anything other than “Ctrl letter”.

    However, the terminal mappings have some restrictions that don’t apply to thetcshmappings. For example, shell mappings don’t have a 16 character restriction, allowing for full pathnames. Also, it was relatively easy to ask the shell to press Enter to launch the desired command.

    Terminal bindings affect only the current user’s terminal. Any other users who are logged in on different terminals are not affected. However, if the mappings are added to rc.conf (which only the superuser can do), they will affect all terminals. Since bindings are terminal specific, even invokingsuwon’t change the behavior, as the user is still stuck at the same terminal.

    More Mapping Caveats

    There are some other caveats to consider when choosing which key to map. If you use thetcshshell and enjoy viewing your history [Hack #1], you’ll be disappointed if you remap your up and down arrows. The right and left arrows can also be problematic if you use them for navigation, say, in a text editor. Finally, if you’re physically sitting at your FreeBSD system, F1 through F8 are already mapped to virtual terminals and F9 is mapped to your GUI terminal. By default, F10 to F12 are unmapped.

    If you start experimenting with mappings and find you’re stuck with one you don’t like, you can quickly return all of your keys to their default mappings with this command:

      % kbdcontrol -F

    On the other hand, if you find some new mappings you absolutely can’t live without, make them permanent. If you have superuser privileges on a FreeBSD system you physically sit at, you can carefully add the mappings to /etc/rc.conf. Here, I’ve added two mappings. One maps lynx to the Menu key and the other maps startx to the left GUI key:

      keychange="64 lynx"
     
    keychange="62 startx"

    Since the superuser will be setting these mappings, the mapped keys will affect all users on that system. If you want to save your own personal mappings, add your specifickbdcontrolcommands to the end of your shell configuration file. For example, I’ve added these to the very end of my ~/.cshrc file, just before the last line which saysendif:

      % kbdcontrol -f 64 "lynx"
      % 
    kbdcontrol -f 62 "startx"

    Making Mappings Work with X

    This is all extremely handy, but what will happen if you try one of your newly mapped keys from an X Window session? You can press that key all you want, but nothing will happen. You won’t even hear the sound of the system bell beeping at you in protest. This is because the X protocol handles all input and output during an X session.

    You have a few options if you want to take advantage of keyboard bindings while in an X GUI. One is to read the documentation for your particular window manager. Most of the newer window managers provide a point and click interface to manage keyboard bindings. My favorite alternative is to try thexbindkeys_configapplication, which is available in the ports collection [Hack #84]:

      # cd /usr/ports/x11/xbindkeys_config 
      #
    make install clean

    This port also requires xbindkeys:

      # cd /usr/ports/x11/xbindkeys
      # make install clean

    Rather than building both ports, you could instead add this line to /usr/ports/x11/xbindkeys_config/Makefile:

       BUILD_DEPENDS= xbindkeys:${PORTSDIR}/x11/xbindkeys

    This will ask thexbindkeys_configbuild to install both ports.

    Once your builds are complete, open anxtermand type:

      % xbindkeys --defaults  
    ~/.xbindkeysrc
      
      %
    xbindkeys_config

    The GUI in Figure 1-1 will appear.


    Figure 1-1.  The xbindkeys_config program

    Creating a key binding is a simple matter of pressing the New button and typing a useful name into the Name: section. Then, press Get Key and a little window will appear. Press the desired key combination, and voilà, the correct mapping required by X will autofill for you. Associate your desired Action:, then press the Save & Apply & Exit button.

    Any keyboard mappings you create using this utility will be saved to a file called ~/.xbindkeysrc.

    See Also

    • man kbdcontrol
    • man atkbd 
    • Thexbindkeysweb site (http://hocwp.free.fr/xbindkeys/ xbindkeys.html)

    Please check back next week for the continuation of this article.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · This article is an excerpt from the book "BSD Hacks," published by O'Reilly. We hope...
     

    Buy this book now. This article is excerpted from the book BSD Hacks, written by Dru Lavigne (O'Reilly; ISBN: 0596006799). Check it out today at your favorite bookstore. Buy this book now.

       

    ADMINISTRATION ARTICLES

    - Configuring Load-Balanced Clusters
    - Load-Balanced Clusters
    - UNIX Time Format Demystified
    - Making Changes in the CVS
    - Building Your First CVS Repository
    - CVS Quickstart Guide
    - Authorizing Users in Samba
    - Handling User Accounts in Samba
    - Authentication in Samba
    - Accounts, Authentication, and Authorization
    - Advanced Concepts on Dealing with Files and ...
    - Dealing with Files and Filesystems
    - More Hacks for the User Environment in BSD
    - Personalizing the User Environment in BSD
    - Customizing the User Environment in BSD

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway