Skip to content

Commit ad5690a

Browse files
committed
experimental drive letter support. implements #4
You now can use links in the form [[Z:\foo\bar]]. On Windows it will try to access that drive, on Linux and Mac it will try to access /media/Z/foo/bar. In all cases the OS user/admin needs to take care that the drive/mount is available
1 parent 35c32cf commit ad5690a

File tree

5 files changed

+57
-14
lines changed

5 files changed

+57
-14
lines changed

src/.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
; http://editorconfig.org/
2+
3+
[*.go]
4+
indent_style = tab
5+

src/setup/darwin.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"howett.net/plist"
99
"os"
1010
"os/exec"
11+
"regexp"
12+
"strings"
1113
)
1214

1315
const launchServicesPlist = "~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist"
@@ -37,7 +39,17 @@ func Uninstall() error {
3739
}
3840

3941
func Run(path string) error {
40-
out, err := exec.Command("open", "smb:"+path).CombinedOutput()
42+
// drive letter detection
43+
isLetter, _ := regexp.MatchString("^/[C-Z]//", path)
44+
if isLetter {
45+
// we assume that the path is auto-mounted under /media/<letter>
46+
path = strings.Replace(path, "//", "/", 1)
47+
path = "/media/" + path[1:]
48+
} else {
49+
path = "smb:" + path
50+
}
51+
52+
out, err := exec.Command("open", path).CombinedOutput()
4153
if err != nil {
4254
return fmt.Errorf("Failed to execute open command.\n%s\n%s", err.Error(), out)
4355
}

src/setup/linux.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os"
1212
"os/exec"
1313
"os/user"
14+
"regexp"
1415
"strings"
1516
)
1617

@@ -68,7 +69,17 @@ func Uninstall() error {
6869
}
6970

7071
func Run(path string) error {
71-
out, err := exec.Command("xdg-open", "smb:"+path).CombinedOutput()
72+
// drive letter detection
73+
isLetter, _ := regexp.MatchString("^/[C-Z]//", path)
74+
if isLetter {
75+
// we assume that the path is auto-mounted under /media/<letter>
76+
path = strings.Replace(path, "//", "/", 1)
77+
path = "/media/" + path[1:]
78+
} else {
79+
path = "smb:" + path
80+
}
81+
82+
out, err := exec.Command("xdg-open", path).CombinedOutput()
7283
if err != nil {
7384
return fmt.Errorf("Failed to execute xdg-open command.\n%s\n%s", err.Error(), out)
7485
}

src/setup/windows.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"golang.org/x/sys/windows/registry"
99
"os"
1010
"os/exec"
11+
"regexp"
1112
"strings"
1213
)
1314

@@ -80,6 +81,13 @@ func Uninstall() error {
8081
}
8182

8283
func Run(path string) error {
84+
// drive letter detection
85+
isLetter, _ := regexp.MatchString("^/[C-Z]//", path)
86+
if isLetter {
87+
path = strings.Replace(path, "//", ":", 1)
88+
path = path[1:]
89+
}
90+
8391
path = strings.Replace(path, "/", "\\", -1)
8492

8593
// note: the empty parameter is the title of the window and required even though it should be optional

syntax.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,42 @@ public function getPType()
2525
/** @inheritDoc */
2626
public function getSort()
2727
{
28-
return 155;
28+
return 150;
2929
}
3030

3131
/** @inheritDoc */
3232
public function connectTo($mode)
3333
{
34-
$this->Lexer->addSpecialPattern('<FIXME>', $mode, 'plugin_golocal');
35-
// $this->Lexer->addEntryPattern('<FIXME>', $mode, 'plugin_golocal');
34+
$this->Lexer->addSpecialPattern('\\[\\[[C-Z]:\\\\[^]]*\\]\\]', $mode, 'plugin_golocal');
3635
}
3736

38-
// /** @inheritDoc */
39-
// public function postConnect()
40-
// {
41-
// $this->Lexer->addExitPattern('</FIXME>', 'plugin_golocal');
42-
// }
4337

4438
/** @inheritDoc */
4539
public function handle($match, $state, $pos, Doku_Handler $handler)
4640
{
47-
$data = [];
41+
$match = substr($match, 2, -2);
42+
[$path, $title] = sexplode('|', $match, 2);
43+
$path = trim($path);
44+
$title = trim($title);
45+
if (!$title) $title = $path;
4846

49-
return $data;
47+
return [$path, $title];
5048
}
5149

5250
/** @inheritDoc */
5351
public function render($mode, Doku_Renderer $renderer, $data)
5452
{
55-
if ($mode !== 'xhtml') {
56-
return false;
53+
if ($mode == 'xhtml') {
54+
55+
$params = [
56+
'href' => 'file:////' . str_replace(':', '/', str_replace('\\', '/', $data[0])),
57+
'title' => $data[0],
58+
'class' => 'windows'
59+
];
60+
61+
$renderer->doc .= '<a ' . buildAttributes($params) . '>' . hsc($data[1]) . '</a>';
62+
} else {
63+
$renderer->cdata($data[1]);
5764
}
5865

5966
return true;

0 commit comments

Comments
 (0)