73
62

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Finderで開いてるディレクトリへcdするコマンド

Last updated at Posted at 2021-02-20

Finderで開いてるディレクトリへcdするコマンドを作ります。

~/.zshrc
cdf() {
  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"; pwd
  else
    echo 'No Finder window found' >&2
  fi
}

alias f='open .'

シェルを開き直します。

$ exec $SHELL -l

Finderでcdしたいディレクトリを開いておきます。

$ cdf

移動できればokです。

$ f

カレントディレクトリをFinderで開くエイリアスを付けておくと便利です。

参考

73
62
6

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
73
62

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?