From 126c8c14b87239f6c20a7c5402cf4ef9226b0bb2 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 28 Sep 2015 16:22:29 +0200 Subject: [PATCH] machinectl: Add "shell" subcommand --- share/completions/machinectl.fish | 16 ++++++++++++++-- share/functions/__fish_systemd_machines.fish | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/share/completions/machinectl.fish b/share/completions/machinectl.fish index f345867b3..1b8396083 100644 --- a/share/completions/machinectl.fish +++ b/share/completions/machinectl.fish @@ -2,7 +2,7 @@ complete -f -e -c machinectl set -l commands list status show start login enable disable poweroff reboot \ terminate kill bind copy-{to,from} list-images image-status show-image clone rename read-only remove set-limit pull-{tar,raw,dkr} \ -{import,export}-{raw,tar} {list,cancel}-transfers +{import,export}-{raw,tar} {list,cancel}-transfers shell function __fish_systemd_has_machine_image set -l images (__fish_systemd_machine_images) @@ -17,9 +17,15 @@ function __fish_systemd_has_machine_image end function __fish_systemd_has_machine + set -l cmd + if not count $argv >/dev/null + set cmd (commandline -opc) + else + set cmd $argv + end set -l machines (__fish_systemd_machines) for m in $machines - if contains -- $m (commandline -opc) + if contains -- $m $cmd echo $m return 0 end @@ -71,6 +77,8 @@ complete -f -c machinectl -n "__fish_seen_subcommand_from bind" -l read-only -d complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a "copy-to" -d "Copy file or directory to a machine" complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a "copy-from" -d "Copy file or directory from a machine" +complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a "shell" -d "Open a shell on a machine" + # Image commands complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a "list-images" -d "Show a list of locally installed machines" complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a "image-status" -d "Show information about machine images (human-readable)" @@ -110,5 +118,9 @@ complete -f -c machinectl -n "__fish_seen_subcommand_from start clone rename ima # while login takes exactly one machine and nothing else, which fish currently doesn't do complete -f -c machinectl -n "__fish_seen_subcommand_from login bind copy-to copy-from; and not __fish_systemd_has_machine" -a "(__fish_systemd_machines)" +complete -f -c machinectl -n "__fish_seen_subcommand_from login bind copy-to copy-from shell; and not __fish_systemd_has_machine" -a "(__fish_systemd_machines)" +# This is imperfect as we print the _local_ users +complete -f -c machinectl -n "__fish_seen_subcommand_from shell; and not __fish_systemd_has_machine (commandline -opc | cut -d"@" -f2-)" -a "(__fish_print_users)@(__fish_systemd_machines)" + complete -f -c machinectl -n "__fish_seen_subcommand_from read-only; and not __fish_systemd_has_machine_image" -a "(__fish_systemd_machine_images)" complete -f -c machinectl -n "__fish_seen_subcommand_from read-only; and __fish_systemd_has_machine_image" -a "yes no" diff --git a/share/functions/__fish_systemd_machines.fish b/share/functions/__fish_systemd_machines.fish index 40f833ad3..09becb2d3 100644 --- a/share/functions/__fish_systemd_machines.fish +++ b/share/functions/__fish_systemd_machines.fish @@ -1,4 +1,4 @@ # It seems machinectl will eliminate spaces from machine names so we don't need to handle that function __fish_systemd_machines - machinectl --no-legend --no-pager list | while read -l a b; echo $a; end + machinectl --no-legend --no-pager list --all | while read -l a b; echo $a; end end