LightTable/LightTable — pull request #1763 by Lucas-C (2014-12-03 09:50:16+00:00)
Title: Fixing issue with opening file names containing spaces as command-line parameters

Specifically:
- using a different separator \ to separate arguments than to
escape spaces \ in filenames in the deployed Bash script
- doing arguments splitting BEFORE `'s// /'` substitution
- getting rid of the 'is invoked in terminal' distinction

Fixes #1762

Tests:
- in a terminal :
```
$ touch "a b"
$ /opt/LightTable/deploy/LightTable a\ b
```
- same test without a terminal, using the Ubuntu ALT+F2 launcher
- tested the following code in `lein trampoline cljsbuild repl-rhino` :
```clojure
(ns cljs.user (:require [clojure.string :as string]))

; Old function
(defn rebuild-argv [argstr]
(-> (subs argstr (.indexOf argstr "dir"))
(string/replace "" "-")
(string/replace "" " ")
(string/split #" ")
(to-array)))
(string/join ";" (rebuild-argv "dir=/home/lucas/filename"))
; Return: "--dir=/home/lucas/;file;name"

; New function
(defn rebuild-argv [argstr]
(map #(string/replace % "" "-")
(map #(string/replace % "" " ")
(to-array (string/split (subs argstr (.indexOf argstr "dir")) #"")))))
(string/join ";" (rebuild-argv "dir=/home/lucas/filename"))
; Return: "--dir=/home/lucas/;file name"
```

For reference, there are the 2 last commits that edited the `rebuild-argv` function :
- [0.5.1 fixes](https://github.com/LightTable/LightTable/commit/c747525758555a45eca1289047e50150bec4748c#diff-d03f7bf743045da7e1e49e701aee9d54L13) on Aug 26, 2013
- [clean import](https://github.com/LightTable/LightTable/commit/296dedb97d3e06a709854284bdf2f59b4b03dac1) on Jul 5, 2013

Side notes:
- the whole space / dash characters escape system looks a bit cumbersome and not documented at all, but I'll keep it that way for now
- I don't get why the `(subs argstr (.indexOf argstr "dir")` line is needed, I think it can actually be troublesome if no `dir=` option is provided, but I won't touch that in this commit