Skip to content

Commit 9c891bf

Browse files
committed
Fix FmCopy command
The FmCopyCommand should copy the path with the correct separator to clipboard, which means to use `\` on Windows. Otherwise it is useless for external programs. The Command is changed as follows: 1. copy absolute path with `\` on Windows and `/` on Linux or Mac 2. copy relative path with `\` on Windows and `/` on Linux or Mac 3. copy "path from root" with `/` on all OSs as it is expected for use in Sublime Text only.
1 parent 0173432 commit 9c891bf

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

commands/copy.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@ def run(self, which, paths=None):
1515
if which == "name":
1616
text.append(os.path.basename(path))
1717
elif which == "absolute path":
18-
text.append(path)
19-
elif which in ("path from root", "relative path"):
18+
text.append(os.path.abspath(path))
19+
elif which == "relative path":
2020
for folder in folders:
21-
if folder not in path:
22-
continue
23-
24-
text.append(os.path.join("/", path.replace(folder, "")))
25-
if which == "relative path":
26-
# remove the initial /
27-
text[-1] = text[-1][1:]
28-
break
21+
if folder in path:
22+
text.append(os.path.relpath(path, folder))
23+
break
24+
elif which == "path from root":
25+
for folder in folders:
26+
if folder in path:
27+
norm_path = os.path.relpath(path, folder)
28+
text.append("/" + norm_path.replace(os.path.sep, "/"))
29+
break
2930

30-
sublime.set_clipboard("\n".join(bit.replace(os.path.sep, "/") for bit in text))
31+
sublime.set_clipboard("\n".join(text))

0 commit comments

Comments
 (0)