![gio open이 어떤 프로그램을 사용하고 있는지 확인하세요.](https://linux55.com/image/223752/gio%20open%EC%9D%B4%20%EC%96%B4%EB%96%A4%20%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%A8%EC%9D%84%20%EC%82%AC%EC%9A%A9%ED%95%98%EA%B3%A0%20%EC%9E%88%EB%8A%94%EC%A7%80%20%ED%99%95%EC%9D%B8%ED%95%98%EC%84%B8%EC%9A%94..png)
이 명령을 실행하면 해당 특정 파일 형식에 대한 기본 응용 프로그램을 사용하여 파일이 열리는 것을 gio open --help
확인할 수 있습니다 .gio open
파일을 명령줄로 여는 응용 프로그램의 출력을 어떻게 얻을 수 있습니까?
나는 비슷한 것을 gio open somefile.txt --print-application
출력하고 싶습니다 gedit
.
답변1
gio
이를 사용할 수는 없지만 xdg-mime
파일의 파일 형식을 쿼리한 다음 기본 애플리케이션의 설명 파일을 가져오는 데 사용할 수 있습니다.
# This prints the mime type of somefile.txt
xdg-mime query filetype somefile.txt
# Output, for example: text/plain
# This queries the default application that opens a mime type
xdg-mime query default text/plain
# Output, for example: gedit.desktop
프로세스 대체를 통해 이 두 가지를 결합하거나 이를 쉘 함수에 넣을 수 있습니다.
# do a substitution to do this on one line
xdg-mime query default $(xdg-mime query filetype somefile.txt)
# Or make a small function that solves the whole thing:
function get_handler_application() {
filetype="$(xdg-mime query filetype "$1")"
xdg-mime query default "${filetype}"
}
# call like:
# get_handler_application somefile.txt
그러나 사실은 당신이 얻는 결과가 다음과 같다는 것을 알게 될 것입니다.아니요실행 파일이지만 .desktop 파일 - 데스크톱 파일에는 프로그램 호출 시 사용해야 하는 모든 옵션이 포함되어 있으므로 이는 중요한 기능입니다.
:
환경 변수의 구분된 각 경로 아래에 있는 "applications"라는 디렉터리에서 이러한 데스크톱 파일을 찾을 수 있습니다 $XDG_DATA_DIRS
.
쉘이 다음과 같은 경우 zsh
매우 우아하게 처리됩니다 .
#!/usr/bin/zsh
# Copyright 2023 Marcus Müller
# SPDX-License-Identifier: GPL-3.0-or-later
# We can get the name of the file handler this way,
# for example:
# get_handler_application aaargh.txt
# outputs:
# text/plain
function get_handler_application() {
filetype="$(xdg-mime query filetype "$1")"
xdg-mime query default "${filetype}"
}
# Get the full path to the specific file that opens this file
# There's multiple paths, and user-defined ones take priority
# over system-defined ones. For example:
# get_handler_desktop_file aaargh.txt
# outputs:
# pluma.desktop
function get_handler_desktop_file(){
desktop_fname="$(get_handler_application "$1")"
for candidate in ${(ps.:.)XDG_DATA_DIRS}; do
fullpath="${candidate}/applications/${desktop_fname}"
[[ -r "${fullpath}" ]] && printf '%s' ${fullpath} && break
done
}
# Get all the commands that are specified in the desktop file.
# There can be multiple, because some file handlers have extended
# options for opening things, like "open in new window" or "make
# new document from this template.
# For example:
# get_handler_command_lines holygrail.html
# outputs:
# firefox %u
# firefox --new-window %u
# firefox --private-window %u
# firefox --ProfileManager
function get_handler_command_lines() {
sed -n 's/^Exec=\(.*\)*/\1/p' "$(get_handler_desktop_file "$1")"
}
답변2
gio
단 두 단계만으로 이를 수행할 수 있습니다. 다음을
통해 콘텐츠 유형(예: MIME 유형)을 가져옵니다 gio info
.
gio info -a standard::content-type clip.mp4
다음을 인쇄하세요:
uri: file:///home/tmp/clip.mp4
attributes:
standard::content-type: video/mp4
이제 실행할 수 있는 MIME 유형을 알았습니다.
gio mime video/mp4
해당 MIME 유형에 대해 등록된 모든 처리기를 인쇄합니다. 기본값이 먼저 나열됩니다.
Default application for 'video/mp4': mpv.desktop
Registered applications:
mpv.desktop
smplayer.desktop
Recommended applications:
mpv.desktop
smplayer.desktop
따라서 이 경우 파일 이 gio
사용됩니다.mpv
open
clip.mp4