# Multiple keyboard layouts



## a1111exe (Mar 4, 2012)

Hi everyone,

I'm not sure if this is a right branch to open such a thread, but the keyboard is a really shiny gadget for me - *I* use it a lot, and *I* love using it, and *I* need (in capital letters) to use it in some special ways as described below. 

Simple as it is: *I* need the ability in fast and convenient switching keyboard layouts between English, Hebrew, and Russian. Something like famous alt+shift from well known OS. I have being trying hard to Google this issue, but all *I* got until this moment is feeling a complete idiot.

Ok, *I*'m a noob, but not an idiot. I just need someone to point me such sequence of manuals and howtos that *I* could read through them and implement a real life practical solution.

I really don't want to give up FreeBSD, and *I* believe that *I* don't have to. But *I* have to work in system that supports the described demand, no other option.

Thanks a lot!


----------



## bbzz (Mar 5, 2012)

It's pretty simple. Change layout with *setxkbmap*, like so:
[CMD=""]setxkbmap us[/CMD]
[cmd=""]setxkbmap ru[/cmd]

Bind commands with specific key sequence (that depends on your desktop environment).


----------



## a1111exe (Mar 5, 2012)

bbzz said:
			
		

> It's pretty simple. Change layout with *setxkbmap*, like so:
> [CMD=""]setxkbmap us[/CMD]
> [cmd=""]setxkbmap ru[/cmd]
> 
> Bind commands with specific key sequence (that depends on your desktop environment).



Thank you for advise and such a fast attention! 

Though it's questionable if this will be so simple for me, because it seems that to achieve a habitual alt+shift behavior *I* have to find out a command(s) to detect which layout is on, and write some little conditional script.

At l*ea*st *I* have a clue. And *I* obviously missed something when trying to Google this up. Sorry for bothering.


----------



## a1111exe (Mar 9, 2012)

Well, hello again. 

I just want to clarify that it was not so simple, and *I* finally have written my first script in bash. With the Lord's bless that's how the resolution is achieved (at least in my case):

1. The script:


```
#!/usr/local/bin/bash
if [ ! -f /home/learning/l_ch ]; then
    setxkbmap ru
    echo ru > /home/learning/l_ch
elif grep -q ru /home/learning/l_ch; then
    setxkbmap il
    echo he > /home/learning/l_ch
elif grep -q he /home/learning/l_ch; then
    setxkbmap us
    echo en > /home/learning/l_ch
elif grep -q en /home/learning/l_ch; then
    setxkbmap ru
    echo ru > /home/learning/l_ch
fi
```

At first *I* tried to manage things through environment variables. Very fast *I* discovered that

1) it's from hard to nearly impossible (need to be a genius or magician) to script in tcsh/csh;
2) bash scripts can run but can't set the environment variables in tcsh/csh environment (so *I* constantly switched my shells to bash);
3) my very first fancy shiny script that uses environment variables in bash environment works fine from prompt but when it comes to run it from lxde-rc.xml - this theory thing that the child shell can't change variables of the parent shell becomes very real; *I* tried to trick it with *source scriptname*, but it seems that lxde-rc.xml can't handle sequences of commands or it's just me that couldn't find out how to make it handle this; so *I* had to put my variable in a file, and after some pain received the working script that can be successfully run from lxde-rc.xml:


```
[root@learning_pc /home/learning/.config/openbox]# ls
lxde-rc.xml
```


```
...
  </keybind>
  <!-- Change language layouts -->
  <keybind key="W-Tab">
      <action name="Execute">
          <command>l_switch_1.sh</command>
      </action>
  </keybind>
      
</keyboard>
```

So it was that simple. And now I have another problem: how can *I* manage that switching language will work only on active window? It should be possible (*I* saw this in Windows and Ubuntu on e17), and *I*'ll be happy if someone will turn me in the right way.

Thanks again!


----------



## kpa (Mar 9, 2012)

You script should work without any modification as a /bin/sh script. In general try to avoid writing shell scripts that require a non standard shell, stick to sh(1).


----------



## a1111exe (Mar 9, 2012)

kpa said:
			
		

> You script should work without any modification as a /bin/sh script. In general try to avoid writing shell scripts that require a non standard shell, stick to sh(1).


And why is that? It's *Free*BSD, isn't it? 
If *I* wanted to stick to something that just works *I*'d stick to windows. On the other hand why should *I* learn a couple of shells when *I* can learn only one that
1) has more tutorials, and (far) more Google-searchable;
2) usable on other *nix operating systems and default on many Linux distributions (*I* have Ubuntu with e17 at work so it is very relevant for me)?

The time is of the essence, and maybe it'll be more wise to spend some spare time to study some serious scripting language (e.g. Python) than a couple of shells.


----------



## kpa (Mar 9, 2012)

/bin/sh is available on every single installation of FreeBSD, shells/bash is an optionally installed port/package.


----------



## a1111exe (Mar 9, 2012)

kpa said:
			
		

> /bin/sh is available on every single installation of FreeBSD, shells/bash is an optionally installed port/package.


I can't imagine myself in a situation, where *I* have to script on FreeBSD system and have no option to change the shell. In such a situation (can't change shell, can't install GIMP, can't install Inkscape, can't install VirtualBox, etc) *I* just leave to more friendly system/environment.


----------



## DutchDaemon (Mar 9, 2012)

Keep ignoring well-intended advice, and we'll see what happens after an upgrade of devel/gettext.


----------



## a1111exe (Mar 13, 2012)

DutchDaemon said:
			
		

> Keep ignoring well-intended advice, and we'll see what happens after an upgrade of devel/gettext.


So move other shells out of ports/packages if it is so unstable/forbidden/punishing to use them.

And what happens? I'll tell you: there are plenty of other operating systems in the world. Don't be mad at me - it's true. I use FreeBSD now for only one purpose: learning. So *I*'m not afraid to reinstall it a couple of times. If *I*'ll like it *I*'ll stay with it, if not - *I*'m not scared, sorry.


----------



## DutchDaemon (Mar 13, 2012)

Oh, learn you will ..


----------



## a1111exe (Mar 15, 2012)

DutchDaemon said:
			
		

> Oh, learn you will ..



That's the point. But not sh, not in the first place


----------

