From 718870578cb3932dd2fb91d968b48018f9412297 Mon Sep 17 00:00:00 2001 From: Leo Date: Mon, 6 Sep 2021 07:14:57 +0000 Subject: [PATCH] startup: add completion for fish shell upstream: https://gitlab.com/chinstrap/startup/-/merge_requests/41 --- srcpkgs/startup/files/init-checkconf.fish | 7 ++ srcpkgs/startup/files/initctl.fish | 125 +++++++++++++++++++++ srcpkgs/startup/files/initctl2dot.fish | 16 +++ srcpkgs/startup/files/reload.fish | 29 +++++ srcpkgs/startup/files/restart.fish | 29 +++++ srcpkgs/startup/files/start.fish | 29 +++++ srcpkgs/startup/files/startup-monitor.fish | 5 + srcpkgs/startup/files/startup.fish | 17 +++ srcpkgs/startup/files/status.fish | 36 ++++++ srcpkgs/startup/files/stop.fish | 29 +++++ srcpkgs/startup/template | 16 ++- 11 files changed, 337 insertions(+), 1 deletion(-) create mode 100644 srcpkgs/startup/files/init-checkconf.fish create mode 100644 srcpkgs/startup/files/initctl.fish create mode 100644 srcpkgs/startup/files/initctl2dot.fish create mode 100644 srcpkgs/startup/files/reload.fish create mode 100644 srcpkgs/startup/files/restart.fish create mode 100644 srcpkgs/startup/files/start.fish create mode 100644 srcpkgs/startup/files/startup-monitor.fish create mode 100644 srcpkgs/startup/files/startup.fish create mode 100644 srcpkgs/startup/files/status.fish create mode 100644 srcpkgs/startup/files/stop.fish diff --git a/srcpkgs/startup/files/init-checkconf.fish b/srcpkgs/startup/files/init-checkconf.fish new file mode 100644 index 000000000000..d14b4b4b7054 --- /dev/null +++ b/srcpkgs/startup/files/init-checkconf.fish @@ -0,0 +1,7 @@ +# Global options +complete -f -c init-checkconf -s d -l debug -d 'Show some debug output' +complete -r -F -c init-checkconf -s f -l file -d 'Path to job configuration file to check' +complete -r -F -c init-checkconf -s i -l initctl-path -d 'Path to initctl(8) binary' +complete -f -c init-checkconf -s s -l noscript -d 'Do not check script sections' +complete -r -F -c init-checkconf -s x -l startup-path -d 'Payh to startup(8) binary' +complete -f -c init-checkconf -s h -l help -d 'Display usage statement' diff --git a/srcpkgs/startup/files/initctl.fish b/srcpkgs/startup/files/initctl.fish new file mode 100644 index 000000000000..0c5cc8a3445f --- /dev/null +++ b/srcpkgs/startup/files/initctl.fish @@ -0,0 +1,125 @@ +# Global options +complete -f -c initctl -l session -d 'Use existing session D-Bus session (for testing)' +complete -f -c initctl -l system -d 'Use system D-Bus' +complete -x -c initctl -l dest -d 'Name for the Startup daemon in system D-Bus' +complete -f -c initctl -l user -d 'Run in user mode' +complete -f -c initctl -s q -l quiet -d 'Only output errors' +complete -f -c initctl -s v -l verbose -d 'Include informational messages' +complete -f -c initctl -l help -d 'Show help' +complete -f -c initctl -l version -d 'Output version information' + +# Job commands +complete -f -c initctl -n __fish_use_subcommand -a start -d 'Start job' +complete -f -c initctl -n __fish_use_subcommand -a stop -d 'Stop job' +complete -f -c initctl -n __fish_use_subcommand -a restart -d 'Restart job' +complete -f -c initctl -n __fish_use_subcommand -a reload -d 'Reload job' +complete -f -c initctl -n __fish_use_subcommand -a status -d 'Query status of job' +complete -f -c initctl -n __fish_use_subcommand -a list -d 'List known jobs' + +# Event commands +complete -f -c initctl -n __fish_use_subcommand -a emit -d 'Emit an event' + +# Environment commands +complete -f -c initctl -n __fish_use_subcommand -a get-env -d 'Retrieve value of a job environment variable' +complete -f -c initctl -n __fish_use_subcommand -a list-env -d 'Show all job environment variables' +complete -f -c initctl -n __fish_use_subcommand -a reset-env -d 'Revert all job environment variable changes' +complete -f -c initctl -n __fish_use_subcommand -a set-env -d 'Set one or more job environment variables' +complete -f -c initctl -n __fish_use_subcommand -a unset-env -d 'Remove one or more job environment variables' + +# Other commands +complete -f -c initctl -n __fish_use_subcommand -a reload-configuration -d 'Reload init daemon configuration' +complete -f -c initctl -n __fish_use_subcommand -a version -d 'Request version of the init daemon' +complete -f -c initctl -n __fish_use_subcommand -a log-priority -d 'Change minimum priority of log messages from init daemon' +complete -f -c initctl -n __fish_use_subcommand -a show-config -d 'Show emits, start on and stop on defaults for a job' +complete -f -c initctl -n __fish_use_subcommand -a check-config -d 'Check for unreachable jobs/event conditions' +complete -f -c initctl -n __fish_use_subcommand -a usage -d 'Show job usage message if available' +complete -f -c initctl -n __fish_use_subcommand -a notify-cgroup-manager-address -d 'Inform Upstart of D-Bus address cgroup manager is available on' +complete -f -c initctl -n __fish_use_subcommand -a notify-dbus-address -d 'Inform Upstart of D-Bus address to connect to' +complete -f -c initctl -n __fish_use_subcommand -a notify-disk-writeable -d 'Inform Upstart that disk is now writeable' +complete -f -c initctl -n __fish_use_subcommand -a list-sessions -d 'List all sessions' +complete -f -c initctl -n __fish_use_subcommand -a re-exec -d 'Perform stateful re-exec' +complete -f -c initctl -n __fish_use_subcommand -a help -d 'Display list of commands' + +# -n|--no-wait for some of the Job commands +complete -f -c initctl -n "__fish_seen_subcommand_from start stop restart emit" -s n -l no-wait -d 'Do not wait for action to return' + +# -r|--retain for some of the Environment commands +complete -f -c initctl -n "__fish_seen_subcommand_from set-env unset-env reset-env" -s r -l retain -d 'Do not modify already set variables' + +# Offer all 'stop/waiting' jobs with 'start' subcommand +complete -f -c initctl -n "__fish_seen_subcommand_from start" -a "(__fish_initctl_run list | string match --entire stop/waiting | string split ' ' -f 1)" -d Job + +# Offer all 'start/*' jobs with 'stop', 'reload' and 'restart' subcommands +complete -f -c initctl -n "__fish_seen_subcommand_from stop reload restart" -a "(__fish_initctl_run list | string match --entire start/running | string split ' ' -f 1)" -d Job + +# Offer all jobs with its status to the 'status' subcommand +complete -f -c initctl -n "__fish_seen_subcommand_from status" -a "(__fish_initctl_list_with_status)" + +# Offer all jobs to the 'check-config' subcommand +complete -f -c initctl -n "__fish_seen_subcommand_from check-config" -a "(__fish_initctl_run list | string split ' ' -f 1)" -d Job + +# Offer all envs from 'list-env' subcommand to 'get-env' and 'unset-env' +complete -f -c initctl -n "__fish_seen_subcommand_from get-env unset-env" -a "(__fish_initctl_run list-env | string replace -r '=' '\tVariable: ')" + +# Possible priority levels for 'log-priority' subcommand +complete -f -c initctl -n "__fish_seen_subcommand_from log-priority" -a "debug info message warn error fatal" -d 'Priority' + +# -e|--enumerate option for 'show-config' subcommand +complete -f -c initctl -n "__fish_seen_subcommand_from show-config" -s e -l enumerate -d 'Print per line each "start on" and "stop on" condition for each event or job' + +# -i|--ignore-events and -w|--warn for 'check-config' subcommand +complete -x -c initctl -n "__fish_seen_subcommand_from check-config" -s i -l ignore-events -d 'Comma-separated list of events to ignore' +complete -f -c initctl -n "__fish_seen_subcommand_from check-config" -s w -l warn -d 'treat any unknown jobs and events as errors' + +# Show all the events from 'emits' in configuration to emit +complete -x -c initctl -n "__fish_seen_subcommand_from emit" -a "(__fish_initctl_get_events)" -d 'Event' + +function __fish_initctl_context -d 'Get the current startup context based on the commandline' + if __fish_seen_argument -l user + echo -- user + else if __fish_seen_argument -l session + echo -- session + else if __fish_seen_argument -l system + echo -- system + else if set -q UPSTART_SESSION + echo -- user + else + echo -- system + end +end + +function __fish_initctl_run -d 'Run initctl with the appropriate context' + initctl --(__fish_initctl_context) $argv +end + +function __fish_initctl_list_with_status -d 'Get Job and status from initctl' + __fish_initctl_run list \ + | cut -d ' ' -f 1-2 \ + | string replace -r ',$' '' \ + | string replace -r ' ' '\tJob: ' +end + +function __fish_initctl_extract_events -d 'Extract emitted events from job configuration' + grep -E '^[[:space:]]*emits ' $argv/*.conf \ + | cut -d : -f 2- \ + | string replace 'emit ' '' \ + | string replace ' ' \n \ + | sort -u +end + +function __fish_initctl_get_events -d 'Print all events that jobs in the current context emit' + switch (__fish_initctl_context) + case system + set -l dirs /etc/startup /etc/init /usr/share/start /usr/share/xdg/startup + for d in (string replace : ' ' $XDG_CONFIG_DIRS) + set -l dirs $dirs $d/startup $d/upstart + end + __fish_initctl_extract_events $dirs + case user session + if set -q XDG_CONFIG_HOME + __fish_initctl_extract_events $XDG_CONFIG_HOME/startup $XDG_CONFIG_HOME/upstart + else + __fish_initctl_extract_events $HOME/.config/startup $HOME/.config/upstart + end + end +end diff --git a/srcpkgs/startup/files/initctl2dot.fish b/srcpkgs/startup/files/initctl2dot.fish new file mode 100644 index 000000000000..868bd9b5dbf8 --- /dev/null +++ b/srcpkgs/startup/files/initctl2dot.fish @@ -0,0 +1,16 @@ +# global options +complete -x -c initctl2dot -s f -l infile -d 'File to read initctl(8) output from instead of (initctl show-config -e)' +complete -f -c initctl2dot -s h -l help -d 'Display usage statement' +complete -x -c initctl2dot -s r -l restrict-to-jobs -d 'Comma-separated list of jobs to consider instead of all jobs' +complete -x -c initctl2dot -s w -l outfile -d 'File to write output to' +complete -x -c initctl2dot -l color-emits -d 'Color for "emits" lines' +complete -x -c initctl2dot -l color-start-on -d 'Color for "start on" lines' +complete -x -c initctl2dot -l color-stop-on -d 'Color for "stop on" lines' +complete -x -c initctl2dot -l color-event -d 'Color for event boxes' +complete -x -c initctl2dot -l color-text -d 'Color for text in summary' +complete -x -c initctl2dot -l color-bg -d 'Color for background of the diagram' +complete -x -c initctl2dot -l color-event-text -d 'Color for text for event boxes' +complete -x -c initctl2dot -l color-job-text -d 'Color for text in job boxes' +complete -x -c initctl2dot -l color-job -d 'Color for job boxes' +complete -f -c initctl2dot -l system -d 'Connect to the system session' +complete -f -c initctl2dot -l user -d 'Connect to the user session' diff --git a/srcpkgs/startup/files/reload.fish b/srcpkgs/startup/files/reload.fish new file mode 100644 index 000000000000..8fd9d500a739 --- /dev/null +++ b/srcpkgs/startup/files/reload.fish @@ -0,0 +1,29 @@ +complete -f -c reload -n "__fish_is_initctl" -a "(__fish_initctl_run list | string match --entire start/running | string split ' ' -f 1)" -d Job + +function __fish_is_initctl -d 'Follow symlinks to check if given binary is initctl' + set -l cmd (commandline -poc) + set -l cmd $cmd[1] # Binary + set -l fullcmd (realpath (which $cmd)) + if [ (basename $fullcmd) = initctl ]; + return 0 + end + return 1 +end + +function __fish_initctl_context -d 'Get the current startup context based on the commandline' + if __fish_seen_argument -l user + echo -- user + else if __fish_seen_argument -l session + echo -- session + else if __fish_seen_argument -l system + echo -- system + else if set -q UPSTART_SESSION + echo -- user + else + echo -- system + end +end + +function __fish_initctl_run -d 'Run initctl with the appropriate context' + initctl --(__fish_initctl_context) $argv +end diff --git a/srcpkgs/startup/files/restart.fish b/srcpkgs/startup/files/restart.fish new file mode 100644 index 000000000000..8b246534920a --- /dev/null +++ b/srcpkgs/startup/files/restart.fish @@ -0,0 +1,29 @@ +complete -f -c restart -n "__fish_is_initctl" -a "(__fish_initctl_run list | string match --entire start/running | string split ' ' -f 1)" -d Job + +function __fish_is_initctl -d 'Follow symlinks to check if given binary is initctl' + set -l cmd (commandline -poc) + set -l cmd $cmd[1] # Binary + set -l fullcmd (realpath (which $cmd)) + if [ (basename $fullcmd) = initctl ]; + return 0 + end + return 1 +end + +function __fish_initctl_context -d 'Get the current startup context based on the commandline' + if __fish_seen_argument -l user + echo -- user + else if __fish_seen_argument -l session + echo -- session + else if __fish_seen_argument -l system + echo -- system + else if set -q UPSTART_SESSION + echo -- user + else + echo -- system + end +end + +function __fish_initctl_run -d 'Run initctl with the appropriate context' + initctl --(__fish_initctl_context) $argv +end diff --git a/srcpkgs/startup/files/start.fish b/srcpkgs/startup/files/start.fish new file mode 100644 index 000000000000..514a6db251f2 --- /dev/null +++ b/srcpkgs/startup/files/start.fish @@ -0,0 +1,29 @@ +complete -f -c start -n "__fish_is_initctl" -a "(__fish_initctl_run list | string match --entire stop/waiting | string split ' ' -f 1)" -d Job + +function __fish_is_initctl + set -l cmd (commandline -poc) + set -l cmd $cmd[1] # Binary + set -l fullcmd (realpath (which $cmd)) + if [ (basename $fullcmd) = initctl ]; + return 0 + end + return 1 +end + +function __fish_initctl_context -d 'Get the current startup context based on the commandline' + if __fish_seen_argument -l user + echo -- user + else if __fish_seen_argument -l session + echo -- session + else if __fish_seen_argument -l system + echo -- system + else if set -q UPSTART_SESSION + echo -- user + else + echo -- system + end +end + +function __fish_initctl_run -d 'Run initctl with the appropriate context' + initctl --(__fish_initctl_context) $argv +end diff --git a/srcpkgs/startup/files/startup-monitor.fish b/srcpkgs/startup/files/startup-monitor.fish new file mode 100644 index 000000000000..70fa34ea29cb --- /dev/null +++ b/srcpkgs/startup/files/startup-monitor.fish @@ -0,0 +1,5 @@ +# Global options +complete -x -c startup-monitor -s d -l destination -d 'Which endpoint to connect to' -a "session-socket session-system system-socket system-bus" +complete -f -c startup-monitor -s h -l help -d 'Show brief usage summary' +complete -f -c startup-monitor -s n -l no-gui -d 'Run in command-line mode' +complete -x -c startup-monitor -s s -l separator -d 'Specify alternate field separator for command-line output' diff --git a/srcpkgs/startup/files/startup.fish b/srcpkgs/startup/files/startup.fish new file mode 100644 index 000000000000..56b0313cc1b1 --- /dev/null +++ b/srcpkgs/startup/files/startup.fish @@ -0,0 +1,17 @@ +# Options +complete -r -F -c startup -l append-confdir -d 'Append directories to look for job configuration files' +complete -r -F -c startup -l confdir -d 'Read job configurationo files from this directory rather than defaults' +complete -x -c startup -l default-console -d 'Default value for "console" stanza' +complete -f -c startup -l no-cgroups -d 'Do not honour cgroup stanza' +complete -f -c startup -l no-dbus -d 'Do connect to a D-Bus bus' +complete -f -c startup -l no-inherint-env -d 'Stop jobs from inheriting initial environment' +complete -r -F -c startup -l logdir -d 'Write job output log files to this directory' +complete -f -c startup -l no-log -d 'Disable logging of job output' +complete -f -c startup -l no-session -d 'Disable chroot sessions' +complete -f -c startup -l no-startup-event -d 'Do not emit initial startup event' +complete -r -F -c startup -l prepend-confdir -d 'Prepend directories to look for job configuration files' +complete -f -c startup -l session -d 'Connect to the D-Bus session bus' +complete -x -c startup -l startup-event -d 'emit a different event at startup than the default one' +complete -f -c starutp -s q -l quiet -d 'Only output errors' +complete -f -c startup -s v -l verbose -d 'Output verbose messages about job state changes and event emissions' +complete -f -c startup -l version -d 'Output version information and exit' diff --git a/srcpkgs/startup/files/status.fish b/srcpkgs/startup/files/status.fish new file mode 100644 index 000000000000..d52205a86e7e --- /dev/null +++ b/srcpkgs/startup/files/status.fish @@ -0,0 +1,36 @@ +complete -f -c status -n "__fish_is_initctl" -a "(__fish_initctl_list_with_status)" -d Job + +function __fish_is_initctl -d 'Follow symlinks to check if given binary is initctl' + set -l cmd (commandline -poc) + set -l cmd $cmd[1] # Binary + set -l fullcmd (realpath (which $cmd)) + if [ (basename $fullcmd) = initctl ]; + return 0 + end + return 1 +end + +function __fish_initctl_context -d 'Get the current startup context based on the commandline' + if __fish_seen_argument -l user + echo -- user + else if __fish_seen_argument -l session + echo -- session + else if __fish_seen_argument -l system + echo -- system + else if set -q UPSTART_SESSION + echo -- user + else + echo -- system + end +end + +function __fish_initctl_run -d 'Run initctl with the appropriate context' + initctl --(__fish_initctl_context) $argv +end + +function __fish_initctl_list_with_status -d 'Get Job and status from initctl' + __fish_initctl_run list \ + | cut -d ' ' -f 1-2 \ + | string replace -r ',$' '' \ + | string replace -r ' ' '\tJob: ' +end diff --git a/srcpkgs/startup/files/stop.fish b/srcpkgs/startup/files/stop.fish new file mode 100644 index 000000000000..dcf0ab692b62 --- /dev/null +++ b/srcpkgs/startup/files/stop.fish @@ -0,0 +1,29 @@ +complete -f -c stop -n "__fish_is_initctl" -a "(__fish_initctl_run list | string match --entire start/running | string split ' ' -f 1)" -d Job + +function __fish_is_initctl -d 'Follow symlinks to check if given binary is initctl' + set -l cmd (commandline -poc) + set -l cmd $cmd[1] # Binary + set -l fullcmd (realpath (which $cmd)) + if [ (basename $fullcmd) = initctl ]; + return 0 + end + return 1 +end + +function __fish_initctl_context -d 'Get the current startup context based on the commandline' + if __fish_seen_argument -l user + echo -- user + else if __fish_seen_argument -l session + echo -- session + else if __fish_seen_argument -l system + echo -- system + else if set -q UPSTART_SESSION + echo -- user + else + echo -- system + end +end + +function __fish_initctl_run -d 'Run initctl with the appropriate context' + initctl --(__fish_initctl_context) $argv +end diff --git a/srcpkgs/startup/template b/srcpkgs/startup/template index eeeee53501a1..38d11dd643b7 100644 --- a/srcpkgs/startup/template +++ b/srcpkgs/startup/template @@ -1,7 +1,7 @@ # Template file for 'startup' pkgname=startup version=2.0.2 -revision=3 +revision=4 build_style=gnu-configure configure_args="--disable-sysvcompat --disable-dconf-bridge --disable-cgroups" make_dirs="/var/log/startup 0750 root adm" @@ -22,6 +22,18 @@ pre_configure() { post_install() { rm -f -- "${DESTDIR}/usr/lib/libupstart.la" + + # Fish completion + vinstall ${FILESDIR}/startup.fish 0644 /usr/share/fish/completions + vinstall ${FILESDIR}/startup-monitor.fish 0644 /usr/share/fish/completions + vinstall ${FILESDIR}/initctl.fish 0644 /usr/share/fish/completions + vinstall ${FILESDIR}/initctl2dot.fish 0644 /usr/share/fish/completions + vinstall ${FILESDIR}/init-checkconf.fish 0644 /usr/share/fish/completions + vinstall ${FILESDIR}/start.fish 0644 /usr/share/fish/completions + vinstall ${FILESDIR}/stop.fish 0644 /usr/share/fish/completions + vinstall ${FILESDIR}/reload.fish 0644 /usr/share/fish/completions + vinstall ${FILESDIR}/restart.fish 0644 /usr/share/fish/completions + vinstall ${FILESDIR}/status.fish 0644 /usr/share/fish/completions } startup-tools_package() { @@ -33,6 +45,8 @@ startup-tools_package() { vmove usr/share/icons vmove usr/share/applications vmove usr/share/man/man8/startup-monitor.8 + vmove usr/share/fish/completions/startup-monitor.fish + vmove usr/share/fish/completions/initctl2dot.fish } }