Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,21 @@ Define the sd script in your shell by adding the following to a shell startup fi
source "<PATH_TO_SD_SCRIPT>"
```

#### Fuzzy finding
If [fzf](https://github.com/junegunn/fzf) is in `$PATH` shifting to a non matching point will bring fzf up with a list of all points, pre filtered with your non matching point.

After:
```bash
sd add foo
sd add bar
sd add baz

sd ba
```
you will face fzf prompting yout to choose between baz and bar




# Contributing
Pull requests are always welcome.
11 changes: 8 additions & 3 deletions sd
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,17 @@ sd() {
point_path="$sdd/$requested_point"

if [[ ! -L "$point_path" ]]; then
echo "Can't shift to point '$requested_point' because it doesn't exist."

type fzf >/dev/null 2>&1 || {
echo "Can't shift to point '$requested_point' because it doesn't exist."
return 1
}
point_path="$sdd/$(find "$sdd" -maxdepth 1 -type l -exec basename "{}" \; |fzf -q "$*")"
if [ "$?" -ne "0" ] ; then
return 1
fi
fi

local requested_destination="$(readlink $point_path)/$subpath"

cd "$requested_destination"
return $?
}
Expand Down
25 changes: 25 additions & 0 deletions shpec/sd_shpec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,29 @@ describe "sd"
rmdir "$path_with_spaces"
end
end
describe "using fzf"
it "should use fzf if availible"
cd /tmp
sd add __TEMP &> /dev/null
stub_command "fzf" "echo __TEMP"
cd /
shifted_pwd="$(sd tmp && pwd)"
assert equal "$shifted_pwd" "/tmp"
rm "$sdd/__TEMP"
end

it "should pass all arguments to fzf as a search query"
stub_command "fzf" 'echo "$*" > /tmp/fzfargs'
sd foobar
assert equal "-q foobar" "$(cat /tmp/fzfargs)"
rm /tmp/fzfargs
end

it "shouldn't do anything if fzf returns non-zero"
stub_command "fzf" "return 130"
cd /tmp
sd nonexistent
assert equal "$(pwd)" "/tmp"
end
end
end