Keymap issues with NX from Mac OS X Lion to Ubuntu - macos

I have issues with the keymap of my NX session being garbled.
I have a Macbook Air running OS X Lion. I use OpenNX to start a session with an Ubuntu server running FreeNX. The session type is Gnome.
My keymap is very off (eg. w gives =, delete gives ",", t gives w). I tried:
xmodmap -pke > nxclient.xmodmap
on the client and,
xmodmap nxclient.xmodmap
on the server and I recover many of my keys, but it is still unusable. I tried the Gnome keyboard layouts but none worked. The problem also occurs with an XFCE session.
I would appreciate any tips. x2go worked on client and server using Gnome with no issues. Unfortunately, it does not work on Mac OS X Lion currently.

I found a surprisingly simple solution: disconnect the X2Go session and reconnect. This fixes the Mac keyboard issue for me (which seems to persist beyond OS X Lion).

I wanted to provide a complete practical solution. I was experiencing the same problem on some Fedora FC20 machines. That's the complete how-to that should work copying and pasting.
username is your username to connect remotely using ssh to the machine you need to run x2go on and machine is the hostname of that machine.
NOTE: If you have custom keymappings on the target machine they tend to mess up with x2go. To make this work I needed to reset the keymappings and set a bare English (US). I was using International English (US) with Dead keys and it was not working...
Has been tested on Mac Book Pro Mid 2010, 2011 and 2013. New Retina machines seem to not be affected by this bug.
Create a keymap definition file using xmodmap on your local machine (the client machine), XQuartz might be necessary for having this command available. It's also necessary to use x2go by the way.
xmodmap -pke > osx-keymap
If xmodmap is not found that means it's not in the PATH, if you installed XQuartz the command should be placed in /usr/X11/bin/xmodmap so instead of using just xmodmap prepend to it the full path.
Append some modifiers to the file (as from the ato answer)
echo '! Now reset all the modifiers too
!
clear shift
clear lock
clear control
clear mod1
clear mod2
clear mod3
clear mod4
clear mod5
add shift = Shift_L Shift_R
add lock = Caps_Lock
add control = Control_L Control_R
add mod1 = Alt_L Alt_R
add mod2 = Meta_L Meta_R' >> osx-keymap
Load the file on the machine (username is your username to login on the machines. Change it!)
scp osx-keymap username#machine:~/.Xmodmap
Create a script on the Desktop that can be run just using the mouse if the keyboard does not work
ssh username#machine <<"STR"
echo '#/usr/bin/env bash
xmodmap ~/.Xmodmap;'>~/Desktop/fix_keyboard.sh; chmod +x ~/Desktop/fix_keyboard.sh
STR
Connect with x2go. Basically it should work.
If it still does not work try to:
disconnect and reconnect with x2go
click on the run_keyboard.sh on the desktop with the mouse and select Run.
as before but then disconnect and reconnect with x2go
Unfortunately is not a complete solution. Some computers are reported to not work with it

Append this to the end of your nxclient.xmodmap generated by xmodmap -pke to get a usable layout:
!
! Now reset all the modifiers too
!
clear shift
clear lock
clear control
clear mod1
clear mod2
clear mod3
clear mod4
clear mod5
add shift = Shift_L Shift_R
add lock = Caps_Lock
add control = Control_L Control_R
add mod1 = Alt_L Alt_R
add mod2 = Meta_L Meta_R

This answer was given by #Simon in the comments of the question and works for me (x2go / Xquartz):
On OSX do:
xmodmap -pke > keymap-x2go-osx.xmodmap
echo "xmodmap ~/keymap-x2go-osx.xmodmap" > x2go-xinit
Edit keymap-x2go-osx.xmodmap and add modifier reset from #ato’s answer, then copy it to the VM:
scp keymap-x2go-osx.xmodmap -P your_port your_ip:/home/your_user/
scp x2go-xinit -P your_port your_ip:/home/your_user/.xinit

What has worked for me has been going to the system menu -> keyboard -> Layouts tab -> keyboard model -> apple -> Macintosh old. However, there are issues. I can't seem to use Control+C, Control+V, or the arrow keys. If your arrow keys do work I would be grateful if you told me what your .nxs keyboard options look like.

We had the same problem, though running xfce, which is similiar to gnome2 though. I just found a solution (running Mac OSX 10.9.1):
Download the newest x2go client (4.0.1.3 at time of posting)
Setup your x2go-session to "automatically detect keyboard settings"
Connect and realize that e.g. tabulator is only working when you are additionally pressing the control key.
Solution: Edit the keyboard shortcuts in "~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml" (on the server) and delete the entry which is set up to "Super + Tab"
Enjoy your functional keyboard
Credits go to goofrider.

Try to change your Shell from tcsh to bash. Tcsh cause keyboard problem.

You can simply fix by changing one setting in Xquarts. To fix:
Open Xquarts
Go to preferences
Check follow system keyboard layout.
Done!

Related

How do I more easily copy and paste all the content in open file on remote server over ssh using tmux and iterm2?

Problem: I'm on a mac running a tmux server. Within my local tmux session, I connect to a remote linux server and open a file with vim. The text I want does not fit in a single pane without having to scroll. I want to grab the text in the file and copy and paste all of it to my local machine's memory.
Current Solution:
My current procedure for copying and pasting is very convoluted:
Zoom on the pane with ctl-b z
Turn off numbering in vim with :set nonumber
If the file or text I want does not fit in entire pane, I hit cmd - until the text is small enough to fit in the entire pane
Select text I need with my mouse while holding down the option key.
Hit cmd-c to copy to my local machine.
Better Solution?
My current solution is tedious and I'm tired of wondering if there is a better way. Anyone got a better solution?
Ideally, I'd love to be able to select the text with vim and have iterm2 somehow detect what has been selected in a pane and run a single keystroke to copy to my local machine. Not sure if that's possible or not.
OK, I went with the solution at github.com/wincent/clipper which works on my mac running macos 11.2.3.
The install instructions seem to be a little dated and are a bit confusing if you don't read them carefully. It took some trial and error to figure out how to get this working with vim on the remote machine:
Install with brew on your mac
Launch clipper as a daemon with brew services start clipper
On the remote machine, add the following line to your vimrc file:
nnoremap <leader>y :call system('nc -q 1 localhost 8377', #0)<CR>
Note: I had to add the -q 1 in there because I found vim would hang otherwise. The -q 1 arguments are not in the official documentation.
In your mac's ~/.ssh/config file:
Host *
RemoteForward 8377 localhost:8377
Make sure your remote server has port 8377 open!
On the remote machine, open a file with vim. Yank some lines. Then hit <leader>y.
Note: It took a while before it finally dawned on me that just <leader>y doesnt' work by itself. It's a two-step vim command process: 1) yank the text with a vim command 2) send the copied text to your mac with <leader>y.
That's it. My life feels so much better now. :)

How to open GUI app with different $HOME path in Mac OS X

I'm wondering how I might go about opening a Mac OS X application using a different $HOME path.
Specifically, I'm trying to start a browser and have different sessions, so they don't interfere with each other.
I tried HOME=/Users/daniel/test open /Applications/Firefox.app/ via BASH, but it didn't work (opened using the existing session from ~/Library). man open didn't offer any help.
I then tried creating a different user and did sudo su mickey -c 'open /Applications/Firefox.app/' andsudo su mickey -lc 'open /Applications/Firefox.app/', hoping I could at least launch an app as a different user (works in Linux), but again no donut, and man su doesn't help here either. It still just opened using my ~/Library stuff.
I know there's some funkiness with environment variables and BASH vs. WM, and I'm guessing I need to do some plist-y magic, but I'm not sure how to go about it.
Any ideas?
TIA,
Daniel :)
You can try to do it using launchctl. See the Daemons and Services Programming Guide. You will need to create a plist for the one-time job. There is a UserName key (see the launchd.plist man).

iTerm 2 profiles

I have recently switched over to iTerm2 and love it. I am wondering though if there is a way to use profiles to correspond to what environment/specific machine you are on.
Say if I am doing tasks in one window on my mac the profile is displayed as default, but if I ssh into a machine (lets say dev0), the profile on iTerm will update to profile dev0. Once I've finished with dev0 and call exit, the profile will switch to default again.
I realize one work around is to open up a specific profile whenever I want to ssh into another machine and have a way to distinguish, but if the connection is closed it requires you to notice based off text rather than say the background of the window.
Is this possible? If not how can this feature be added, and is there a way I can contribute?
iTerm2 supports a custom escape code that changes the profile on the fly. Put it in your .bashrc or .bash_profile.
<esc>]50;SetProfile=X^G
where X is the profile. For instance, to change the profile to one called "Foo", us this shell script:
#!/bin/bash
echo -e "\033]50;SetProfile=Foo\a"
To change it back when you log out, put code to change the profile back to default in ~/.bash_logout.
for zsh users
lets say you have 2 profiles, one named mac (for your primary machine) and one for linux (your remote machine)
when entering the session, we need to tell zsh to load our profile
connect to remote linux
in ~/.zshrc add echo -e "\033]50;SetProfile=linux\a"
source your files for immediate effect: source ~/.zshrc
your new theme should be visible within the iterm session.
when exiting the session, we need to tell zsh to switch back to our original profile
connect to remote linux
in linux ~/.zlogout add the following
if [ "$SHLVL" = 1 ]; then
echo -e "\033]50;SetProfile=mac\a"
clear
fi
now you can swap profiles with ease <3.
if you are using bash, i believe the steps are similar but you would instead modify ~/.bashrc and ~/.bash_logout
demo
The latest iTerm2 nightly (Build 2.9.20150329-nightly at the time of writing) allows you to do that easily. You can download it here.
Once you've installed and opened it:
Log in to your remote machine via ssh and click iTerm2 (the app menu) > Install Shell Integration. It will download a script with curl and install it. Do the same on your local machine.
Go to Preferences > Profiles.
Create a new profile for your local machine. Customize it to fit your needs (change background color, name, etc)
Go to the Advanced tab and scroll to the bottom.
In Automatic Profile Switching, click '+' and add the hostname of your local machine. The hostname is the one you get when running echo $HOST on the target machine. It is not always the one you see in your prompt.
Create another profile, this time for your remote machine, and customize it.
Add the hostname of the remote machine in Automatic Profile Switching.
Now, if you ssh into the remote machine, your profile will change, and if you exit out of the ssh session, you will be back to your local profile.
You can combine this solution with #esod's answer seamlessly.
Note: it didn't work for me until I created a profile specifically for the desktop instead of using the default profile.
See the documentation for more info.
step 1:
custom your iterm profile, e.g. dark, light
step 2:
add code before to your shell profile, e.g .bashrc or .zshrc
# Change iterm2 profile. Usage it2prof ProfileName (case sensitive)
it2prof() { echo -e "\033]50;SetProfile=$1\a" }
step 3:
make sense your profile
exec $SHELL -l
step 4:
toggle your iterm theme profile
it2prof dark
it2prof light
I had this same wish and found this can be accomplished in iTerm 2 (Build 1.0.0.20130319) in the application's preferences.
You can assign a profile (say a remote profile) with a different preset than your default preset by going to:
Profiles -> Open Profiles
select the profile and click Edit Profiles...
Go to the Colors Tab and choose a preset for this profile from the list in Load Presets...
Further, I've set up Keys shortcut for different profiles so I can have one iTerm window look different than another window. I did this by:
Creating a new a Profile in Preferences
Creating a new Profile Shortcut Key in Preferences-> Keys whose action is New Window with Profile
My Default profile has a black background but sometimes it helps me to have a white background. I duplicate my Default profile and name the new profile DefaultLight. On my Default profile I go to the Keys tab where I create a new Profile Shortcut Key whose Keyboard Shortcut is ^+cmd+n, whose action is New Window with Profile, and whose Profile is DefaultLight.
After saving the prefrences, cmd+n opens a new window with a black background and ^+cmd+n opens a new window with a white background.
There's also a New Tab with Profile action in the Keyboard Shortcut Keys Preference if you're interested in taking this even further.
In my case, I need to combine Yohaï Berreby's answer with my hosts' setting to implement this feature.
In Automatic Profile Switching, click '+' and add the hostname of your local machine. The hostname is the one you get when running echo $HOST on the target machine. It is not always the one you see in your prompt.
My staging server doesn't set $HOST and host name is :
[devel#alveo-staging ~]$ hostname
alveo-staging
But I can't set the rule with hostname as alveo-staging. Because in fact alveo-staging is just an alias of the real hostname (alveo-staging.xxx), which can be set in /etc/hosts.
So the quick solution to this is to use * wildcards, to set the rule as *staging*.
Then it works.
For Fishell user:
1. Create a fish function:
functions it2prof > ~/.config/fish/functions/it2prof.fish
Add this content to ~/.config/fish/functions/it2prof.fish file and save:
function it2prof
echo -e "\033]50;SetProfile=$argv\a"
end
enjoy your command:
it2prof whatever_profile_you_define

Copy and paste in vim via keyboard between different mac terminals?

Can anyone help me with this:
I'm trying to figure out how to copy and paste text between 2 different instances of vim on different terminals (using iterm2 or mac terminal). I can do it using the mouse if I do ":set mouse=a" but I'd like to be able to do it using the keyboard.
I've googled around and it says you can use the "* or "+ registers to copy/paste to/from the system clipboard, but when I type * or + in vim, the mac makes one of those sounds it makes when you can't do something. I've also done ":set clipboard=unnamed" but that hasn't worked either.
I'm using Mac OSX 10.7 (Lion) and iTerm2 or Mac terminal.
Thanks for the help
Could you add the output of :version?
I can yank with yy or y in one Vim instance running in Terminal.app window A and put with p or P in another Vim instance running in Terminal.app window B with this line in my ~/.vimrc:
set clipboard+=unnamed
without using specific clipboard registers (* or +).
And why do you have two Vim instances running in different terminals? SSH/local? If one is in an SSH session yanking/putting won't work because the two machines (local/remote) don't share the same clipboard(s).
EDIT
I suspected that Vim wasn't compiled with the right flag(s). Apparently that's the case.
Since you are using Mac OS X's default Vim my opinion is that you shouldn't need to re-compile it or even compile anything as it often leads to more problem's than it's worth.
Instead, download the latest MacVim build and use the (CLI) Vim executable within MacVim's bundle: it has all the same functionalities as MacVim (within the constraints of the CLI, of course).
Add this line to your ~/.bashrc or ~/.profile or wherever you are used to put aliases and custom bash functions:
alias vim='/path/to/MacVim.app/Contents/MacOS/Vim'
If you want to copy an entire file into your target file.
Open your target file in vim.
Put your cursor where you want it and type the following:
:r /path_to_file/file.ext
This will copy an entire file to where your cursor is...

Delete gnome terminal configuration

I made a mistake in my gnome terminal configuration. I entered a command to start with in the preferences, but that command fails, and now all I get is a window that opens and closes right away, and I basically can't use gnome terminal anymore :-( Is there any way I can remove the configuration file and restart fresh??
Thanks!
Open the XTerm (Standard terminal for linux) and enter this command
gnome-terminal -e bash
It opens the gnome-terminal. Open profile preferences and configure your terminal to "Hold the terminal open".
Editing preferences
$HOME/.gconfd/saved_state
the above file might be of interest depending on exactly what configuration you changed. Of course, it holds configuration from other programs as well.
If you are on the newer gnome terminal that uses dconf, it's a little trickier, but still doable:
Profiles are stored with a UUID, you need to find the UUID of the profile to remove:
dconf dump /org/gnome/terminal/ | less
Search for a visible-name='...' entry matching the profile you want to remove. Look above that for the section header like [legacy/profiles:/:...]. The full name of the item you want to delete is thus /org/gnome/terminal/legacy/profiles:/:.... Delete it thus:
dconf reset -f /org/gnome/terminal/legacy/profiles:/:...
Side note: This Q&A probably should be moved to unix.stackexchange.com.

Resources