키보드로 터미널 링크 열기

키보드로 터미널 링크 열기

매우 유용한 것 중 하나 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끼워 넣다.

관련 정보