Skip to content

Commit 40d1720

Browse files
committed
include the current directory in share's information
also put everything on a single line with masked urls fixes: #302
1 parent c4ff21b commit 40d1720

File tree

1 file changed

+42
-25
lines changed

1 file changed

+42
-25
lines changed

commands/share.go

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package commands
22

33
import (
44
"fmt"
5+
"log"
56
"os"
67
"ret/config"
78
"ret/theme"
89
"ret/util"
10+
"strings"
911
)
1012

1113
func init() {
@@ -30,46 +32,61 @@ func ShareHelp() string {
3032
}
3133

3234
func Share(args []string) {
35+
path, err := os.Getwd()
36+
if err != nil {
37+
log.Fatalln("💥 "+theme.ColorRed+"error"+theme.ColorReset+": %v", err)
38+
}
39+
40+
splits := strings.Split(path, "/")
41+
dir := splits[len(splits)-1]
42+
3343
flag, err := util.GetCurrentFlag()
3444
if err != nil {
3545
flag = config.FlagFormat
3646
}
3747

3848
gistUrl := ""
3949

40-
if len(config.GistToken) > 0 {
41-
files := map[string]interface{}{}
50+
if len(config.GistToken) == 0 {
51+
Chat([]string{fmt.Sprintf("🏁 `%s` **%s**", flag, dir)})
52+
return
53+
}
4254

43-
buffer, err := os.ReadFile(config.PwnScriptName)
44-
if err == nil {
45-
files[config.PwnScriptName] = map[string]interface{}{
46-
"content": string(buffer),
47-
}
48-
}
55+
files := map[string]interface{}{}
4956

50-
buffer, err = os.ReadFile(config.CryptoScriptName)
51-
if err == nil {
52-
files[config.CryptoScriptName] = map[string]interface{}{
53-
"content": string(buffer),
54-
}
57+
buffer, err := os.ReadFile(config.PwnScriptName)
58+
if err == nil {
59+
files[config.PwnScriptName] = map[string]interface{}{
60+
"content": string(buffer),
5561
}
62+
}
5663

57-
buffer, err = os.ReadFile(config.NotesFileName)
58-
if err == nil {
59-
// does not like .ret/notes.json
60-
files["notes.json"] = map[string]interface{}{
61-
"content": string(buffer),
62-
}
64+
buffer, err = os.ReadFile(config.CryptoScriptName)
65+
if err == nil {
66+
files[config.CryptoScriptName] = map[string]interface{}{
67+
"content": string(buffer),
6368
}
69+
}
6470

65-
files["flag.txt"] = map[string]interface{}{
66-
"content": string(flag),
71+
buffer, err = os.ReadFile(config.NotesFileName)
72+
if err == nil {
73+
// does not like .ret/notes.json
74+
files["notes.json"] = map[string]interface{}{
75+
"content": string(buffer),
6776
}
77+
}
6878

69-
if len(files) > 0 {
70-
gistUrl = "**" + util.Gist(files) + "**"
71-
}
79+
files["flag.txt"] = map[string]interface{}{
80+
"content": string(flag),
81+
}
82+
83+
files["path.txt"] = map[string]interface{}{
84+
"content": path,
85+
}
86+
87+
if len(files) > 0 {
88+
gistUrl = util.Gist(files)
7289
}
7390

74-
Chat([]string{fmt.Sprintf("🏁 `%s`\n%s", flag, gistUrl)})
91+
Chat([]string{fmt.Sprintf("🏁 `%s` **[%s](%s)**", flag, dir, gistUrl)})
7592
}

0 commit comments

Comments
 (0)