I had exactly the same problem (Ubuntu + Wine + WinSCP + Sublime
) and Sublime was giving me blank pages once I've tried to edit with it.
Googling gave me nothing so I've made my own solution for that (tested on Ubuntu 14.04 Trusty
)
Here is my solution and research.
Solution
Solution tested and works with Ubuntu 14.04 Trusty
+ Sublime 3
+ Wine-1.6.2
. I think it will also work for Debian (haven't tested).
I've split solution into 2 scripts to have two universal tools instead of one specific.
The solution is add a script to fix the path before it's get's to Sublime:
- First script
wine2unix-path
will transform Wine "windows path" into real file system path and fix it's format (quotes and double backslashes \\
)
- Second script
sublime.exe
will use fixed real file path from wine2unix-path
and will pass it into Sublime.
I've named first script "sublime.exe" because otherwise Wine refuses to see it in "Editors" settings, when I update editor path.
Steps to do:
- Create
/usr/local/bin/wine2unix-path
- Create
/usr/local/bin/sublime.exe
- Update editor path in
WinScp
Step 1. wine2unix-path
Example usage: wine2unix-path c:\\Program files\\WinScp\\Log.txt
returns /home/YOUR_CURRENT_LINUX_USER/.wine/drive_c/Program files/WinScp/Log.txt
.
- Create file
sudo touch /usr/local/bin/wine2unix-path
- Make executable
sudo chmod +x /usr/local/bin/wine2unix-path
Put following script into it:
#!/bin/bash
# Trim quotes
FILE=$(echo "$@" | sed -e "s#\(^['\"]*\)\|\(['\"]*$\)##g")
USER_NAME=$(id -u -n)
DRIVE_LETTER="`echo $FILE | sed -e "s/^\([a-Z]\):.*/\1/" | awk '{print tolower($0)}'`"
echo "$FILE" | sed \
-e 's#\\#\/#g' \
-e "s#^[a-Z]:#/home/${USER_NAME}/.wine/drive\_${DRIVE_LETTER}#"
exit 0
What this script do:
FILE
- Get file path and trim "
and '
quotes if there is any
USER_NAME
- Get current user name /home/USER
DRIVE_LETTER
- Get drive letter from file path (first character). It may be different C:\
refers to .wine/drive_c
, D:\
refers to .wine/drive_d
etc.
- Update file path
- Replace root path
C:\
with full path to wine folder. C:\
becomes /home/USER/.wine/drive_c
- Replaces
\\
(escaped backslashes in a windows way) with \
, otherwise C:\\users\\files
become C:usersfiles
when it passed to sublime.
- Output result file path (real file path)
Step 2. sublime.exe
- Create file
sudo touch /usr/local/bin/sublime.exe
- Make executable
sudo chmod +x /usr/local/bin/sublime.exe
- Put there provided below
- Change
/opt/sublime_text/sublime_text
path in script below (last line) with yours sublime path.
My Sublime version 3103
is located at /opt/sublime_text/sublime_text
#!/bin/bash
# Wrapper script to open sublime from Wine
#
# File path passed as a first argument should be "quoted" and "escaped"
# other wise spaces will split path into two
#
# For example: sublime.exe "c:\\Program files\\WinScp\\Log.txt"
#
# wine2unix-path is a help script to convert "Wine windows paths"
# to real paths in linux so sublime can access it
#
# For for example:
# ./sublime.exe "c:\\Program files\\WinScp\\Log.txt"
# Will result:
# /home/YOUR_CURRENT_LINUX_USER/.wine/drive_c/Program files/WinScp/Log.txt
unixpath="`wine2unix-path $1`"
/opt/sublime_text/sublime_text "$unixpath"
What this script do:
- Converts Wine file path to real file path.
- Passes this path quoted (to avoid split path by spaces) to sublime.
Step 3. Update editor path in WinScp
- Open
WinScp
- Go to
Options > Preferences > Editors
- If you already have Sublime in editors:
- Select line with sublime
- Click
Edit
button
- Set following path for "External editor"
Z:\usr\local\bin\sublime.exe \"!.!\"
- Click
Ok
. Done
- If you don't have Sublime in editors:
- Click
Add
(to add sublime editor and assign it to file types).
- Set following path for "External editor"
Z:\usr\local\bin\sublime.exe \"!.!\"
- Set you list of file types you want to edit with it in "Use this editor for following files". I use it for PHP files and some configs
*.ini; *.txt; *.php; *.tpl
or *.*
for all file types
- Make sure Sublime line is on top of the list in
Editor preferences
. It will make priority for file types you selected for Sublime.
Picture: Sublime settings in WinScp
Research of the problem
The problem appear in file path that Wine passes to Sublime:
- Path is not quoted with
"
or '
when it passed to sublime
- Path backslashes are doubleescaped
\\
An example:
- File to edit
/server/user/www/my project/some other file.php
- Wine calls sublime
Z:\opt\sublime_text\sublime_text /home/CURRENT_USER/.wine/drive_c/Program files/WinScp/server/user/www/my project/some file.php
(path not quoted or escaped)
- System run it as
/opt/sublime_text/sublime_text /home/CURRENT_USER/.wine/drive_c/Program files/WinScp/server/user/www/my project/some file.php
.
- So command being interpretative as:
- Command
/opt/sublime_text/sublime_text
- Argument
/home/CURRENT_USER/.wine/drive_c/Program
- Argument
files/WinScp/server/user/www/my
- Argument
project/some
- Argument
file.php
As the result path being split by spaces because of the lack quotes.
As I found later there is also problem with double escapes \\
in a path
Z:
. Have you tried to set the editor toZ:/usr/bin/subl
? Though in general I agree with @MattDMo: there are plenty of file managers like that for Linux, some of that have SSH/SFPT support through gvfs and then there's SSHFS. – David Foerster May 28 '16 at 09:43