git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

commit6d97e1f4e19f80bb7796dab6e0d27731037eb520
parent53f0d60e1e
authorLeon Henrik Plickat <[email protected]>
date2021-03-13 17:54
Add bash completion for riverctl

 build.zig                 | 13 +++++++++
 completions/bash/riverctl | 69 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+)

diff --git a/build.zig b/build.zig
index 306c0ba..abf7f6b 100644
--- a/build.zig
+++ b/build.zig
@@ -25,6 +25,12 @@ pub fn build(b: *zbs.Builder) !void {
         break :scdoc_found true;
     };
 
+    const bash_completion = b.option(
+        bool,
+        "bash-completion",
+        "Set to true to install bash completion for riverctl. Defaults to true.",
+    ) orelse true;
+
     const examples = b.option(bool, "examples", "Set to true to build examples") orelse false;
 
     const resolved_prefix = try std.fs.path.resolve(b.allocator, &[_][]const u8{b.install_prefix.?});
@@ -88,6 +94,13 @@ pub fn build(b: *zbs.Builder) !void {
         try scdoc_step.install();
     }
 
+    if (bash_completion) {
+        b.installFile(
+            "completions/bash/riverctl",
+            "share/bash-completion/completions/riverctl",
+        );
+    }
+
     if (examples) {
         inline for (.{ "status", "options" }) |example_name| {
             const example = b.addExecutable(example_name, "example/" ++ example_name ++ ".zig");
diff --git a/completions/bash/riverctl b/completions/bash/riverctl
new file mode 100644
index 0000000..e744cd1
--- /dev/null
+++ b/completions/bash/riverctl
@@ -0,0 +1,69 @@
+function __riverctl_completion ()
+{
+	if [ "${COMP_CWORD}" -eq 1 ]
+	then
+		OPTS=" \
+			csd-filter-add \
+			exit \
+			float-filter-add \
+			focus-output \
+			focus-view \
+			layout \
+			mod-main-count \
+			mod-main-factor \
+			move \
+			resize \
+			snap \
+			send-to-output \
+			spawn \
+			swap \
+			toggle-float \
+			toggle-fullscreen \
+			zoom \
+			set-focused-tags \
+			set-view-tags \
+			toggle-focused-tags \
+			toggle-view-tags \
+			spawn-tagmask \
+			declare-mode \
+			enter-mode \
+			map \
+			map-pointer \
+			unmap \
+			unmap-pointer \
+			attach-mode \
+			background-color \
+			border-color-focused \
+			border-color-unfocused \
+			border-width \
+			focus-follow-cursor \
+			opacity \
+			outer-padding \
+			set-repeat \
+			view-padding \
+			xcursor-theme \
+			declare-option \
+			get-option \
+			set-option \
+			mod-option"
+		COMPREPLY=($(compgen -W "${OPTS}" -- "${COMP_WORDS[1]}"))
+	elif [ "${COMP_CWORD}" -eq 2 ]
+	then
+		case "${COMP_WORDS[1]}" in
+			"focus-output"|"focus-view"|"send-to-output"|"swap") OPTS="next previous" ;;
+			"move"|"snap") OPTS="up down left right" ;;
+			"resize") OPTS="horizontal vertical" ;;
+			"map"|"unmap") OPTS="-release" ;;
+			"attach-mode") OPTS="top bottom" ;;
+			"focus-follows-cursor") OPTS="disabled normal strict" ;;
+			"declare-option"|"get-option"|"set-option"|"mod-option") OPTS="-output -focused-output" ;;
+			*) return ;;
+		esac
+		COMPREPLY=($(compgen -W "${OPTS}" -- "${COMP_WORDS[2]}"))
+	else
+		return
+	fi
+}
+
+complete -F __riverctl_completion riverctl
+