1

I put LightTable in /opt/LightTable

By default, when you install the text editor LightTable in ubuntu 14.04 64 bits, you don't have an "open with LightTable" when you right-click the file you want to open with it.

Therefore I created a file /home/theuser/.local/share/applications/LightTable.desktop containing :

[Desktop Entry]
Name=LighTable Text Editor
Comment=Edit text files
Exec=/opt/LightTable/LightTable %f
Terminal=false
Type=Application
Icon=/opt/LightTable/core/img/lticon.png
Categories=Utility;TextEditor;
StartupNotify=true
MimeType=text/plain

so that a "open with LightTable" appears when I want open a file with LighTable. Now, the problems begin. When I do this, it only opens LightTable, as if I only ran the script

/opt/LightTable/LightTable

Therefore I went to see the script :

#!/bin/bash

BIN=ltbin
HERE=`dirname $(readlink -f $0)`

LIBUDEV_0=libudev.so.0
LIBUDEV_1=libudev.so.1

add_udev_symlinks() {
  # 64-bit specific; look for libudev.so.0, and if that can't be
  # found link it to libudev.so.1
  FOLDERS="/lib64 /lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu /usr/lib64 /usr/lib /lib"

  for folder in $FOLDERS; do
    if [ -f "${folder}/${LIBUDEV_0}" ]; then
      return 0
    fi
  done

  for folder in $FOLDERS; do
    if [ -f "${folder}/${LIBUDEV_1}" ]; then
      ln -snf "${folder}/${LIBUDEV_1}" "${HERE}/${LIBUDEV_0}"
      return 0
    fi
  done

  echo "${LIBUDEV_0} or ${LIBUDEV_1} not found in any of ${FOLDERS}".
  exit 1
}

add_udev_symlinks

ARGS="$@"

CORRECTED=${ARGS//-/<d>}
CORRECTED=${CORRECTED// /<s>}

if [ -t 0 ] && [ $# != 0 ]; then
  #We're in a terminal...
  LD_LIBRARY_PATH="$HERE:$LD_LIBRARY_PATH" $HERE/$BIN "<d><d>dir=`pwd`<s>$CORRECTED" &
else
  #We were double clicked
  LD_LIBRARY_PATH="$HERE:$LD_LIBRARY_PATH" $HERE/$BIN &
fi

and replaced its ending if/else/fi by a simple :

LD_LIBRARY_PATH="$HERE:$LD_LIBRARY_PATH" $HERE/$BIN "<d><d>dir=`pwd`<s>$CORRECTED" &

so that the right behaviour (the one when opening a file from the terminal) is chosen.

This almost made my day. Now, if I double-click a file or right-click it and select "open with LightTable", the file is indeed opened in LightTable... but : this is true only if the file name and the path to the file have no blank space in their names.

If the file named "the file" is in the path thepath without space in it, when I double-click it, it opens two blank files "the" and "file" in LightTable. The same behavior is constated if thepath has space(s) in it.

Would someone have an idea ? I guess I should correct the bash script, but I'm not an expert in it. (I am not even sure that the script is really wrong...)

Thanks in advance

MEF

Olórin
  • 3,367
  • 2
  • 22
  • 42
  • I tried the same patch and am facing the same issue. It seems like the issue is with Light Table's parsing of the cli args: https://github.com/LightTable/LightTable/blob/master/src/lt/objs/cli.cljs Notice how it splits blindly everything that has a space in it. Not sure whether there is a workaround... – Marwane K.A. Oct 23 '14 at 09:06
  • I just reported the issue at: https://github.com/LightTable/LightTable/issues/1688 – Marwane K.A. Oct 23 '14 at 09:31
  • Actually I already reported it : https://github.com/LightTable/LightTable/issues/1659 You should maybe revert your report, because the issue is apparently already assigned to someone from lighttable's tean. Thx nevertheless for your initiative ! – Olórin Oct 23 '14 at 09:35

2 Answers2

0

Your question has a tl;dr quality about it.

When you store "$@" in a variable, you really have to use an array and lots of quotes to preserve the elements with whitespace:

ARGS=("$@")
CORRECTED=("${ARGS[@]//-/<d>}")
CORRECTED=("${CORRECTED[@]// /<s>}")

But then the way you have to pass the args is a problem:

LD_LIBRARY_PATH="$HERE:$LD_LIBRARY_PATH" $HERE/$BIN "<d><d>dir=`pwd`<s>$CORRECTED" &

It's impossible to expand the array into a single space-delimited string and then somehow extract the elements that have significant whitespace. You may have to do this, and see if it works:

export LD_LIBRARY_PATH="$HERE:$LD_LIBRARY_PATH"   # might as well put on own line
"$HERE/$BIN" "<d><d>dir=`pwd`<s>" "${CORRECTED[@]}" &
# ...........^^^^^^^^^^^^^^^^^^^^ standalone argument
glenn jackman
  • 238,783
  • 38
  • 220
  • 352
  • Thx for you answer. I am just giving it a try and the result of double-clicking a plain text file is now the opening of an empty instance of LightTable. Wrt the too long didn't read issue, I would say that I added the strict minimum of needed info : config, what I tweaked already, plus the script. Don't see how to shorten it without being imprecise... But I'll try to do better next time :-) – Olórin Oct 02 '14 at 16:12
0

Actually, this is a bug in LightTable.

I opened an issue (https://github.com/LightTable/LightTable/issues/1762) and submitted a patch (https://github.com/LightTable/LightTable/pull/1763) to fix this :

There are 2 issues here:

  • currently the deployed Bash script doesn't pass any arguments to LightTable if it's not invoked from a terminal, but this is needed e.g. to make a gnome desktop shortcut. This issue can also be reproduced by using the ALT+F2 launcher under Ubuntu.
  • independently LightTable cannot currently open files whose names contain ' ' characters.
Lucas Cimon
  • 1,859
  • 2
  • 24
  • 33