Add fish completions (#2247)

* Add fish completions

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Fix minor bug in `flameshot config` output

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Add fish completions to install target

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Add release note

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Update rpm package spec

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>
This commit is contained in:
Haris Gušić
2022-01-14 22:55:56 +01:00
committed by GitHub
parent 2a034d13a8
commit ab32f40348
6 changed files with 121 additions and 3 deletions

View File

@@ -0,0 +1,111 @@
set -l SUBCOMMANDS gui screen full launcher config
####################
# HELPER FUNCTIONS #
####################
# Complete the subcommand provided as the first argument.
# The rest of the arguments are the same as fish's `complete`. The option
# '-c flameshot' is implicit.
function __flameshot_complete --argument-names cmd
set -l conditions "__fish_seen_subcommand_from $cmd"
argparse -i "n/condition=" -- $argv[2..]
[ -n "$_flag_n" ] && set -l conditions "$conditions && $_flag_n"
complete -c flameshot $argv -n "$conditions"
end
# Return success if the command line contains no positional arguments
function __flameshot_no_positional_args
set -l -- args (commandline -po) # cmdline broken up into list
set -l -- cmdline (commandline -p) # single string
set -l -- n (count $args) # number of cmdline tokens
for i in (seq 2 $n)
set -l arg $args[$i]
[ -z "$arg" ] && continue # can be caused by '--' argument
# If the the last token is a positional argument and there is no
# trailing space, we ignore it
[ "$i" = "$n" ] && [ (string sub -s -1 "$cmdline") != ' ' ] && break
if string match -rvq '^-' -- "$arg" # doesn't start with -
return 1
end
end
# contains a '--' argument
string match -r -- '\s--\s' "$cmdline" && return 1
return 0
end
# Complete paths matching $argv
function __flameshot_complete_paths
complete -C"nOnExIsTeNtCoMmAndZIOAGA2329jdbfaFkahDf21234h8z43 $argv"
end
# Complete the region option
function __flameshot_complete_region --argument subcommand
if [ "$subcommand" = "screen" ]
echo all\tCapture entire screen
else
echo all\tCapture all screens
echo screen0\tCapture screen 0
echo screen1\tCapture screen 1
echo screen2\tCapture screen 2
echo screen3\tCapture screen 3
end
echo WxH+X+Y\tCustom region in pixels
end
# Complete screen numbers
function __flameshot_complete_screen_number
echo 0\tScreen 0
echo 1\tScreen 1
echo 2\tScreen 2
echo 3\tScreen 3
end
###############
# COMPLETIONS #
###############
# No subcommand
complete -c flameshot -n __flameshot_no_positional_args -f -a "$SUBCOMMANDS"
complete -c flameshot -l "help" -s "h" -f -d "Display help message"
complete -c flameshot -l "version" -s "v" -f -d "Display version information" -n __flameshot_no_positional_args
# GUI subcommand
__flameshot_complete gui -f
__flameshot_complete gui -l "path" -s "p" -rk -d "Output file or directory"
__flameshot_complete gui -l "clipboard" -s "c" -f -d "Copy screenshot to the clipboard"
__flameshot_complete gui -l "delay" -s "d" -frk -d "Delay time in milliseconds"
__flameshot_complete gui -l "region" -frk -d "Screenshot region to select (WxH+X+Y)" -a "(__flameshot_complete_region gui)"
__flameshot_complete gui -l "raw" -s "r" -f -d "Print raw PNG capture"
__flameshot_complete gui -l "print-geometry" -s "g" -f -d "Print geometry of the selection"
__flameshot_complete gui -l "upload" -s "u" -f -d "Upload the screenshot"
__flameshot_complete gui -l "pin" -f -d "Pin the screenshot to the screen"
__flameshot_complete gui -l "accept-on-select" -s "s" -f -d "Accept capture as soon as a selection is made"
# SCREEN subcommand
__flameshot_complete screen -f
__flameshot_complete screen -l "number" -s "n" -frk -d "Screen number (starting from 0)" -a "(__flameshot_complete_screen_number)"
__flameshot_complete screen -l "path" -s "p" -rk -d "Output file or directory"
__flameshot_complete screen -l "clipboard" -s "c" -f -d "Copy screenshot to the clipboard"
__flameshot_complete screen -l "delay" -s "d" -frk -d "Delay time in milliseconds"
__flameshot_complete screen -l "region" -frk -d "Screenshot region to select (WxH+X+Y)" -a "(__flameshot_complete_region screen)"
__flameshot_complete screen -l "raw" -s "r" -f -d "Print raw PNG capture"
__flameshot_complete screen -l "upload" -s "u" -f -d "Upload the screenshot"
__flameshot_complete screen -l "pin" -f -d "Pin the screenshot to the screen"
# FULL command
__flameshot_complete full -f
__flameshot_complete full -l "path" -s "p" -rk -d "Output file or directory"
__flameshot_complete full -l "clipboard" -s "c" -f -d "Copy screenshot to the clipboard"
__flameshot_complete full -l "delay" -s "d" -frk -d "Delay time in milliseconds"
__flameshot_complete full -l "region" -frk -d "Screenshot region to select (WxH+X+Y)" -a "(__flameshot_complete_region full)"
__flameshot_complete full -l "raw" -s "r" -f -d "Print raw PNG capture"
__flameshot_complete full -l "upload" -s "u" -f -d "Upload the screenshot"
# LAUNCHER command doesn't have any completions specific to itself
# CONFIG command -- TODO will be completed in a future version
__flameshot_complete config -f
__flameshot_complete config -l "check" -f -d "Check the configuration for errors"

View File

@@ -63,6 +63,8 @@ We will be in beta for 1-2 weeks depending on what kind of issues are found and
- Added an option to enable anti-aliasing when zooming in on a pinned image. - Added an option to enable anti-aliasing when zooming in on a pinned image.
- Added completions for the fish shell
## Bug Fixes ## Bug Fixes
- The border that indicates an object is moveable is no longer saved or copied with the underlying image. - The border that indicates an object is moveable is no longer saved or copied with the underlying image.

View File

@@ -116,6 +116,7 @@ desktop-file-validate %{buildroot}%{_datadir}/applications/*.desktop
%endif %endif
%{_datadir}/bash-completion/completions/%{name} %{_datadir}/bash-completion/completions/%{name}
%{_datadir}/zsh/site-functions/_%{name} %{_datadir}/zsh/site-functions/_%{name}
%{_datadir}/fish/vendor_completions.d/%{name}.fish
%{_datadir}/dbus-1/interfaces/org.flameshot.Flameshot.xml %{_datadir}/dbus-1/interfaces/org.flameshot.Flameshot.xml
%{_datadir}/dbus-1/services/org.flameshot.Flameshot.service %{_datadir}/dbus-1/services/org.flameshot.Flameshot.service
%{_datadir}/icons/hicolor/*/apps/*.png %{_datadir}/icons/hicolor/*/apps/*.png

View File

@@ -283,12 +283,15 @@ if (UNIX)
configure_file(${CMAKE_SOURCE_DIR}/data/appdata/org.flameshot.Flameshot.metainfo.xml configure_file(${CMAKE_SOURCE_DIR}/data/appdata/org.flameshot.Flameshot.metainfo.xml
${CMAKE_CURRENT_BINARY_DIR}/share/metainfo/org.flameshot.Flameshot.metainfo.xml COPYONLY) ${CMAKE_CURRENT_BINARY_DIR}/share/metainfo/org.flameshot.Flameshot.metainfo.xml COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/data/shell-completion/flameshot configure_file(${CMAKE_SOURCE_DIR}/data/shell-completion/flameshot.bash_zsh
${CMAKE_CURRENT_BINARY_DIR}/share/bash-completion/completions/flameshot COPYONLY) ${CMAKE_CURRENT_BINARY_DIR}/share/bash-completion/completions/flameshot COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/data/shell-completion/flameshot configure_file(${CMAKE_SOURCE_DIR}/data/shell-completion/flameshot.bash_zsh
${CMAKE_CURRENT_BINARY_DIR}/share/zsh/site-functions/_flameshot COPYONLY) ${CMAKE_CURRENT_BINARY_DIR}/share/zsh/site-functions/_flameshot COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/data/shell-completion/flameshot.fish
${CMAKE_CURRENT_BINARY_DIR}/share/fish/vendor_completions.d/flameshot.fish COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/data/dbus/org.flameshot.Flameshot.xml configure_file(${CMAKE_SOURCE_DIR}/data/dbus/org.flameshot.Flameshot.xml
${CMAKE_CURRENT_BINARY_DIR}/share/dbus-1/interfaces/org.flameshot.Flameshot.xml COPYONLY) ${CMAKE_CURRENT_BINARY_DIR}/share/dbus-1/interfaces/org.flameshot.Flameshot.xml COPYONLY)

View File

@@ -501,7 +501,8 @@ int main(int argc, char* argv[])
AbstractLogger err = AbstractLogger::error(AbstractLogger::Stderr); AbstractLogger err = AbstractLogger::error(AbstractLogger::Stderr);
bool ok = ConfigHandler().checkForErrors(&err); bool ok = ConfigHandler().checkForErrors(&err);
if (ok) { if (ok) {
err << QStringLiteral("No errors detected.\n"); AbstractLogger::info()
<< QStringLiteral("No errors detected.\n");
goto finish; goto finish;
} else { } else {
return 1; return 1;