Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mborho/rem
Browse files Browse the repository at this point in the history
  • Loading branch information
mborho committed Jul 1, 2021
2 parents 2491d7d + 3aad554 commit bf19dfa
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Go
on:
push:
branches:
- "*"
- "**"
pull_request:
branches:
- "*"
- "**"

jobs:

Expand Down
3 changes: 3 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var (
helpFlag *bool
addFlag *bool
tagFlag *string
printFlag *bool
filter *string
)

Expand All @@ -36,6 +37,7 @@ func init() {
helpFlag = flag.Bool("h", false, "show this help")
addFlag = flag.Bool("a", false, "add a command")
tagFlag = flag.String("t", "", "tag for command")
printFlag = flag.Bool("p", false, "print command before executing")
filter = flag.String("f", "", "List commands by regexp filter.")
}

Expand All @@ -49,6 +51,7 @@ func run(remfile string) error {
filename: remfile,
global: *globalFlag,
},
printBeforeExec: *printFlag,
}
rem.read()

Expand Down
1 change: 1 addition & 0 deletions help.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ COMMANDS:
FLAGS:
-g - Use global rem file ~/.rem
-t - Tag for command when adding with -a/add.
-p - Print command to stdout before executing index/tag.
EXAMPLES:
rem add ls -la - Adds "ls -la" to list.
Expand Down
7 changes: 6 additions & 1 deletion line.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (l *Line) read(line string) {
}
}

func (l *Line) execute() error {
func (l *Line) execute(printCmd bool) error {
// get the pid of the calling shell
pr, err := ps.FindProcess(os.Getppid())
if err != nil {
Expand All @@ -63,6 +63,11 @@ func (l *Line) execute() error {
l.execFlag = "-c"
}

// print cmd before executing
if printCmd == true {
fmt.Println(l.cmd)
}

// /bin/bash -c "ls -la"
execParts := []string{callerPath, l.execFlag, l.cmd}

Expand Down
11 changes: 6 additions & 5 deletions rem.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ import (
)

type Rem struct {
path string
lines []*Line
hasTags bool
path string
lines []*Line
hasTags bool
printBeforeExec bool
File
}

Expand All @@ -56,13 +57,13 @@ func (r *Rem) executeIndex(index int) error {
if err != nil {
return err
}
return line.execute()
return line.execute(r.printBeforeExec)
}

func (r *Rem) executeTag(tag string) error {
for _, line := range r.lines {
if line.tag == tag {
return line.execute()
return line.execute(r.printBeforeExec)
}
}
return errors.New("Tag not found.")
Expand Down

0 comments on commit bf19dfa

Please sign in to comment.