キーボードで端末リンクを開く

キーボードで端末リンクを開く

非常に便利なものの1つurxvtは、キーボードショートカットを使用してターミナル画面に表示されるハイパーリンクをナビゲートして開くことができることです(urxvt*IIRC項目のいくつかを追加)。.Xresources

これでこの機能をオンにしましたが、xfce4-terminalこの機能は消えました。周りを見回しました~/.config/xfce4/terminal/accels.scmが、関連内容が見つかりませんでした。現在は、マウスを押してCtrlブラウザで開こうとする端末のURLをクリックする必要があります。

質問:キーボードのみを使用してxfce4端末から印刷されたURLを選択して開くことはできますか?

この機能を提供する他の端末エミュレータについて聞きたいのですが、まだurxvtに戻る予定はありません。

答え1

@ibuprofenの答えを少し拡張すると、URLが複数行にまたがっていない限り、回避策は次のとおりです。

  1. 開く++CtrlShiftF
  2. 正規表現を使用した検索の有効化
  3. http\S+検索語で入力
  4. Enter目的のURLが強調表示されるまでタップします。
  5. ~によるとEsc
  6. Ctrl+ Shift+を押してCURLをクリップボードにコピーします。
  7. Ctrl+を使用してブラウザに貼り付けます(アドレスバーに焦点を当てるには、まず+などのキーをV押す必要があります)。CtrlL

答え2

これは、Linux、BSD、またはmacOSでBashを実行しているすべての端末で機能します。(ビデオデモ)

注:最後のリンクのみが開きますが、間違いなくインタラクティブな選択に拡張することができます。

# Add this somewhere in your .bashrc

# Record terminal to this file.
__terminal_recording_file="${HOME}/.cache/terminal_recording"

function __start_recording_terminal () {
  # if the file exists, don't record, as this means that the recording is
  # already happening in the current shell.
  if [[ -f "$__terminal_recording_file" ]]; then
    return
  fi

  # save the PID of the shell that started the recording
  echo $$ >| "$__terminal_recording_file.pid"

  # Start recording, with "flushing" option to have quick access to the last
  # output, and quiet option to disable "started recording" message.
  # Also, check if script can be run with '-f' (linux) or '-F' (macOS)
  script -q -f /dev/null >/dev/null 2>&1
  local script_can_be_run_with_f="$?"
  if [[ "$script_can_be_run_with_f" -ne 0 ]]; then
    script -q -F "$__terminal_recording_file"
  else
    script -q -f "$__terminal_recording_file"
  fi
}
start_recording_terminal # comment this line to disable recording

function __open_last_visible_link_in_terminal () {
  # look for the last thing that looks like a link in the last 50 lines of the
  # terminal recording (assumed to be the currently visible part of the
  # terminal)
  local link="$( tail -n 50 "$__terminal_recording_file" | tac | grep -Eo -m 1 --color=never 'https?://[[:print:]]+')"
  if [[ -z "$link" ]]; then
    echo "No link found"
    return 1
  fi

  echo "Opening link: $link"
  open "$link"
}

# Bind Ctrl-K to "__open_last_visible_link_in_terminal" in all modes
# Also, it runs Ctrl-u first, so that the command line is cleared and it
# doesn't interfere.
bind -m emacs     '"\C-k":"\C-u __open_last_visible_link_in_terminal\n"'
bind -m vi-insert '"\C-k":"\C-u __open_last_visible_link_in_terminal\n"'
bind -m vi        '"\C-k":"\C-u __open_last_visible_link_in_terminal\n"'

# cleanup function on Bash exit
function __cleanup () {
  # if a recording is happening and the parent of this shell is the recording
  # command, kill the shell that started the recording and remove the files
  ps -p $PPID | grep -q 'script -q'
  is_parent_script="$?"
  if [[ -f "$__terminal_recording_file" && "$is_parent_script" -eq 0 ]]; then
    rm "$__terminal_recording_file"

    # kill the shell that started the recording
    local pid="$(cat "$__terminal_recording_file.pid")"
    rm "$__terminal_recording_file.pid"
    kill -9 "$pid"
  fi
}
trap __cleanup EXIT

ところで、Alacrittyには以下の機能が組み込まれています。https://wiki.archlinux.org/title/Alacritty#Regex_hints

次のコマンドを使用してtmuxでも実行できます。tmux-urlviewはめ込む。

関連情報