# Zsh to Bash conversion notes: # 1. Replaced zsh-specific glob modifiers (*oc[1]N) with ls/stat for timestamp sorting # 2. Changed local variable declarations to use standard Bash syntax # 3. Replaced array indexing and pattern matching with Bash equivalents # 4. Added nullglob behavior manually using conditional checks # 5. Used parameter expansion instead of zsh-specific syntax
# Find the latest VSCode server node process by modification time vscode_servers=("$HOME"/.vscode-server/cli/servers/*/server/node) if [[ ${#vscode_servers[@]} -eq 0 ]]; then # Also check the legacy .vscodeserver directory if .vscode-server is empty vscode_servers=("$HOME"/.vscodeserver/cli/servers/*/server/node) if [[ ${#vscode_servers[@]} -eq 0 ]]; then echo"VSCode remote server directory not found" exit 1 fi fi
# Find the most recently modified server directory latest_server="" for server in"${vscode_servers[@]}"; do if [[ -f $server ]]; then if [[ -z $latest_server ]] || [[ $server -nt $latest_server ]]; then latest_server=$server fi fi done
if [[ -z $latest_server ]]; then echo"VSCode remote server process not found" exit 1 fi
node_process=$latest_server
# Find the running server process our_process="" while IFS= read -r line; do if [[ $line == *"$node_process"* && $line == *"start-server"* ]]; then our_process=$line break fi done < <(ps ux)
if [[ -z $our_process ]]; then echo"Running VSCode server not found" exit 1 fi
# Extract PID from the process info our_pid=$(echo"$our_process" | awk '{print $2}') if [[ -z $our_pid ]]; then echo"PID for VSCode server could not be found" exit 1 fi
# Find the socket associated with the PID our_socket=$(ss -lx -p -s | grep "pid=$our_pid" | grep "\.sock" | head -n1) if [[ -z $our_socket ]]; then echo"VSCode IPC socket not found" exit 1 fi
# Extract socket path from output socket_path=$(echo"$our_socket" | awk '{print $5}') if [[ -z $socket_path ]]; then echo"VSCode IPC socket path could not be extracted" exit 1 fi
# Trim the "/node" string from the node_process path base_process=${node_process%"/node"}
# Execute with the appropriate environment variable VSCODE_IPC_HOOK_CLI="$socket_path""${base_process}/bin/remote-cli/code""$@"
添加到bashrc
1 2 3 4 5
# 1. 设为可执行文件 chmod +x code.sh # 2. 添加别名并写入bashrc vim ~/.bashrc alias code=/path/to/code.sh