2022-01-01 18:24:20 -08:00
|
|
|
#!/bin/bash
|
2022-01-02 17:46:16 -08:00
|
|
|
# Source this and then run `cds`
|
2022-01-01 18:24:20 -08:00
|
|
|
# cd search: cd to a directory, given part of its name
|
2022-03-31 01:03:49 -07:00
|
|
|
|
|
|
|
# Requires: fd, fzy
|
|
|
|
# Usage: takes `fd` arguments
|
2022-01-01 18:24:20 -08:00
|
|
|
|
|
|
|
cds() {
|
2022-03-31 01:03:49 -07:00
|
|
|
DIR="$(fd -t d $@ | fzy)"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
if [ -f "$DIR" ]; then
|
2022-01-01 18:24:20 -08:00
|
|
|
cd "$(dirname "$DIR")" && pwd
|
|
|
|
else
|
|
|
|
cd "$DIR" && pwd
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|