diff --git a/Makefile b/Makefile index 394f139..a6f67b0 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ build: - @go build . + @go build -ldflags "-s -w" . run: @go run . test: - @go test ./... \ No newline at end of file + @go test ./... diff --git a/main.go b/main.go index 8d3065a..918d517 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "os" dirp "github.com/avindra/dirp/src" @@ -29,6 +30,9 @@ func main() { } else { dirp.PrintHook() // fish } + } else if arg0 == "cfg" { + fmt.Print(dirp.GetConfigPath()) + os.Exit(2) } return } diff --git a/src/hook.go b/src/hook.go index 66dff8d..459e853 100644 --- a/src/hook.go +++ b/src/hook.go @@ -12,10 +12,16 @@ if [[ $? -eq 0 ]]; then fi function dir() { - dir=$(dirp $@) - if [[ -n $dir ]]; then - echo "Switching to $dir... " - pushd "$dir" + response=$(dirp $@) + status=$? + if [[ -n $response ]]; then + if [[ $status -eq 2 ]]; then + $EDITOR "$response" + return $? + fi + + echo "Switching to $response... " + pushd "$response" fi } @@ -25,21 +31,19 @@ function dir() { // PrintHook emits shell code for Fish func PrintHook() { fmt.Println(`function dir - if [ "$argv[1]" = "cfg" ] - $EDITOR "$HOME/.config/dir/list" + set response (dirp $argv) + if [ $status = 2 ] + $EDITOR "$response" return $status - else - # default - set selection (dirp $argv) end - if [ "x$selection" = "x" ] + if [ "x$response" = "x" ] echo -n "How are we doing @ " uptime return $status end - echo "Switching to $selection" + echo "Switching to $response" pushd "$selection" end`) }