Skip to content

Instantly share code, notes, and snippets.

@winebarrel
Created October 23, 2026 04:34
Show Gist options
  • Select an option

  • Save winebarrel/ee2c6dfa5e82651ecfea3d6875692686 to your computer and use it in GitHub Desktop.

Select an option

Save winebarrel/ee2c6dfa5e82651ecfea3d6875692686 to your computer and use it in GitHub Desktop.
zed() {
local db="$HOME/Library/Application Support/Zed/db/0-stable/db.sqlite"
local arg target
# オプションを付けた場合や、ディレクトリ以外を開く場合はそのまま渡す
for arg in "$@"; do
[[ $arg == -* ]] && { command zed "$@"; return }
done
if (( $# != 1 )) || [[ ! -d $1 ]]; then
command zed "$@"; return
fi
target=${1:A} # 絶対パスに直し、シンボリックリンクも解決する
# 今のセッションで、まったく同じディレクトリが開かれているか調べる
local exact
exact=$(sqlite3 -readonly "$db" "
select 1 from workspaces
where session_id = (select value from kv_store where key = 'session_id')
and paths = '${target//\'/\'\'}'
limit 1" 2>/dev/null)
if [[ -n $exact ]]; then
command zed "$target" # 同じディレクトリなら既存のウィンドウにフォーカス
else
command zed -n "$target" # 下位ディレクトリや、まだ開いていないディレクトリは新しいウィンドウで開く
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment