dotfiles/.config/shell/functions/cds

19 lines
402 B
Text
Raw Normal View History

#!/bin/bash
# Source this and then run `cds`
# cd search: cd to a directory, given part of its name
2022-03-31 01:03:49 -07:00
# Requires: fd, fzf
2022-03-31 01:03:49 -07:00
# Usage: takes `fd` arguments
cds() {
DIR="$(fd -t d $@ | fzf -1 -q "$SEARCH_TERM" --layout=reverse --info=inline --height=10%)"
2022-03-31 01:03:49 -07:00
if [ $? -eq 0 ]; then
if [ -f "$DIR" ]; then
cd "$(dirname "$DIR")" && pwd
else
cd "$DIR" && pwd
fi
fi
}