codex: make desktop launch helpers cwd-aware
This commit is contained in:
@@ -9,12 +9,12 @@ suppress_unstable_features_warning = true
|
|||||||
# ~/.codex/config.local-state.toml.
|
# ~/.codex/config.local-state.toml.
|
||||||
|
|
||||||
[mcp_servers.chrome-devtools]
|
[mcp_servers.chrome-devtools]
|
||||||
command = "npx"
|
command = "/usr/bin/env"
|
||||||
args = ["-y", "chrome-devtools-mcp@latest", "--auto-connect"]
|
args = ["PATH=/etc/profiles/per-user/imalison/bin:/run/current-system/sw/bin:/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin", "npx", "-y", "chrome-devtools-mcp@latest", "--auto-connect"]
|
||||||
|
|
||||||
[mcp_servers.observability]
|
[mcp_servers.observability]
|
||||||
command = "npx"
|
command = "/usr/bin/env"
|
||||||
args = ["-y", "@google-cloud/observability-mcp"]
|
args = ["PATH=/etc/profiles/per-user/imalison/bin:/run/current-system/sw/bin:/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin", "npx", "-y", "@google-cloud/observability-mcp"]
|
||||||
|
|
||||||
[mcp_servers.openaiDeveloperDocs]
|
[mcp_servers.openaiDeveloperDocs]
|
||||||
url = "https://developers.openai.com/mcp"
|
url = "https://developers.openai.com/mcp"
|
||||||
|
|||||||
@@ -1,22 +1,76 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
function _tmcodex_expand_dir {
|
||||||
|
case "$1" in
|
||||||
|
"~")
|
||||||
|
printf '%s\n' "$HOME"
|
||||||
|
;;
|
||||||
|
"~/"*)
|
||||||
|
printf '%s\n' "$HOME/${1#"~/"}"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
printf '%s\n' "$1"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
function _tmcodex_resolve_dir {
|
||||||
|
dir="$(_tmcodex_expand_dir "$1")"
|
||||||
|
if [ ! -d "$dir" ]; then
|
||||||
|
echo "tmcodex: directory not found: $1" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd -- "$dir" && pwd -P
|
||||||
|
}
|
||||||
|
|
||||||
function tmcodex {
|
function tmcodex {
|
||||||
|
launch_dir="$PWD"
|
||||||
|
|
||||||
|
case "${1:-}" in
|
||||||
|
-C|--cd)
|
||||||
|
if [ -z "${2:-}" ]; then
|
||||||
|
echo "tmcodex: $1 requires a directory" >&2
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
launch_dir="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--cd=*)
|
||||||
|
launch_dir="${1#--cd=}"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
expanded_first_arg="$(_tmcodex_expand_dir "${1:-}")"
|
||||||
|
if [ -n "${1:-}" ] && [ -d "$expanded_first_arg" ]; then
|
||||||
|
launch_dir="$1"
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
launch_dir="$(_tmcodex_resolve_dir "$launch_dir")" || return
|
||||||
|
|
||||||
# Record launch directories so rofi_tmcodex can offer good defaults.
|
# Record launch directories so rofi_tmcodex can offer good defaults.
|
||||||
state_dir="${XDG_STATE_HOME:-$HOME/.local/state}/rofi-tmcodex"
|
state_dir="${XDG_STATE_HOME:-$HOME/.local/state}/rofi-tmcodex"
|
||||||
history_file="$state_dir/dirs"
|
history_file="$state_dir/dirs"
|
||||||
mkdir -p "$state_dir" 2>/dev/null || true
|
mkdir -p "$state_dir" 2>/dev/null || true
|
||||||
if [ -d "$PWD" ]; then
|
if [ -d "$launch_dir" ]; then
|
||||||
tmp="$(mktemp 2>/dev/null || true)"
|
tmp="$(mktemp 2>/dev/null || true)"
|
||||||
if [ -n "$tmp" ]; then
|
if [ -n "$tmp" ]; then
|
||||||
{ printf '%s\n' "$PWD"; cat "$history_file" 2>/dev/null || true; } \
|
{ printf '%s\n' "$launch_dir"; cat "$history_file" 2>/dev/null || true; } \
|
||||||
| awk 'NF && !seen[$0]++' \
|
| awk 'NF && !seen[$0]++' \
|
||||||
| head -n 200 >"$tmp" 2>/dev/null || true
|
| head -n 200 >"$tmp" 2>/dev/null || true
|
||||||
mv -f "$tmp" "$history_file" 2>/dev/null || true
|
mv -f "$tmp" "$history_file" 2>/dev/null || true
|
||||||
else
|
else
|
||||||
printf '%s\n' "$PWD" >>"$history_file" 2>/dev/null || true
|
printf '%s\n' "$launch_dir" >>"$history_file" 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
trw codex --dangerously-bypass-approvals-and-sandbox --cd "$PWD" "$@"
|
|
||||||
|
(
|
||||||
|
cd -- "$launch_dir" || exit
|
||||||
|
trw codex --dangerously-bypass-approvals-and-sandbox --cd "$launch_dir" "$@"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
tmcodex "$@"
|
tmcodex "$@"
|
||||||
|
|||||||
Reference in New Issue
Block a user