From 8a6001587fce391135d9779da3cf0b73db329b7c Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Tue, 27 Aug 2024 13:47:53 -0700 Subject: [PATCH] Add pwdf function and cdf alias for macOS users This commit adds a new function 'pwdf' to get the current Finder directory and an alias 'cdf' to change to that directory, improving integration between Terminal and Finder for macOS users. --- zshrc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/zshrc b/zshrc index 536178a..1052f20 100755 --- a/zshrc +++ b/zshrc @@ -290,6 +290,23 @@ function cd () { fi } +if mac; then + # Courtesy of https://curtclifton.net/finder-and-terminal-are-friends + pwdf() { + /usr/bin/osascript <<" EOT" + tell application "Finder" + try + set currFolder to (folder of the front window as alias) + on error + set currFolder to (path to desktop folder as alias) + end try + POSIX path of currFolder + end tell + EOT + } + alias cdf='cd "`pwdf`"' +fi + ### Unsorted (new) stuff # ======================= # if commands takes more than 60 seconds tell me how long it took