1
0
Fork 0

adds `cdx` function which locates directory of an executable in your path and changes to it

pull/483/head
Wil Moore III 11 years ago
parent a4bacb8bb9
commit afb097ccfa

@ -124,6 +124,7 @@ Functions
### Files and Directories
- `cdls` changes to a directory and lists its contents.
- `cdx` locates directory of an executable in your path and changes to it.
- `dut` displays the grand total disk usage using human readable units.
- `find-exec` finds files and executes a command on them.
- `mkdcd` makes a directory and changes to it.
@ -153,6 +154,7 @@ Authors
- [Robby Russell](https://github.com/robbyrussell)
- [Suraj N. Kurapati](https://github.com/sunaku)
- [Sorin Ionescu](https://github.com/sorin-ionescu)
- [Wil Moore III](https://github.com/wilmoore)
[1]: https://github.com/sorin-ionescu/prezto/issues

@ -185,3 +185,24 @@ function psu {
ps -U "${1:-$USER}" -o 'pid,%cpu,%mem,command' "${(@)argv[2,-1]}"
}
# locates directory of an executable in your path and changes to it.
function cdx {
local exe="$1"
local fqe="$(command -v $exe 2>/dev/null)"
local dir="$(dirname $fqe 2>/dev/null)"
if [[ ! -x "$fqe" ]]; then
echo "cdx: '$exe' not found."
return 1
fi
if [[ ! -d "$dir" ]]; then
echo "cdx: '$dir' is not a directory"
return 1
fi
cd $dir
return $?
}

Loading…
Cancel
Save