summaryrefslogtreecommitdiff
path: root/src/bashrc
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2014-10-26 12:33:50 +0400
committerIgor Pashev <pashev.igor@gmail.com>2014-10-26 12:33:50 +0400
commit47e6e7c84f008a53061e661f31ae96629bc694ef (patch)
tree648a07f3b5b9d67ce19b0fd72e8caa1175c98f1a /src/bashrc
downloadpcp-debian.tar.gz
Debian 3.9.10debian/3.9.10debian
Diffstat (limited to 'src/bashrc')
-rw-r--r--src/bashrc/GNUmakefile32
-rw-r--r--src/bashrc/pcp_completion.sh68
2 files changed, 100 insertions, 0 deletions
diff --git a/src/bashrc/GNUmakefile b/src/bashrc/GNUmakefile
new file mode 100644
index 0000000..9c4900f
--- /dev/null
+++ b/src/bashrc/GNUmakefile
@@ -0,0 +1,32 @@
+#
+# Copyright (c) 2009 Aconex. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+
+TOPDIR = ../..
+include $(TOPDIR)/src/include/builddefs
+
+BASHRC = pcp_completion.sh
+BASHDIR = $(PCP_ETC_DIR)/bash_completion.d
+LSRCFILES = $(BASHRC)
+
+default: $(BASHRC)
+
+include $(BUILDRULES)
+
+install: default
+ $(INSTALL) -d $(BASHDIR)
+ $(INSTALL) -m 644 $(BASHRC) $(BASHDIR)/pcp
+
+default_pcp: default
+
+install_pcp: install
diff --git a/src/bashrc/pcp_completion.sh b/src/bashrc/pcp_completion.sh
new file mode 100644
index 0000000..fe0ce82
--- /dev/null
+++ b/src/bashrc/pcp_completion.sh
@@ -0,0 +1,68 @@
+# Programmable completion for Performance Co-Pilot commands under bash.
+# Author: Roman Revyakin (Roman), rrevyakin@aconex.com
+
+_pminfo_complete ()
+{
+ local cur=${COMP_WORDS[$COMP_CWORD]}
+ local opt_regex= curpos_expand=
+
+ COMPREPLY=()
+
+ # Options that need no completion and the cursor position to start
+ # expansion from for different programs
+ case ${COMP_WORDS[0]} in
+ pminfo)
+ opt_regex="-[abhnOZ]"
+ curpos_expand=1
+ ;;
+
+ pmprobe)
+ opt_regex="-[ahnOZ]"
+ curpos_expand=1
+ ;;
+
+ pmdumptext)
+ opt_regex="-[AacdfhnOPRsStTUwZ]"
+ curpos_expand=1
+ ;;
+
+ pmdumplog)
+ opt_regex="-[nSTZ]"
+ curpos_expand=1
+ ;;
+
+ pmlogsummary)
+ opt_regex="-[BnpSTZ]"
+ curpos_expand=2
+ ;;
+
+ pmstore)
+ opt_regex="-[hin]"
+ curpos_expand=1
+ ;;
+
+ pmval)
+ opt_regex="-[AafhinOpSsTtwZ]"
+ curpos_expand=1
+ ;;
+
+ pmevent)
+ opt_regex="-[ahKOpSsTtZ]"
+ curpos_expand=1
+ ;;
+
+ esac # --- end of case ---
+
+ # We expand either straight from the cursor if it is at the position to
+ # expand or check for the preceding options whether to expand or not
+ if (( $COMP_CWORD == $curpos_expand )) || \
+ ( (( $COMP_CWORD > $curpos_expand )) \
+ && ! [[ "${COMP_WORDS[$((COMP_CWORD-1))]}" =~ $opt_regex ]]
+ )
+ then
+ COMPREPLY=(`compgen -W '$(command pminfo)' 2>/dev/null $cur`)
+ fi
+
+} # ---------- end of function _pminfo_complete ----------
+
+complete -F _pminfo_complete -o default pminfo pmprobe pmdumptext pmdumplog pmlogsummary pmstore pmval pmevent