summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateusz Czapliński <czapkofan@gmail.com>2018-10-25 23:33:07 +0200
committerMateusz Czapliński <czapkofan@gmail.com>2018-10-25 23:33:16 +0200
commitb04907d9a4b39f4e60af49f1b0802baf14c79665 (patch)
tree60e0c1069e24c584b7f755a06cc06d86c6396398
parentc61fb07f4e9a4944a80820f4735ff201b319e0bb (diff)
add -o/--output-script option
For reddit.com/u/attrigh and other zsh users. https://www.reddit.com/r/commandline/comments/9qt0ay/ultimate_plumber_is_a_tool_for_writing_linux/e8d53n1
-rw-r--r--up.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/up.go b/up.go
index 608559b..4eb68ee 100644
--- a/up.go
+++ b/up.go
@@ -72,7 +72,8 @@ const version = "0.2 (2018-10-25)"
var (
// TODO: dangerous? immediate? raw? unsafe? ...
// FIXME(akavel): mark the unsafe mode vs. safe mode with some colour or status; also inform/mark what command's results are displayed...
- unsafeMode = pflag.Bool("unsafe-full-throttle", false, "enable mode in which command is executed immediately after any change")
+ unsafeMode = pflag.Bool("unsafe-full-throttle", false, "enable mode in which command is executed immediately after any change")
+ outputScript = pflag.StringP("output-script", "o", "", "save the command to specified `file` if Ctrl-X is pressed (default: up<N>.sh)")
)
func main() {
@@ -637,9 +638,18 @@ func ctrlKey(base tcell.Key) key { return key(tcell.ModCtrl)<<16 + key(base)
func writeScript(command string, tui tcell.Screen) {
os.Stderr.WriteString("up: Ultimate Plumber v" + version + " https://github.com/akavel/up\n")
- os.Stderr.WriteString("up: writing: .")
var f *os.File
var err error
+ if *outputScript != "" {
+ os.Stderr.WriteString("up: writing " + *outputScript)
+ f, err = os.OpenFile(*outputScript, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755)
+ if err != nil {
+ goto fallback_tmp
+ }
+ goto try_file
+ }
+
+ os.Stderr.WriteString("up: writing: .")
for i := 1; i < 1000; i++ {
f, err = os.OpenFile(fmt.Sprintf("up%d.sh", i), os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0755)
switch {