From 27ed45f215ba4387d94f5e77b64453040422a6ff Mon Sep 17 00:00:00 2001 From: Louis Royer Date: Fri, 4 Oct 2024 14:57:18 +0200 Subject: [PATCH] Add support for bash-completion This allows autocomplete when calling aegisub from terminal. Before this commit, when having for example `file.webm` and `file.ass` in the directory, both were proposed while only the later could be open using CLI argument. --- meson.build | 13 +++++++++++++ meson_options.txt | 1 + tools/bash-completion.sh | 2 ++ 3 files changed, 16 insertions(+) create mode 100644 tools/bash-completion.sh diff --git a/meson.build b/meson.build index 3d1e01b7a4..59cc2175d0 100644 --- a/meson.build +++ b/meson.build @@ -384,6 +384,19 @@ subdir('po') subdir('src') subdir('tests') +if get_option('bash_completion') + bash_comp = dependency('bash_completion', required: false) + if bash_comp.found() + bash_install_dir = bash_comp.get_variable( + pkgconfig: 'completionsdir', + pkgconfig_define: ['datadir', datadir] + ) + else + bash_install_dir = join_paths(datadir, 'bash-completion', 'completions') + endif + install_data('tools/bash-completion.sh', install_dir: bash_install_dir, rename: 'aegisub') +endif + aegisub_cpp_pch = ['src/include/agi_pre.h'] aegisub_c_pch = ['src/include/agi_pre_c.h'] diff --git a/meson_options.txt b/meson_options.txt index 5509d90bda..071f1818eb 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -26,3 +26,4 @@ option('update_server', type: 'string', value: 'https://updates.aegisub.org', de option('update_url', type: 'string', value: '/trunk', description: 'Base path to use for the update checker') option('build_osx_bundle', type: 'boolean', value: 'false', description: 'Package Aegisub.app on OSX') +option('bash_completion', type: 'boolean', value: 'true', description: 'Install bash shell completions.') diff --git a/tools/bash-completion.sh b/tools/bash-completion.sh new file mode 100644 index 0000000000..87cbbeefb2 --- /dev/null +++ b/tools/bash-completion.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +complete -f -o plusdirs -X '!*.@(ass|ssa|mkv|mka|mks|sub|srt|ttxt|txt)' aegisub