Skip to content

Commit

Permalink
Add rc hook
Browse files Browse the repository at this point in the history
  • Loading branch information
avindra committed Jan 28, 2021
1 parent 2f59333 commit fe05ae3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
11 changes: 9 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ func main() {
cfg := dirp.FindDirs(arg0)
dirp.Selector(cfg)
} else if arg0 == "hook" {
if len(args) >= 2 && args[1] == "fish" {
dirp.PrintFishHook()
if len(args) >= 2 {
switch args[1] {
case "fish":
dirp.PrintFishHook()
case "rc":
dirp.PrintRcHook()
default:
panic("I don't know about " + args[1])
}
} else {
dirp.PrintHook()
}
Expand Down
27 changes: 26 additions & 1 deletion src/hook.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package dirp

import "fmt"
import (
"fmt"
"strings"
)

// PrintHook emits shell code for Bash, ZSH, sh, BusyBox, etc
func PrintHook() {
Expand Down Expand Up @@ -53,3 +56,25 @@ func PrintFishHook() {
pushd "$stdout"
end`)
}

// PrintRcHook emits code for rc, the plan 9 shell
func PrintRcHook() {
src := `fn dir {
stdout=` + "`" + `{dirp $*};
if (~ $bqstatus 2 ) {
$EDITOR $stdout;
return $status;
};
if (~ "x$stdout" "x" ) {
echo -n How are we doing @;
uptime;
return $status;
};
echo Switching to $stdout;
cd $stdout
}`

fmt.Println(strings.ReplaceAll(src, "\t", " "))
}

0 comments on commit fe05ae3

Please sign in to comment.