2006-02-08 19:20:05 +10:00
|
|
|
#
|
|
|
|
# This allows us to use 'open FILENAME' to open a given file in the default
|
|
|
|
# application for the file.
|
|
|
|
#
|
2017-02-13 17:30:38 +01:00
|
|
|
if not command -sq open
|
2016-11-27 21:27:22 -08:00
|
|
|
function open --description "Open file in default application"
|
2020-03-09 19:36:12 +01:00
|
|
|
set -l options h/help
|
2018-11-22 12:43:35 +01:00
|
|
|
argparse -n open $options -- $argv
|
2017-07-13 13:55:15 -07:00
|
|
|
or return
|
|
|
|
|
|
|
|
if set -q _flag_help
|
|
|
|
__fish_print_help open
|
|
|
|
return 0
|
2016-11-27 21:27:22 -08:00
|
|
|
end
|
2006-11-18 02:24:38 +10:00
|
|
|
|
2018-11-22 12:43:35 +01:00
|
|
|
if not set -q argv[1]
|
2022-04-03 20:57:55 -07:00
|
|
|
printf (_ "%ls: Expected at least %d args, got only %d\n") open 1 0 >&2
|
2018-11-22 12:43:35 +01:00
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
2016-11-27 21:27:22 -08:00
|
|
|
if type -q -f cygstart
|
|
|
|
for i in $argv
|
|
|
|
cygstart $i
|
|
|
|
end
|
|
|
|
else if type -q -f xdg-open
|
|
|
|
for i in $argv
|
2023-10-04 15:57:32 +02:00
|
|
|
xdg-open $i
|
2016-11-27 21:27:22 -08:00
|
|
|
end
|
|
|
|
else
|
2022-04-03 20:57:55 -07:00
|
|
|
echo (_ 'No open utility found. Try installing "xdg-open" or "xdg-utils".') >&2
|
2016-11-27 21:27:22 -08:00
|
|
|
end
|
|
|
|
end
|
2006-02-08 19:20:05 +10:00
|
|
|
end
|