# SSH, X11 Forwarding, and Terminal Multiplexers

Terminal multiplexers like GNU Screen and tmux are indispensable for running remote jobs, but they don’t always play nicely with X11 forwarding (i.e. ssh -X or ssh -Y). This can result in remotely-launched GUI programs failing to display and similar difficulties. Typically, I’ll start a job in screen while at lab, go home, and reconnect remotely, only to find that X11 forwarding works correctly outside of but not inside of screen. The same happens with tmux.

Most aggravating to me in this situation is the failure of a bash alias cpd that I use quite frequently:

This alias copies the current working directory into the clipboard, making it easier to navigate the filesystem, copy files between machines, and so on. Unfortunately, it requires X11 forwarding to work.

The root cause of the problem here is that the DISPLAY environment variable needs to be set appropriately or X11 forwarding breaks. For example, when running locally DISPLAY is usually :0, but when logged in remotely it should be localhost:x.0, where x is some number. Normally you don’t have to think about this, but when reconnecting to a screen session the terminal doesn’t know when DISPLAY needs to change. Setting DISPLAY manually is possible but entirely too much work to do on a regular basis.

## A solution …

To resolve this problem in a way that is transparent to the user, we can automatically cache the value of DISPLAY before every command run outside of screen, and set the value of DISPLAY to the cache before every command run inside of screen.

You can paste this into your .bashrc. Beware the potential complication if you use PROMPT_COMMAND.

## … that mostly works

This can break down when you are doing more complicated things. For example:

• Create a screen session on a work machine.
• Go home.
• In terminal A, ssh in and re-attach.
• In terminal B, ssh in again.
• Disconnect terminal B.

The screen session running at work, visible in terminal A, ends up with a bad DISPLAY setting and X11 forwarding fails. Fortunately, it is easy to recover from these kinds of failures: Just detach and re-attach the screen session.

## A note on security

If you’re using X11 forwarding, be aware there are security risks involved. It’s best to use X11 forwarding selectively, either with ssh -X on the terminal or by specifically configuring your ~/.ssh/config file to allow it for only certain machines. For example, this appears in my ssh config file for a remote machine capek that I trust. All other connections have X11 forwarding disabled by default.

# SSH, X11 Forwarding, and Terminal Multiplexers

Terminal multiplexers like GNU Screen and tmux are indispensable for running remote jobs, but they don’t always play nicely with X11 forwarding (i.e. ssh -X or ssh -Y). This can result in remotely-launched GUI programs failing to display and similar difficulties. Typically, I’ll start a job in screen while at lab, go home, and reconnect remotely, only to find that X11 forwarding works correctly outside of but not inside of screen. The same happens with tmux.

Most aggravating to me in this situation is the failure of a bash alias cpd that I use quite frequently:

This alias copies the current working directory into the clipboard, making it easier to navigate the filesystem, copy files between machines, and so on. Unfortunately, it requires X11 forwarding to work.

The root cause of the problem here is that the DISPLAY environment variable needs to be set appropriately or X11 forwarding breaks. For example, when running locally DISPLAY is usually :0, but when logged in remotely it should be localhost:x.0, where x is some number. Normally you don’t have to think about this, but when reconnecting to a screen session the terminal doesn’t know when DISPLAY needs to change. Setting DISPLAY manually is possible but entirely too much work to do on a regular basis.

## A solution …

To resolve this problem in a way that is transparent to the user, we can automatically cache the value of DISPLAY before every command run outside of screen, and set the value of DISPLAY to the cache before every command run inside of screen.

You can paste this into your .bashrc. Beware the potential complication if you use PROMPT_COMMAND.

## … that mostly works

This can break down when you are doing more complicated things. For example:

• Create a screen session on a work machine.
• Go home.
• In terminal A, ssh in and re-attach.
• In terminal B, ssh in again.
• Disconnect terminal B.

The screen session running at work, visible in terminal A, ends up with a bad DISPLAY setting and X11 forwarding fails. Fortunately, it is easy to recover from these kinds of failures: Just detach and re-attach the screen session.

## A note on security

If you’re using X11 forwarding, be aware there are security risks involved. It’s best to use X11 forwarding selectively, either with ssh -X on the terminal or by specifically configuring your ~/.ssh/config file to allow it for only certain machines. For example, this appears in my ssh config file for a remote machine capek that I trust. All other connections have X11 forwarding disabled by default.

# Quickly Navigating Large Repositories From the Terminal

The tools grep, ack, and ag are great for searching repositories, but often we don’t just want to find a match, we want to navigate to a match and make changes. What follows are some bash functions for rapidly searching a repository and opening selected matches.

This is my primary method for navigating source repositories. I’ve written enough emails with this content that I decided it was time to write it up properly once and for all. I’ll discuss C++ in particular here, but the functions are easy to adapt to whatever language you work in.

### cgrep and yank

Here’s a list of the most frequently used commands in my Bash history, with a count in the left column.

So what is this cgrep thing, and why is it my 6th-most-used command? It greps through all C++ source files and returns matches like this:

This is similar to the output of ack --nogroup --cpp imread, but with the addition that you can quickly open one of the matches and navigate to the appropriate line number using yank.

Running this will open ./src/program/image_cut.cpp in a running Emacs window and move to the imread call on line 253. I use emacsclient to make this possible, and presumably you can do something similar with Vim or whatever editor you use.

It looks like this.

### More examples from my Bash history

Because this is all happening on the command line, you can apply whatever Unix filters might be useful. Here I wanted to see all usages of isinf except those in the PCL library.

Because cgrep is using grep under the hood, all the usual options you know and love still apply. Here I was showing usages of the Eigen library’s InnerIterator, with 10 following lines of context. This makes it easy to scan for errors, then jump to the location with yank to fix them.

We can also define a variation on cgrep to only search in header files. Here I was looking for compound assignment operators in class declarations.

## Details

Here’s how cgrep and friends are implemented. You can paste this in your .bashrc. To hook up yank to emacsclient, you’ll also probably want export EDITOR='emacsclient -n' in your .bashrc and (server-start) in your Emacs init file.

Related, the cfiles function is handy for doing large search and replace operations.

If you’re wondering how to easily get a list of your own most frequently used commands, you can use something like this. The awk command likely won’t translate to your machine because I am using a custom definition of HISTTIMEFORMAT, but you get the idea.

## Changelog

• 2013-12-10: Added screencast example, clarified that the point is fast navigation rather than just search.
• 2013-12-13: Made video scale automatically.

# Quickly Navigating Large Repositories From the Terminal

The tools grep, ack, and ag are great for searching repositories, but often we don’t just want to find a match, we want to navigate to a match and make changes. What follows are some bash functions for rapidly searching a repository and opening selected matches.

This is my primary method for navigating source repositories. I’ve written enough emails with this content that I decided it was time to write it up properly once and for all. I’ll discuss C++ in particular here, but the functions are easy to adapt to whatever language you work in.

### cgrep and yank

Here’s a list of the most frequently used commands in my Bash history, with a count in the left column.

So what is this cgrep thing, and why is it my 6th-most-used command? It greps through all C++ source files and returns matches like this:

This is similar to the output of ack --nogroup --cpp imread, but with the addition that you can quickly open one of the matches and navigate to the appropriate line number using yank.

Running this will open ./src/program/image_cut.cpp in a running Emacs window and move to the imread call on line 253. I use emacsclient to make this possible, and presumably you can do something similar with Vim or whatever editor you use.

It looks like this.

### More examples from my Bash history

Because this is all happening on the command line, you can apply whatever Unix filters might be useful. Here I wanted to see all usages of isinf except those in the PCL library.

Because cgrep is using grep under the hood, all the usual options you know and love still apply. Here I was showing usages of the Eigen library’s InnerIterator, with 10 following lines of context. This makes it easy to scan for errors, then jump to the location with yank to fix them.

We can also define a variation on cgrep to only search in header files. Here I was looking for compound assignment operators in class declarations.

## Details

Here’s how cgrep and friends are implemented. You can paste this in your .bashrc. To hook up yank to emacsclient, you’ll also probably want export EDITOR='emacsclient -n' in your .bashrc and (server-start) in your Emacs init file.

Related, the cfiles function is handy for doing large search and replace operations.

If you’re wondering how to easily get a list of your own most frequently used commands, you can use something like this. The awk command likely won’t translate to your machine because I am using a custom definition of HISTTIMEFORMAT, but you get the idea.

## Changelog

• 2013-12-10: Added screencast example, clarified that the point is fast navigation rather than just search.
• 2013-12-13: Made video scale automatically.

# Sensor Deformation and Distortion

Unsurprisingly, gross physical deformation of an RGBD sensor body will produce changes in the distortion pattern of the sensor. Surprisingly, you can cause this yourself quite easily without being aware of it.

We ran in to this when mounting an Asus Xtion Pro Live using velcro cinch straps around the sensor body. Pulling to hand tightness easily causes noticeable changes in the distortion pattern. If you’re trying to calibrate a sensor using our CLAMS work, this can really mess you up.

Here are some examples showing the change in the raw sensor output when tightening vs loosening the straps. Mount your sensors with care!

# Sensor Deformation and Distortion

Unsurprisingly, gross physical deformation of an RGBD sensor body will produce changes in the distortion pattern of the sensor. Surprisingly, you can cause this yourself quite easily without being aware of it.

We ran in to this when mounting an Asus Xtion Pro Live using velcro cinch straps around the sensor body. Pulling to hand tightness easily causes noticeable changes in the distortion pattern. If you’re trying to calibrate a sensor using our CLAMS work, this can really mess you up.

Here are some examples showing the change in the raw sensor output when tightening vs loosening the straps. Mount your sensors with care!

# PrimeSense Distortion and View Angle

After presenting our work on unsupervised calibration of PrimeSense sensors at RSS2013, several people asked if the distortion is a function of view angle. In light of how these sensors work this is a reasonable concern. However, we’re not seeing evidence of this. If you are, please contact me.

What follows are animated gifs of the learned distortion model working at different view angles. If the depth distortion was significantly a function of view angle, I’d expect the results to appear unreasonable, and this isn’t the case.

Here’s a typical scene looking at a long table, wooden chairs, and a white wall. At 7 meters, the wall is highly distorted in the raw data, and applying the learned distortion model results in a reasonably flat wall.

Switching to a top-down view, here’s the result at about 40 degrees. Again, the wall becomes flat after applying the learned distortion model.

At about 20 degrees, the distortion is getting harder to see from top-down. This is because the distortion is a depth multiplier; at this angle the displacement of the points is mostly in line with the wall.

Viewing the same scene from the side is telling. We should be seeing straight lines at the intersection of the flat wall and the left & top edges of the view frustum. These straight lines only appear after applying the learned distortion model.

This corresponds nicely to the learned distortion model, which says the upper left corner peels away from the sensor. (Red means raw data must be pushed further away to produce accurate readings, blue means raw data must be pulled closer.)

# PrimeSense Distortion and View Angle

After presenting our work on unsupervised calibration of PrimeSense sensors at RSS2013, several people asked if the distortion is a function of view angle. In light of how these sensors work this is a reasonable concern. However, we’re not seeing evidence of this. If you are, please contact me.

What follows are animated gifs of the learned distortion model working at different view angles. If the depth distortion was significantly a function of view angle, I’d expect the results to appear unreasonable, and this isn’t the case.

Here’s a typical scene looking at a long table, wooden chairs, and a white wall. At 7 meters, the wall is highly distorted in the raw data, and applying the learned distortion model results in a reasonably flat wall.

Switching to a top-down view, here’s the result at about 40 degrees. Again, the wall becomes flat after applying the learned distortion model.

At about 20 degrees, the distortion is getting harder to see from top-down. This is because the distortion is a depth multiplier; at this angle the displacement of the points is mostly in line with the wall.

Viewing the same scene from the side is telling. We should be seeing straight lines at the intersection of the flat wall and the left & top edges of the view frustum. These straight lines only appear after applying the learned distortion model.

This corresponds nicely to the learned distortion model, which says the upper left corner peels away from the sensor. (Red means raw data must be pushed further away to produce accurate readings, blue means raw data must be pulled closer.)

# Test Post

This is a test post to see if Octopress is suitable for my purposes. Conclusion: yes. There’s nothing here for general consumption, but I’ve left this page up in the offchance you’re wondering if Octopress is for you.

You can more or less just paste the YouTube embed line directly into the markdown file. I needed to add ‘http:’ to the URL supplied by YouTube. Adding ?rel=0&vq=hd1080 to the end of the URL will prevent it from showing related video suggestions at the end and make it play in HD.

### Images

Images should be placed in the octopress/source/images directory. A link path looks like /images/2013-07-15_oblique_angle_test/00-animated.gif. When the site is generated, they’ll end up in the octopress/public/images directory.

### Math

Latex is not supported by default but it is quite easy to add:

### Lists

The indentation isn’t quite showing up correctly in my browser, but this can probably be fixed.

• This is a list item
• Something else
• Foo
• Bar

### Long text

Bacon ipsum dolor sit amet sirloin corned beef jowl prosciutto flank kielbasa, fatback salami bacon shankle hamburger pork chop tongue beef. Ham hock strip steak hamburger jowl, shoulder bacon fatback. Biltong meatloaf prosciutto bacon drumstick ground round venison swine cow jerky tri-tip tongue fatback rump. Tenderloin ribeye venison pork belly shankle. Short loin ham hock tenderloin strip steak leberkas jowl pancetta swine drumstick chuck.

Turkey filet mignon hamburger ball tip brisket beef ribs corned beef tenderloin andouille capicola kielbasa. Venison shoulder hamburger, capicola swine drumstick short ribs beef ribs pig corned beef pork pork loin meatloaf. Salami andouille meatball, biltong jerky bacon ball tip. Doner shoulder ground round tri-tip turducken chicken t-bone pork shank. Bresaola pig ribeye strip steak ham hock brisket boudin flank, bacon short ribs pancetta turducken biltong meatball rump. Kielbasa pastrami cow, meatloaf bacon short ribs tail tongue swine andouille rump ground round.

Short loin fatback jerky hamburger ribeye bacon swine bresaola. Corned beef shankle pork chop, pork fatback leberkas salami chuck ribeye sausage rump bresaola meatball tri-tip capicola. Hamburger chuck tongue capicola turkey ground round short loin pork meatball andouille tail cow. Pork loin sirloin frankfurter, turducken pastrami andouille short ribs tongue shank spare ribs flank. Chicken flank tenderloin short loin capicola sausage bresaola venison boudin prosciutto swine cow jerky. Tongue biltong boudin pig fatback, ribeye beef turducken. Tongue shank pork chop sirloin jowl.

Swine ham hock ribeye, meatball tri-tip salami ham pork pastrami tail beef. Drumstick bacon prosciutto ham hock pork belly beef, strip steak pork. Boudin strip steak flank tri-tip brisket ribeye ham. Pancetta meatball short loin tri-tip hamburger swine filet mignon pig kielbasa ribeye.

Jowl swine shankle turkey ham turducken pastrami prosciutto short ribs ground round beef ribs pig. Pancetta bacon fatback boudin kielbasa turducken. Sausage t-bone prosciutto jerky bresaola ground round leberkas jowl meatball capicola chuck. Boudin jerky bresaola rump pork loin prosciutto sirloin swine drumstick.

Thanks to Bacon Ipsum.