From 4235e212de86ed7370f86ab01c45a603c308b0d8 Mon Sep 17 00:00:00 2001 From: EmilyGraceSeville7cf Date: Mon, 16 Sep 2024 00:55:21 +1000 Subject: [PATCH] fish(completion): support termux-sensor command --- share/completions/termux-sensor.fish | 61 +++++++++++++++++++ ..._fish_termux_api__complete_sensor_ids.fish | 6 ++ 2 files changed, 67 insertions(+) create mode 100644 share/completions/termux-sensor.fish create mode 100644 share/functions/__fish_termux_api__complete_sensor_ids.fish diff --git a/share/completions/termux-sensor.fish b/share/completions/termux-sensor.fish new file mode 100644 index 000000000..1d32e97d8 --- /dev/null +++ b/share/completions/termux-sensor.fish @@ -0,0 +1,61 @@ +function __fish_termux_api__complete_sensor_ids_as_list + set ids (__fish_termux_api__complete_sensor_ids) + set token (commandline -t -c) + + set delimiter , + + switch "$token" + case '*,' + set delimiter + end + + test -z "$token" && set delimiter + + for id in $ids + string unescape -- "$token$delimiter$id" + end +end + +set command termux-sensor + +complete -c $command -f + +complete -c $command \ + -s h \ + -l help \ + -d 'Show [h]elp' + +complete -c $command \ + -s a \ + -l all \ + -d 'Listen to all sensors' + +complete -c $command \ + -s c \ + -l cleanup \ + -d 'Release sensor resources' + +complete -c $command \ + -s l \ + -l list \ + -d '[l]ist sensors' + +complete -c $command \ + -a '(__fish_termux_api__complete_sensor_ids_as_list)' \ + -s s \ + -l sensors \ + -d 'Specify comma-separated [s]ensors to listen to' \ + -x + +complete -c $command \ + -s d \ + -l delay \ + -d 'Specify an interval between sensor updates' \ + -x + +complete -c $command \ + -a 'continuous\tdefault' \ + -s n \ + -l limit \ + -d 'Specify a number of times to read senors' \ + -x diff --git a/share/functions/__fish_termux_api__complete_sensor_ids.fish b/share/functions/__fish_termux_api__complete_sensor_ids.fish new file mode 100644 index 000000000..a6dd1adc3 --- /dev/null +++ b/share/functions/__fish_termux_api__complete_sensor_ids.fish @@ -0,0 +1,6 @@ +function __fish_termux_api__complete_sensor_ids + set -l command termux-sensor -l + set ids ($command | jq --raw-output '.sensors[]') + + string join \n -- $ids +end