]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
manager: kresctl: scripts for shells completion added
authorAleš Mrázek <ales.mrazek@nic.cz>
Sun, 18 Sep 2022 20:35:07 +0000 (22:35 +0200)
committerAleš Mrázek <ales.mrazek@nic.cz>
Tue, 10 Jan 2023 18:57:13 +0000 (19:57 +0100)
etc/meson.build
etc/shell-completion/kresctl.bash [new file with mode: 0644]
etc/shell-completion/kresctl.fish [new file with mode: 0644]
etc/shell-completion/meson.build [new file with mode: 0644]
meson.build

index 31859baf0b4e64ed5b0fbea9d458d03141872bdb..b2e250b9f2c2e9ad2faae433cc145838c5a93b26 100644 (file)
@@ -30,6 +30,7 @@ endif
 
 subdir('config')
 
+subdir('shell-completion')
 
 install_data(
   sources: etc_files,
diff --git a/etc/shell-completion/kresctl.bash b/etc/shell-completion/kresctl.bash
new file mode 100644 (file)
index 0000000..7363913
--- /dev/null
@@ -0,0 +1,22 @@
+#/usr/bin/env bash
+
+# completion function for the kresctl
+_kresctl_completion() {
+    local cur prev opts
+    COMPREPLY=()
+    cur="${COMP_WORDS[COMP_CWORD]}"
+    prev="${COMP_WORDS[COMP_CWORD-1]}"
+
+    # get options
+    opts=$(kresctl completion --bash "${COMP_WORDS}")
+
+    if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
+    COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
+    return 0
+    fi
+
+    return 0
+}
+
+# use the bash default completion for other arguments
+complete -o filenames -o nospace -o bashdefault -F _kresctl_completion kresctl
\ No newline at end of file
diff --git a/etc/shell-completion/kresctl.fish b/etc/shell-completion/kresctl.fish
new file mode 100644 (file)
index 0000000..8fc75a8
--- /dev/null
@@ -0,0 +1,6 @@
+function __fish_git
+    set -l args (commandline -pco)
+    eval command kresctl $args
+end
+
+complete -c kresctl -a '(_kresctl_completion)' -f
\ No newline at end of file
diff --git a/etc/shell-completion/meson.build b/etc/shell-completion/meson.build
new file mode 100644 (file)
index 0000000..64b1996
--- /dev/null
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+# Install kresctl completion for bash
+install_data(
+  sources: 'kresctl.bash',
+  rename: 'kresctl',
+  install_dir: completions_dir / 'bash-completion' / 'completions',
+)
+
+# Install kresctl completion for fish
+install_data(
+  sources: 'kresctl.fish',
+  install_dir: completions_dir / 'fish' / 'vendor_completions.d',
+)
index 4f677818999ff59a7fe4255a6770cee1bbfed678..11e32874861523e91d30848de317cf6404d32cf0 100644 (file)
@@ -59,6 +59,7 @@ systemd_cache_dir = prefix / get_option('localstatedir') / 'cache' / 'knot-resol
 systemd_unit_dir = prefix / 'lib' / 'systemd' / 'system'
 systemd_tmpfiles_dir = prefix / 'lib' / 'tmpfiles.d'
 systemd_sysusers_dir = prefix / 'lib' / 'sysusers.d'
+completions_dir = prefix / 'usr' / 'share'
 mod_inc_dir = include_directories('.', 'contrib/')
 
 ## Trust anchors