commit f4c91fc6555366a5d3af86381cf973ff8df0909a parent 00f36f436170a6559b0f2004ad1c75a2ce0c2047 Author: Alex Balgavy <alex@balgavy.eu> Date: Tue, 22 Dec 2020 11:30:22 +0100 shell: simplified cdf Diffstat:
M | shell/functions | | | 9 | +++++---- |
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/shell/functions b/shell/functions @@ -51,11 +51,12 @@ fi if command -v osascript &> /dev/null; then # cd to current Finder directory cdf() { - local target=$(osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)') - if [ "$target" != "" ]; then - cd "$target" || return; pwd + target="$(osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)')" + if [ -n "$target" ]; then + cd "$target" || printf "Could not cd to %s.\n" >&2 + pwd else - echo 'No Finder window found' >&2 + printf 'No Finder window found.\n' >&2 fi }