Skip to content

Commit

Permalink
port "dir cfg" to bash
Browse files Browse the repository at this point in the history
 * exit 2 from `dirp` signals that stdout contains path
   to config file
  • Loading branch information
avindra committed Jan 22, 2021
1 parent 93a4f18 commit 9bde789
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
build:
@go build .
@go build -ldflags "-s -w" .

run:
@go run .

test:
@go test ./...
@go test ./...
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"os"

dirp "github.com/avindra/dirp/src"
Expand Down Expand Up @@ -29,6 +30,9 @@ func main() {
} else {
dirp.PrintHook() // fish
}
} else if arg0 == "cfg" {
fmt.Print(dirp.GetConfigPath())
os.Exit(2)
}
return
}
Expand Down
26 changes: 15 additions & 11 deletions src/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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`)
}

0 comments on commit 9bde789

Please sign in to comment.