Remote Apps, Local GUI on Windoze (Cygwin+X-Server)

Long time ago a friend of mine showed me how to run locally the GUI of a remote application with cygwin[1], a couple of years ago a request in my job required a X server on the server which sounded like a bad idea to me, this is a cleaner approach to run those apps that require a display, when you are running a windoze. It’s even easier if you are running Linux as it is very likely you will be running in a top of a X server.

Installation:

  1. Download the cygwin setup binary from here[2].
  2. Open the Cygwin Setup and select the following packages to install.
      openssh
      xorg-server
      xhost
      xinit
      x-start-menu-icons
      twm

Configuration:.

  1. You need your local IP, remote IP
  2. Open cygwin and run startx this will start your X-Server locally.
  3. Run: xhost +<remoteIP> on the shell opened by the X-Server.
  4. Connect to the remote server: ssh -X -l<user> <remoteIP>.
  5. Export your local display on the remote Server: export DISPLAY=<localIP>:0.0
  6. Run a graphical application that will be displayed on your local X-Server and Enjoy the Graphical Interface of a remote process in your locally

For troubleshooting/clarification, read the man pages of ssh, xhost and xserver.

[1] http://www.cygwin.com
[2] http://cygwin.com/setup.exe

git(init, remote, branch, tag, merge, cherry-pick) by example.

I’m barely new to git, almost 4 months, and everyday I feel more comfortable with it, yesterday kad helped me to understand better the creation of branches, so I made a quick test to add them and took me to a more complete example of using init, remote, branch, tag, merge and cherry-picks, so I wanted to share.

A) Creating a local and remote Repo.

01. mkdir -p ~/{git-master/test.git,git-test/{test1,test2}}
02. pushd ~/git-master/test.git
03. git init --bare
04. popd
05. pushd ~/git-test/test1
06. git init
07. echo "This is the first file in the repo." > README
08. git add README
09. git commit -m "First commit" README
10. git remote add origin ~/git-master/test.git
11. git push origin master

B) Creating a local and remote Branch, submitting some code, creating a tag.

12. git checkout -b dev
13. git push origin dev
14. echo "This is the first file in the dev branch." > DEV
15. git add DEV16. git commit -m "First commit on dev" DEV
17. git push
18. git tag -a -m "First tag in the repo" v0.1
19. git push --tags
20. echo "This is a modification of DEV file." >> DEV
21. git commit -a -m "A modification on DEV."
22. git push

C) Creating a Branch from a tag, merging master with that tag, deleting a tag.

23. git checkout -b v0.1
24. git checkout master
25. git merge v0.1
26. git push
27. git branch -D v0.1

D) Doing a cherry-pick from another branch.

28: git cherry-pick -x 5732771b183abe6ad0b587ef9442d00c73e238f0

Detailed Description of the commands above

A) Creating a local and remote Repo

03. Creates a “bare”git repo with the content of .git only
Initialized empty Git repository in ~/git-master/test.git/
06. Initalizes a git repo, all the matadata is stored in .git
Initialized empty Git repository in ~/git-test/test1/.git/
08-09. Start tracking README, Commit the tracked changes of README to the repo.
[master (root-commit) 88ef530] First commit
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 README


10-11. Create a remote with label origin in ~/git-master/test.git, could be in a remote machine with all the different possibilities(ssh, ftp, git, etc). Once created Push to “origin” the “master” branch.
Counting objects: 3, done.
Writing objects: 100% (3/3), 235 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To ~/git-master/test.git
* [new branch] master -> master

B) Creating a local and remote Branch, submitting some code, creating a tag.
12. Create a new branch named “dev” and switch to it.
Switched to a new branch ‘dev’

13. Push to that remote “origin” the branch “dev”
Total 0 (delta 0), reused 0 (delta 0)
To /home/tgarcia/git-master/test.git
* [new branch] dev -> dev


15-16. Adding to track the file DEV and commiting the changes.
[dev 290d4d1] First commit on dev
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 DEV


17. Push the changes, look that this will push to the remote “origin/dev”
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Unpacking objects: 100% (3/3), done.
Writing objects: 100% (3/3), 302 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To ~/git-master/test.git
88ef530..290d4d1 dev -> dev


18. Create a tag called “v0.1” with the message “First tag in the repo”.
19. Push the tags. (will do to the remote/”current branch”).
Counting objects: 1, done.
Writing objects: 100% (1/1), 164 bytes, done.
Total 1 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (1/1), done.
To ~/git-master/test.git
* [new tag] v0.1 -> v0.1


21. Commit all the changes to thracked files, in this case DEV.
[dev 5732771] A modification on DEV.
1 files changed, 1 insertions(+), 0 deletions(-)


C) Creating a Branch from a tag, merging master with that tag, deleting a tag.
22. Push the changes.
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 337 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To ~/git-master/test.git
290d4d1..5732771 dev -> dev


23. Create a new branch from the tag “v0.1”
Switched to a new branch ‘v0.1’

24. Switch to the “master” branch.
Switched to branch ‘master’

25. Merge the current branch(master) with branch “v0.1”
warning: refname ‘v0.1’ is ambiguous.
warning: refname ‘v0.1’ is ambiguous.
Updating 88ef530..290d4d1
Fast forward
DEV | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 DEV


26. Push the changes to the remote.
Total 0 (delta 0), reused 0 (delta 0)
To ~/git-master/test.git
88ef530..290d4d1 master -> master


27. Delete the branch “v0.1”
Deleted branch v0.1 (was 5732771).
if you attempt git branch -d v0.1 you will get:
error: The branch ‘v0.1’ is not an ancestor of your current HEAD.
If you are sure you want to delete it, run ‘git branch -D v0.1’.


D) Doing a cherry-pick from another branch.
28. Cherry-pick the change sha1 into the current branch(master)
Finished one cherry-pick.
[master 1bf5f99] A modification on DEV. (cherry picked from commit 5732771b183abe6ad0b587ef9442d00c73e238f0)
1 files changed, 1 insertions(+), 0 deletions(-)

Emacs keybinding over Remote Terminal

Hi hate when I have to connect to a remote server and some keys like up, down, home, end, etc. don’t work. This is because the way the key is sent over the terminal and interpreted on the remote system.

At least on Emacs you can re-define the keys, or as in this case define them, to serve as required.

I’m on Ubuntu 9.04(Jaunty Jackalope) connecting remotely to a Red Hat Enterprise(Taroon); when at the remote emacs I hit <C-right> I got an ugly “5C”, hitting <home> does nothing! Argh!

After googling in different pages I finally figure this out:

In your .emacs configuration file add as many key definitions as needed like this template:

;; key bindings over remote terminal
(define-key function-key-map "e<key>" [<key-name>])

Where <key> is the raw value of the key, to get that value simply press C-q <key> this will print that value that you need. e.g

Pressing C-q <home> prints ^[OH, remove the “^[“ and replace the key value, then on the key-name use the name of that key, in this case “home”.

The purpose of this definition is to let know emacs that the key <home> needs to move to the begining of the line, in emacs language is “move-beginning-of-line”, to bind them use:

(global-set-key [home] 'move-beginning-of-line)

This should solve the issue, but I realized that only letting know emacs what raw key is know as “home” or whatever is enough to bind the keys to commands.

I ended with something like this:

;; key bindings over remote terminal
(define-key function-key-map "eOH" [home])
(define-key function-key-map "eOF" [end])
(define-key function-key-map "e[1;5A" [C-up])
(define-key function-key-map "e[1;5B" [C-down])
(define-key function-key-map "e[1;5D" [C-left])
(define-key function-key-map "e[1;5C" [C-right])

TIP: If you need to define the binding of keys to commands, you can use C-h c <key> to know what command is being used, e.g.

Pressing C-h c <home> prints in the *Messages* buffer:

<home> runs the command move-beginning-of-line.