-
-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[+] #12 Add alias command which gives a session a human readable name
- Loading branch information
1 parent
26d0754
commit 3c725ee
Showing
5 changed files
with
113 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package dispatcher | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/WangYihang/Platypus/lib/context" | ||
"github.com/WangYihang/Platypus/lib/util/log" | ||
"github.com/fatih/color" | ||
) | ||
|
||
func (dispatcher Dispatcher) Alias(args []string) { | ||
if len(args) != 1 { | ||
log.Error("Arguments error, use `Help Alias` to get more information") | ||
dispatcher.AliasHelp([]string{}) | ||
return | ||
} | ||
|
||
// Ensure the interactive session is set | ||
context.Ctx.AllowInterrupt = true | ||
if context.Ctx.Current == nil { | ||
log.Error("Interactive session is not set, please use `Jump` command to set the interactive Interact") | ||
return | ||
} | ||
|
||
// Alias session | ||
log.Info("Renaming session: %s", context.Ctx.Current.FullDesc()) | ||
context.Ctx.Current.Alias = strings.TrimSpace(args[0]) | ||
|
||
// Update prompt | ||
var user string | ||
if context.Ctx.Current.User == "" { | ||
user = "unknown" | ||
} else { | ||
user = context.Ctx.Current.User | ||
} | ||
ReadLineInstance.SetPrompt(color.CyanString( | ||
"[%s] (%s) %s [%s] » ", | ||
context.Ctx.Current.Alias, | ||
context.Ctx.Current.OS.String(), | ||
context.Ctx.Current.Conn.RemoteAddr().String(), | ||
user, | ||
)) | ||
} | ||
|
||
func (dispatcher Dispatcher) AliasHelp(args []string) { | ||
fmt.Println("Usage of Alias") | ||
fmt.Println("\tAlias") | ||
} | ||
|
||
func (dispatcher Dispatcher) AliasDesc(args []string) { | ||
fmt.Println("Alias") | ||
fmt.Println("\tAlias the current session with a human-readable name.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters