|
9 | 9 | "os" |
10 | 10 | "path/filepath" |
11 | 11 | "regexp" |
| 12 | + "strings" |
12 | 13 | "time" |
13 | 14 |
|
14 | 15 | "github.com/alessio/shellescape" |
@@ -60,11 +61,30 @@ func main() { |
60 | 61 | fmt.Println("client connected", c.ID) |
61 | 62 | defer fmt.Println("client disconnected", c.ID) |
62 | 63 | f := format.FindStringSubmatch(c.ID) |
63 | | - if len(f) == 3 { |
64 | | - id := fmt.Sprintf("%s-%s", f[2], f[1]) |
65 | | - hello := fmt.Sprintf(args.hello, id, c.PWD) |
| 64 | + if len(f) != 3 { |
| 65 | + return |
| 66 | + } |
| 67 | + id := fmt.Sprintf("%s-%s", f[2], f[1]) |
| 68 | + noEditTargets := true |
| 69 | + for _, t := range c.Targets() { |
| 70 | + var hello string |
| 71 | + switch { |
| 72 | + case strings.HasPrefix(t, "/dev/null"): |
| 73 | + t = strings.TrimPrefix(t, "/dev/null") |
| 74 | + hello = fmt.Sprintf("this target is not exists: %s", t) |
| 75 | + case strings.HasPrefix(t, "/dev/err"): |
| 76 | + t = strings.TrimPrefix(t, "/dev/err") |
| 77 | + hello = fmt.Sprintf("this target cannot be opened: %s", t) |
| 78 | + default: |
| 79 | + noEditTargets = false |
| 80 | + hello = fmt.Sprintf(args.hello, id, t) |
| 81 | + } |
66 | 82 | c.Exec(fmt.Sprintf(">&2 echo lo: %s", shellescape.Quote(hello))) |
67 | 83 | } |
| 84 | + if noEditTargets { |
| 85 | + c.Exec(fmt.Sprintf(">&2 echo lo: no editable targets, exit")) |
| 86 | + c.Close() |
| 87 | + } |
68 | 88 | <-c.Closed() |
69 | 89 | }(client) |
70 | 90 | } |
|
0 commit comments