From b13179d4f4921db84c2f870d1b372fe537449e96 Mon Sep 17 00:00:00 2001 From: SanskritFritz Date: Sun, 20 Apr 2014 00:44:09 +0200 Subject: [PATCH] Functions instead of static variables for conditions. --- share/completions/journalctl.fish | 6 +- share/completions/obnam.fish | 47 +++++++++------- share/completions/systemctl.fish | 56 ++++++++++++------- share/functions/__fish_systemctl_mounts.fish | 4 ++ .../__fish_systemctl_service_paths.fish | 4 ++ .../functions/__fish_systemctl_services.fish | 4 ++ share/functions/__fish_systemctl_sockets.fish | 4 ++ 7 files changed, 80 insertions(+), 45 deletions(-) create mode 100644 share/functions/__fish_systemctl_mounts.fish create mode 100644 share/functions/__fish_systemctl_service_paths.fish create mode 100644 share/functions/__fish_systemctl_services.fish create mode 100644 share/functions/__fish_systemctl_sockets.fish diff --git a/share/completions/journalctl.fish b/share/completions/journalctl.fish index 827aa3473..e6e52b1a8 100644 --- a/share/completions/journalctl.fish +++ b/share/completions/journalctl.fish @@ -1,6 +1,4 @@ -set -l all_units '(systemctl list-unit-files --no-pager --no-legend | while read -l unit_name unit_state; echo -e $unit_name\t$unit_state;end | sed "s/ //g")' - complete -c journalctl -f -s h -l help -d 'Prints a short help text and exits' complete -c journalctl -f -l version -d 'Prints a short version string and exits' complete -c journalctl -f -l no-pager -d 'Do not pipe output into a pager' @@ -12,13 +10,13 @@ complete -c journalctl -f -s o -l output -d 'Controls the formatting' -xa 'short complete -c journalctl -f -s q -l quiet -d 'Suppress warning about normal user' complete -c journalctl -f -s m -l merge -d 'Show entries interleaved from all journals' complete -c journalctl -f -s b -l this-boot -d 'Show data only from current boot' -complete -c journalctl -f -s u -l unit -d 'Show data only of the specified unit' -xa "$all_units" +complete -c journalctl -f -s u -l unit -d 'Show data only of the specified unit' -xa "(__fish_systemctl_services)" complete -c journalctl -f -s p -l priority -d 'Filter by priority' -xa 'emerg 0 alert 1 crit 2 err 3 warning 4 notice 5 info 6 debug 7' complete -c journalctl -f -s c -l cursor -d 'Start from the passing cursor' complete -c journalctl -f -l since -d 'Entries on or newer than DATE' -xa 'yesterday today tomorrow now' complete -c journalctl -f -l until -d 'Entries on or older than DATE' -xa 'yesterday today tomorrow now' complete -c journalctl -f -s F -l field -d 'Print all possible data values' -complete -c journalctl -f -s D -l directory -d 'Specify journal directory' -xa "(__fish_complete_directories (commandline -ct) 'Directory')" +complete -c journalctl -f -s D -l directory -d 'Specify journal directory' -xa "(__fish_complete_directories)" complete -c journalctl -f -l new-id128 -d 'Generate a new 128 bit ID' complete -c journalctl -f -l header -d 'Show internal header information' complete -c journalctl -f -l disk-usage -d 'Shows the current disk usage' diff --git a/share/completions/obnam.fish b/share/completions/obnam.fish index 4bad90d0d..1b4616659 100644 --- a/share/completions/obnam.fish +++ b/share/completions/obnam.fish @@ -1,26 +1,31 @@ -set -l nocommand 'commandline | not sgrep -qe "add-key\|backup\|client-keys\|clients\|diff\|dump-repo\|force-lock\|forget\|fsck\|generations\|genids\|list-keys\|list-toplevels\|ls\|mount\|nagios-last-backup-age\|remove-client\|remove-key\|restore\|verify"' +function nocommand + if commandline | sgrep -qe "add-key\|backup\|client-keys\|clients\|diff\|dump-repo\|force-lock\|forget\|fsck\|generations\|genids\|list-keys\|list-toplevels\|ls\|mount\|nagios-last-backup-age\|remove-client\|remove-key\|restore\|verify" + return 1 + end + return 0 +end -complete --command obnam --no-files --condition $nocommand --arguments 'add-key' --description 'Adds an encryption key to the repository' -complete --command obnam --condition $nocommand --arguments 'backup' --description 'Makes a new backup' -complete --command obnam --no-files --condition $nocommand --arguments 'client-keys' --description 'Lists the keys associated with each client' -complete --command obnam --no-files --condition $nocommand --arguments 'clients' --description 'Lists the clients in the repository' -complete --command obnam --no-files --condition $nocommand --arguments 'diff' --description 'Compares two generations' -complete --command obnam --no-files --condition $nocommand --arguments 'dump-repo' --description 'Dumps the repository' -complete --command obnam --no-files --condition $nocommand --arguments 'force-lock' --description 'Removes a lock file for a client' -complete --command obnam --no-files --condition $nocommand --arguments 'forget' --description 'Removes backup generations' -complete --command obnam --no-files --condition $nocommand --arguments 'fsck' --description 'Checks the consistency of the repository' -complete --command obnam --no-files --condition $nocommand --arguments 'generations' --description 'Lists every backup generation' -complete --command obnam --no-files --condition $nocommand --arguments 'genids' --description 'Lists the identifier for every generation' -complete --command obnam --no-files --condition $nocommand --arguments 'list-keys' --description 'Lists the keys' -complete --command obnam --no-files --condition $nocommand --arguments 'list-toplevels' --description 'Lists the toplevel keys' -complete --command obnam --no-files --condition $nocommand --arguments 'ls' --description 'Lists the contents of a given generation' -complete --command obnam --no-files --condition $nocommand --arguments 'mount' --description 'Makes the repository available via FUSE' -complete --command obnam --no-files --condition $nocommand --arguments 'nagios-last-backup-age' --description 'Check if a backup age exceeds a threshold' -complete --command obnam --no-files --condition $nocommand --arguments 'remove-client' --description 'Removes a client from the repository' -complete --command obnam --no-files --condition $nocommand --arguments 'remove-key' --description 'Removes a key from the repository' -complete --command obnam --no-files --condition $nocommand --arguments 'restore' --description 'Restore files from the repository' -complete --command obnam --no-files --condition $nocommand --arguments 'verify' --description 'Verifies files in the repository' +complete --command obnam --no-files --condition nocommand --arguments 'add-key' --description 'Adds an encryption key to the repository' +complete --command obnam --condition nocommand --arguments 'backup' --description 'Makes a new backup' +complete --command obnam --no-files --condition nocommand --arguments 'client-keys' --description 'Lists the keys associated with each client' +complete --command obnam --no-files --condition nocommand --arguments 'clients' --description 'Lists the clients in the repository' +complete --command obnam --no-files --condition nocommand --arguments 'diff' --description 'Compares two generations' +complete --command obnam --no-files --condition nocommand --arguments 'dump-repo' --description 'Dumps the repository' +complete --command obnam --no-files --condition nocommand --arguments 'force-lock' --description 'Removes a lock file for a client' +complete --command obnam --no-files --condition nocommand --arguments 'forget' --description 'Removes backup generations' +complete --command obnam --no-files --condition nocommand --arguments 'fsck' --description 'Checks the consistency of the repository' +complete --command obnam --no-files --condition nocommand --arguments 'generations' --description 'Lists every backup generation' +complete --command obnam --no-files --condition nocommand --arguments 'genids' --description 'Lists the identifier for every generation' +complete --command obnam --no-files --condition nocommand --arguments 'list-keys' --description 'Lists the keys' +complete --command obnam --no-files --condition nocommand --arguments 'list-toplevels' --description 'Lists the toplevel keys' +complete --command obnam --no-files --condition nocommand --arguments 'ls' --description 'Lists the contents of a given generation' +complete --command obnam --no-files --condition nocommand --arguments 'mount' --description 'Makes the repository available via FUSE' +complete --command obnam --no-files --condition nocommand --arguments 'nagios-last-backup-age' --description 'Check if a backup age exceeds a threshold' +complete --command obnam --no-files --condition nocommand --arguments 'remove-client' --description 'Removes a client from the repository' +complete --command obnam --no-files --condition nocommand --arguments 'remove-key' --description 'Removes a key from the repository' +complete --command obnam --no-files --condition nocommand --arguments 'restore' --description 'Restore files from the repository' +complete --command obnam --no-files --condition nocommand --arguments 'verify' --description 'Verifies files in the repository' complete --command obnam --no-files --long-option always-restore-setuid --description 'Restore setuid/setgid bits in restored files' complete --command obnam --no-files --long-option no-always-restore-setuid --description 'Do not restore setuid/setgid bits in restored files' diff --git a/share/completions/systemctl.fish b/share/completions/systemctl.fish index bd696e594..c9b619083 100644 --- a/share/completions/systemctl.fish +++ b/share/completions/systemctl.fish @@ -1,22 +1,3 @@ -function __fish_systemctl_services - command find /etc/systemd/system -type f -name '*.service' -printf '%f\n' - command find /usr/lib/systemd/system -type f -name '*.service' -printf '%f\n' -end - -function __fish_systemctl_sockets - command find /etc/systemd/system -type f -name '*.socket' -printf '%f\n' - command find /usr/lib/systemd/system -type f -name '*.socket' -printf '%f\n' -end - -function __fish_systemctl_mounts - command find /etc/systemd/system -type f -name '*.mount' -printf '%f\n' - command find /usr/lib/systemd/system -type f -name '*.mount' -printf '%f\n' -end - -function __fish_systemctl_service_paths - command find /etc/systemd/system -type f -name '*.path' -printf '%f\n' - command find /usr/lib/systemd/system -type f -name '*.path' -printf '%f\n' -end function __fish_systemctl_using_command set cmd (commandline -opc) @@ -29,7 +10,7 @@ function __fish_systemctl_using_command end # All systemctl commands -complete -f -c systemctl -n "test (count (commandline -poc)) = 1" -a 'list-units list-sockets start stop reload restart try-restart reload-or-restart reload-or-try-restart isolate kill is-active is-failed status show get-cgroup-attr set-cgroup-attr unset-cgroup-attr set-cgroup help reset-failed list-unit-files enable disable is-enabled reenable preset mask unmask link load list-jobs cancel dump list-dependencies snapshot delete daemon-reload daemon-reexec show-environment set-environment unset-environment default rescue emergency halt poweroff reboot kexec exit suspend hibernate hybrid-sleep switch-root' +complete -f -c systemctl -n "test (count (commandline -poc)) = 1" -a 'list-units list-sockets start stop reload restart try-restart reload-or-restart reload-or-try-restart isolate kill is-active is-failed status show get-cgroup-attr set-cgroup-attr unset-cgroup-attr set-cgroup help reset-failed list-unit-files enable disable is-enabled reenable preset mask unmask link load list-jobs cancel dump list-dependencies snapshot delete daemon-reload daemon-reexec show show-environment set-environment unset-environment default rescue emergency halt poweroff reboot kexec exit suspend hibernate hybrid-sleep switch-root' #### Units commands @@ -74,3 +55,38 @@ complete -f -c systemctl -n '__fish_systemctl_using_command disable' -a '(__fish complete -f -c systemctl -n '__fish_systemctl_using_command disable' -a '(__fish_systemctl_sockets)' -d 'Socket' complete -f -c systemctl -n '__fish_systemctl_using_command disable' -a '(__fish_systemctl_mounts)' -d 'Mount' complete -f -c systemctl -n '__fish_systemctl_using_command disable' -a '(__fish_systemctl_service_paths)' -d 'Path' + +complete -c systemctl -s t -l type -d 'List of unit types' -xa 'help service, mount, socket, target,' +complete -c systemctl -l state -d 'List of unit states' -xa 'LOAD, SUB, ACTIVE,' +complete -c systemctl -s p -l property -d 'Properties displayed in the "show" command' +complete -c systemctl -s a -l all -d 'Show all units or properties' +complete -c systemctl -s r -l recursive -d 'Show also units of local containers' +complete -c systemctl -l reverse -d 'Show reverse dependencies between units' +complete -c systemctl -l after -d 'Show units ordered before specified unit' +complete -c systemctl -l before -d 'Show units ordered after specified unit' +complete -c systemctl -s l -l full -d 'Do not ellipsize anything' +complete -c systemctl -l show-types -d 'Show the type of the socket' +complete -c systemctl -l job-mode -d 'How to deal with queued jobs' -xa 'fail replace replace-irreversibly isolate ignore-dependencies ignore-requirements flush' +complete -c systemctl -s i -l ignore-inhibitors -d 'Ignore inhibitor locks on shutdown or sleep' +complete -c systemctl -s q -l quiet -d 'Suppress output to STDOUT' +complete -c systemctl -l no-block -d 'Do not wait for the requested operation to finish' +complete -c systemctl -l no-legend -d 'Do not print header and footer' +complete -c systemctl -l user -d 'Talk to the service manager of the calling user' +complete -c systemctl -l system -d 'Talk to the service manager of the system.' +complete -c systemctl -l no-wall -d 'Do not send wall message before halt' +complete -c systemctl -l global -d 'Enable or disable for all users' +complete -c systemctl -l no-reload -d 'Do not reload daemon configuration' +complete -c systemctl -l no-ask-password -d 'Disable asking for password' +complete -c systemctl -l kill-who -d 'Send signal to which process' -xa 'main control all' +complete -c systemctl -s s -l signal -d 'Which signal to send' -xa 'SIGTERM SIGINT SIGSTOP SIGKILL SIGHUP SIGCONT' +complete -c systemctl -s f -l force -d 'Overwrite conflicting existing symlinks' +complete -c systemctl -l root -d 'Use alternative root path' +complete -c systemctl -l runtime -d 'Make changes only temporarily' +complete -c systemctl -s n -l lines -d 'Number of journal lines to show' +complete -c systemctl -s o -l output -d 'Control journal formatting' -xa 'short short-monotonic verbose export json json-pretty json-sse cat' +complete -c systemctl -l plain -d 'list-dependencies flat, not as tree' +complete -c systemctl -s H -l host -d 'Execute the operation remotely' +complete -c systemctl -s M -l machine -d 'Execute operation locally' +complete -c systemctl -s h -l help -d 'Print a short help and exit' +complete -c systemctl -l version -d 'Print a short version and exit' +complete -c systemctl -l no-pager -d 'Do not pipe output into a pager' diff --git a/share/functions/__fish_systemctl_mounts.fish b/share/functions/__fish_systemctl_mounts.fish new file mode 100644 index 000000000..706e6ee87 --- /dev/null +++ b/share/functions/__fish_systemctl_mounts.fish @@ -0,0 +1,4 @@ +function __fish_systemctl_mounts + command find /etc/systemd/system -type f -name '*.mount' -printf '%f\n' + command find /usr/lib/systemd/system -type f -name '*.mount' -printf '%f\n' +end diff --git a/share/functions/__fish_systemctl_service_paths.fish b/share/functions/__fish_systemctl_service_paths.fish new file mode 100644 index 000000000..6f8435cf8 --- /dev/null +++ b/share/functions/__fish_systemctl_service_paths.fish @@ -0,0 +1,4 @@ +function __fish_systemctl_service_paths + command find /etc/systemd/system -type f -name '*.path' -printf '%f\n' + command find /usr/lib/systemd/system -type f -name '*.path' -printf '%f\n' +end diff --git a/share/functions/__fish_systemctl_services.fish b/share/functions/__fish_systemctl_services.fish new file mode 100644 index 000000000..a9fd38ba5 --- /dev/null +++ b/share/functions/__fish_systemctl_services.fish @@ -0,0 +1,4 @@ +function __fish_systemctl_services + command find /etc/systemd/system -type f -name '*.service' -printf '%f\n' + command find /usr/lib/systemd/system -type f -name '*.service' -printf '%f\n' +end diff --git a/share/functions/__fish_systemctl_sockets.fish b/share/functions/__fish_systemctl_sockets.fish new file mode 100644 index 000000000..0fe5b6e80 --- /dev/null +++ b/share/functions/__fish_systemctl_sockets.fish @@ -0,0 +1,4 @@ +function __fish_systemctl_sockets + command find /etc/systemd/system -type f -name '*.socket' -printf '%f\n' + command find /usr/lib/systemd/system -type f -name '*.socket' -printf '%f\n' +end