cds: big improvements
This commit is contained in:
parent
fc03d2531f
commit
f97cf48ba4
1 changed files with 6 additions and 9 deletions
|
@ -1,21 +1,18 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Source this and then run `cds`
|
# Source this and then run `cds`
|
||||||
|
|
||||||
# cd search: cd to a directory, given part of its name
|
# cd search: cd to a directory, given part of its name
|
||||||
# (also can take arguments for an `fd` commnd)
|
|
||||||
# (also can cd to a file if `-t f` is passed)
|
# Requires: fd, fzy
|
||||||
|
# Usage: takes `fd` arguments
|
||||||
|
|
||||||
cds() {
|
cds() {
|
||||||
if ! [ -z "$1" ];then
|
DIR="$(fd -t d $@ | fzy)"
|
||||||
DIR="$(fd --max-results=1 -t d $@)"
|
if [ $? -eq 0 ]; then
|
||||||
if [ -f "$DIR" ];then
|
if [ -f "$DIR" ]; then
|
||||||
cd "$(dirname "$DIR")" && pwd
|
cd "$(dirname "$DIR")" && pwd
|
||||||
else
|
else
|
||||||
cd "$DIR" && pwd
|
cd "$DIR" && pwd
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
echo "$0: no arguments provided"
|
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue