Skip to content

Instantly share code, notes, and snippets.

@garywill
Created February 8, 2025 13:26
Show Gist options
  • Save garywill/c4633f0e82497e6a62b00137908861fa to your computer and use it in GitHub Desktop.
Save garywill/c4633f0e82497e6a62b00137908861fa to your computer and use it in GitHub Desktop.

Revisions

  1. garywill created this gist Feb 8, 2025.
    25 changes: 25 additions & 0 deletions terminal-opentabs.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #!/bin/bash

    arr_tab_run_cmd=("$@")
    nargs=${#arr_tab_run_cmd[@]}

    terminal_args=(--window)

    for ((i=0; i<nargs; i++)); do
    if [ $i -eq 0 ]; then
    echo "第一个tab: ${arr_tab_run_cmd[$i]}"
    terminal_args+=(-H -e)
    else
    echo "更多tab: ${arr_tab_run_cmd[$i]}"
    terminal_args+=(--tab -H -e)
    fi

    # 使用 printf "%q" 安全转义命令参数
    escaped_cmd=$(printf "%q" "${arr_tab_run_cmd[$i]}")
    terminal_args+=("bash -c $escaped_cmd")
    done

    # echo "传给终端程序的所有参数:"
    # printf "%s\n" "${terminal_args[@]}"

    xfce4-terminal "${terminal_args[@]}"