]> git.proxmox.com Git - pve-client.git/commitdiff
add simple bash completion code
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 24 May 2018 08:26:29 +0000 (10:26 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 24 May 2018 08:27:01 +0000 (10:27 +0200)
Makefile
debian/install
pveclient
pveclient.bash-completion [new file with mode: 0644]

index 6eccaecbcb792840ace65238392f049697849258..d37025b6d408bdde4e8aa9f4484b27b228987040 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -8,6 +8,7 @@ DESTDIR=
 
 LIB_DIR=${DESTDIR}/usr/share/${PACKAGE}
 DOCDIR=${DESTDIR}/usr/share/doc/${PACKAGE}
+BASHCOMPLDIR=${DESTDIR}/usr/share/bash-completion/completions/
 
 all: ${DEB}
 
@@ -34,6 +35,8 @@ install:  pve-api-definition.js
        install -D -m 0644 PVE/APIClient/Commands/lxc.pm ${LIB_DIR}/PVE/APIClient/Commands/lxc.pm
        install -D -m 0644 pve-api-definition.js ${LIB_DIR}/pve-api-definition.js
        install -D -m 0755 pveclient ${DESTDIR}/usr/bin/pveclient
+       install -D -m 0644 pveclient.bash-completion ${BASHCOMPLDIR}/pveclient.bash-completion
+
 
 pve-api-definition.js:
        ./extractapi.pl > pve-api-definition.js.tmp
index 5f2514081c6bedc3c9f9d28dd863861982fffb04..4079fc6a3fcc67129925860aa9f2bdd6da69679c 100644 (file)
@@ -1,2 +1,3 @@
 /usr/share
-/usr/bin
\ No newline at end of file
+/usr/bin
+/usr/share/bash-completion/completions
index d24ec49f63e79039fee51efa1c4f3d7a0718e9cb..d8d4d15da682bc772558e0099d75761dd46b6d12 100755 (executable)
--- a/pveclient
+++ b/pveclient
@@ -80,6 +80,21 @@ if ($cmd eq 'get') {
     PVE::APIClient::Commands::lxc->run_cli_handler();
 } elsif ($cmd eq 'remote') {
     PVE::APIClient::Commands::remote->run_cli_handler();
+} elsif ($cmd eq 'bashcomplete') {
+
+    my $cmdline = substr($ENV{COMP_LINE}, 0, $ENV{COMP_POINT});
+    $cmdline =~ s/$cur$//;
+
+    my ($bash_command, $cur, $prev) = @ARGV;
+
+    my $args = [split(/\s+/, $cmdline)];
+
+    if (scalar(@$args) == 1) {
+       foreach my $p (qw(get set create delete lxc remote)) {
+           print "$p\n" if $p =~ m/^$cur/;
+       }
+    }
+
 } else {
     print_usage();
 }
diff --git a/pveclient.bash-completion b/pveclient.bash-completion
new file mode 100644 (file)
index 0000000..983b432
--- /dev/null
@@ -0,0 +1,8 @@
+# pveclient bash completion
+
+# see http://tiswww.case.edu/php/chet/bash/FAQ
+# and __ltrim_colon_completions() in /usr/share/bash-completion/bash_completion
+# this modifies global var, but I found no better way
+COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
+
+complete -C 'pveclient bashcomplete' pveclient